diff --git a/AHITClient.py b/AHITClient.py index 844e84ac6a..390337108d 100644 --- a/AHITClient.py +++ b/AHITClient.py @@ -9,6 +9,8 @@ from MultiServer import Endpoint from CommonClient import CommonContext, gui_enabled, ClientCommandProcessor, logger, \ get_base_parser +DEBUG = False + class AHITJSONToTextParser(JSONtoTextParser): def _handle_color(self, node: JSONMessagePart): @@ -41,7 +43,6 @@ class AHITContext(CommonContext): self.connected_msg = None self.game_connected = False self.awaiting_info = False - self.log_network = False self.full_inventory: List[Any] = [] self.server_msgs: List[Any] = [] @@ -63,7 +64,7 @@ class AHITContext(CommonContext): if not self.endpoint or not self.endpoint.socket.open or self.endpoint.socket.closed: return False - if self.log_network: + if DEBUG: logger.info(f"Outgoing message: {msgs}") await self.endpoint.socket.send(msgs) @@ -139,12 +140,28 @@ async def proxy(websocket, path: str = "/", ctx: AHITContext = None): async for data in websocket: for msg in decode(data): if msg["cmd"] == "Connect": + # Proxy is connecting, make sure it is valid + if msg["game"] != "A Hat in Time": + logger.info("Aborting proxy connection: game is not A Hat in Time") + await ctx.disconnect_proxy() + break + + if ctx.seed_name: + seed = msg.get("seed", "") + if seed != "" and seed != ctx.seed_name: + logger.info("Aborting proxy connection: seed mismatch from save file") + await ctx.disconnect_proxy() + break + if ctx.connected_msg: await ctx.send_msgs_proxy(ctx.connected_msg) ctx.update_items() continue - if ctx.log_network: + if not ctx.is_proxy_connected(): + break + + if DEBUG: logger.info(f"Incoming message: {msg}") await ctx.send_msgs([msg]) diff --git a/worlds/ahit/__init__.py b/worlds/ahit/__init__.py index 0ae5f0035d..ea8eb1b5b6 100644 --- a/worlds/ahit/__init__.py +++ b/worlds/ahit/__init__.py @@ -170,7 +170,7 @@ class HatInTimeWorld(World): "Chapter6Cost": chapter_timepiece_costs[self.player][ChapterIndex.CRUISE], "Chapter7Cost": chapter_timepiece_costs[self.player][ChapterIndex.METRO], "BadgeSellerItemCount": badge_seller_count[self.player], - "SeedNumber": self.multiworld.seed} # For shop prices + "SeedNumber": str(self.multiworld.seed)} # For shop prices if self.multiworld.HatItems[self.player].value == 0: slot_data.setdefault("SprintYarnCost", hat_yarn_costs[self.player][HatType.SPRINT])