From 4b31b6704299926b4b21f177393c1ef17fb3fd39 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 1 Dec 2022 14:29:10 +0000 Subject: [PATCH] CAPI: Only perform queries for Live galaxy. * This is *temporary* pending properly implementing utilising the Legacy CAPI host. * Check in the EDMarketConnector.EDApp.capi_request_data() function *and* also in some companion.session functions. But not absolutely all possible entry points because we'll be undoing it when we implement Legacy support. This *is* sufficient for the current core code entry points. If any plugin is invoking its own CAPI requests, well it shouldn't be. --- EDMarketConnector.py | 13 ++++++++++++- L10n/en.template | 3 +++ companion.py | 22 +++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 041f7331..36d7215c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -944,7 +944,7 @@ class AppWindow(object): return True - def capi_request_data(self, event=None) -> None: + def capi_request_data(self, event=None) -> None: # noqa: CCR001 """ Perform CAPI data retrieval and associated actions. @@ -969,6 +969,17 @@ class AppWindow(object): self.status['text'] = _('CAPI query aborted: Game mode unknown') return + if monitor.state['GameVersion'] is None: + logger.trace_if('capi.worker', 'Aborting Query: GameVersion unknown') + # LANG: CAPI queries aborted because GameVersion unknown + self.status['text'] = _('CAPI query aborted: GameVersion unknown') + return + + if not monitor.is_live_galaxy(): + logger.warning("Dropping CAPI request because this is the Legacy galaxy, which is not yet supported") + self.status['text'] = 'CAPI for Legacy not yet supported' + return + if not monitor.system: logger.trace_if('capi.worker', 'Aborting Query: Current star system unknown') # LANG: CAPI queries aborted because current star system name unknown diff --git a/L10n/en.template b/L10n/en.template index 8bbfad96..6ed81d22 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -214,6 +214,9 @@ /* EDMarketConnector.py: CAPI queries aborted because game mode unknown; In files: EDMarketConnector.py:967; */ "CAPI query aborted: Game mode unknown" = "CAPI query aborted: Game mode unknown"; +/* EDMarketConnector.py: CAPI queries aborted because GameVersion unknown; In files: EDMarketConnector.py:974; */ +"CAPI query aborted: GameVersion unknown" = "CAPI query aborted: GameVersion unknown"; + /* EDMarketConnector.py: CAPI queries aborted because current star system name unknown; In files: EDMarketConnector.py:973; */ "CAPI query aborted: Current system unknown" = "CAPI query aborted: Current system unknown"; diff --git a/companion.py b/companion.py index 91b306e3..352e7fb0 100644 --- a/companion.py +++ b/companion.py @@ -55,6 +55,7 @@ auth_timeout = 30 # timeout for initial auth FRONTIER_AUTH_SERVER = 'https://auth.frontierstore.net' SERVER_LIVE = 'https://companion.orerve.net' +SERVER_LEGACY = 'https://legacy-companion.orerve.net' SERVER_BETA = 'https://pts-companion.orerve.net' commodity_map: Dict = {} @@ -679,7 +680,6 @@ class Session(object): self.close() self.credentials = credentials - self.server = self.credentials['beta'] and SERVER_BETA or SERVER_LIVE self.state = Session.STATE_INIT self.auth = Auth(self.credentials['cmdr']) @@ -743,7 +743,7 @@ class Session(object): """Worker thread that performs actual CAPI queries.""" logger.debug('CAPI worker thread starting') - def capi_single_query( # noqa: CCR001 + def capi_single_query( capi_endpoint: str, timeout: int = capi_default_requests_timeout ) -> CAPIData: """ @@ -754,6 +754,10 @@ class Session(object): :return: The resulting CAPI data, of type CAPIData. """ capi_data: CAPIData + if not monitor.is_live_galaxy(): + logger.warning("Dropping CAPI request because this is the Legacy galaxy") + return capi_data + try: logger.trace_if('capi.worker', 'Sending HTTP request...') if conf_module.capi_pretend_down: @@ -936,7 +940,7 @@ class Session(object): ) # If the query came from EDMC.(py|exe) there's no tk to send an - # event too, so assume it will be polling there response queue. + # event too, so assume it will be polling the response queue. if query.tk_response_event is not None: logger.trace_if('capi.worker', 'Sending <>') self.tk_master.event_generate('<>') @@ -964,6 +968,18 @@ class Session(object): :param play_sound: Whether the app should play a sound on error. :param auto_update: Whether this request was triggered automatically. """ + if self.credentials is not None and self.credentials['beta']: + self.server = SERVER_BETA + + elif monitor.is_live_galaxy(): + self.server = SERVER_LIVE + + else: + logger.warning("Dropping CAPI request because this is the Legacy galaxy, which is not yet supported") + # self.server = SERVER_LEGACY + self.server = None + return + # Ask the thread worker to perform all three queries logger.trace_if('capi.worker', 'Enqueueing request') self.capi_request_queue.put(