From d5cdff5ec9a12851f0e1c7a5116daa81be4ac9de Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 13 May 2021 01:37:50 +0200 Subject: [PATCH] filter hints to whom they concern --- MultiServer.py | 14 +++++++++----- NetUtils.py | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 23d96be5..dfb348ae 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -321,16 +321,20 @@ class Context(Node): def notify_hints(ctx: Context, team: int, hints: typing.List[NetUtils.Hint]): - cmd = ctx.dumper([{"cmd": "Hint", "hints" : hints}]) - commands = ctx.dumper([hint.as_network_message() for hint in hints]) - + concerns = collections.defaultdict(list) + for hint in hints: + net_msg = hint.as_network_message() + concerns[hint.receiving_player].append(net_msg) + if not hint.local: + concerns[hint.finding_player].append(net_msg) for text in (format_hint(ctx, team, hint) for hint in hints): logging.info("Notice (Team #%d): %s" % (team + 1, text)) for client in ctx.endpoints: if client.auth and client.team == team: - asyncio.create_task(ctx.send_encoded_msgs(client, cmd)) - asyncio.create_task(ctx.send_encoded_msgs(client, commands)) + client_hints = concerns[client.slot] + if client_hints: + asyncio.create_task(ctx.send_msgs(client, client_hints)) def update_aliases(ctx: Context, team: int, client: typing.Optional[Client] = None): diff --git a/NetUtils.py b/NetUtils.py index 524fb7bf..91c0d937 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -308,3 +308,7 @@ class Hint(typing.NamedTuple): add_json_text(parts, ".") return {"cmd": "PrintJSON", "data": parts, "type": "hint"} + + @property + def local(self): + return self.receiving_player == self.finding_player