# FFF_vtt A self-hosted browser virtual tabletop for one table: one GM and up to six players on phones, tablets or laptops. Everyone opens the same site link; each person signs in with a personal key. The server decides what each player sees — line of sight, explored area, tokens, map tiles — so a modified client cannot reveal anything its player is not entitled to. No accounts, no external database, one scene, no RPG rules or dice. Status: the client (M4) is built; `devbox run serve` puts a table on the LAN for the manual phone playtest. The NixOS deployment module is M6 and not written yet — for a permanent install you still run the binary behind your own TLS nginx (the manual path below is the fallback). --- ## Using it ### What you need - A Linux host with [devbox](https://www.jetify.com/devbox), or a machine that already has the `fff-vtt` binary and the built client. - An HTTPS site in front of it. The session cookie is `Secure`, so plain HTTP will not keep you signed in. The server itself always binds `127.0.0.1`; nginx is the only public face. ### Start a LAN playtest (one command) From the repo root, inside devbox: ```sh devbox run serve ``` It builds the server binary and the client, starts a TLS + HTTP/2 nginx on the laptop's LAN address in front of the server (the server itself stays on `127.0.0.1`), and prints: - the `https://:8443` URL to open on the phone and the laptop, - the GM key (created on first run; an existing key is printed, never replaced), - the certificate-trust steps for Android Chrome and for a laptop (Linux/macOS/Firefox). To import a map on the same first start, pass `--image` (an offline import runs before the server; a fresh state dir is created and migrated first): ```sh devbox run serve -- --image=run/map16384.png --tile-size=64 ``` Ctrl-C stops nginx and the server and releases the port; the next start works. State (`state.db`, `tiles/`), the GM key and the certificate live under `run/lan` and are **not** wiped, so a session survives a restart and a phone that trusted the certificate does not have to trust it again. | setting | env | default | |---|---|---| | LAN address nginx binds | `FFF_VTT_LAN_HOST` | detected LAN IPv4 (`ip -4 route get 1.1.1.1`) | | nginx TLS port | `FFF_VTT_LAN_PORT` | `8443` | | state directory | `FFF_VTT_STATE_DIR` | `run/lan` | The certificate's SAN is the LAN address. If the laptop's address changes, `serve` regenerates the certificate (and prints the trust steps again). This is the playtest path, not the M6 deployment: no systemd unit, hardening or backups. ### Manual fallback: build it once Everything below is what `devbox run serve` automates; use it when you need to arrange the processes yourself (or to see the paths involved). From the repo root, inside devbox: ```sh devbox run -- nimble install -d -y devbox run -- nim c --mm:orc --nimblePath:.devbox/nimble/pkgs2 \ --nimcache:run/nimcache/fff-vtt -o:run/fff-vtt server/main.nim devbox run -- bash -c 'cd client && npm ci && npm run build' # writes client/dist ``` `--nimcache` inside `run/` matters in a worktree: Nim's default cache is shared by every checkout of the repo and two parallel builds corrupt each other. ### Create the GM key Only the command line can create or rotate the GM: ```sh devbox run -- ./run/fff-vtt gm-key --state-dir=run # prints: GM key: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ``` Re-running prints the same key. `gm-key --new` rotates it and revokes every GM session; it refuses (exit 3) while the server is running on that state dir, so stop the server first. There is no in-browser way to become GM and no first-visitor claim: without the key you only ever see the sign-in page. ### Import the map The map is a source image plus a tiled copy the server gates per player. One offline command slices the image and updates the scene; the server must be **stopped** for it (it reads the scene once at startup) and restarted afterwards. The command also works on a fresh/empty state dir: it creates the directory, migrates the DB and seeds the scene through the same startup path as the server. ImageMagick comes from the root devbox. ```sh # stop the server first, then: devbox run -- ./run/fff-vtt import --state-dir=run --image=/path/to/map.png --tile-size=64 # restart the server with the usual command ``` | argument | meaning | |---|---| | `--image=` | source PNG or WebP (required); tiles are always PNG | | `--tile-size=` | tile edge, default the scene's current tile size; must be a positive multiple of the 32 px explored cell (so 32 or the 64 px fallback) | | `--scene=` | target scene; v1 has exactly one, id 1 | | `--state-dir=` | the same state dir as the server (default `run`); created and migrated if absent | Tiles land in `/tiles/1/v/_.png`, origin at the world origin, which is exactly what the gate parses and nginx's internal `/_tiles/` alias serves. The command sets the scene's width, height and tile size from the image. Importing again grows `art_version` and writes a new `v` directory, so browsers never keep a stale tile; old versions stay on disk until the M6 cleanup. Any problem exits non-zero and writes no tiles: a missing/unreadable source, an unsupported or multi-frame image, a scene other than 1, a tile size that is not a multiple of the cell, a malformed state DB, or a server still holding the state-dir lock (exit 3). Slicing streams: one ImageMagick decode of the source supplies raw row bands, and a small pool of `magick` children cuts one tile row each (live caches and file descriptors are bounded by the worker count, never by the tile count). A long import reports where it is on stderr, e.g. `rows 128/256, tiles 32768/65536`; a failure prints the image, the row band and ImageMagick's own message. **A 16384 px scene with 50 tokens (the phone-playtest target).** 1. Prepare a 16384×16384 PNG or WebP. `--tile-size=64` is the designed fallback and gives 256×256 = 65,536 tiles (32 px would give 262,144 files). On this 16-core box such an import takes about 20 s and peaks near 400 MB RSS (the old one-shot crop died at 4-8 GB and 65k fds, #83); the decode still uses ImageMagick's disk-backed pixel cache, so allow a few GB of temp space. 2. Start with the import in one step: `devbox run serve -- --image=run/map16384.png --tile-size=64` (or stop the server, run `fff-vtt import` as above, then restart it). 3. Create the 50 tokens with the seeding tool, not 50 panel submits (a rerun does not double up): ```sh NODE_EXTRA_CA_CERTS=run/lan/tls/cert.pem \ devbox run seed -- --url=https://:8443 --tokens=49 --vision=1 ``` `--replace` clears the labelled `Seed NN` tokens first; `--seed` changes the deterministic layout; the GM token panel's X/Y now default to the current viewport centre. Tokens, walls and explored state are untouched by the import. 4. Point nginx's `/_tiles/` alias at `/tiles` as shown below. ### Start the server ```sh devbox run -- ./run/fff-vtt --port=9000 --state-dir=run \ --public-origin=https://vtt.example.com ``` | flag | env | default | meaning | |---|---|---|---| | `--public-origin` | `FFF_VTT_PUBLIC_ORIGIN` | `http://localhost:8080` | origin the site is served from; compared byte for byte with the browser's `Origin` header, so it must match exactly | | `--port` | `FFF_VTT_PORT` | `9000` | listen port on `127.0.0.1` | | `--state-dir` | `FFF_VTT_STATE_DIR` | `run` | holds `state.db`, `instance.lock` and `tiles/` | Flags win over env, env wins over defaults. A second server on the same state dir refuses to start (the `instance.lock`). ### Put nginx in front The server answers `/healthz`, `/join`, `/tiles/` and the `/ws` upgrade. Everything else — the client build, TLS, the internal tile route — is nginx. This is the shape; `tools/nginx.mjs` generates exactly this config for the tests and is the reference to copy: ```nginx # inside http { ... } map $http_upgrade $conn_up { default upgrade; '' close; } server { listen 443 ssl; http2 on; ssl_certificate /path/cert.pem; ssl_certificate_key /path/key.pem; location = /healthz { proxy_pass http://127.0.0.1:9000; } location = /join { proxy_pass http://127.0.0.1:9000; access_log off; add_header Referrer-Policy no-referrer; } location /tiles/ { proxy_pass http://127.0.0.1:9000; } # server decides, answers X-Accel-Redirect location = /ws { proxy_pass http://127.0.0.1:9000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $conn_up; proxy_read_timeout 1h; proxy_buffering off; } location /_tiles/ { internal; alias /srv/fff-vtt/tiles/; } # never reachable from outside location /assets/ { root /srv/fff-vtt/dist; try_files $uri =404; add_header Cache-Control "public, max-age=31536000, immutable"; } location = /index.html { root /srv/fff-vtt/dist; try_files /index.html =404; add_header Cache-Control "no-cache"; } location / { root /srv/fff-vtt/dist; try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache"; } } ``` `/_tiles/` must point at `/tiles`; the server only tells nginx which tile to serve and never sends the bytes itself. Nothing about production deployment (systemd unit, NixOS module, backup timer) exists in the repo yet; that is M6. ### At the table, as GM 1. Open the site, paste the GM key. The GM is created with the display name `GM` and is not asked to pick one. 2. **Player keys.** In the GM panel, *Create player key* makes an unused key (24 characters in five groups of four; case and dashes do not matter). Hand it to one player and that player is bound to it. *Show* reveals it again, *Replace* rotates it and closes all that player's sessions, *Remove* frees the slot and hands their characters and tokens to the GM. Maximum six players; unused keys count toward the cap. 3. **Map.** Only one scene exists. It is seeded at 4096×4096 px with 32 px tiles and cells, a 400 px default vision radius, a 20 px default token radius and no grid (the grid toggle exists, but the seeded grid size is 0 and only `scene.set` can change it). Replace the map with the offline import CLI described under *Import the map* (`fff-vtt import`, server stopped first, restarted after): it writes the tile tree under `/tiles/1/v/` and sets the width, height and tile size. There is still **no browser upload** (post-v1). A player is served a tile only after they have explored a cell that overlaps it; the GM always gets every tile. Because one 32 px cell is the unit of disclosure, do not paint secret doors, traps or notes into map art near places players can reach — keep secrets as GM-only tokens. 4. **Tokens.** *Create token* takes a kind, a descriptive name, an actual name, a position (X/Y default to the current viewport centre), a radius (blank = scene default), a `gm_only` flag and a controller (a player, or blank for the GM). *Select* a token to edit or remove it, resize it, or add and clear `stuck`/`squeezed` statuses. The GM may drag any token; a player only their own. 5. **Characters and reveals.** Create a character with a descriptive name, an actual name and an owner; rename it, move it to another owner, reveal its actual name to one player or to everyone, remove it (refused while a token still links it). Each player's encountered list is visible to you and you can delete entries. 6. **Who sees it.** The GM token panel shows which players currently see a token. In this build the answer is binary — seen or not seen; the graded visible fraction arrives with wall heights. 7. **Walls.** Arm a preset (`wall`, `door`, `window`, `one_way`) and click twice to draw a segment. Select a wall for its derived kind, a free-text label (never sent to players), the *Players see a marker* switch, open/close, `secret`/`locked`, the one-way flip, the raw switches behind *Advanced switches*, delete, and a single-step *Undo*. A secret or locked door looks exactly like a solid wall to players. Thickness, height and placement controls are not in this build (ADR-0012). ### Not in this build yet The server already speaks these; the browser has no control for them, so a table needs them only if you write to the wire yourself: - the token `vision` switch. It lives in the token's `flags` on the wire, and a token created from the panel has no vision, so a player token made only through the UI sees no fog of its own; - the token's character link (`character_id`); - a property editor (`prop.set` / `prop.unset`, the `public`/`owner`/`gm` buckets); - a scene settings panel (`scene.set`: name, grid size, default vision and token radii); - renaming a player (`player.rename`). Still missing entirely: - browser map upload (post-v1; the offline `fff-vtt import` CLI exists); - wall thickness, height, see-over and wall placement (built after the phone playtest, ADR-0012); - the graded who-sees-it fraction (needs wall heights); - the NixOS module, systemd unit and backup timer (M6); - chat, dice, rulers, pings, audio, multiple scenes, accounts. ### As a player 1. Open the same link and enter your key. The first sign-in asks for a display name once; it must be unique at the table. 2. One-finger drag pans, wheel or pinch zooms (0.5× to 4×). 3. Drag your own token. The move is drawn immediately, then confirmed by the server or rolled back when a wall or the step limit refuses it. 4. Fog colours: opaque black is floor you have never seen, dimmed map is floor you explored earlier, clear map is what you can see right now. The little lit-window icon is a window you have already seen part of. 5. The badge shows `connected`, `reconnecting` or `offline`. A dropped connection keeps the map on screen and retries; the server then resyncs everything. ### Measure fps on the phone Open the site with `?perf=1` appended to the URL (for example `https://192.168.1.50:8443/?perf=1`). After sign-in a small overlay appears in the top-right: ``` fps 59.8 · frame p50 16.6 p95 17.1 ms · JS p50 1.20 p95 2.40 ms · tokens 50 · zoom 1.00 ``` It is off by default and adds no per-frame work when off. The line is computed over the last 10 s: `fps` and the frame interval from the render loop, and `JS` is the main-thread time from the first ticker listener to after the render submission, so it is an upper bound on the app's JS cost. `chrome://inspect/#devices` remains the optional cross-check (Frame Rendering Stats + Performance panel); it needs USB debugging, the overlay does not. ### When something goes wrong - **"Key not recognised."** — wrong or unknown key; the server deliberately says the same thing for both. Ask the GM to *Show* the key again. Case, dashes and spaces are ignored. - **The page says to reload** — the client and server disagree about the protocol version (a deployment replaced one side only). Reload; if it keeps happening, rebuild the client so both sides come from the same commit. - **You are back at the sign-in page** — the key was replaced, you were removed from the table, or the GM key was rotated. Ask the GM for the current key. - **The badge says reconnecting** — the network dropped. Retries back off 1, 2, 4, 8, 10 seconds with jitter; a terminal reason (`revoked`, version mismatch) never retries. - **A move snaps back** — a wall or the per-step distance limit refused it. Refusals never reveal where the wall is. - **The server will not start** — `state dir locked` means another instance already runs on that directory; `gm-key --new` hits the same lock. Exit 1 is a database or state-dir error, 2 a bad flag or env value. --- ## For developers ### Rules of the environment - Everything runs through devbox: `devbox run