The typed views carry the bucket filter: `PlayerTokenView` has `propsPublic`
always and `propsOwner` only when the recipient controls the token, and no
field for the `gm` bucket at all, so a later change to the frame builder
cannot leak one. Statuses are `StatusKind` values for a player (no `source`,
5.5/6.1 note 6) and full `(status, source)` entries for the GM.
Both negative controls for the new rules live behind `-d:leakfault` and in
the type, so the shipped binary has neither the fields nor the branches:
`gmProp` (the gm bucket reaches a player), `ownerProp` (the owner bucket
reaches a non-controller) and `statusSource` (a viewer learns the cause).
The `otherOwner` fault now carries the owner bucket too, so it stays one
class (the `mine` claim) instead of also tripping the bucket check.
moverules.nim replaces the M2 `blocked` bool with the 5.5 status model: the
rules own the `walls` source (`stuckWalls`, `squeezedWalls`) and take
`locked` (any entry, any source) as input, so a GM-sourced lock refuses a
player move without the rules ever knowing what caused it. Identity is kept
on KEEP, cleared on CLEAR, and only tokens the event touches change.
Every geometry path now uses the token's own radius (5.6): the overlap test,
the escape check, the capsule, the door push and the step cap's neighbour
rules. `resizeToken` implements 5.6: a shrink never pushes and clears the
walls entries only when the overlap ends, a grow that overlaps is displaced
by a deterministic greedy relaxation (radial off the first overlapped wall,
scene order, at most 16 rounds, one flipped-side pass) and a grow that cannot
be placed stays put and becomes squeezed(walls). A step whose centre path
would cross a wall ends the pass, so the relaxation never carries a token
through a wall.
worldmap.nim is the bridge: `ruleToken`/`ruleWall`/`moveScene` build the
rules' input from the records, `applyOutcome` copies the position, the
door-push history and the walls-sourced entries back, and `wallsStatuses`
does the same for a caller that writes its own row. All of them return fresh
sequences instead of mutating a shared one.
Migration step 6 ("token details") adds the three prop buckets to `entity`
and creates `entity_status`, the `(status, source)` set of 5.5. A token's
status rows are rewritten with its row, so a status change and the `token`
frame that reports it commit together.
server/props.nim owns the buckets, their caps (64 keys per bucket, a key of
1..64 code points, a value of at most 8 KB of serialized JSON) and the
property-schema registry: empty at start with a permissive fallback, because
DESIGN 8 says v1 never interprets props; a key the rules module registers is
enforced (kind and bucket). server/text.nim is the one copy of the 6.5 text
rule, shared by names and prop keys.
tokens.nim gains `props` and `statuses` on the record, the sorted-unique
entry helpers, `isLocked`, `parseRadius`/`parseStatusKind`/`parseStatusSource`,
the prop and status columns in insert/replace, and `loadStatuses` joined on
the scene. Every helper builds a fresh sequence: a copied record shares its
seq buffer, so an in-place edit would reach the authoritative list before
the transaction commits (4.2 step 6).
Startup restores each player's grid from its chunk rows (explored_loaded log) and every
mutation writes only the chunks its refresh dirtied, in the mutation's transaction: a move
keeps position and chunks in one NORMAL commit, a GM authoring write adds one NORMAL chunk
transaction under the same lock, before the ack. db.withTransaction is the shared seam.
Migration step 5 creates explored_chunk: one 512-byte bitmap per (player, scene, 64x64-cell
chunk), both FKs cascading. server/explored.nim owns the format (row-major, LSB-first bits),
dirty-chunk detection, the upsert and the startup restore. tests/texplored.nim pins the layout,
the whole-chunk encoding, the upsert replacement, the per-player keying, the restore and the
write cost (0.015 ms avg / 0.035 ms p99); tests/tdb.nim covers step 5 and a schema-4 fixture.
token.create/update/remove (GM) and token.move (controller, or GM) through
moverules: the uniform nack for locked/over-cap/collision and for an out-of-bounds
GM move, one not-allowed code for a player's unknown and not-yours targets, not-found
for the GM; accepted moves are persisted with NORMAL durability and the mover's
vision recomputed. token.update honours kind, both names, controller, gm_only,
flags and vision_radius, and refuses character_id until slice 8.
connect now sends hello, the GM walls snapshot and the 6.3 token half (vision,
explored full, tokens) under the global lock, so hello is always the first frame and
the resync is the diff base. Egress runs under the same lock, per mutation, so no two
threads touch a connection's known table and an unnamed player is never fed state.
door.set applies the 5.5 push: the move rules compute the new positions against the
pre-write state, the positions are persisted in one transaction, then memory and
vision follow (stuck/squeezed are slice 7). player.remove hands the controlled
tokens to the GM in memory as the FK already does in the DB.
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.
server/vision.nim keeps one PlayerVision per player: a visibility polygon per
controlled token carrying the vision flag (range = the token's vision_radius or the
scene default), the explored set as the union of cellsTouched over history (only
grows, cells outside the world dropped), and the fresh cells of the current
mutation. The token-visibility rule of 3.1 (controlled always, otherwise inside own
LOS and not gm_only) exists exactly once there.
server/worldmap.nim translates the authoritative records into the inputs the pure
geometry and move-rule modules take, so those modules never see a wire field.
Migration step 4 ("tokens") creates the entity table: the token id, scene, kind,
both names, position, nullable radius/owner/vision_radius, gm_only and flags. A
NULL owner is GM-controlled, so player.remove hands that player's tokens to the GM
through the FK; radius, props and character_id stay out until slices 7-8.
server/tokens.nim holds the record, the 6.1 field rules (12 CSPRNG characters from
a 64-symbol alphabet, trimmed names, kind, positive vision_radius), the write-through
persistence (FULL for GM authoring, NORMAL for a move) and the loader. db_connector
quotes every argument, so the three nullable columns are emitted as numeric literals
while text still goes through ? arguments.
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.
Migration step 3 ("world") creates scene and wall and seeds the single v1 scene
(id 1, 4096x4096, tile = cell 32, vision 400, token radius 20, art_version 1,
next_wall_id 1). server/world.nim holds the in-memory scene with SQLite as
write-through persistence: per-scene wall ids from next_wall_id (monotonic,
never reused, #3), 6.1 validation (a != b, in bounds, a wall is never open),
flags as an opaque JSON object, and one transaction with synchronous=FULL
around every GM authoring write (Q12); memory follows COMMIT, so a failed
write leaves both sides unchanged.
Tests: tests/tworld.nim (ids, reload, doors, validation, pragma, failed write),
tests/tdb.nim (version 3, history, a slice-2 DB migrating to slice 3).
The protocol shell over the socket, in DESIGN 6.5 order: spend a token, parse, then
unknown type / unnamed player / role / fields / lookup / semantics. Every readable
intent gets exactly one ack with a 6.5 code; an unreadable frame gets one error.
- hello {proto, role, me} as the first frame (n = 1); the scene block lands in slice 5
- /ws?proto=N is required: 400 when absent or not an integer, 101 + closing 4003 on
a mismatch (no hello, no state)
- intent bucket 30/s burst 100 and the 10-in-10-s malformed flood (closing 1008);
a rate-limited intent applies nothing and the connection stays open
- mummy maxMessageLen stated explicitly (64 KB) and mummy's own log lines routed
through the event log instead of stdout
- server Ping(seq) right after hello and every 20 s (lag enforcement stays M5);
inbound Pings are answered with a Pong, which mummy does not do itself
- close reasons: every server-initiated close sends closing {reason, code} then the
close frame, and slice 2's eviction/revocation paths do the same (FIXED, #18)
Conn now carries what DESIGN 6/6.4/6.5 need per connection, all under the one
registry lock: the outgoing n counter (starts at 1, server frames only), the intent
token bucket, the malformed-flood window, the player's named flag and the last Pong.
None of it is shared, so the n counter is not a global side channel (H25).
activate/revokePlayer now hand back the doomed Conn values instead of raw sockets:
the caller still has the frame count, so the final closing frame carries the right n
before the close. Tests cover per-connection counters, the bucket and the flood
window in isolation, and that a snapshot survives the lock.
Pure, mummy-free module for the protocol shell: the envelope rules of DESIGN 6.5
step 2 (UTF-8 text, JSON object, string t, integer reqId in 0..2^31-1), the frame
builders of 6.1 including closal/closing, the per-connection intent token bucket
(30/s, burst 100) and the malformed-flood window (10 in any 10 s), plus the FIXED
constants: proto 1, 64 KB inbound, close codes 4001/4002/4003/1008 and their reason
strings. The 29-intent catalogue and the GM-only set live here so 'unknown type'
and role checks have one definition.
Found while testing: std/json parseJson("") returns nil instead of raising, and
node{"t"} is nil for a missing key, so both are guarded (a bare {} would have
crashed the handler).
Control passes; a-d still caught (1,2,2,1,1 expected tests), new e-j each caught. Logs regenerated.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Pure in-process module (server/moverules.nim, plain data, no IO) per DESIGN 5.5. Replaces moveBlocked tests
(ported at r=0), the KNOWN LIMITATION pin and the Q14 pin with positive escape/capsule assertions and
blocked-policy tests. tests/tprobing.nim: in-process T8 probing test with a concrete bound (stepCap + r).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cellsTouched is now a scanline over cell rows (prototype per-cell version kept test-only in
tests/refold.nim). Differential tests (random polygons, concave, grid-aligned) and a brute-force
explored oracle (0.5 px tolerance) cover it; regression corpus = prototype leak-run polygons.
moveBlocked leaves geometry.nim (replaced by server/moverules.nim next); geometry primitives exported.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fixture tests/fixtures/scene.json copied from prototype data/; seed test no longer skips if missing.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>