diff --git a/EDMarketConnector.py b/EDMarketConnector.py index fc4bca2c..f2d6ac4d 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -916,7 +916,7 @@ class AppWindow(object): def login(self): """Initiate CAPI/Frontier login and set other necessary state.""" - should_return, new_data = killswitch.check_killswitch('capi.auth', {}) + should_return, __ = killswitch.check_killswitch('capi.auth', {}) if should_return: logger.warning('capi.auth has been disabled via killswitch. Returning.') self.status['text'] = 'CAPI auth disabled by killswitch' @@ -1007,7 +1007,7 @@ class AppWindow(object): :param event: Tk generated event details. """ logger.trace_if('capi.worker', 'Begin') - should_return, new_data = killswitch.check_killswitch('capi.auth', {}) + should_return, __ = killswitch.check_killswitch('capi.auth', {}) if should_return: logger.warning('capi.auth has been disabled via killswitch. Returning.') self.status['text'] = 'CAPI auth disabled by killswitch' @@ -1093,7 +1093,7 @@ class AppWindow(object): :param event: Tk generated event details. """ logger.trace_if('capi.worker', 'Begin') - should_return, new_data = killswitch.check_killswitch('capi.fleetcarrier', {}) + should_return, __ = killswitch.check_killswitch('capi.request.fleetcarrier', {}) if should_return: logger.warning('capi.fleetcarrier has been disabled via killswitch. Returning.') self.status['text'] = 'CAPI fleetcarrier disabled by killswitch' @@ -1106,12 +1106,6 @@ class AppWindow(object): self.status['text'] = _('CAPI query aborted: Cmdr name unknown') return - if not monitor.mode: - logger.trace_if('capi.worker', 'Aborting Query: Game Mode unknown') - # LANG: CAPI queries aborted because game mode unknown - 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 @@ -1120,6 +1114,7 @@ class AppWindow(object): if not companion.session.retrying: if time() < self.capi_fleetcarrier_query_holdoff_time: # Was invoked while in cooldown + logger.debug('CAPI fleetcarrier query aborted, too soon since last request') return # LANG: Status - Attempting to retrieve data from Frontier CAPI @@ -1173,7 +1168,7 @@ class AppWindow(object): if __debug__: # Recording companion.session.dump_capi_data(capi_response.capi_data) - err = plug.notify_capi_fleetcarrierdata(capi_response.capi_data, monitor.is_beta) + err = plug.notify_capi_fleetcarrierdata(capi_response.capi_data) self.status['text'] = err and err or '' if err: play_bad = True @@ -1306,7 +1301,7 @@ class AppWindow(object): if err: play_bad = True - should_return, new_data = killswitch.check_killswitch('capi.request./market', {}) + should_return, __ = killswitch.check_killswitch('capi.request./market', {}) if should_return: logger.warning("capi.request./market has been disabled by killswitch. Returning.") @@ -1561,12 +1556,12 @@ class AppWindow(object): auto_update = True if auto_update: - should_return, new_data = killswitch.check_killswitch('capi.auth', {}) + should_return, __ = killswitch.check_killswitch('capi.auth', {}) if not should_return: self.w.after(int(SERVER_RETRY * 1000), self.capi_request_data) - if entry['event'] in ['CarrierBuy', 'CarrierStats', 'CarrierTradeOrder']: # 'CargoTransfer' too? - should_return, new_data = killswitch.check_killswitch('capi.fleetcarrier', {}) + if entry['event'] in ('CarrierBuy', 'CarrierStats'): + should_return, __ = killswitch.check_killswitch('capi.request.fleetcarrier', {}) if not should_return: self.w.after(int(SERVER_RETRY * 1000), self.capi_request_fleetcarrier_data) diff --git a/PLUGINS.md b/PLUGINS.md index f768b7aa..3bb6f2ee 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -941,12 +941,12 @@ def cmdr_data(data, is_beta): | `data` | `CAPIData` | `/profile` API response, with `/market` and `/shipyard` added under the keys `marketdata` and `shipdata` | | `is_beta` | `bool` | If the game is currently in beta | -If a plugin has a `capi_fleetcarrier()` function it gets called when the application has just fetched fresh Fleetcarrier data from Frontier's CAPI servers. This is done when `CarrierBuy`, `CarrierStats` or `CarrierTradeOrder` events are detected in the Player Journal. To avoid flooding Frontier's CAPI server, a throttle is applied to ensure a significant interval between requests (currently 15 mins). +If a plugin has a `capi_fleetcarrier()` function it gets called when the application has just fetched fresh Fleetcarrier data from Frontier's CAPI servers. This is done when `CarrierBuy`or `CarrierStats` events are detected in the Player Journal. To avoid flooding Frontier's CAPI server, a throttle is applied to ensure a significant interval between requests (currently 15 mins). Also be aware that calls to the `/fleetcarrier` CAPI endpoint have been reported to take a very long time to return, potentially up to 20 minutes. Delays in responses from this endpoint could delay other CAPI queries. ```python from companion import CAPIData, SERVER_LIVE, SERVER_LEGACY, SERVER_BETA -def capi_fleetcarrier(data, is_beta): +def capi_fleetcarrier(data): """ We have new data on our Fleet Carrier """ @@ -969,7 +969,6 @@ def capi_fleetcarrier(data, is_beta): | Parameter | Type | Description | | :-------- | :--------------: | :------------------------------------------------------------------------------------------------------- | | `data` | `CAPIData` | `/fleetcarrier` API response | -| `is_beta` | `bool` | If the game is currently in beta | `CAPIData` is a class, which you can `from companion import CAPIDATA`, and is based on `UserDict`. The actual data from CAPI queries is thus accessible diff --git a/companion.py b/companion.py index 26f46287..70b7e1cc 100644 --- a/companion.py +++ b/companion.py @@ -48,6 +48,7 @@ else: capi_query_cooldown = 60 # Minimum time between (sets of) CAPI queries capi_fleetcarrier_query_cooldown = 60 * 15 # Minimum time between CAPI fleetcarrier queries capi_default_requests_timeout = 10 +capi_fleetcarrier_requests_timeout = 60 auth_timeout = 30 # timeout for initial auth # Used by both class Auth and Session @@ -960,7 +961,8 @@ class Session(object): capi_data = capi_station_queries(query.capi_host) elif query.endpoint == self.FRONTIER_CAPI_PATH_FLEETCARRIER: - capi_data = capi_single_query(query.capi_host, self.FRONTIER_CAPI_PATH_FLEETCARRIER) + capi_data = capi_single_query(query.capi_host, self.FRONTIER_CAPI_PATH_FLEETCARRIER, + timeout=capi_fleetcarrier_requests_timeout) else: capi_data = capi_single_query(query.capi_host, self.FRONTIER_CAPI_PATH_PROFILE) diff --git a/plug.py b/plug.py index 9b68082c..d77c5fa9 100644 --- a/plug.py +++ b/plug.py @@ -402,23 +402,21 @@ def notify_capidata( def notify_capi_fleetcarrierdata( - data: companion.CAPIData, - is_beta: bool + data: companion.CAPIData ) -> Optional[str]: """ Send the latest CAPI Fleetcarrier data from the FD servers to each plugin. - :param data: - :param is_beta: whether the player is in a Beta universe. + :param data: The CAPIData returned in the CAPI response :returns: Error message from the first plugin that returns one (if any) """ error = None for plugin in PLUGINS: - fc_data = plugin._get_func('capi_fleetcarrier') - - if fc_data: + fc_callback = plugin._get_func('capi_fleetcarrier') + if fc_callback is not None and callable(fc_callback): try: - newerror = fc_data(data, is_beta) + # Pass a copy of the CAPIData in case the callee modifies it + newerror = fc_callback(copy.deepcopy(data)) error = error or newerror except Exception: