1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# Deployment notes
How to run X-Haven (web) in production. Two supported shapes: a single
container (Docker) or the two source trees directly (Dart + Node). The game
is a **single server process** — there is nothing to scale out per player;
more players just mean more WebSocket connections on the same server.
## Running with Docker
```bash
docker build -t xhaven .
docker run --rm -p 4567:4567 -v xhaven-saves:/app/saves xhaven
```
- Port: published `4567` → container `4567` (override with `-p 8080:4567` and
`--env PORT=8080`).
- State: everything the server persists lives under `/app/saves`
(`game.json` the live snapshot, `seats.json` seat ownership,
`settings.json` server-side settings, plus named saves). Mount a volume
there and redeploys keep the game.
- Health: `GET /healthz` answers 200; the image ships a `HEALTHCHECK`
(TCP probe, dependency-free).
## Running from source
```bash
cd web && npm ci && npm run build # → web/dist
cd ../server
dart pub get
dart run bin/main.dart \
--port 4567 \
--static-dir ../web/dist \
--saves-dir /var/lib/xhaven/saves
```
Flags (all optional, see `server/bin/main.dart`):
| flag | default | meaning |
|----------------|------------------|--------------------------------------------------|
| `--port` | `4567` (or `$PORT`) | HTTP + WebSocket port |
| `--static-dir` | `../web/dist` | the built web app (SPA fallback included) |
| `--saves-dir` | `saves` | game state, seats, settings, named saves |
| `--data-dir` | `assets/data/` | campaign/monster/scenario JSON (served at `/data/`) |
Game artwork (`assets/images/`, ~66 MB) and in-game translations
(`assets/i18n/`) are served from the paths relative to the working
directory; keep the server's `assets/` tree next to `bin/`.
## Reverse proxy / TLS
The app is a plain-HTTP + WebSocket server; put it behind any TLS-terminating
proxy (Caddy, nginx, …). The only non-HTTP route is the WebSocket upgrade at
`/ws` — forward it with the usual `Upgrade`/`Connection` headers. All other
routes are ordinary GETs, and the client derives the WS URL from the page
origin (`wss://` under TLS), so no client configuration is needed.
Long idle connections are kept alive by the client's 25 s keepalive `ping`;
proxy idle timeouts above ~30 s are fine.
## Persistence & restarts
- The server saves on **every action** (synchronous write-through), so a
crash loses at most the in-flight frame.
- On boot it restores `game.json` + `seats.json`: characters, the scenario,
round state, initiative entries, and seat ownership all survive a restart.
Reconnected browsers (same session cookie) resume with their seats; the
first `welcome` after reconnect carries the full state.
- Undo history is **not** persisted: after a restart the command index
restarts at 0 and the undo/redo buttons stay disabled until new actions
are taken. State itself is fully restored.
- Named saves (the Load/Save State menu) live under the saves dir and
survive indefinitely.
## Performance (measured, Phase 7)
Protocol cost under a full table, measured with
`server/tool/perf_measure.dart` (6 connected clients — 4 players + 2
spectators — playing 3 full rounds of "#1 Roadside Ambush" with 4 characters
and 10 monsters; localhost):
| metric | value |
|-----------------------------------------|---------|
| state JSON, full-table scale | **11.2 kB** |
| largest `update` frame (envelope+state) | 11.4 kB |
| fan-out per executed action (6 clients) | 68.5 kB |
| traffic per connection over 49 actions | ~460 kB |
| server-side action latency (localhost) | ~10 ms |
The protocol is a full snapshot per action (bandwidth for simplicity): cost
scales linearly with state size × connections. At this scale that is trivial
for LAN or even WAN; the state grows slowly (characters, monsters, note rows,
decks) — a heavy multi-scenario game would be tens of kB, still fine.
Static assets:
- `index.html` and SPA routes: `cache-control: no-cache` (deploys reach open
tabs on refresh).
- Content-hashed build assets, `/data/` JSON, `/i18n/`, and the 66 MB
`/images/` set: `public, max-age=31536000, immutable` — the browser fetches
each image once and then from cache; the 66 MB art set is a one-time
download per device.
- Class artwork is `loading="lazy"` in the list.
## Smoke-test list
After deploying, verify in two browser tabs (and a third as spectator) —
these are exactly what the E2E suite (`e2e/`) automates:
1. **Connect** — the "Connecting…" banner disappears on every tab; each tab
shows the table.
2. **Onboard** — in tab A open *Add Character* and add *Hatchet*; the row
appears on all tabs and tab A's Draw button enables (tab A is now a
player).
3. **Scenario** — tab A: *Set Scenario* → *#1 Roadside Ambush*.
4. **Second player** — tab B adds *Voidwarden*; all tabs show both rows.
5. **Spectator** — tab C shows both rows **read-only**: no initiative input,
no *Claim* chip, Draw disabled.
6. **Secret initiative** — tab A enters `4` in Hatchet's initiative slot.
Tab A sees the value; tabs B and C show `??`.
7. **Draw** — tab B enters `2`, then tab A taps *Draw*. All three tabs
switch to *Next Round* at once and show initiatives `4` / `2`.
8. **Turns** — tap the turn-done zone for each character; the round
completes.
9. **Next round** — tap *Next Round*; every tab shows *Round 2/* and the
initiative slots are secret again (only owners' inputs enabled).
10. **Reconnect** — reload tab C, then kill and restart the server; all
tabs show "Reconnecting…" and resync with the full state (seats kept).
|