From 53ab224fba18b5f0805db3a90f6667753cbe01fd Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 22 Feb 2022 12:17:21 +0100 Subject: [PATCH] MultiServer: rip Store, Modify -> Set, Retrieve -> Get, Modified -> SetReply, ModifyNotify -> SetNotify --- MultiServer.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 9dced8ec..570caf24 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1525,15 +1525,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): bounceclient.slot in slots): await ctx.send_encoded_msgs(bounceclient, msg) - elif cmd == "Store": - if "data" not in args or type(args["data"]) != dict: - await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", - "text": 'Store', "original_cmd": cmd}]) - return - for key, value in args["data"].items(): - ctx.stored_data[key] = value - - elif cmd == "Retrieve": + elif cmd == "Get": if "data" not in args or type(args["data"]) != list: await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'Retrieve', "original_cmd": cmd}]) @@ -1543,26 +1535,28 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): args["data"] = {key: ctx.stored_data.get(key, None) for key in keys} await ctx.send_msgs(client, [args]) - elif cmd == "Modify": + elif cmd == "Set": if "key" not in args or "value" not in args: await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", - "text": 'Modify', "original_cmd": cmd}]) + "text": 'Set', "original_cmd": cmd}]) return - args["cmd"] = "Modified" + args["cmd"] = "SetReply" value = ctx.stored_data.get(args["key"], args.get("default", 0)) args["original_value"] = value - operation = args.get("operation", "add") + operation = args.get("operation", "replace") func = modify_functions[operation] value = func(value, args.get("value")) ctx.stored_data[args["key"]] = args["value"] = value targets = set(ctx.stored_data_notification_clients[args["key"]]) - targets.add(client) - ctx.broadcast(targets, [args]) + if args.get("want_reply", True): + targets.add(client) + if targets: + ctx.broadcast(targets, [args]) - elif cmd == "ModifyNotify": + elif cmd == "SetNotify": if "data" not in args or type(args["data"]) != list: await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", - "text": 'ModifyNotify', "original_cmd": cmd}]) + "text": 'SetNotify', "original_cmd": cmd}]) return for key in args["data"]: ctx.stored_data_notification_clients[key].add(client)