Compare commits

...

3 Commits

Author SHA1 Message Date
Fabian Dill
ba3f695a41 Merge branch 'main' into multiserver_public_data_store_keys 2024-06-03 15:26:44 +02:00
Fabian Dill
03a31ee3b8 Update MultiServer.py 2024-04-09 00:26:34 +02:00
Fabian Dill
001fdfbe9f MultiServer: introduce Get keys that don't need auth 2023-12-04 21:50:10 +01:00

View File

@@ -177,11 +177,11 @@ 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
spheres: typing.List[typing.Dict[int, typing.Set[int]]]
""" each sphere is { player: { location_id, ... } } """
logger: logging.Logger
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",
remaining_mode: str = "disabled", auto_shutdown: typing.SupportsFloat = 0, compatibility: int = 2,
@@ -253,6 +253,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()
@@ -1628,10 +1629,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:
ctx.logger.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`"}])
@@ -1734,6 +1750,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:
@@ -1829,18 +1848,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 \