From 07065b0bf35a9c10e8c290597d1b5aec0a04ef5d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 4 Jun 2021 17:35:37 +0100 Subject: [PATCH 1/5] inara: Comment out generic setCommanderTravelLocation event This interferes with more specific such events, i.e. from Journal `Location` event, if sent in the same batch. --- plugins/inara.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 5cd53dd5..a940173f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -451,15 +451,17 @@ def journal_entry( # noqa: C901, CCR001 # Update location # Might not be available if this event is a 'StartUp' and we're replaying # a log. - if system: - new_add_event( - 'setCommanderTravelLocation', - entry['timestamp'], - OrderedDict([ - ('starsystemName', system), - ('stationName', station), # Can be None - ]) - ) + # XXX: This interferes with other more specific setCommanderTravelLocation events in the same + # batch. + # if system: + # new_add_event( + # 'setCommanderTravelLocation', + # entry['timestamp'], + # OrderedDict([ + # ('starsystemName', system), + # ('stationName', station), # Can be None + # ]) + # ) # Update ship if state['ShipID']: # Unknown if started in Fighter or SRV @@ -1511,7 +1513,6 @@ def send_data(url: str, data: Mapping[str, Any]) -> bool: # noqa: CCR001 :param data: the data to POST :return: success state """ - r = this.session.post(url, data=json.dumps(data, separators=(',', ':')), timeout=_TIMEOUT) r.raise_for_status() reply = r.json() From fa0a7c48a2d4897d5d7492710c0acb62187c8eab Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 4 Jun 2021 17:47:32 +0100 Subject: [PATCH 2/5] Inara: setCommanderTravelLocation for SupercruiseExit and ApproachSettlement --- plugins/inara.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/inara.py b/plugins/inara.py index a940173f..d35dc944 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -619,6 +619,26 @@ def journal_entry( # noqa: C901, CCR001 this.undocked = False + elif event_name == 'SupercruiseExit': + to_send = { + 'starsystemName': entry['StarSystem'], + } + + if entry['BodyType'] == 'Planet': + to_send['starsystemBodyName'] = entry['Body'] + + new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) + + elif event_name == 'ApproachSettlement': + to_send = { + 'starsystemName': system, + 'stationName': entry['Name'], + 'marketid': entry['MarketID'], + 'starsystemBodyName': entry['BodyName'], + 'starsystemBodyCoords': [entry['Latitude'], entry['Longitude']] + } + new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) + elif event_name == 'FSDJump': this.undocked = False to_send = { From f6777f0237e146d25922987007ab113fb357c8e6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 4 Jun 2021 18:45:43 +0100 Subject: [PATCH 3/5] Inara: Only ApproachSettlement if we have system & fix key case * If you're near a settlement on login you get an ApproachSettlement before `monitor` has system set to pass into `journal_entry()`. * We had a case-type of an Inara API key, so it wasn't setting the BodyName. * TRACE level logging of what we actually send to Inara. --- plugins/inara.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index d35dc944..86867aff 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -630,14 +630,17 @@ def journal_entry( # noqa: C901, CCR001 new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) elif event_name == 'ApproachSettlement': - to_send = { - 'starsystemName': system, - 'stationName': entry['Name'], - 'marketid': entry['MarketID'], - 'starsystemBodyName': entry['BodyName'], - 'starsystemBodyCoords': [entry['Latitude'], entry['Longitude']] - } - new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) + # If you're near a Settlement on login this event is recorded, but + # we might not yet have system logged for use. + if system: + to_send = { + 'starsystemName': system, + 'stationName': entry['Name'], + 'marketid': entry['MarketID'], + 'starsystemBodyName': entry['BodyName'], + 'starsystemBodyCoords': [entry['Latitude'], entry['Longitude']] + } + new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) elif event_name == 'FSDJump': this.undocked = False @@ -1197,7 +1200,7 @@ def journal_entry( # noqa: C901, CCR001 # These were included thus we are landed to_send['starsystemBodyCoords'] = [entry['Latitude'], entry['Longitude']] # if we're not Docked, but have these, we're either landed or close enough that it doesn't matter. - to_send['starSystemBodyName'] = entry['Body'] + to_send['starsystemBodyName'] = entry['Body'] new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) @@ -1483,6 +1486,7 @@ def new_worker(): ] } logger.info(f'sending {len(data["events"])} events for {creds.cmdr}') + logger.trace(f'Events:\n{json.dumps(data)}\n') try_send_data(TARGET_URL, data) time.sleep(WORKER_WAIT_TIME) From 7a69ca5e6b2f6b8f3ed6307728ab24dd727a6fa9 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 4 Jun 2021 18:57:05 +0100 Subject: [PATCH 4/5] Inara: Remove useless/wrong setCommanderTravelLocation from SupercruiseEntry This is old code, pre-dating the move to EDCD. We could only possibly set the system name and address from this, and would always have already set this from login Location event, or any jump-in event. --- plugins/inara.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 86867aff..50ab078f 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -605,18 +605,6 @@ def journal_entry( # noqa: C901, CCR001 this.station = None elif event_name == 'SupercruiseEntry': - if this.undocked: - # Staying in system after undocking - send any pending events from in-station action - new_add_event( - 'setCommanderTravelLocation', - entry['timestamp'], - { - 'starsystemName': system, - 'shipType': state['ShipType'], - 'shipGameID': state['ShipID'], - } - ) - this.undocked = False elif event_name == 'SupercruiseExit': From 1d3ee4d6a9811bfc09513d9e2291c8f9b874f6bd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 4 Jun 2021 18:58:41 +0100 Subject: [PATCH 5/5] Inara: Fix case on Inara 'marketID' key --- plugins/inara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index 50ab078f..5e216007 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -624,7 +624,7 @@ def journal_entry( # noqa: C901, CCR001 to_send = { 'starsystemName': system, 'stationName': entry['Name'], - 'marketid': entry['MarketID'], + 'marketID': entry['MarketID'], 'starsystemBodyName': entry['BodyName'], 'starsystemBodyCoords': [entry['Latitude'], entry['Longitude']] }