From 8e5953408e5b4c288d40431ad9af30cb65c38d1a Mon Sep 17 00:00:00 2001 From: aussig Date: Wed, 21 Dec 2022 23:00:35 +0000 Subject: [PATCH] Handling of /fleetcarrier CAPI endpoint and implementation of plugin callback function --- EDMarketConnector.py | 23 ++++++++++++++++++++++- plug.py | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index bc8d2f29..5193a0d6 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1112,7 +1112,28 @@ class AppWindow(object): raise ValueError(msg) # Validation - if 'commander' not in capi_response.capi_data: + if capi_response.capi_data.source_endpoint == companion.session.FRONTIER_CAPI_PATH_FLEETCARRIER: + if 'name' not in capi_response.capi_data: + # LANG: No data was returned for the fleetcarrier from the Frontier CAPI + err = self.status['text'] = _('CAPI: No fleetcarrier data returned') + + elif not capi_response.capi_data.get('name', {}).get('callsign'): + # LANG: We didn't have the fleetcarrier callsign when we should have + err = self.status['text'] = _("CAPI: Fleetcarrier data incomplete") # Shouldn't happen + + else: + if __debug__: # Recording + companion.session.dump_capi_data(capi_response.capi_data) + + err = plug.notify_capi_fleetcarrierdata(capi_response.capi_data, monitor.is_beta) + self.status['text'] = err and err or '' + if err: + play_bad = True + + # TODO: Need to set a different holdoff time for the FC CAPI request + self.capi_query_holdoff_time = capi_response.query_time + companion.capi_query_cooldown + + elif 'commander' not in capi_response.capi_data: # This can happen with EGS Auth if no commander created yet # LANG: No data was returned for the commander from the Frontier CAPI err = self.status['text'] = _('CAPI: No commander data returned') diff --git a/plug.py b/plug.py index deeb6ebe..9b68082c 100644 --- a/plug.py +++ b/plug.py @@ -401,6 +401,32 @@ def notify_capidata( return error +def notify_capi_fleetcarrierdata( + data: companion.CAPIData, + is_beta: bool +) -> 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. + :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: + try: + newerror = fc_data(data, is_beta) + error = error or newerror + + except Exception: + logger.exception(f'Plugin "{plugin.name}" failed on receiving Fleetcarrier data') + + return error + + def show_error(err: str) -> None: """ Display an error message in the status line of the main window.