Skip to content

Commit

Permalink
Update Client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CookieCat45 committed Jul 30, 2024
1 parent 63874e1 commit 8a65f7f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions worlds/ahit/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
Expand All @@ -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))
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8a65f7f

Please sign in to comment.