Skip to content

Commit

Permalink
MultiServer: Notify clients of hint points (ArchipelagoMW#1548)
Browse files Browse the repository at this point in the history
* notify clients of their amount of hint points on initial connection and when hinting

* send in connect packet instead of sending a RoomUpdate on connect

* send hint_points update in `on_new_hint`

* add to connected packet docs

* hint_points isn't a new variable on RoomUpdate now

* note roomupdate can contain connected members

* add the hint point stuff to commonclient

* only show hint points when relevant and default to 0

* Revert "note roomupdate can contain connected members"

* remove hint_points from roomupdate args list and condense explanation of possible packet args

* updates from phar's review

* Small tweak to wording in RoomUpdate

---------

Co-authored-by: Fabian Dill <[email protected]>
Co-authored-by: Phar <[email protected]>
  • Loading branch information
3 people authored Apr 10, 2023
1 parent c7284f9 commit 77fbd0e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class CommonContext:
server_address: typing.Optional[str]
password: typing.Optional[str]
hint_cost: typing.Optional[int]
hint_points: typing.Optional[int]
player_names: typing.Dict[int, str]

finished_game: bool
Expand Down Expand Up @@ -711,6 +712,7 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
ctx.slot = args["slot"]
# int keys get lost in JSON transfer
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
ctx.hint_points = args.get("hint_points", 0)
ctx.consume_players_package(args["players"])
msgs = []
if ctx.locations_checked:
Expand Down
7 changes: 6 additions & 1 deletion MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ def on_new_hint(self, team: int, slot: int):
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.broadcast(self.clients[team][slot], [{
"cmd": "RoomUpdate",
"hint_points": get_slot_points(self, team, slot)
}])


def update_aliases(ctx: Context, team: int):
Expand Down Expand Up @@ -1639,7 +1643,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
"players": ctx.get_players_package(),
"missing_locations": get_missing_checks(ctx, team, slot),
"checked_locations": get_checked_checks(ctx, team, slot),
"slot_info": ctx.slot_info
"slot_info": ctx.slot_info,
"hint_points": get_slot_points(ctx, team, slot),
}
reply = [connected_packet]
start_inventory = get_start_inventory(ctx, slot, client.remote_start_inventory)
Expand Down
22 changes: 11 additions & 11 deletions docs/network protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ Sent to clients when the connection handshake is successfully completed.
| missing_locations | list\[int\] | Contains ids of remaining locations that need to be checked. Useful for trackers, among other things. |
| checked_locations | list\[int\] | Contains ids of all locations that have been checked. Useful for trackers, among other things. Location ids are in the range of ± 2<sup>53</sup>-1. |
| slot_data | dict\[str, any\] | Contains a json object for slot related data, differs per game. Empty if not required. Not present if slot_data in [Connect](#Connect) is false. |
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information |
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information. |
| hint_points | int | Number of hint points that the current player has. |

### ReceivedItems
Sent to clients when they receive an item.
Expand All @@ -146,17 +147,16 @@ Sent to clients to acknowledge a received [LocationScouts](#LocationScouts) pack
| locations | list\[[NetworkItem](#NetworkItem)\] | Contains list of item(s) in the location(s) scouted. |

### RoomUpdate
Sent when there is a need to update information about the present game session. Generally useful for async games.
Once authenticated (received Connected), this may also contain data from Connected.
Sent when there is a need to update information about the present game session.
#### Arguments
The arguments for RoomUpdate are identical to [RoomInfo](#RoomInfo) barring:

| Name | Type | Notes |
| ---- | ---- | ----- |
| hint_points | int | New argument. The client's current hint points. |
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Send in the event of an alias rename. Always sends all players, whether connected or not. |
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
| missing_locations | list\[int\] | Should never be sent as an update, if needed is the inverse of checked_locations. |
RoomUpdate may contain the same arguments from [RoomInfo](#RoomInfo) and, once authenticated, arguments from
[Connected](#Connected) with the following exceptions:

| Name | Type | Notes |
|-------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Sent in the event of an alias rename. Always sends all players, whether connected or not. |
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
| missing_locations | - | Never sent in this packet. If needed, it is the inverse of `checked_locations`. |

All arguments for this packet are optional, only changes are sent.

Expand Down
6 changes: 3 additions & 3 deletions kvui.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ def get_text(self):
min_cost = int(ctx.server_version >= (0, 3, 9))
text += f"\nA new !hint <itemname> costs {ctx.hint_cost}% of checks made. " \
f"For you this means every " \
f"{max(min_cost, int(ctx.hint_cost * 0.01 * ctx.total_locations))}" \
f" location checks."
f"{max(min_cost, int(ctx.hint_cost * 0.01 * ctx.total_locations))} " \
"location checks." \
f"\nYou currently have {ctx.hint_points} points."
elif ctx.hint_cost == 0:
text += "\n!hint is free to use."

else:
text += f"\nYou are not authenticated yet."

Expand Down

0 comments on commit 77fbd0e

Please sign in to comment.