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

Implement suggestions from PR #1773.

This commit is contained in:
aussig 2022-12-22 16:21:42 +00:00
parent cb2a6b6995
commit 9e17c46b25
4 changed files with 20 additions and 26 deletions

View File

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

View File

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

View File

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

14
plug.py
View File

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