1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-19 02:17:38 +03:00

Merge pull request from EDCD/enhancement/1715/inara-live-galaxy-only

inara: Send only Live galaxy data after Update 14
This commit is contained in:
Athanasius 2022-11-27 13:55:35 +00:00 committed by GitHub
commit 642d1912d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

@ -21,6 +21,8 @@ from typing import Tuple
if TYPE_CHECKING: if TYPE_CHECKING:
import tkinter import tkinter
import semantic_version
import util_ships import util_ships
from config import config from config import config
from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised 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 # Context for journal handling
self.version: Optional[str] = None self.version: Optional[str] = None
self.version_semantic: Optional[semantic_version.Version] = None
self.is_beta = False self.is_beta = False
self.mode: Optional[str] = None self.mode: Optional[str] = None
self.group: 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._fcmaterials_retries_remaining = 0
self._last_fcmaterials_journal_timestamp: Optional[float] = None 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() self.__init_state()
def __init_state(self) -> None: def __init_state(self) -> None:
@ -293,6 +301,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.currentdir = None self.currentdir = None
self.version = None self.version = None
self.version_semantic = None
self.mode = None self.mode = None
self.group = None self.group = None
self.cmdr = None self.cmdr = None
@ -1677,6 +1686,20 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['GameVersion'] = entry['gameversion'] self.state['GameVersion'] = entry['gameversion']
self.state['GameBuild'] = entry['build'] self.state['GameBuild'] = entry['build']
self.version = self.state['GameVersion'] self.version = self.state['GameVersion']
try:
self.version_semantic = semantic_version.Version.coerce(self.state['GameVersion'])
except Exception:
# Catching all Exceptions as this is *one* call, and we won't
# get caught out by any semantic_version changes.
self.version_semantic = None
logger.error(f"Couldn't coerce {self.state['GameVersion']=}")
pass
else:
logger.info(f"Parsed {self.state['GameVersion']=} into {self.version_semantic=}")
self.is_beta = any(v in self.version.lower() for v in ('alpha', 'beta')) # type: ignore self.is_beta = any(v in self.version.lower() for v in ('alpha', 'beta')) # type: ignore
except KeyError: except KeyError:
if not suppress: if not suppress:
@ -2348,6 +2371,25 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self._last_fcmaterials_journal_timestamp = None self._last_fcmaterials_journal_timestamp = None
return file 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 # singleton
monitor = EDLogs() monitor = EDLogs()

@ -28,6 +28,7 @@ import time
import tkinter as tk import tkinter as tk
from collections import OrderedDict, defaultdict, deque from collections import OrderedDict, defaultdict, deque
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from operator import itemgetter from operator import itemgetter
from threading import Lock, Thread from threading import Lock, Thread
from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, List, Mapping, NamedTuple, Optional 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 companion import CAPIData
from config import applongname, appversion, config, debug_senders from config import applongname, appversion, config, debug_senders
from EDMCLogging import get_main_logger from EDMCLogging import get_main_logger
from monitor import monitor
from ttkHyperlinkLabel import HyperlinkLabel from ttkHyperlinkLabel import HyperlinkLabel
logger = get_main_logger() logger = get_main_logger()
@ -88,6 +90,11 @@ class This:
def __init__(self): def __init__(self):
self.session = timeout_session.new_session() self.session = timeout_session.new_session()
self.thread: Thread 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.lastlocation = None # eventData from the last Commander's Flight Log event
self.lastship = None # eventData from the last addCommanderShip or setCommanderShip 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: def plugin_app(parent: tk.Tk) -> None:
"""Plugin UI setup Hook.""" """Plugin UI setup Hook."""
this.parent = parent
this.system_link = parent.children['system'] # system label in main window this.system_link = parent.children['system'] # system label in main window
this.station_link = parent.children['station'] # station label in main window this.station_link = parent.children['station'] # station label in main window
this.system_link.bind_all('<<InaraLocation>>', update_location) 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. :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) should_return, new_entry = killswitch.check_killswitch('plugins.inara.journal', entry, logger)
if should_return: if should_return:
plug.show_error(_('Inara disabled. See Log.')) # LANG: INARA support disabled via killswitch plug.show_error(_('Inara disabled. See Log.')) # LANG: INARA support disabled via killswitch