From 8184e9940989be08961cf8aedd248af0efb28976 Mon Sep 17 00:00:00 2001 From: espeon65536 Date: Wed, 25 May 2022 23:10:51 -0500 Subject: [PATCH] OoT: add version check to lua script + client --- OoTClient.py | 35 ++++++++++++++++++++++------------ data/lua/OOT/oot_connector.lua | 4 +++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/OoTClient.py b/OoTClient.py index ca758c7b..95d315f9 100644 --- a/OoTClient.py +++ b/OoTClient.py @@ -48,6 +48,7 @@ deathlink_sent_this_death: we interacted with the multiworld on this death, wait oot_loc_name_to_id = network_data_package["games"]["Ocarina of Time"]["location_name_to_id"] +script_version: int = 1 def get_item_value(ap_id): return ap_id - 66000 @@ -78,6 +79,7 @@ class OoTContext(CommonContext): self.deathlink_enabled = False self.deathlink_pending = False self.deathlink_sent_this_death = False + self.version_warning = False async def server_auth(self, password_requested: bool = False): if password_requested and not self.password: @@ -166,21 +168,30 @@ async def n64_sync_task(ctx: OoTContext): try: await asyncio.wait_for(writer.drain(), timeout=1.5) try: - # Data will return a dict with up to five fields: + # Data will return a dict with up to six fields: # 1. str: player name (always) - # 2. bool: deathlink active (always) - # 3. dict[str, bool]: checked locations - # 4. bool: whether Link is currently at 0 HP - # 5. bool: whether the game currently registers as complete + # 2. int: script version (always) + # 3. bool: deathlink active (always) + # 4. dict[str, bool]: checked locations + # 5. bool: whether Link is currently at 0 HP + # 6. bool: whether the game currently registers as complete data = await asyncio.wait_for(reader.readline(), timeout=10) data_decoded = json.loads(data.decode()) - if ctx.game is not None and 'locations' in data_decoded: - # Not just a keep alive ping, parse - asyncio.create_task(parse_payload(data_decoded, ctx, False)) - if not ctx.auth: - ctx.auth = data_decoded['playerName'] - if ctx.awaiting_rom: - await ctx.server_auth(False) + reported_version = data_decoded.get('scriptVersion', 0) + if reported_version == script_version: + if ctx.game is not None and 'locations' in data_decoded: + # Not just a keep alive ping, parse + asyncio.create_task(parse_payload(data_decoded, ctx, False)) + if not ctx.auth: + ctx.auth = data_decoded['playerName'] + if ctx.awaiting_rom: + await ctx.server_auth(False) + else: + if not ctx.version_warning: + logger.warning(f"Your Lua script is version {reported_version}, expected {script_version}. " + "Please update to the latest version. " + "Your connection to the Archipelago server will not be accepted.") + ctx.version_warning = True except asyncio.TimeoutError: logger.debug("Read Timed Out, Reconnecting") error_status = CONNECTION_TIMING_OUT_STATUS diff --git a/data/lua/OOT/oot_connector.lua b/data/lua/OOT/oot_connector.lua index bfb41ed0..97171814 100644 --- a/data/lua/OOT/oot_connector.lua +++ b/data/lua/OOT/oot_connector.lua @@ -2,7 +2,8 @@ local socket = require("socket") local json = require('json') local math = require('math') -local script_version = '2022-03-22' -- Should be the last modified date +local last_modified_date = '2022-05-25' -- Should be the last modified date +local script_version = 1 -------------------------------------------------- -- Heavily modified form of RiptideSage's tracker @@ -1781,6 +1782,7 @@ function receive() -- Determine message to send back local retTable = {} retTable["playerName"] = get_player_name() + retTable["scriptVersion"] = script_version retTable["deathlinkActive"] = deathlink_enabled() if InSafeState() then retTable["locations"] = check_all_locations(master_quest_table_address)