1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-05-07 10:51:04 +03:00

412 Commits

Author SHA1 Message Date
Athanasius
f4ac9907a3
monitor/EnumWindows: Handle possible false-positive exception
Somehow I didn't run into this with testing *this* invocation of
`win32gui.EnumWindows()`, but then I did over in EDMarketConnector.py.  So,
as I had to handle the exception there, let's also do it here.
2023-01-13 15:13:43 +00:00
Athanasius
85ed69463c
monitor: Don't synthesize StartUp if current event is ShutDown 2023-01-13 14:04:01 +00:00
Athanasius
bb258aeb0a
monitor: Check if found 'ed process' is running as current user
This is something the old code *didn't actually do*.

Tested with a 'pseudo ed' process (same MainWindowTitle) running as myself
(test matches), and via `runas` as another user (doesn't match).
2023-01-13 12:29:56 +00:00
Athanasius
95b52bff01
monitor: Comment about 'as this User' not actually being true
Both the current `develop` code and this PR's new code share this behaviour.
What the code does is look for windows/processes *in the current Windows
session*, no matter if they're owned by the session user or not.

Neither version will find a process, that would match, if it's running in
another session, i.e. you'd need to switch to it via the windows Login screen.
2023-01-13 11:07:15 +00:00
Athanasius
4f017a77e8
monitor: Change last ctypes code to pywin32 instead
* All of the implementation of the EnumWindows callback.

The documentation for pywin32 isn't great, in terms of finding the call
convention and necessary form of parameters, but once you do this is *much*
cleaner than using ctypes directly.

I'm not 100% certain that `win32api.OpenProcess()` has the same semantic as
the previous `GetProcessHandleFromHwnd()`, i.e. only getting the `handle`
back if the process is owned by the current user.  If the user has
Windows Administrator rights they can probably kill other users' processes ?
2023-01-12 18:31:45 +00:00
Athanasius
b24e998931
monitor: Replace EnumWindows() with pywin32 version 2023-01-12 17:50:52 +00:00
Athanasius
2c469441e0
monitor: Just use the pywin32 win32gui.GetWindowText(), it works
After over an hour's struggle trying to get the win32/user32
`GetWindowTextW()` prototyped properly, and running into problem after problem:

    1. Once you properly prototype this, including defining the 2nd `lpString`
      parameter as 'out', ctypes wants to just *return* that.
    2. This leads to then implementing a `.errcheck` property so that you
      can *also* check the INT result for errors.
    3. But then you just run into another error.

I finally found <https://stackoverflow.com/a/10905155> which pointed out
you can simply use `win32gui.GetWindowText()` from `pywin32`.  Tested, it
simply works, no errors/exceptions.
2023-01-12 17:35:01 +00:00
Athanasius
d5a1fc4001
monitor: Prototype GetWindowTextW & GetWindowTextLengthW 2023-01-12 16:23:32 +00:00
Athanasius
0a8d383310
monitor: Prototype CloseHandle 2023-01-12 16:13:00 +00:00
Athanasius
aaf83645f7
monitor: Properly prototype EnumWindows 2023-01-12 16:04:44 +00:00
Athanasius
e5709727b6
monitor: Rename GetWindowTextLength to GetWindowTextLengthW
It's using the win32/user32 GetWindowTextLengthW() so name it appropriately.
2023-01-12 15:52:49 +00:00
Athanasius
3d41be7651
monitor: log INFO when for-plugins StartUp event synthesized
This is actually to do with a reported issue around the ctypes code in
`EDLogs.gamerunning()` causing:

```python
exception ignored on calling ctypes callback function: <function EDLogs.game_running.<locals>.callback at 0x0000020E9C9D0EA0>
Traceback (most recent call last):
  File "monitor.pyc", line 2041, in callback
  File "monitor.pyc", line 2034, in WindowTitle
ctypes.ArgumentError: argument 1: OverflowError: int too long to convert
```

Although I can't personally get this to trigger at all under 64-bit python,
either in PyCharm *or* with the 5.7.1-alpha1 64-bit pre-release.

`game_running()` is only used in a few places, and the key things it
malfunctioning might cause are lack of the synthetic `ShutDown` (already
has an INFO logging) and `StartUp` events.
2023-01-12 14:50:44 +00:00
Athanasius
79bbc8917f
Move 'this is the GameVersion we found' logging to DEBUG
This quietens it for normal EDMC.py usage.
2022-12-14 10:51:37 +00:00
Athanasius
25ed649b7a
monitor/NavRoute: Load NavRoute after catching_up ends.
This is to allow restart of EDMarketConnector whilst the game is running
to have `state['NavRoute']` hold data when the synthetic `StartUp` event
is passed to plugins.

NB: Probably need to note this in PLUGINS.md
2022-12-06 15:34:12 +00:00
Athanasius
d902093f0b
Merge pull request #1682 from EDCD/fix/1431/eddn-replay-enhancements
Change EDDN 'replay' to using an sqlite3 DB & otherwise improve
2022-11-27 15:24:28 +00:00
Athanasius
b3eff6ab32
monitor: Catch any failure to coerce gameversion
Also, log either the error or the success.  That will aid us in diagnosing
any future issues.
2022-11-27 13:02:54 +00:00
Athanasius
8a58220a66
inara: Send only Live galaxy data after Update 14
* Adds `monitor.is_live_galaxy()` for general use.
* Assumes Update 14 starts after 2022-11-29T09:00:00+00:00.  That's the
  currently schedule day, and recently the servers have been down by the time.
  Likelihood of them coming back *up* quickly seems slim to none.
* If we couldn't parse the `gameversion` from Journal using
  `semantic_version.Version.coerce()` this will fail, and assume we're on
  the Legacy galaxy.
2022-11-27 12:47:19 +00:00
Athanasius
a2d2723f49
monitor: Add an 'IsDocked' flag to monitor.state.
* This is cleaner than starting to track it in `plugins/eddn.py` specifically.
* This is literally only about if we're piloting a ship that is docked, so
  not even trying to resolve "on-foot, in a station, 'Location' said not
  docked though".
2022-11-22 15:29:05 +00:00
Athanasius
ddba99bfd8
monitor: Handle NavRouteClear & un-() an assert
* Stop trying to load `NavRoute.json` if it contained a `NavRouteClear`.
* `assert` is a *keyword*, not a function.
2022-08-10 11:28:10 +01:00
Athanasius
8e8f09ade3
Journal: FCMaterials: Implement parsing separate file
This re-uses much of the NavRoute.json code, with a minor tweak to *not*
store the result in monitor.state, instead just returning it to caller.
2022-06-04 17:27:08 +01:00
Athanasius
9f08b003c5
monitor: __navroute_retry(): be less noisy
No need to log at INFO for the retry counts, as this appears to be working,
make it DEBUG instead.

This was making the EDMC.py output needlessly noisy.
2022-03-18 09:51:35 +00:00
Athanasius
c89548c2ba
monitor: journal_newest_filename(): Check for None directory
os.listdir(None) operates on '.', which is wrong in this context, so be
sure to avoid that.
2022-03-18 09:49:02 +00:00
Athanasius
4b12a6c484
monitor: Properly type new_journal_file
Python was guessing and not allowing 'None', which it will be at shutdown
if this code triggers.
2022-03-18 09:46:35 +00:00
Athanasius
04930c59ac
monitor: Properly determine *newest* Journal file
Using os.path.getctime for the order, not the filename.  This addresses the
changed Journal filenames in Odyssey Update 11, whilst keeping compatibility
with the Horizons Update 11 old-name-style filenames.
2022-03-15 16:08:18 +00:00
Athanasius
e17a40aaff
monitor: Change Journal file regex, because Frontier are being a PITA
They've changed it to an ISO8601 style full date/time now.  But the Odyssey
client still uses the old format.
2022-03-15 13:56:48 +00:00
Athanasius
46e914fcec
monitor: Revert state['StarSystem'] addition, it's not needed.
We pass `monitor.system` in to `journal_entry()` anyway, so it doesn't need
to be separately in the passed `state`.
2022-02-11 11:57:05 +00:00
Athanasius
f1ba8ee5e1
eddn: Fix up approachsettlement & adjust other such function signatures
1. We need StarPos (as well as StarSystem)
2. Adding more state tracking in this plugin is misguided.
3. So added it in monitor instead, putting *copies* of data in the
  monitor.state dictionary.
4. So we reference those, but only available in journal_entry() itself, else
  we'd need to pass the whole of `state` in.
5. So instead pass in the bits of `state` only when we need them.
2022-02-09 16:07:16 +00:00
Athanasius
f8e0fb3658
monitor: Fold 'EngineerCraft' to lower case in event_type comparison 2022-02-04 12:22:47 +00:00
Athanasius
5e612d56b3
Merge pull request #1411 from A-UNDERSCORE-D/sys-plaform-mypy
Ensure that platform guards are recognised by mypy
2022-01-27 12:58:26 +00:00
Athanasius
3a4690d292
monitor: Gate navroute on *not* being in journal catch up mode
We can't just use `EDLogs.live` here as it'll get set `true` when the
`Commander` event is seen *during the catch up*.  We need that catchup
to have finished before we'll try processing a `NavRoute` event and
file.
2022-01-26 17:29:29 +00:00
A_D
eb28a3b502
Use sys.platform, minor type updates 2022-01-26 18:51:41 +02:00
Athanasius
e98aec0169
monitor: Comment what MAX_NAVROUTE_DISCREPANCY is
So as to disambiguate from "some discrepancy within the route data".
2022-01-26 16:38:01 +00:00
A_D
62a0a96dc6
resolve final review comments 2022-01-26 17:42:50 +02:00
A_D
36ecb69964
refactor to use retry function for all attempts at navroute 2022-01-26 13:17:27 +02:00
A_D
06d4842da2
Be more parinoid about navroute files 2022-01-25 20:17:05 +02:00
A_D
d4c6cd94fe
retry navroute parsing after failure 2022-01-25 20:17:04 +02:00
Athanasius
8363e8c646
monitor: Don't re-init Enginers/Rank/Reputation on LoadGame
The order of Journal events changed from:

  1. LoadGame
  2. Rank
  3. Progress

to:

  1. Rank
  2. Progress
  3. LoadGame

in Odyssey, and in at least current 'base game' and Horizons clients as
well.  Also 'Reputation' event is before 'LoadGame' now.  So simply
allow those events to have populated the data, don't re-init on
LoadGame.

Yes, I'm preferring to leave the lines in, but commented, so it's clear
why those aren't being init'd, *and* why 'Statistics' still is, and as
of what game version.
2021-11-21 11:24:18 +00:00
Athanasius
919136874d
CAPI: Re-auth when Access Token expired: Need to .close() first
The old code did this, and without it we enter a loop of:

1. CAPI says unauthorized
2. We call login()
3. But companion.session.state == STATE_OK, so do nothing
4. Re-scheduled CAPI request goes back to 1.
2021-11-06 08:41:09 +00:00
Athanasius
2754385281
monitor: Use trace_if('journal.startup', ...) for game load-in 2021-08-13 15:14:03 +01:00
Athanasius
1378f765cc
monitor: Convert to logger.trace_if() 2021-08-13 15:14:02 +01:00
A_D
05e6838637
removed trace_on imports 2021-08-12 16:49:27 +02:00
A_D
fefa3d351d
replaced if x in trace_on with trace_if 2021-08-12 16:46:55 +02:00
Athanasius
97808f5561
monitor.py: Access trace_on via whole-config import
This is necessary so as to see the same instance of config.trace_on as
is set up by EDMarketConnector.py.
2021-08-11 12:33:22 +01:00
0bb06232b8
monitor.py: add default value to entry.get('GameMode') in CQC detection 2021-08-11 14:24:27 +03:00
bd32b44903
monitor.py: fix CQC to lower case 2021-08-11 13:50:09 +03:00
42ce2ad414
monitor.py: trace loadgames to CQC only if in trace_on 2021-08-10 14:27:47 +03:00
7b823dd64d
Remove commented out logger.debug() 2021-08-10 03:16:57 +03:00
e9ee65da14
Code style fix 2021-08-10 03:15:50 +03:00
3283439485
Code style fixes 2021-08-10 03:00:36 +03:00
a00a677746
monitor.py: use trace instead debug to log CQC loadgames 2021-08-10 02:49:58 +03:00