From 6b54f721b0263c0da0f74e1dd85b1d6904a530c7 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 14:49:43 +0100 Subject: [PATCH 01/12] eddn: approachsettlement: Location cross-check paranoia --- plugins/eddn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index df6fdab2..24ed24b9 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1159,7 +1159,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### - # In this case should add StarSystem and StarPos + # In this case should add SystemName and StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, system_name, system_starpos) if isinstance(ret, str): return ret From 834debde988e5f0612da3880b0deb979dbc8ef5e Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 14:56:33 +0100 Subject: [PATCH 02/12] eddn: codexentry: Location cross-check paranoia --- plugins/eddn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 24ed24b9..d39c6c60 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -946,7 +946,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### - # General 'system' augmentations + # In this case should add StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, entry['System'], system_starpos) if isinstance(ret, str): return ret From 4baa2490af890e024c9c1c5eac301ba2550b838a Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:00:19 +0100 Subject: [PATCH 03/12] eddn: fssallbodiesfound: Location cross-check paranoia --- plugins/eddn.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index d39c6c60..464045b3 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1207,7 +1207,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### - # In this case should add StarSystem and StarPos + # In this case should add StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, system_name, system_starpos) if isinstance(ret, str): return ret From 3702b465e563c75db14ec7a1f60a9173bb5a6b40 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:03:02 +0100 Subject: [PATCH 04/12] eddn: fssdiscoveryscan: Location cross-check paranoia --- plugins/eddn.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index 464045b3..abb128ce 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -854,6 +854,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### + # In this case should add StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, system_name, system_starpos) if isinstance(ret, str): return ret From e38ea28ba6371ff07db4ec4ca6fa69ad389fbb32 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:05:11 +0100 Subject: [PATCH 05/12] eddn: navbeaconscan: Location cross-check paranoia --- plugins/eddn.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index abb128ce..ff88b1da 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -896,6 +896,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### + # In this case should add StarSystem and StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, system_name, system_starpos) if isinstance(ret, str): return ret From 2e6d6b8c02e9574390f7c4c9fc984fa90ceddd34 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:07:25 +0100 Subject: [PATCH 06/12] eddn: scanbarycentre: Location cross-check paranoia --- plugins/eddn.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index ff88b1da..8d40262e 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1045,6 +1045,12 @@ class EDDN: ####################################################################### # Augmentations ####################################################################### + # In this case should add StarPos, but only if the + # SystemAddress of where we think we are matches. + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("SystemAddress isn't current location! Can't add augmentations!") + return 'Wrong System! Missed jump ?' + ret = this.eddn.entry_augment_system_data(entry, entry['StarSystem'], system_starpos) if isinstance(ret, str): return ret From 4a207429cdaad416ba17f503ec0833a930bfd9aa Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:20:45 +0100 Subject: [PATCH 07/12] eddn: journal schema: Add notes about present/missing fields --- plugins/eddn.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index 8d40262e..5335d0ac 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1694,6 +1694,16 @@ def journal_entry( # noqa: C901, CCR001 entry['Body'] = this.body_name entry['BodyType'] = 'Planet' + # The generic journal schema is for events: + # Docked, FSDJump, Scan, Location, SAASignalsFound, CarrierJump + # (Also CodexEntry, but that has its own schema and handling). + # StarSystem SystemAddress StarPos + # Docked Y Y N + # FSDJump Y Y Y + # Scan Y Y N + # Location Y Y Y + # SAASignalsFound N Y N + # CarrierJump Y Y Y # add mandatory StarSystem, StarPos and SystemAddress properties to Scan events if 'StarSystem' not in entry: if not system: From 4fcd2ae3f3beb2eb3c9ca53c0ebb89ffe302683c Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:30:20 +0100 Subject: [PATCH 08/12] eddn: journal: Make `SystemAddress` a check, not an augmentation On checking, all of the events valid for the journal schema (and CodexEntry has its own schema and separate EDMC code) already contain SystemAddress, so it would never be added as an augmentation. Instead, turn this into a sanity check. --- plugins/eddn.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 5335d0ac..2e219541 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1697,6 +1697,7 @@ def journal_entry( # noqa: C901, CCR001 # The generic journal schema is for events: # Docked, FSDJump, Scan, Location, SAASignalsFound, CarrierJump # (Also CodexEntry, but that has its own schema and handling). + # Journals 2021-08-23 to 2022-05-29 # StarSystem SystemAddress StarPos # Docked Y Y N # FSDJump Y Y Y @@ -1704,7 +1705,12 @@ def journal_entry( # noqa: C901, CCR001 # Location Y Y Y # SAASignalsFound N Y N # CarrierJump Y Y Y - # add mandatory StarSystem, StarPos and SystemAddress properties to Scan events + + if 'SystemAddress' not in entry: + logger.warning("journal schema event doesn't contain SystemAddress when it should, aborting") + return "No SystemAddress in event, aborting send" + + # add mandatory StarSystem and StarPos properties to events if 'StarSystem' not in entry: if not system: logger.warning("system is falsey, can't add StarSystem") @@ -1725,13 +1731,6 @@ def journal_entry( # noqa: C901, CCR001 entry['StarPos'] = list(this.coordinates) - if 'SystemAddress' not in entry: - if not this.systemaddress: - logger.warning("this.systemaddress is falsey, can't add SystemAddress") - return "this.systemaddress is falsey, can't add SystemAddress" - - entry['SystemAddress'] = this.systemaddress - try: this.eddn.export_journal_generic(cmdr, is_beta, filter_localised(entry)) From 9fd3c3852a39f64efe9928b47be95d784a62e459 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sun, 29 May 2022 15:36:42 +0100 Subject: [PATCH 09/12] eddn: journal: Add SystemAddress cross-check to StarSystem augmentation --- plugins/eddn.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/eddn.py b/plugins/eddn.py index 2e219541..bc043926 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1712,6 +1712,10 @@ def journal_entry( # noqa: C901, CCR001 # add mandatory StarSystem and StarPos properties to events if 'StarSystem' not in entry: + if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: + logger.warning("event has no StarSystem, but SystemAddress isn't current location") + return "Wrong System! Delayed Scan event?" + if not system: logger.warning("system is falsey, can't add StarSystem") return "system is falsey, can't add StarSystem" From 020aa325a737ad503201cf75101caa0b09c72d29 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Wed, 1 Jun 2022 16:17:34 +0100 Subject: [PATCH 10/12] eddn: Cite event name in some logging Not needed where we're in an event-specific function, but is in generic event handling. --- plugins/eddn.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index bc043926..8db26469 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -1707,30 +1707,31 @@ def journal_entry( # noqa: C901, CCR001 # CarrierJump Y Y Y if 'SystemAddress' not in entry: - logger.warning("journal schema event doesn't contain SystemAddress when it should, aborting") + logger.warning(f"journal schema event({entry['event']}) doesn't contain SystemAddress when it should, " + "aborting") return "No SystemAddress in event, aborting send" # add mandatory StarSystem and StarPos properties to events if 'StarSystem' not in entry: if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: - logger.warning("event has no StarSystem, but SystemAddress isn't current location") + logger.warning(f"event({entry['event']}) has no StarSystem, but SystemAddress isn't current location") return "Wrong System! Delayed Scan event?" if not system: - logger.warning("system is falsey, can't add StarSystem") + logger.warning(f"system is falsey, can't add StarSystem to {entry['event']} event") return "system is falsey, can't add StarSystem" entry['StarSystem'] = system if 'StarPos' not in entry: if not this.coordinates: - logger.warning("this.coordinates is falsey, can't add StarPos") + logger.warning(f"this.coordinates is falsey, can't add StarPos to {entry['event']} event") return "this.coordinates is falsey, can't add StarPos" # Gazelle[TD] reported seeing a lagged Scan event with incorrect # augmented StarPos: <https://github.com/EDCD/EDMarketConnector/issues/961> if this.systemaddress is None or this.systemaddress != entry['SystemAddress']: - logger.warning("event has no StarPos, but SystemAddress isn't current location") + logger.warning(f"event({entry['event']}) has no StarPos, but SystemAddress isn't current location") return "Wrong System! Delayed Scan event?" entry['StarPos'] = list(this.coordinates) From 1349b2bca159d1dc959c14b3d9832076d6680b40 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Wed, 1 Jun 2022 16:24:51 +0100 Subject: [PATCH 11/12] eddn: codexentry: Ody Update 12 will add BodyID * So add a check to see if the event already has it, and leave it if so. * And might as well have a check on BodyName in case that gets added as well. --- plugins/eddn.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index 8db26469..c934f6d7 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -976,15 +976,20 @@ class EDDN: f' "{this.status_body_name}" ({type(this.status_body_name)})') else: - entry['BodyName'] = this.status_body_name - # Only set BodyID if journal BodyName matches the Status.json one. - # This avoids binary body issues. - if this.status_body_name == this.body_name: - if this.body_id is not None and isinstance(this.body_id, int): - entry['BodyID'] = this.body_id + # In case Frontier add it in + if entry.get('BodyName', None) is None: + entry['BodyName'] = this.status_body_name - else: - logger.warning(f'this.body_id was not set properly: "{this.body_id}" ({type(this.body_id)})') + # Frontier are adding this in Odyssey Update 12 + if entry.get('BodyID', None) is None: + # Only set BodyID if journal BodyName matches the Status.json one. + # This avoids binary body issues. + if this.status_body_name == this.body_name: + if this.body_id is not None and isinstance(this.body_id, int): + entry['BodyID'] = this.body_id + + else: + logger.warning(f'this.body_id was not set properly: "{this.body_id}" ({type(this.body_id)})') ####################################################################### # Check just the top-level strings with minLength=1 in the schema From 62c8af4dc049a7fc0e87f090f27b54eac0ee0217 Mon Sep 17 00:00:00 2001 From: Athanasius <github@miggy.org> Date: Sat, 4 Jun 2022 14:55:27 +0100 Subject: [PATCH 12/12] eddn: Use `if '<key>' not in <dict>:` idiom. --- plugins/eddn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/eddn.py b/plugins/eddn.py index c934f6d7..05835a12 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -977,11 +977,11 @@ class EDDN: else: # In case Frontier add it in - if entry.get('BodyName', None) is None: + if 'BodyName' not in entry: entry['BodyName'] = this.status_body_name # Frontier are adding this in Odyssey Update 12 - if entry.get('BodyID', None) is None: + if 'BodyID' not in entry: # Only set BodyID if journal BodyName matches the Status.json one. # This avoids binary body issues. if this.status_body_name == this.body_name: