Skip to content

Commit

Permalink
EDSM: Timed latch for notifying about Legacy galaxy data
Browse files Browse the repository at this point in the history
This avoids the spam from EDSM itself objecting to the passed gameversion.
We don't even send anything but Live data now.
  • Loading branch information
Athanasius committed Dec 1, 2022
1 parent db4f59d commit abe1317
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions plugins/edsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import json
import threading
import tkinter as tk
from datetime import datetime, timedelta, timezone
from queue import Queue
from threading import Thread
from time import sleep
Expand All @@ -42,6 +43,7 @@
import requests

import killswitch
import monitor
import myNotebook as nb # noqa: N813
import plug
from companion import CAPIData
Expand Down Expand Up @@ -74,6 +76,9 @@ def __init__(self):
self.game_version = ""
self.game_build = ""

# Handle only sending Live galaxy data
self.legacy_galaxy_last_notified: Optional[datetime] = None

self.session: requests.Session = requests.Session()
self.session.headers['User-Agent'] = user_agent
self.queue: Queue = Queue() # Items to be sent to EDSM by worker thread
Expand Down Expand Up @@ -420,20 +425,30 @@ def credentials(cmdr: str) -> Optional[Tuple[str, str]]:

def journal_entry( # noqa: C901, CCR001
cmdr: str, is_beta: bool, system: str, station: str, entry: MutableMapping[str, Any], state: Mapping[str, Any]
) -> None:
"""Journal Entry hook."""
) -> str:
"""
Process a Journal event.
:param cmdr:
:param is_beta:
:param system:
:param station:
:param entry:
:param state:
:return: str - empty if no error, else error string.
"""
should_return, new_entry = killswitch.check_killswitch('plugins.edsm.journal', entry, logger)
if should_return:
# LANG: EDSM plugin - Journal handling disabled by killswitch
plug.show_error(_('EDSM Handler disabled. See Log.'))
return
return ''

should_return, new_entry = killswitch.check_killswitch(
f'plugins.edsm.journal.event.{entry["event"]}', data=new_entry, log=logger
)

if should_return:
return
return ''

this.game_version = state['GameVersion']
this.game_build = state['GameBuild']
Expand Down Expand Up @@ -530,6 +545,21 @@ def journal_entry( # noqa: C901, CCR001

# Queue all events to send to EDSM. worker() will take care of dropping EDSM discarded events
if config.get_int('edsm_out') and not is_beta and not this.multicrew and credentials(cmdr):
if not monitor.monitor.is_live_galaxy():
logger.info("EDSM only accepts Live galaxy data")
# Since Update 14 on 2022-11-29 Inara only accepts Live data.
if (
this.legacy_galaxy_last_notified is None
or (datetime.now(timezone.utc) - this.legacy_galaxy_last_notified) > timedelta(seconds=300)
):
# LANG: The Inara API only accepts Live galaxy data, not Legacy galaxy data
logger.info("EDSM only accepts Live galaxy data")
# this.parent.children['status']['text'] =
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
return _("EDSM only accepts Live galaxy data")

return ''

# Introduce transient states into the event
transient = {
'_systemName': system,
Expand Down Expand Up @@ -563,6 +593,8 @@ def journal_entry( # noqa: C901, CCR001

this.queue.put((cmdr, this.game_version, this.game_build, entry))

return ''


# Update system data
def cmdr_data(data: CAPIData, is_beta: bool) -> None:
Expand Down

0 comments on commit abe1317

Please sign in to comment.