server: wall and door intents, GM wall snapshot and fan-out (#19)

wall.add, wall.update, wall.remove and door.set leave the unknown-type rollout
list: field shapes and ranges per 6.1 (and the payload rules recorded FIXED in
4.4/6.1), lookup failures not-found, non-GM refused by the existing GM-only
gate. wall.add acks {id} from the scene's next_wall_id; wall.update patches
a/b/kind/flags only (open belongs to door.set); door.set is invalid on a plain
wall. Effects go to every GM connection only: wall / wall_gone, plus one walls
snapshot right after hello (the wall part of the 6.3 resync). Players receive
no wall data in any message (3.1, T2).

protocol.nim gains the wallObject/wallsFrame/wallFrame/wallGoneFrame builders
(no n: the sender stamps it per recipient) and the five wall intents in the
implemented set.
This commit is contained in:
2026-11-15 08:49:20 +01:00
parent bf9ab3edfd
commit a8f508ef2e
3 changed files with 291 additions and 8 deletions
+26 -3
View File
@@ -11,6 +11,7 @@
## decision (#18, option A): the server sends one final `closing {reason, code}` message and then
## closes; the client reads the reason from that message and 1005 from the close event.
import std/[json, monotimes, unicode]
import geometry
const
ProtoVersion* = 1
@@ -79,9 +80,10 @@ const
"name.reveal", "name.reveal_all", "encountered.remove",
]
ImplementedIntents* = ["conn.ping", "act.do", "key.create", "key.replace", "player.remove"]
## What this slice actually handles. The rest of the catalogue answers `unknown-type` until
## its slice lands (DESIGN 6.1 note, #18).
ImplementedIntents* = ["conn.ping", "act.do", "key.create", "key.replace", "player.remove",
"wall.add", "wall.update", "wall.remove", "door.set"]
## What the built slices actually handle (slice 3 #18 plus slice 4 #19's walls and doors).
## The rest of the catalogue answers `unknown-type` until its slice lands (DESIGN 6.1 note).
type
Envelope* = object
@@ -179,6 +181,27 @@ 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}
# 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.
proc wallObject*(id: int, a, b: Vec, kind: string, open: bool, flags: JsonNode): JsonNode =
## One wall as the wire shows it: the same shape inside `walls` and in a `wall` upsert.
%*{"id": id, "a": [a.x, a.y], "b": [b.x, b.y], "kind": kind, "open": open,
"flags": (if flags.isNil: newJObject() else: flags)}
proc wallsFrame*(scene: int, walls: seq[JsonNode]): JsonNode =
## The GM snapshot of every wall in the scene (DESIGN 6.1 `walls`, 6.3: on connect and resync).
%*{"t": "walls", "scene": scene, "walls": walls}
proc wallFrame*(scene: int, wall: JsonNode): JsonNode =
## `wall` upsert (doors included; this replaces the prototype's `door` message).
result = %*{"t": "wall", "scene": scene}
for key, value in wall: result[key] = value
proc wallGoneFrame*(scene, id: int): JsonNode =
%*{"t": "wall_gone", "scene": scene, "id": id}
# ---------------------------------------------------------------------------------------------------
# Intent rate limit (DESIGN 6.4)