Skip to content

Commit

Permalink
MultiServer: SetReply _read_hints_{team}_{slot} update when item(s)…
Browse files Browse the repository at this point in the history
… found.
  • Loading branch information
ThePhar committed Nov 27, 2023
1 parent f54f862 commit e6cf7f8
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,14 @@ def notify_hints(self, team: int, hints: typing.List[NetUtils.Hint], only_new: b
for client in clients:
async_start(self.send_msgs(client, client_hints))

def notify_hints_update(self, team: int, *slots: int):
"""Broadcast update to read-only hints key for relevant slots."""
for slot in slots:
key: str = f"_read_hints_{team}_{slot}"
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
if targets:
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])

# "events"

def on_goal_achieved(self, client: Client):
Expand All @@ -705,10 +713,7 @@ def on_goal_achieved(self, client: Client):
self.save() # save goal completion flag

def on_new_hint(self, team: int, slot: int):
key: str = f"_read_hints_{team}_{slot}"
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
if targets:
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])
self.notify_hints_update(team, slot)
self.broadcast(self.clients[team][slot], [{
"cmd": "RoomUpdate",
"hint_points": get_slot_points(self, team, slot)
Expand Down Expand Up @@ -955,18 +960,34 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations: typi
if new_locations:
if count_activity:
ctx.client_activity_timers[team, slot] = datetime.datetime.now(datetime.timezone.utc)

ctx.location_checks[team, slot] |= new_locations
slots_with_updated_hints: typing.Set[int] = set()
hint_locations_to_receiver: typing.Dict[int, int] = {
hint.location: hint.receiving_player
for hint in ctx.get_rechecked_hints(team, slot)
if hint.finding_player == slot
}

for location in new_locations:
item_id, target_player, flags = ctx.locations[slot][location]
new_item = NetworkItem(item_id, location, slot, flags)
send_items_to(ctx, team, target_player, new_item)
if location in hint_locations_to_receiver:
slots_with_updated_hints.add(slot)
if hint_locations_to_receiver[location] not in slots_with_updated_hints:
ctx.recheck_hints(team, hint_locations_to_receiver[location])
slots_with_updated_hints.add(hint_locations_to_receiver[location])

logging.info('(Team #%d) %s sent %s to %s (%s)' % (
team + 1, ctx.player_names[(team, slot)], ctx.item_names[item_id],
ctx.player_names[(team, target_player)], ctx.location_names[location]))
info_text = json_format_send_event(new_item, target_player)
ctx.broadcast_team(team, [info_text])

ctx.location_checks[team, slot] |= new_locations
if slots_with_updated_hints:
ctx.notify_hints_update(team, *slots_with_updated_hints)

send_new_items(ctx)
ctx.broadcast(ctx.clients[team][slot], [{
"cmd": "RoomUpdate",
Expand Down

0 comments on commit e6cf7f8

Please sign in to comment.