server: typed recipient views and the single egress (#20)

server/views.nim is the only place where world state becomes bytes: a Recipient
builds a GmTokenView or a PlayerTokenView first, and only then a frame. Player
frames carry the public props bucket (plus owner for the controller), the
controller's vision_radius, and never kind, controller, gm_only, flags, radius_own
or either raw name; the GM gets all of it plus both names. The per-connection Known
table diffs on the built frame, so token/token_gone are exactly the changes and the
vision frame is re-sent only when the polygons move.

server/faults.nim compiles the negative-control hook only with -d:leakfault; the
shipped binary contains no LEAK_FAULT string and tools/fault.test.mjs asserts it.

hello gains the scene block (and extra for the GM); the protocol's implemented set
now names the four token intents.
This commit is contained in:
2026-11-15 09:35:14 +01:00
parent e6b53e06f5
commit 5f5bf3293b
5 changed files with 542 additions and 8 deletions
+16 -2
View File
@@ -40,7 +40,7 @@ suite "envelope (6.5 step 2)":
test "the catalogue is the 29 intents of 6.1 and the built set is a subset":
check IntentCatalogue.len == 29
check ImplementedIntents.len == 9 # slice 3's five + slice 4's four wall intents
check ImplementedIntents.len == 13 # slice 3's five + slice 4's four walls + slice 5's four token intents
for t in ImplementedIntents:
check t in IntentCatalogue
check isCatalogueIntent(t)
@@ -61,9 +61,13 @@ suite "envelope (6.5 step 2)":
for t in ["wall.add", "wall.update", "wall.remove", "door.set"]:
check isImplementedIntent(t)
check isGmOnlyIntent(t) # walls are GM-only (3.1, T2)
for t in ["token.create", "token.update", "token.move", "token.remove"]:
check isImplementedIntent(t)
check not isImplementedIntent("player.setname")
check not isImplementedIntent("scene.set")
check not isImplementedIntent("token.create")
check not isImplementedIntent("token.resize")
check not isImplementedIntent("status.set")
check not isImplementedIntent("character.create")
suite "intent rate limit (6.4: 30/s, burst 100)":
test "a fresh bucket allows exactly the burst, then refuses":
@@ -137,6 +141,8 @@ suite "malformed flood (6.5 row 8: 10 inside any 10 s)":
suite "server frames (6.1)":
test "hello carries proto, role, me and n; an unnamed player's name is null":
let h = helloFrame(ProtoVersion, 1, "player", 4, newJNull())
check not h.hasKey("scene") # an unnamed player gets proto, role, me only (6.1)
check not h.hasKey("extra")
check h["t"].getStr == "hello"
check h["proto"].getInt == 1
check h["role"].getStr == "player"
@@ -146,6 +152,14 @@ suite "server frames (6.1)":
let named = helloFrame(ProtoVersion, 2, "gm", 1, %"GM")
check named["me"]["name"].getStr == "GM"
test "a named recipient's hello carries the scene block, and the GM also `extra`":
let sceneJson = %*{"id": 1, "w": 4096}
let p = helloFrame(ProtoVersion, 3, "player", 4, %"Alice", sceneJson)
check p["scene"]["id"].getInt == 1
check not p.hasKey("extra")
let gm = helloFrame(ProtoVersion, 4, "gm", 1, %"GM", sceneJson, %*{})
check gm["extra"].kind == JObject
test "ack ok carries its result fields and never a code":
let a = ackFrame(9, 3, %*{"key": "ABCD-EFGH"})
check a["t"].getStr == "ack"