design: record slice 2 decisions (#17)
This commit is contained in:
+12
-6
@@ -1,6 +1,6 @@
|
||||
# FFF_vtt design
|
||||
|
||||
Status: draft v0.13, 2026-11-14 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents.
|
||||
Status: draft v0.14, 2026-11-14 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14; v0.14 records #17 (getting in: keys, sessions, the auth slice) in 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents.
|
||||
|
||||
Legend:
|
||||
- **[FIXED]** owner decision, not up for debate here.
|
||||
@@ -137,6 +137,9 @@ Notes:
|
||||
- **Rejected [FIXED, #6]:** per-person invite links; GM types the name at key creation; delete-and-reinvite only; deleting a player's characters with the player; a shared-link visit creating a player; a separate GM link path.
|
||||
- **First GM login [FIXED, owner decision 2026-11-10, #5; amended #6].** Only the server CLI creates the GM: `fff-vtt gm-key` creates the single GM player (role `gm`, display name `GM`) if none exists, and prints the GM key. Re-running prints the same key; existing GM sessions are unaffected. `fff-vtt gm-key --new` rotates: new GM key, old one invalid, all GM sessions revoked. `--new` refuses while the running server holds its lock on the data dir; the read-only print works at any time. The GM's own key rotates only this way (no live replace). The GM signs in like a player: shared link, then GM key. Access control is filesystem permissions on the data files; no extra password. A visitor without a key never becomes GM (no first-visitor claim); they see only a "need a key" page. The GM may rename.
|
||||
- Rejected: env/config seed (secret leaks via config, repo, backups); auto-print at startup (secrets in logs); first visitor claims GM (takeover); rotate on every lookup (logs out GM devices); live rotation while the server runs (needs an admin channel to the running server).
|
||||
- **Key and session formats [FIXED (owner-delegated, 2026-11-14, #17)].** Player and GM keys are 20 symbols in 5 groups of 4 separated by dashes (24 characters shown), alphabet `ABCDEFGHJKMNPQRSTUVWXYZ23456789` (no `0/O`, `1/I/L`), drawn from the OS CSPRNG (`std/sysrand`, `getrandom`): ~99 bits. Comparison normalizes ASCII case, dashes and spaces and is length-independent (no early exit); at most 7 stored keys are compared. A session token is 32 CSPRNG bytes as lowercase hex (64 characters); only `sha256(token)` is stored. SHA-256 is a small in-repo implementation (`server/crypto.nim`, FIPS known-answer tested) because the pinned Nim stdlib has no SHA-2 and this adds no dependency. The cookie is `fff_session` (6.6).
|
||||
- **`fff-vtt gm-key` wiring [FIXED (owner-delegated, 2026-11-14, #17)].** `fff-vtt gm-key [--new] [config flags]` opens (and migrates) the DB with the normal config keys, creates the GM (role `gm`, name `GM`) when absent, and prints one line `GM key: <key>`; re-runs print the same key. `--new` rotates, revokes all GM sessions, and prints `GM key (new): <key>`. The server holds an exclusive `fcntl(F_SETLK)` write lock on `<stateDir>/instance.lock` for its lifetime (also refusing a second server); `--new` tries the same lock and exits **3** without touching the DB while it is held. The read-only print takes no lock and works while the server runs. Other exit codes: 0 ok, 1 DB/state-dir error, 2 config error.
|
||||
- **Application close codes at the mummy pin [OPEN, found in #17].** Mummy 0.4.8 exposes only `close(ws)`, which sends an empty close frame (a browser reports **1005**); the app codes 4001/4002/4003 of 6.5 cannot be sent without patching or forking mummy. Slice 2 closes revoked and evicted connections this way and tests the close, not the code. Slice 3 (#18) must choose: accept 1005 and amend 6.5, or take the fork fallback (4.3).
|
||||
|
||||
### 3.3 Tiles
|
||||
- Browser asks `GET /tiles/<scene>/v<art_version>/<x>_<y>.png` (Nim path). Nim parses strictly (digits only, length-bounded, range-checked against scene size; malformed or out-of-range -> `404`), checks the session's explored grid (the explored-area logic of 5.1), and answers `200` with `X-Accel-Redirect: /_tiles/<scene>/v<art_version>/<x>_<y>.png`, or `403` if unexplored [FIXED, owner decision 2026-11-14, #7]. nginx serves the bytes from an `internal` location; direct hits on `/_tiles/` give 404 [MEASURED: `prototype-server-vision/results/smoke.log`, README "Phase 2a"].
|
||||
@@ -253,7 +256,7 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc
|
||||
- Exactly one scene in v1 (Q3): `scene_id` keys stay in the schema.
|
||||
- Prototype stores one row per explored cell (`exp(role, c)`, one INSERT per new cell, `HANDOFF.md`); real build stores **chunked bitmaps**: a chunk is e.g. 64x64 cells = 512 B; dirty chunks upserted per mutation [PROPOSED]. Sizes [INFERRED]: 4096 px map / 32 px cell = 16 384 cells = 2 KB bitmap; 16384 px map = 262 144 cells = 32 KB.
|
||||
- Entity move = one UPSERT of x,y (prototype: `INSERT OR REPLACE INTO tok`).
|
||||
- Migrations: `PRAGMA user_version` + forward-only migration list; startup refuses to run on a newer DB [PROPOSED]. Detail [FIXED (owner-delegated, 2026-11-14, #16)]: `schema_migration(version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at TEXT NOT NULL)` is the history; `user_version` carries the same latest version, and startup refuses when the two disagree or the history is not contiguous from 1. One transaction per step (DDL + history row + `user_version`); a failing step rolls back completely, and an up-to-date DB is not written at all (re-open is a no-op). Step 1 (M3 slice 1) creates `meta(k TEXT PRIMARY KEY, v TEXT NOT NULL)`.
|
||||
- Migrations: `PRAGMA user_version` + forward-only migration list; startup refuses to run on a newer DB [PROPOSED]. Detail [FIXED (owner-delegated, 2026-11-14, #16)]: `schema_migration(version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at TEXT NOT NULL)` is the history; `user_version` carries the same latest version, and startup refuses when the two disagree or the history is not contiguous from 1. One transaction per step (DDL + history row + `user_version`); a failing step rolls back completely, and an up-to-date DB is not written at all (re-open is a no-op). Step 1 (M3 slice 1) creates `meta(k TEXT PRIMARY KEY, v TEXT NOT NULL)`. Step 2 (M3 slice 2, `auth`) creates `player(id, name TEXT UNIQUE NULL until first sign-in, role 'gm'|'player', colour, created_at)`, a partial unique index `player_single_gm` on `role='gm'`, `player_key(player_id PK FK ON DELETE CASCADE, secret TEXT plaintext, created_at)`, and `session(id, player_id FK ON DELETE CASCADE, token_hash TEXT UNIQUE, created_at, last_seen)` plus `session_player`; removing a player therefore removes its key and sessions. `session.last_seen` exists but is not updated in M3 (sessions never expire, Q10). A step may hold several statements; the runner executes them in order inside the step's transaction (db_connector prepares one statement per call).
|
||||
- Startup: load everything into memory, recompute vision for all players (prototype does, in one transaction) so `vision` is never stale vs walls.
|
||||
- Shutdown: install a SIGTERM handler [prototype has only SIGINT, `HANDOFF.md`]: stop accepting, close sockets, final `wal_checkpoint(TRUNCATE)`, exit. Durability does not depend on it (WAL commit before ack).
|
||||
|
||||
@@ -513,10 +516,10 @@ Player name text: trimmed, NFC, 1 to 32 code points, no control characters. Char
|
||||
| 9 | inbound message over 64 KB, bad opcode/rsv, unmasked or oversized control frame | mummy closes TCP with **no close frame** (client sees 1006); not catchable by app code | open |
|
||||
| 10 | server shutdown (SIGTERM) | WS **1001** (going away) [M5, 4.4 handler] | M5 |
|
||||
|
||||
WS close reasons are the static strings in bold above. Close codes 4001-4003 are the app's range; 1008 and 1001 are the RFC 6455 standard codes. Lagging clients (M5, 4.3) get no close and no frame: they are not fed until resync, and nginx closes dead peers (M5).
|
||||
WS close reasons are the static strings in bold above. Close codes 4001-4003 are the app's range; 1008 and 1001 are the RFC 6455 standard codes. Lagging clients (M5, 4.3) get no close and no frame: they are not fed until resync, and nginx closes dead peers (M5). At the mummy 0.4.8 pin the application codes 4001-4003 cannot be sent: `close(ws)` emits an empty close frame (1005). Slice 2 closes on revocation and eviction without a code; the choice between accepting 1005 (amending this table) and the fork fallback is OPEN for slice 3 (3.2).
|
||||
|
||||
### 6.6 HTTP surface in M3
|
||||
- `POST /join` (the sign-in page; HTTP, not WS; 3.2). Body `application/x-www-form-urlencoded`, one field `key`, at most 1 KB (mummy closes the connection above its limit). Key comparison ignores case, dashes and spaces and is constant-time. Valid key (player or GM): `303` to `/` with `Set-Cookie: fff_session=<random>; HttpOnly; Secure; SameSite=Strict; Path=/` [name PROPOSED]. Invalid key: `401`, no body detail, no cookie. Wrong method `405`; missing `key` or wrong content type `400`. No rate limit (owner, #6). The body is never logged (T6).
|
||||
- `POST /join` (the sign-in page; HTTP, not WS; 3.2). Body `application/x-www-form-urlencoded`, one field `key`, at most 1 KB (the server answers `400` above that; mummy closes far above it). Key comparison ignores case, dashes and spaces and is constant-time. Valid key (player or GM): `303` to `/` with `Set-Cookie: fff_session=<random>; HttpOnly; Secure; SameSite=Strict; Path=/` and `Referrer-Policy: no-referrer`; the session token is a fresh 32-byte hex value and only its SHA-256 is stored (3.2). Invalid key: `401`, no body detail, no cookie. Wrong method `405`; missing `key` or wrong content type `400`. No rate limit (owner, #6). The body is never logged (T6). Cookie name `fff_session` [FIXED (owner-delegated, 2026-11-14, #17)].
|
||||
- `GET /ws`: 6.5 (rows 1-4).
|
||||
- `GET /tiles/<scene>/v<art_version>/<x>_<y>.png`: 3.3 (`200` with `X-Accel-Redirect`, `403` unexplored, `404` malformed/out of range).
|
||||
- `GET /healthz`: 200 `{"status":"ok"}` from M3 slice 1 [FIXED (owner-delegated, 2026-11-14, #16)]; M5 makes it report whether the global lock can be acquired within a bound (11.3).
|
||||
@@ -585,8 +588,8 @@ All ids are server-assigned. **Walls [FIXED, owner decision 2026-11-10, #3]**: p
|
||||
- **Names [FIXED, #14]**: every character and every plain token has a `descriptive_name` (e.g. "a grumpy man") and an `actual_name` (e.g. "Lord Vex"). Players see the descriptive name until the GM reveals the actual name to that player; the GM can also reveal to all at once (`reveal_all`). The owner of a character always sees its actual name. A character's tokens use the character's names, so one reveal covers all of them. Applies to player characters too (introductions). A reveal cannot be undone in v1 (no un-reveal intent). Reveals are not revoked when ownership changes [PROPOSED].
|
||||
- **Encountered list [FIXED, #14]**: per player, every token that the player's controlled tokens have ever seen, shown under the name that player knows. Out of sight: greyed ("met before, whereabouts unknown"). `gm_only` tokens never enter it; a token that becomes `gm_only` after a player met it keeps its entry (greyed). Entries are never removed automatically (not on token removal, scene change or a `gm_only` flip); only the GM removes an entry for a player. Server tracks and persists it. No browsable list of all characters for players. Not the player roster (Q9 lists players only).
|
||||
- **Player**: `id, name (NULL until first sign-in; unique among players), role (gm|player), colour`. Exactly one GM. A player is a real person who signs in with a player key; not a character. A player may own several characters. Max 6 players; unused keys count toward the cap. GM can rename. Remove: see 3.2 [FIXED, #6].
|
||||
- **Player key**: `player_id, secret (plaintext, re-showable by GM, Q11 FIXED), created`; one current key per player; replace overwrites. The GM's key is the GM player's key (3.2). Not a session [FIXED, #6].
|
||||
- **Session**: `id, player_id, token_hash, created, last_seen`; never expires (Q10 FIXED).
|
||||
- **Player key**: `player_id, secret (plaintext, re-showable by GM, Q11 FIXED), created`; one current key per player; replace overwrites. Format: 20 symbols in 5 groups of 4 with dashes, alphabet without look-alikes, CSPRNG (~99 bits) [FIXED, #6; implementation detail #17 in 3.2]. The GM's key is the GM player's key (3.2). Not a session [FIXED, #6].
|
||||
- **Session**: `id, player_id, token_hash (SHA-256 hex of a 32-byte CSPRNG token; the token itself is never stored), created, last_seen`; never expires (Q10 FIXED).
|
||||
- **Explored grid**: per `(player, scene)`, strictly per player (Q9 FIXED): bitset over `ceil(w/cell) x ceil(h/cell)` cells; persisted as chunked bitmaps (4.4). Only grows. Players with no vision-enabled entity have an empty grid.
|
||||
- **Vision polygons**: runtime only, never persisted (recomputed at start).
|
||||
- **Connection (runtime)**: id, player, `known` map, last vision ver, counter.
|
||||
@@ -662,6 +665,7 @@ Principles carried from the prototype: the checker must be independent of the co
|
||||
- Config keys [FIXED (owner-delegated, 2026-11-14, #16)]: `--public-origin` / `FFF_VTT_PUBLIC_ORIGIN`, `--port` / `FFF_VTT_PORT`, `--state-dir` / `FFF_VTT_STATE_DIR`. Flag wins over env wins over default; defaults `http://localhost:8080`, `9000`, `run`. The origin is canonicalised (lowercase scheme/host, no trailing slash) because it is compared byte for byte with the browser's `Origin` (3.2). The listen address is not a key: the binary always binds `127.0.0.1`.
|
||||
- Unit hardening: `DynamicUser` or dedicated user, `StateDirectory=fff-vtt`, `ProtectSystem=strict`, `ProtectHome`, `NoNewPrivileges`, `PrivateTmp`, `RestrictAddressFamilies=AF_INET AF_INET6`, `MemoryMax`. Add `AF_UNIX` only if the FFF sidecar (section 9, option b) is chosen; revisit at Q19. Listen on `127.0.0.1:<port>` only [MEASURED prototype binds 127.0.0.1].
|
||||
- `fff-vtt gm-key` (3.2) must run as the service user (e.g. `sudo -u <service user> fff-vtt gm-key`, or a wrapper in the module), so the DB and its WAL files stay owned by that user; with `DynamicUser` the module needs a fixed user name or a wrapper. [FIXED, owner-delegated, 2026-11-14, #13]
|
||||
- The server takes the state-dir lock at startup and the CLI honours it (3.2): an `fcntl` write lock on `<stateDir>/instance.lock`; `gm-key --new` exits 3 while the server runs. [FIXED, owner-delegated, 2026-11-14, #17]
|
||||
- `Restart=on-failure`; `TimeoutStopSec` short; SIGTERM handler flushes (4.4).
|
||||
- **Client build**: Vite `dist/` produced by Nix (or CI), served by nginx from the store path. Hashed assets, long cache; `index.html` no-cache.
|
||||
- **nginx** (shape of the vhost, adapt to the existing server config; reference only, I did not read the owner's NixOS repo for this doc):
|
||||
@@ -815,4 +819,6 @@ Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #11)]: M3 mes
|
||||
|
||||
Owner also decided 2026-11-14 (review of #11 flags) [FIXED (owner decision)]: (1) players cannot create or edit characters or props in v1 (GM only); opening that later is a permission change on the existing intents, not a redesign (1). (2) A revealed name cannot be un-revealed: no un-reveal intent (8, 6.1). (3) `character.remove` is refused with `in-use` while tokens link the character (6.1, 6.5). (4) Encountered stays encountered: a `gm_only` flip leaves the entry, greyed (8, 6.1). (5) Status markers do not reveal their cause to non-GM viewers: `statuses[].source` goes to the GM only (3.1, 5.5, 6.1; amends #4). The controlling owner is not given `source` either, as the doc has no owner-view rule for statuses; revisit if wanted.
|
||||
|
||||
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #17)]: M3 slice 2 ("getting in"). Storage is migration step 2 (`auth`): `player`, `player_key`, `session`, a single-GM partial unique index, cascading deletes (4.4). Players/keys/sessions: 3.2 and 8. Cookie `fff_session`, `POST /join` as in 6.6. `fff-vtt gm-key [--new]` and the `<stateDir>/instance.lock` fcntl lock with exit 3 are recorded in 3.2/11.1. Slice 2 implements only the three GM intents auth needs (`key.create`, `key.replace`, `player.remove`) with the 6.1 ack shape; the rest of the envelope, error frames, rate limits and unknown-type answers stay slice 3 (#18). The application close codes of 6.5 are not expressible at the mummy pin (3.2); slice 3 decides. See 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13.
|
||||
|
||||
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #16)]: M3 slice 1 groundwork ("bare server"). Config keys, defaults, precedence and the canonical origin: 11.1. Migration history DDL, the agreement/contiguity rule and one-transaction-per-step: 4.4. Secret redaction (value registry plus sensitive field names, minimum secret length 8): 11.3. `GET /healthz` answers `200 {"status":"ok"}` from slice 1; the lock-bounded health check stays M5: 6.6, 11.3. `devbox run test` runs `nimble test` first and only then `node --test tools/*.test.mjs` (10.4); both logs land in `results/`. The server's listen address is the constant `config.BindAddress` = `127.0.0.1`, not a config key (T15). Dependencies: `fff_vtt.nimble` requires `mummy == 0.4.8` and `db_connector == 0.1.0`; devbox adds nodejs 26 and sqlite (`out`+`bin`, with `LD_LIBRARY_PATH=$DEVBOX_PACKAGES_DIR/lib` for the dlopen). Node 26 `{headers}` re-check: 10.4.
|
||||
|
||||
Reference in New Issue
Block a user