design: fix wall and token ids (#3)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 17:13:25 +01:00
co-authored by Claude Haiku 5.5
parent 91cea1a364
commit 48b77888c6
+9 -9
View File
@@ -156,7 +156,7 @@ Notes:
### 4.1 State model
Single process, in-memory authoritative state, SQLite as write-through persistence (loaded at start, never queried at runtime for reads).
- **World**: scenes; per scene: dimensions, tile config, grid, walls (index == id), entities.
- **World**: scenes; per scene: dimensions, tile config, grid, walls (per-scene stable id, never reused; see 8), entities.
- **Players**: id, name, role (`gm`|`player`), colour; owned entities derive from `entity.owner`.
- **Per-player runtime** (`Role` in prototype, renamed `PlayerState`): current vision polygons (one per owned entity with `vision` enabled), `ver` counter bumped on change, explored set, `fresh` cells added by the current mutation.
- **Per-connection runtime**: `known` table (entity id -> last sent view), last-sent vision `ver`, per-connection counter, player id, role.
@@ -219,9 +219,9 @@ player(id PK, name, role, colour, created_at)
invite(id PK, player_id FK, secret, created_at, revoked_at, used_at) -- secret plaintext (Q11)
session(id PK, player_id FK, token_hash, created_at, last_seen) -- never expires (Q10)
scene(id PK, name, w, h, tile_size, cell, grid_size, vision_radius_default,
art_version, active, extra_json)
wall(id PK, scene_id FK, ax, ay, bx, by, kind, open, flags) -- kind: wall|door|(later: window, one-way)
entity(id PK, scene_id FK, kind, name, x, y, owner_player_id NULL,
art_version, active, next_wall_id, extra_json) -- next_wall_id: monotonic, §8 [FIXED, #3]
wall(scene_id FK, id, ax, ay, bx, by, kind, open, flags, PRIMARY KEY(scene_id, id)) -- kind: wall|door|(later: window, one-way)
entity(id TEXT PK, scene_id FK, kind, name, x, y, owner_player_id NULL,
gm_only, flags, props_public JSON, props_owner JSON, props_gm JSON)
explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, scene_id, cx, cy))
```
@@ -320,8 +320,8 @@ Client -> server (intents). Authority column: P = player, G = GM.
| t | fields (contract) | who | server behaviour |
|---|---|---|---|
| `move` | `reqId:int, id, pos:[x,y]` | P (owned) / G (any) | validate; reply `moveAck` (+ `token` diffs); non-owned -> `error`; P move refused (`blocked`, over step cap, or wall collision; 5.5) -> `moveAck{ok:false, pos:old}`, one uniform nack; G move ignores walls, step cap and `blocked`, then sets/clears `blocked` by overlap; out-of-bounds G move gets the same nack (5.5) |
| `door` | `id, open:bool` | G | toggle; recompute all players; close pushes tokens whose circle overlaps the door aside (perpendicular, valid side; server-originated position change to broadcast, vision recomputed; `blocked` only if no side is valid; Q14, 5.5), open recomputes `blocked` for those tokens (still blocked if another wall overlaps) |
| `wall.add` / `wall.update` / `wall.remove` | wall fields / `id` | G | validate geometry; recompute all players; GM-only broadcast of wall delta; add sets `blocked` on tokens whose circle overlaps the wall, remove recomputes it for those tokens (Keep rule), update = remove + add (Q14, 5.5; update PROPOSED) |
| `door` | `scene, id, open:bool` | G | toggle; recompute all players; close pushes tokens whose circle overlaps the door aside (perpendicular, valid side; server-originated position change to broadcast, vision recomputed; `blocked` only if no side is valid; Q14, 5.5), open recomputes `blocked` for those tokens (still blocked if another wall overlaps) |
| `wall.add` / `wall.update` / `wall.remove` | wall fields (add: server assigns `id`) / `scene, id` | G | validate geometry; recompute all players; GM-only broadcast of wall delta; add sets `blocked` on tokens whose circle overlaps the wall, remove recomputes it for those tokens (Keep rule), update = remove + add (Q14, 5.5; update PROPOSED) |
| `entity.create` / `entity.update` / `entity.remove` | kind, name, pos, owner, props buckets | G | validate against property schema; view diff |
| `prop.set` | `id, bucket, key, value` | G (v1) | owner-bucket writes by players come with FFF actions (section 9) |
| `scene.set` | scene meta | G | broadcasts new `hello`-equivalent reset to all; no `scene.activate` (one scene, Q3) |
@@ -413,12 +413,12 @@ Prototype `client/src/main.ts`: explored rects appended to a `Graphics` mask for
## 8. Data model
All ids are server-assigned, opaque, non-guessable where they are exposed to players (entities); walls use dense integers GM-side only. M3 item: id stability on removal. `removeWall` currently shifts later indices down (dense ids); M3 must give walls stable ids (or renumber with a broadcast) before the WS layer exposes them.
All ids are server-assigned. **Walls [FIXED, owner decision 2026-11-10, #3]**: per-scene ids, each scene counts from 1. Removal never renumbers; ids are never reused. Each scene stores `next_wall_id` (monotonic, never decreases, even if the newest wall is deleted). Wall identity = `(scene, id)` in DB, server and wire. Wall ids are GM-only in v1. **Tokens/entities [FIXED, owner decision 2026-11-10, #3]**: random opaque id, 12 chars from `[A-Za-z0-9_-]`, from a CSPRNG; server checks collision on create. Unique game-wide (not per-scene), so a token may later change scene keeping its id (cross-scene move not in M3). Counted ids would leak hidden tokens through gaps. **Doors are walls** and use wall ids; toggling is GM-only in v1, so any door-id exposure later leaks at most about the wall count (accepted). Rejected: dense ids with renumber broadcast (in-flight intents hit the wrong wall); game-wide wall counter (per-scene ids keep scene copy/export stable).
- **Scene** (exactly one in v1, Q3): `id, name, w, h` (px), `tile_size` (32 default = `explored_cell` [FIXED, Q4]; 64 is the per-scene fallback), `explored_cell` (32 default; `tile_size % cell == 0` required, prototype assumes it silently), `grid_size`, `vision_radius_default`, `art_version`, `active`, free-form `extra`.
- **Wall/Door**: `id, scene, a:[x,y], b:[x,y], kind ('wall'|'door'), open:bool, flags`. `blocks = not (door and open)`. GM-only everywhere. Later kinds (window, one-way, secret door) are extra `kind`/`flags` values; v1 geometry treats any non-open blocker identically.
- **Wall/Door**: `scene, id` (per-scene, see above), `a:[x,y], b:[x,y], kind ('wall'|'door'), open:bool, flags`. `blocks = not (door and open)`. GM-only everywhere. Later kinds (window, one-way, secret door) are extra `kind`/`flags` values; v1 geometry treats any non-open blocker identically.
- **Entity (token and anything else) [PROPOSED, FFF seam]**:
- `id, scene, kind` (free string: `pc`, `npc`, `item`...), `name`, `pos`, `radius`, `owner` (player id or null = GM-controlled), `gm_only`, `flags` (`vision`, `blocks_move`...), `vision_radius` (optional; per-entity numeric with scene default, Q7 FIXED; also the player step cap, 5.5), `blocked` (bool stored flag, Q14, 5.5).
- `id` (random text, see above), `scene, kind` (free string: `pc`, `npc`, `item`...), `name`, `pos`, `radius`, `owner` (player id or null = GM-controlled), `gm_only`, `flags` (`vision`, `blocks_move`...), `vision_radius` (optional; per-entity numeric with scene default, Q7 FIXED; also the player step cap, 5.5), `blocked` (bool stored flag, Q14, 5.5).
- `props`: three JSON objects by visibility bucket: `public` (anyone who sees the entity), `owner` (owner + GM), `gm` (GM only). Keys are strings, values JSON scalars/arrays/objects with a size cap. No hidden state beyond these buckets and `gm_only` in v1 [FIXED, Q19].
- The server never interprets props in v1 except via a registered property schema (type, bucket, writable-by) used for validation and for FFF later.
- **Player**: `id, name, role (gm|player), colour`. Exactly one GM.