1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-18 07:53:11 +03:00

Merge pull request #1144 from EDCD/fix/inara-too-many-setlocation

inara: Don't send a generic setCommanderTravelLocation - be specific
This commit is contained in:
Athanasius 2021-06-04 19:00:21 +01:00 committed by GitHub
commit 3c7d922705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -451,15 +451,17 @@ def journal_entry( # noqa: C901, CCR001
# Update location # Update location
# Might not be available if this event is a 'StartUp' and we're replaying # Might not be available if this event is a 'StartUp' and we're replaying
# a log. # a log.
if system: # XXX: This interferes with other more specific setCommanderTravelLocation events in the same
new_add_event( # batch.
'setCommanderTravelLocation', # if system:
entry['timestamp'], # new_add_event(
OrderedDict([ # 'setCommanderTravelLocation',
('starsystemName', system), # entry['timestamp'],
('stationName', station), # Can be None # OrderedDict([
]) # ('starsystemName', system),
) # ('stationName', station), # Can be None
# ])
# )
# Update ship # Update ship
if state['ShipID']: # Unknown if started in Fighter or SRV if state['ShipID']: # Unknown if started in Fighter or SRV
@ -603,20 +605,31 @@ def journal_entry( # noqa: C901, CCR001
this.station = None this.station = None
elif event_name == 'SupercruiseEntry': elif event_name == 'SupercruiseEntry':
if this.undocked:
# Staying in system after undocking - send any pending events from in-station action
new_add_event(
'setCommanderTravelLocation',
entry['timestamp'],
{
'starsystemName': system,
'shipType': state['ShipType'],
'shipGameID': state['ShipID'],
}
)
this.undocked = False this.undocked = False
elif event_name == 'SupercruiseExit':
to_send = {
'starsystemName': entry['StarSystem'],
}
if entry['BodyType'] == 'Planet':
to_send['starsystemBodyName'] = entry['Body']
new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send)
elif event_name == 'ApproachSettlement':
# If you're near a Settlement on login this event is recorded, but
# we might not yet have system logged for use.
if system:
to_send = {
'starsystemName': system,
'stationName': entry['Name'],
'marketID': entry['MarketID'],
'starsystemBodyName': entry['BodyName'],
'starsystemBodyCoords': [entry['Latitude'], entry['Longitude']]
}
new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send)
elif event_name == 'FSDJump': elif event_name == 'FSDJump':
this.undocked = False this.undocked = False
to_send = { to_send = {
@ -1175,7 +1188,7 @@ def journal_entry( # noqa: C901, CCR001
# These were included thus we are landed # These were included thus we are landed
to_send['starsystemBodyCoords'] = [entry['Latitude'], entry['Longitude']] to_send['starsystemBodyCoords'] = [entry['Latitude'], entry['Longitude']]
# if we're not Docked, but have these, we're either landed or close enough that it doesn't matter. # if we're not Docked, but have these, we're either landed or close enough that it doesn't matter.
to_send['starSystemBodyName'] = entry['Body'] to_send['starsystemBodyName'] = entry['Body']
new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send) new_add_event('setCommanderTravelLocation', entry['timestamp'], to_send)
@ -1461,6 +1474,7 @@ def new_worker():
] ]
} }
logger.info(f'sending {len(data["events"])} events for {creds.cmdr}') logger.info(f'sending {len(data["events"])} events for {creds.cmdr}')
logger.trace(f'Events:\n{json.dumps(data)}\n')
try_send_data(TARGET_URL, data) try_send_data(TARGET_URL, data)
time.sleep(WORKER_WAIT_TIME) time.sleep(WORKER_WAIT_TIME)
@ -1511,7 +1525,6 @@ def send_data(url: str, data: Mapping[str, Any]) -> bool: # noqa: CCR001
:param data: the data to POST :param data: the data to POST
:return: success state :return: success state
""" """
r = this.session.post(url, data=json.dumps(data, separators=(',', ':')), timeout=_TIMEOUT) r = this.session.post(url, data=json.dumps(data, separators=(',', ':')), timeout=_TIMEOUT)
r.raise_for_status() r.raise_for_status()
reply = r.json() reply = r.json()