1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

Handling of /fleetcarrier CAPI endpoint and implementation of plugin callback function

This commit is contained in:
aussig 2022-12-21 23:00:35 +00:00
parent eedf4febdf
commit 8e5953408e
2 changed files with 48 additions and 1 deletions

View File

@ -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')

26
plug.py
View File

@ -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.