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

inara: Send only Live galaxy data after Update 14

* Adds `monitor.is_live_galaxy()` for general use.
* Assumes Update 14 starts after 2022-11-29T09:00:00+00:00.  That's the
  currently schedule day, and recently the servers have been down by the time.
  Likelihood of them coming back *up* quickly seems slim to none.
* If we couldn't parse the `gameversion` from Journal using
  `semantic_version.Version.coerce()` this will fail, and assume we're on
  the Legacy galaxy.
This commit is contained in:
Athanasius 2022-11-27 12:47:19 +00:00
parent 75af13efea
commit 8a58220a66
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
2 changed files with 55 additions and 0 deletions

View File

@ -21,6 +21,8 @@ from typing import Tuple
if TYPE_CHECKING:
import tkinter
import semantic_version
import util_ships
from config import config
from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised
@ -111,6 +113,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# Context for journal handling
self.version: Optional[str] = None
self.version_semantic: Optional[semantic_version.Version] = None
self.is_beta = False
self.mode: Optional[str] = None
self.group: Optional[str] = None
@ -131,6 +134,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self._fcmaterials_retries_remaining = 0
self._last_fcmaterials_journal_timestamp: Optional[float] = None
# For determining Live versus Legacy galaxy.
# The assumption is gameversion will parse via `coerce()` and always
# be >= for Live, and < for Legacy.
self.live_galaxy_base_version = semantic_version.Version('4.0.0')
self.__init_state()
def __init_state(self) -> None:
@ -293,6 +301,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.currentdir = None
self.version = None
self.version_semantic = None
self.mode = None
self.group = None
self.cmdr = None
@ -1677,6 +1686,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['GameVersion'] = entry['gameversion']
self.state['GameBuild'] = entry['build']
self.version = self.state['GameVersion']
self.version_semantic = semantic_version.Version.coerce(self.state['GameVersion'])
self.is_beta = any(v in self.version.lower() for v in ('alpha', 'beta')) # type: ignore
except KeyError:
if not suppress:
@ -2348,6 +2358,25 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self._last_fcmaterials_journal_timestamp = None
return file
def is_live_galaxy(self) -> bool:
"""
Indicate if current tracking indicates Live galaxy.
We assume:
1) `gameversion` remains something that semantic_verison.Version.coerce() can parse.
2) Any Live galaxy client reports a version >= the defined base version.
3) Any Legacy client will always report a version < that base version.
:return: True for Live, False for Legacy or unknown.
"""
# If we don't yet know the version we can't tell, so assume the worst
if self.version_semantic is None:
return False
if self.version_semantic >= self.live_galaxy_base_version:
return True
return False
# singleton
monitor = EDLogs()

View File

@ -28,6 +28,7 @@ import time
import tkinter as tk
from collections import OrderedDict, defaultdict, deque
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from operator import itemgetter
from threading import Lock, Thread
from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, List, Mapping, NamedTuple, Optional
@ -44,6 +45,7 @@ import timeout_session
from companion import CAPIData
from config import applongname, appversion, config, debug_senders
from EDMCLogging import get_main_logger
from monitor import monitor
from ttkHyperlinkLabel import HyperlinkLabel
logger = get_main_logger()
@ -88,6 +90,11 @@ class This:
def __init__(self):
self.session = timeout_session.new_session()
self.thread: Thread
self.parent: tk.Tk
# Handle only sending Live galaxy data
self.legacy_galaxy_last_notified: Optional[datetime] = None
self.lastlocation = None # eventData from the last Commander's Flight Log event
self.lastship = None # eventData from the last addCommanderShip or setCommanderShip event
@ -210,6 +217,7 @@ def plugin_start3(plugin_dir: str) -> str:
def plugin_app(parent: tk.Tk) -> None:
"""Plugin UI setup Hook."""
this.parent = parent
this.system_link = parent.children['system'] # system label in main window
this.station_link = parent.children['station'] # station label in main window
this.system_link.bind_all('<<InaraLocation>>', update_location)
@ -361,6 +369,24 @@ def journal_entry( # noqa: C901, CCR001
:return: str - empty if no error, else error string.
"""
if not monitor.is_live_galaxy():
# This only applies after Update 14, which as of 2022-11-27 is scheduled
# for 2022-11-29, with the game servers presumably being down around
# 09:00
if datetime.now(timezone.utc) >= datetime.fromisoformat("2022-11-27T09:00:00+00:00"):
# Update 14 ETA has passed, so perform the check
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(_("Inara only accepts Live galaxy data"))
# this.parent.children['status']['text'] =
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
return _("Inara only accepts Live galaxy data")
return ''
should_return, new_entry = killswitch.check_killswitch('plugins.inara.journal', entry, logger)
if should_return:
plug.show_error(_('Inara disabled. See Log.')) # LANG: INARA support disabled via killswitch