diff --git a/worlds/ahit/Client.py b/worlds/ahit/Client.py index 93a1ad44922..ac574d907f7 100644 --- a/worlds/ahit/Client.py +++ b/worlds/ahit/Client.py @@ -4,7 +4,7 @@ import functools from copy import deepcopy from typing import List, Any, Iterable -from NetUtils import decode, encode, JSONtoTextParser, JSONMessagePart, NetworkItem +from NetUtils import decode, encode, JSONtoTextParser, JSONMessagePart, NetworkItem, NetworkPlayer from MultiServer import Endpoint from CommonClient import CommonContext, gui_enabled, ClientCommandProcessor, logger, get_base_parser @@ -103,10 +103,17 @@ def on_package(self, cmd: str, args: dict): if cmd == "Connected": json = args # This data is not needed and causes the game to freeze for long periods of time in large asyncs. - if json["slot_info"]: + if "slot_info" in json.keys(): json["slot_info"] = {} - if json["players"]: - json["players"] = [] + if "players" in json.keys(): + me: NetworkPlayer + for n in json["players"]: + if n.slot == json["slot"] and n.team == json["team"]: + me = n + break + + # Only put our player info in there as we actually need it + json["players"] = [me] if DEBUG: print(json) self.connected_msg = encode([json]) @@ -118,7 +125,7 @@ def on_package(self, cmd: str, args: dict): elif cmd == "RoomUpdate": # Same story as above json = args - if json["players"]: + if "players" in json.keys(): json["players"] = [] self.server_msgs.append(encode(json)) @@ -182,6 +189,17 @@ async def proxy(websocket, path: str = "/", ctx: AHITContext = None): await ctx.disconnect_proxy() break + if ctx.auth: + name = msg.get("name", "") + if name != "" and name != ctx.auth: + logger.info("Aborting proxy connection: player name mismatch from save file") + logger.info(f"Expected: {ctx.auth}, got: {name}") + text = encode([{"cmd": "PrintJSON", + "data": [{"text": "Connection aborted - player name mismatch"}]}]) + await ctx.send_msgs_proxy(text) + await ctx.disconnect_proxy() + break + if ctx.connected_msg and ctx.is_connected(): await ctx.send_msgs_proxy(ctx.connected_msg) ctx.update_items()