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:
+11
-6
@@ -81,9 +81,11 @@ const
|
||||
]
|
||||
|
||||
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).
|
||||
"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).
|
||||
|
||||
type
|
||||
Envelope* = object
|
||||
@@ -148,13 +150,16 @@ proc withN*(node: JsonNode, n: int): JsonNode =
|
||||
result = node
|
||||
result["n"] = %n
|
||||
|
||||
proc helloFrame*(proto, n: int, role: string, playerId: int, name: JsonNode): JsonNode =
|
||||
## DESIGN 6.1 `hello`. The `scene` block and the world fields arrive with slice 5; M3 slice 3
|
||||
## sends what exists: proto, role, me.
|
||||
proc helloFrame*(proto, n: int, role: string, playerId: int, name: JsonNode,
|
||||
scene: JsonNode = nil, extra: JsonNode = nil): JsonNode =
|
||||
## DESIGN 6.1 `hello`. `scene` is the scene block (views.sceneBlock) and `extra` the scene's free
|
||||
## object (GM only); both are absent for an unnamed player, which gets `proto, role, me` only.
|
||||
var me = newJObject()
|
||||
me["id"] = %playerId
|
||||
me["name"] = name # null while the player has no name yet
|
||||
result = %*{"t": "hello", "proto": proto, "role": role, "me": me, "n": n}
|
||||
if not scene.isNil: result["scene"] = scene
|
||||
if not extra.isNil: result["extra"] = extra
|
||||
|
||||
proc ackFrame*(reqId, n: int, extra: JsonNode = nil): JsonNode =
|
||||
## `ack {reqId, ok:true, ...result fields}`; `extra` holds `id`, `key`, `pos`, `ts`.
|
||||
|
||||
Reference in New Issue
Block a user