From e8639988ced80a1f2fc0626150a4267b2f88fd0e Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 8 Nov 2021 16:07:29 +0100 Subject: [PATCH] MultiServer: original_cmd to InvalidPacket --- LttPClient.py | 4 ++-- MultiServer.py | 19 ++++++++++++------- docs/network protocol.md | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/LttPClient.py b/LttPClient.py index a81071cb..a0ba1d9d 100644 --- a/LttPClient.py +++ b/LttPClient.py @@ -144,8 +144,8 @@ class Context(CommonContext): }]) def on_deathlink(self, data: dict): - snes_buffered_write(self, WRAM_START + 0xF36D, bytes([0])) - snes_buffered_write(self, WRAM_START + 0x0373, bytes([8])) + snes_buffered_write(self, WRAM_START + 0xF36D, bytes([0])) # set current health to 0 + snes_buffered_write(self, WRAM_START + 0x0373, bytes([8])) # deal 1 full heart of damage at next opportunity asyncio.create_task(snes_flush_writes(self)) self.death_state = True super(Context, self).on_deathlink(data) diff --git a/MultiServer.py b/MultiServer.py index 4bbf3486..06c5106f 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1203,19 +1203,20 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): cmd: str = args["cmd"] except: logging.exception(f"Could not get command from {args}") - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", + await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", "original_cmd": None, "text": f"Could not get command from {args} at `cmd`"}]) raise if type(cmd) is not str: - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", + await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", "original_cmd": None, "text": f"Command should be str, got {type(cmd)}"}]) return if cmd == 'Connect': if not args or 'password' not in args or type(args['password']) not in [str, type(None)] or \ 'game' not in args: - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", 'text': 'Connect'}]) + await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", 'text': 'Connect', + "original_cmd": cmd}]) return errors = set() @@ -1285,7 +1286,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): elif client.auth: if cmd == "ConnectUpdate": if not args: - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", 'text': cmd}]) + await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", 'text': cmd, + "original_cmd": cmd}]) return if "tags" in args: @@ -1301,7 +1303,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): elif cmd == 'LocationChecks': if "Tracker" in client.tags: await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", - "text": "Trackers can't register new Location Checks"}]) + "text": "Trackers can't register new Location Checks", + "original_cmd": cmd}]) else: register_location_checks(ctx, client.team, client.slot, args["locations"]) @@ -1310,7 +1313,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): for location in args["locations"]: if type(location) is not int or location not in lookup_any_location_id_to_name: await ctx.send_msgs(client, - [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'LocationScouts'}]) + [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'LocationScouts', + "original_cmd": cmd}]) return target_item, target_player = ctx.locations[client.slot][location] locs.append(NetworkItem(target_item, location, target_player)) @@ -1322,7 +1326,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): elif cmd == 'Say': if "text" not in args or type(args["text"]) is not str or not args["text"].isprintable(): - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'Say'}]) + await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'Say', + "original_cmd": cmd}]) return client.messageprocessor(args["text"]) diff --git a/docs/network protocol.md b/docs/network protocol.md index 8758df25..985f9808 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -184,6 +184,7 @@ Sent to clients if the server caught a problem with a packet. This only occurs f | ---- | ---- | ----- | | type | string | "cmd" if the Packet isn't available/allowed, "arguments" if the problem is with the package data. | | text | string | Error text explaining the caught error. | +| original_cmd | string | Echoes the cmd it failed on. May be null if the cmd was not found. ## (Client -> Server) These packets are sent purely from client to server. They are not accepted by clients.