server: characters, names and the encountered list in the one egress (#23)

This commit is contained in:
2026-11-15 12:01:26 +01:00
parent 75c3e046f8
commit 5977d45a5a
2 changed files with 307 additions and 63 deletions
+27 -6
View File
@@ -80,12 +80,18 @@ const
"name.reveal", "name.reveal_all", "encountered.remove",
]
ImplementedIntents* = ["conn.ping", "act.do", "key.create", "key.replace", "player.remove",
ImplementedIntents* = ["conn.ping", "act.do", "key.create", "key.replace", "key.show",
"player.setname", "player.rename", "player.remove",
"wall.add", "wall.update", "wall.remove", "door.set",
"token.create", "token.update", "token.move", "token.remove"]
## What the built slices actually handle (slice 3 #18, slice 4 #19's walls and doors, slice 5
## #20's tokens and sight). The rest of the catalogue answers `unknown-type` until its slice
## lands (DESIGN 6.1 note).
"token.create", "token.update", "token.move", "token.resize",
"token.remove", "status.set", "status.clear", "prop.set", "prop.unset",
"character.create", "character.update", "character.remove",
"character.reassign", "name.reveal", "name.reveal_all",
"encountered.remove"]
## What the built slices actually handle (slice 3 #18: the shell and the auth intents; slice 4
## #19: walls and doors; slice 5 #20: tokens and sight; slice 7 #22: sizes, statuses and props;
## slice 8 #23: characters, names, encountered, and the players/keys rows). Only `scene.set`
## still answers `unknown-type` (DESIGN 6.1 note).
type
Envelope* = object
@@ -147,7 +153,11 @@ proc isImplementedIntent*(t: string): bool =
# starts at 1 on the connection's first frame and counts server frames only.
proc withN*(node: JsonNode, n: int): JsonNode =
result = node
## Stamps the per-connection counter on a copy. The copy is load-bearing: the egress keeps the
## frame it built in the connection's `known` table as the diff base, and mutating that node here
## would make the *next* comparison see a different frame and re-send state nobody changed (T11,
## 6.4). A deep copy of one frame is cheap next to a send.
result = copy(node)
result["n"] = %n
proc helloFrame*(proto, n: int, role: string, playerId: int, name: JsonNode,
@@ -186,6 +196,17 @@ proc closingFrame*(reason: string, code, n: int): JsonNode =
## reason and the code the close frame cannot carry at the mummy pin.
%*{"t": "closing", "reason": reason, "code": code, "n": n}
proc rosterFrame*(players: seq[JsonNode]): JsonNode =
## `roster {players:[{id, name, role, colour, connected}]}` (6.1): the full list every time, so a
## client never merges. The caller already dropped what this recipient may not see (players get
## named players only, 6.1 leak note 4); the frame itself takes no `n` because it is fanned out to
## several recipients, like the wall frames.
%*{"t": "roster", "players": players}
proc rosterEntry*(id: int, name: JsonNode, role: string, colour: string,
connected: bool): JsonNode =
%*{"id": id, "name": name, "role": role, "colour": colour, "connected": connected}
# Walls and doors (DESIGN 6.1, GM only; slice 4 / #19). These three builders deliberately take NO
# `n`: they are the only frames fanned out to several recipients at once (every GM connection), and
# each recipient gets its own number, added by the sender with `withN` right before the send.