MultiServer: introduce Get keys that don't need auth

This commit is contained in:
Fabian Dill
2023-12-04 21:50:10 +01:00
parent a861ede8b3
commit 001fdfbe9f

View File

@@ -175,6 +175,7 @@ class Context:
all_item_and_group_names: typing.Dict[str, typing.Set[str]]
all_location_and_group_names: typing.Dict[str, typing.Set[str]]
non_hintable_names: typing.Dict[str, typing.Set[str]]
public_stored_data_keys = typing.Set[str] # keys that can be retrieved by a client that has not reached "auth" yet
def __init__(self, host: str, port: int, server_password: str, password: str, location_check_points: int,
hint_cost: int, item_cheat: bool, release_mode: str = "disabled", collect_mode="disabled",
@@ -245,6 +246,7 @@ class Context:
self.all_item_and_group_names = {}
self.all_location_and_group_names = {}
self.non_hintable_names = collections.defaultdict(frozenset)
self.public_stored_data_keys = set()
self._load_game_data()
@@ -1579,10 +1581,25 @@ def get_slot_points(ctx: Context, team: int, slot: int) -> int:
ctx.get_hint_cost(slot) * ctx.hints_used[team, slot])
async def process_get(ctx: Context, client: Client, args: dict, cmd: dict):
if "keys" not in args or not isinstance(args["keys"], list):
await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments",
"text": 'Retrieve', "original_cmd": cmd}])
return
args["cmd"] = "Retrieved"
keys = args["keys"]
args["keys"] = {
key: ctx.read_data.get(key[6:], lambda: None)() if key.startswith("_read_") else
ctx.stored_data.get(key, None)
for key in keys
}
await ctx.send_msgs(client, [args])
async def process_client_cmd(ctx: Context, client: Client, args: dict):
try:
cmd: str = args["cmd"]
except:
except Exception:
logging.exception(f"Could not get command from {args}")
await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "cmd", "original_cmd": None,
"text": f"Could not get command from {args} at `cmd`"}])
@@ -1683,6 +1700,9 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
await ctx.send_msgs(client, [{"cmd": "DataPackage",
"data": {"games": ctx.gamespackage}}])
elif cmd == "Get" and args.get("keys", None) and all(key in ctx.public_stored_data_keys for key in args["keys"]):
await process_get(ctx, client, args, cmd)
elif client.auth:
if cmd == "ConnectUpdate":
if not args:
@@ -1778,18 +1798,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
await ctx.send_encoded_msgs(bounceclient, msg)
elif cmd == "Get":
if "keys" not in args or type(args["keys"]) != list:
await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments",
"text": 'Retrieve', "original_cmd": cmd}])
return
args["cmd"] = "Retrieved"
keys = args["keys"]
args["keys"] = {
key: ctx.read_data.get(key[6:], lambda: None)() if key.startswith("_read_") else
ctx.stored_data.get(key, None)
for key in keys
}
await ctx.send_msgs(client, [args])
await process_get(ctx, client, args, cmd)
elif cmd == "Set":
if "key" not in args or args["key"].startswith("_read_") or \