@hadoku/game-server 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -1,9 +1,27 @@
1
1
  /**
2
- * Runtime config for the Cardtable loopback-UI tunnel server.
2
+ * Runtime config for a game-server app — the PLATFORM half (w119 §C).
3
3
  *
4
- * Every value is env-overridable so the PM2 wrapper (which pulls them from the
5
- * vault broker) can inject them without a code edit.
4
+ * `createConfig` is a factory: every value it returns comes from the `env` object and `envPrefix`
5
+ * it is called with (defaults: `process.env` and `'CARDTABLE'`), read when the factory RUNS, never
6
+ * cached at this module's import. Two calls in one process, with different prefixes and/or
7
+ * env objects, build two independent configs — which is what lets a second game on
8
+ * `@hadoku/game-server` (bomberman) set its own `BOMBERMAN_*` variables instead of cardtable's.
9
+ *
10
+ * `export const CONFIG = createConfig()` below is cardtable's own instance, built the moment this
11
+ * module is first imported — kept for every file that already does `import { CONFIG } from
12
+ * '@hadoku/game-server/config'` and must keep working unchanged.
13
+ *
14
+ * What is NOT here any more: Magic-only settings (catalog, art mirror, draft bot, tournaments,
15
+ * sounds, draft timing, the Forge-hosting envs, the room-stream envs) moved to
16
+ * `games/magic/server/src/config.ts`'s `createMagicConfig`/`MAGIC_CONFIG` — a game with no Forge
17
+ * engine has no business reading `CARDTABLE_DRAFT_BOT_PICK_MS`. Cardtable's deployment-only ArchiveBot
18
+ * settings moved there too (not to `apps/server`): the only two readers,
19
+ * `games/magic/server/src/plugins/{listen,routes}.ts`, are in the `magic` layer, which may not
20
+ * import `apps/server` (the `site` layer) — see `scripts/layers/layers.json`'s allowed directions.
21
+ * Survey: `~/.cache/cardtable-manager/bomberman-survey-2026-11-16.md` §3 has the classification
22
+ * with the original line numbers.
6
23
  */
24
+ import { type Tier } from '@wolffm/service-kernel/auth';
7
25
  /**
8
26
  * The site's own directory (`apps/server`, whose `dist/` PM2 runs), whatever the process's working directory — PM2
9
27
  * starts us from the repo root, `pnpm start` from the package dir, and the two must agree. Bundled,
@@ -16,7 +34,13 @@ export declare const LEGACY_STATE: {
16
34
  readonly dataDir: string;
17
35
  readonly logDir: string;
18
36
  };
19
- export declare const CONFIG: {
37
+ export interface CreateConfigOptions {
38
+ /** Every env var this factory reads is `<envPrefix>_<NAME>`. Default `'CARDTABLE'`. */
39
+ envPrefix?: string;
40
+ /** The environment to read. Default `process.env` — override to build a second config in one process (a test, or a second game). */
41
+ env?: NodeJS.ProcessEnv;
42
+ }
43
+ export interface GameServerConfig {
20
44
  /** Port this server listens on. cloudflared points the tunnel hostname here. */
21
45
  readonly port: number;
22
46
  /**
@@ -45,12 +69,22 @@ export declare const CONFIG: {
45
69
  * The edge gate is the real one, but it lives in another repo on another
46
70
  * deploy cadence, and the tunnel hostname is reachable without it. A floor
47
71
  * here means a route-tiers edit cannot silently widen this app on its own.
72
+ *
73
+ * Validated at factory-call time (`kernelAssertFloor`, moved here from
74
+ * `edge-auth.ts`'s former import-time self-check, w119 §C.4): a floor this
75
+ * build does not know, or `public`, throws out of `createConfig` itself —
76
+ * fails closed exactly as before, just at the one deterministic place that
77
+ * builds the config, not as a side effect of any file happening to import
78
+ * `edge-auth.ts`.
48
79
  */
49
- readonly minTier: string;
80
+ readonly minTier: Tier;
50
81
  /**
51
82
  * Shared secret edge-router stamps as X-Edge-Auth on everything it proxies
52
83
  * (workers/shared/edgeAuth.ts). Identity headers are believed ONLY when this
53
84
  * matches. Unset = FAIL CLOSED: every request is degraded to public/anon.
85
+ *
86
+ * Not prefixed: `EDGE_AUTH_SECRET` is the edge's own shared secret, common to
87
+ * every app behind it, never per-game.
54
88
  */
55
89
  readonly edgeAuthSecret: string;
56
90
  /**
@@ -73,175 +107,65 @@ export declare const CONFIG: {
73
107
  * by prefs-api and answers 502.
74
108
  */
75
109
  readonly serviceKey: string;
76
- /**
77
- * The prefs mount people's own rows are read and written on (`http/musicReviewStore.ts`),
78
- * without `/api/v1`, with the same service key.
79
- */
110
+ /** The prefs mount people's own rows are read and written on, without `/api/v1`, with the same service key. */
80
111
  readonly prefsBaseUrl: string;
81
- /**
82
- * Where security telemetry is posted (`/health/api/telemetry` under it), with
83
- * the same service key as the stats. Unset key = telemetry is off (logged once).
84
- */
112
+ /** Where security telemetry is posted (`/health/api/telemetry` under it), with the same service key as the stats. Unset key = telemetry is off (logged once). */
85
113
  readonly monitoringBaseUrl: string;
86
- /** Watchparty's origin, whose sprites draw a member's character on a room's link preview (`http/preview.ts`). */
114
+ /** Watchparty's origin, whose sprites draw a member's character on a room's link preview. */
87
115
  readonly watchpartyBaseUrl: string;
88
116
  /** Every user id this server has admitted, so `caller-first-seen` fires once per account. */
89
117
  readonly callersSeenFile: string;
90
118
  /** The prefs mount the stats are reported to, without `/api/v1`. */
91
119
  readonly statsBaseUrl: string;
92
- /**
93
- * ArchiveBot's webhook secret for this app, from the vault via the PM2 wrapper. Prod's wrapper
94
- * holds it and PPE's does not, which is what keeps release notes a prod-only post. Unset = the
95
- * boot announcement is skipped (`announce.ts`).
96
- */
97
- readonly archivebotSecret: string;
98
- /** ArchiveBot's webhook server, on loopback beside this one. */
99
- readonly archivebotUrl: string;
100
- /** `CARDTABLE_STATE_DIR`, resolved; empty when unset (the in-clone layout). */
120
+ /** The resolved state dir; empty when unset (the in-clone layout). */
101
121
  readonly stateDir: string;
102
122
  /** Structured access log destination (gitignored, created on boot). */
103
123
  readonly logDir: string;
104
124
  /**
105
125
  * The server's persisted state: the state dir itself when one is set, else
106
126
  * `data/` beside the log directory. `data/` is gitignored, so a `git pull`
107
- * deploy leaves it alone; e2e sets CARDTABLE_LOG_DIR and therefore gets its
127
+ * deploy leaves it alone; e2e sets the log dir var and therefore gets its
108
128
  * own directory rather than production's.
109
129
  */
110
130
  readonly dataDir: string;
111
- /** Every pod that played a round, kept past its room (`CARDTABLE_TOURNAMENTS_FILE`). */
112
- readonly tournamentsFile: string;
113
- /** The front page's scheduled events (`CARDTABLE_EVENTS_FILE`). */
131
+ /** The front page's scheduled events — a generic room-list feature, not Magic's own. */
114
132
  readonly eventsFile: string;
115
- /** The lobby's rooms, one file each (`CARDTABLE_ROOMS_DIR`). */
133
+ /** The lobby's rooms, one file each. */
116
134
  readonly roomsDir: string;
117
- /** The sound builder's uploads and assignments (`CARDTABLE_SOUNDS_DIR`). */
118
- readonly soundsDir: string;
119
- /**
120
- * How long a draft bot takes over a pick (`CARDTABLE_DRAFT_BOT_PICK_MS`): every
121
- * bot holding a pack takes one card per turn. Long enough that bots do not
122
- * drain a pod into the slowest human's pile at once, short enough that a
123
- * quick drafter rarely waits on one.
124
- */
125
- readonly draftBotPickMs: number;
126
- /**
127
- * A CubeCobra draftbot service for the bots' picks (`room/draftbot.ts`), and its
128
- * `X-Internal-Token`. Unset: no draftbot, every bot pick is the heuristic's.
129
- */
130
- readonly draftbotUrl: string;
131
- readonly draftbotToken: string;
132
- /** Each draft's state, so a pod survives a restart (`CARDTABLE_DRAFTS_DIR`). */
133
- readonly draftsDir: string;
134
- /** A friend's Cube Cobra imports, flat `<id>.json` (`CARDTABLE_CUBES_DIR`). */
135
- readonly cubesDir: string;
136
- /** Every match's action log and public stream (`play/recording/`, `CARDTABLE_RECORDINGS_DIR`). */
137
- readonly recordingsDir: string;
138
- /** Every game both players walked away from, kept to be resumed (`play/parked.ts`, `CARDTABLE_PARKED_DIR`). */
139
- readonly parkedDir: string;
140
- /** The card catalog the pools resolve against (`CARDTABLE_CATALOG`). */
141
- readonly catalogPath: string;
142
- /** The art mirror's log (`upload-art`, `CARDTABLE_ART_MIRROR`): which CDN object holds each card image. Missing, every image is Scryfall's. */
143
- readonly artMirrorPath: string;
144
- /**
145
- * `CARDTABLE_NEW_ROOM_FORMAT=newest` pins every new room to the newest
146
- * Standard era instead of a random one: the e2e harnesses set it, because
147
- * their specs read a fresh room's pool and a run must not depend on a draw.
148
- */
149
- readonly newRoomFormat: string | undefined;
150
- /**
151
- * Where Forge matches run (`CARDTABLE_PLAY_HOSTS`): `local`, this machine, as always (the
152
- * default until the claw acceptance run passes), or `claws`, placed across the hosting claws'
153
- * agents with this machine as the backstop (`play/placement/`). Anything else is `local`.
154
- */
155
- readonly playHosts: "local" | "claws";
156
- /**
157
- * The hosting alerts' Discord webhook, from the vault via the PM2 wrapper
158
- * (`.devvault.json`: `DISCORD_CARDTABLE_ALERT_WEBHOOK`). Unset = alerts are logged, not posted.
159
- */
135
+ /** The hosting alerts' Discord webhook, from the vault via the PM2 wrapper. Unset = alerts are logged, not posted. */
160
136
  readonly alertWebhook: string;
161
- /** How long, past the fencing window, the claws' agents hold their JVMs for the next server on a restart. */
162
- readonly restartGraceMs: number;
163
137
  /** The operator's time-boxed force of the backstop host onto the Forge backstop: a JSON file `{"until":"<ISO>"}`. */
164
138
  readonly backstopForceFile: string;
165
- /** `CARDTABLE_PLAY_PROBE=1`: the e2e harness's dev diagnostics — the scenario routes and the frame and stop traces. Never on in production. */
166
- readonly playProbe: boolean;
167
139
  /**
168
- * `CARDTABLE_PLAY_REJOIN_GRACE_MS`: how long a match nobody is at waits before it is parked
169
- * (`play/socket.ts`'s `PlayDeps.rejoinGraceMs`). Unset is play's own five minutes; a spec that
170
- * parks a game sets it shorter. Never set by the deploy path.
171
- */
172
- readonly playRejoinGraceMs: number | undefined;
173
- /**
174
- * `CARDTABLE_E2E_UNCHECKED_POOLS=1`: the jar-less e2e stack's own escape
175
- * hatch, wave 73 §A follow-up (CI `check` run 39715510788: a jar-less
176
- * server can never pass a plan's verdict, so `Lobby.startDraft` refused
177
- * `plan-not-ready` forever and `draft.spec`'s "two friends draft a whole
178
- * pod" never dealt).
179
- *
180
- * With it, `room/plan.ts`'s `checkCards` answers OK for a source whose
181
- * cards all resolved (`missingText` still refuses — this is an escape from
182
- * "no jar", never from "no catalog text") instead of refusing with "Forge
183
- * is not available". A source checked WITH a jar is unaffected either way:
184
- * nothing here ever stands in for a real `forge.check`.
185
- *
186
- * Nothing in this repo's own deploy path (the PM2 wrapper, the vault
187
- * broker) ever sets this — `config.test.ts` pins that a config built from
188
- * a bare `process.env` (nothing set) reads `false`. `e2e/harness.ts` sets
189
- * it on its OWN jar-less server only (never `e2e/play/harness.ts`'s,
190
- * which has a real jar and keeps running the real check regardless of
191
- * this flag). `index.ts` logs a boot warning whenever it reads true, the
192
- * same register `EDGE_AUTH_SECRET`'s own dev hatch warns at.
193
- */
194
- readonly testUncheckedPools: boolean;
195
- /**
196
- * `CARDTABLE_E2E_NO_RATE_LIMITS=1`: both e2e stacks' escape from the
197
- * per-caller limits on making rooms, organizing events and starting matches
198
- * (`http/request.ts`'s `perCallerLimit`). One test identity makes every room
199
- * and starts every match of a whole run, far past any limit a person meets.
200
- * Never set by the deploy path; `config.test.ts` pins it false from a bare
201
- * environment, and `index.ts` warns at boot whenever it reads true.
140
+ * Both e2e stacks' escape from the per-caller limits on making rooms, organizing events and
141
+ * starting matches (`http/request.ts`'s `perCallerLimit`). Never set by the deploy path.
202
142
  */
203
143
  readonly testNoRateLimits: boolean;
204
144
  /**
205
- * `CARDTABLE_E2E_PEOPLE_STAND_IN=1`: look people up (`people.ts`) without a
206
- * service key, from the e2e edge's prefs-api stand-in at `prefsBaseUrl`. The
207
- * e2e stacks hold no key, which is what keeps match stats off there, and
208
- * without this no spec could see a look. Never set by the deploy path.
145
+ * Look people up without a service key, from the e2e edge's prefs-api stand-in. Never set by
146
+ * the deploy path.
209
147
  */
210
148
  readonly testPeopleStandIn: boolean;
211
- /**
212
- * `CARDTABLE_CATALOG_REFRESH`: on by default, so production needs no
213
- * cross-repo change to keep its catalog current with Scryfall's daily
214
- * bulk file (`pools/refresh.ts`, wave 74 §G). `index.ts` starts the job
215
- * only when this reads `true`.
216
- *
217
- * Off (`'0'`) is for every server that is NOT production: CI's forge-e2e
218
- * on the claws, every dev/e2e server a session boots, and a lane's own
219
- * manual smoke-boot. Each of those would otherwise run `createCatalogRefresh`
220
- * against `CARDTABLE_SCRYFALL_DIR ?? ~/.local/share/cardtable/scryfall` at
221
- * its own boot — a real Scryfall download, every time, into land.sh's
222
- * SHARED art cache when the default path is in play (`e2e/harness.ts` and
223
- * `e2e/play/harness.ts` set this to `'0'` in the server env they spawn,
224
- * for exactly this reason — one lane's `.partial` file there is what
225
- * found this).
226
- */
227
- readonly catalogRefresh: boolean;
228
- /**
229
- * `CARDTABLE_PLAY_SEED`: fixes Forge's shuffles, the coin toss and the precon
230
- * pick for every match this server starts, or undefined (production) for an
231
- * unseeded one. Read at each start, not at boot, so a test can set it.
232
- */
233
- readonly playSeed: number | undefined;
234
- /** Container n's noVNC port is this plus n (the static bench publishes 127.0.0.1:6080+n). */
235
- readonly streamBasePort: number;
236
- /** The first host port a room's seat stream may take — see `stream/alloc.ts`. */
237
- readonly roomStreamBasePort: number;
238
- /** The name every room stream container this server owns starts with; `scripts/stream/container.sh` reads the same variable. */
239
- readonly streamNamePrefix: string;
240
- };
149
+ }
150
+ /** Everything a game-server app needs that is not specific to any one game (w119 §C). */
151
+ export declare function createConfig(options?: CreateConfigOptions): GameServerConfig;
152
+ /**
153
+ * Cardtable's own instance, built once at this module's first import (every existing
154
+ * `import { CONFIG } from '@wolffm/game-server/config'` keeps working unchanged). Not `as const`:
155
+ * several test suites (`edge-auth.test.ts`) cast this to a mutable mapped type and swap individual
156
+ * fields for a case, then restore them — that only works on a plain object, which this is.
157
+ */
158
+ export declare const CONFIG: GameServerConfig;
241
159
  /**
242
160
  * Where a Forge match's run directories go (`CARDTABLE_PLAY_WORK_DIR`). Takes the
243
161
  * environment as an argument, as `play/host.ts`'s `jvmHostConfig` does, so a test
244
162
  * can point one host at its own directory.
163
+ *
164
+ * Stays here rather than moving to Magic's config (w119 §C survey calls this Forge-match specific)
165
+ * because `play/local-jvm.ts` — out of this lane's ownership — imports it directly from this
166
+ * module; moving it would break that file's import with no file in this wave's briefs allowed to
167
+ * fix it. `local-jvm.ts` itself is written generic over "any JVM-hosted engine", so this is
168
+ * defensible as the local JVM launcher's own platform-level default, not only Forge's.
245
169
  */
246
170
  export declare function playWorkDir(env?: NodeJS.ProcessEnv): string;
247
171
  export declare const INDEX_HTML: string;
package/dist/config.js CHANGED
@@ -1,12 +1,30 @@
1
1
  /**
2
- * Runtime config for the Cardtable loopback-UI tunnel server.
2
+ * Runtime config for a game-server app — the PLATFORM half (w119 §C).
3
3
  *
4
- * Every value is env-overridable so the PM2 wrapper (which pulls them from the
5
- * vault broker) can inject them without a code edit.
4
+ * `createConfig` is a factory: every value it returns comes from the `env` object and `envPrefix`
5
+ * it is called with (defaults: `process.env` and `'CARDTABLE'`), read when the factory RUNS, never
6
+ * cached at this module's import. Two calls in one process, with different prefixes and/or
7
+ * env objects, build two independent configs — which is what lets a second game on
8
+ * `@hadoku/game-server` (bomberman) set its own `BOMBERMAN_*` variables instead of cardtable's.
9
+ *
10
+ * `export const CONFIG = createConfig()` below is cardtable's own instance, built the moment this
11
+ * module is first imported — kept for every file that already does `import { CONFIG } from
12
+ * '@hadoku/game-server/config'` and must keep working unchanged.
13
+ *
14
+ * What is NOT here any more: Magic-only settings (catalog, art mirror, draft bot, tournaments,
15
+ * sounds, draft timing, the Forge-hosting envs, the room-stream envs) moved to
16
+ * `games/magic/server/src/config.ts`'s `createMagicConfig`/`MAGIC_CONFIG` — a game with no Forge
17
+ * engine has no business reading `CARDTABLE_DRAFT_BOT_PICK_MS`. Cardtable's deployment-only ArchiveBot
18
+ * settings moved there too (not to `apps/server`): the only two readers,
19
+ * `games/magic/server/src/plugins/{listen,routes}.ts`, are in the `magic` layer, which may not
20
+ * import `apps/server` (the `site` layer) — see `scripts/layers/layers.json`'s allowed directions.
21
+ * Survey: `~/.cache/cardtable-manager/bomberman-survey-2026-11-16.md` §3 has the classification
22
+ * with the original line numbers.
6
23
  */
7
- import { homedir, tmpdir } from 'node:os';
24
+ import { tmpdir } from 'node:os';
8
25
  import { fileURLToPath } from 'node:url';
9
26
  import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
27
+ import { assertFloor as kernelAssertFloor } from '@wolffm/service-kernel/auth';
10
28
  const HERE = dirname(fileURLToPath(import.meta.url));
11
29
  /**
12
30
  * The site's own directory (`apps/server`, whose `dist/` PM2 runs), whatever the process's working directory — PM2
@@ -16,254 +34,67 @@ const HERE = dirname(fileURLToPath(import.meta.url));
16
34
  */
17
35
  export const APP_ROOT = basename(HERE) === 'dist' ? dirname(HERE) : resolve(HERE, '../../../apps/server');
18
36
  /** Resolve a configured path against the package root unless it is absolute. */
19
- const resolveDir = (value) => isAbsolute(value) ? value : resolve(APP_ROOT, value);
20
- /**
21
- * Where the server keeps what it writes (`CARDTABLE_STATE_DIR`): rooms, drafts,
22
- * recordings and the rest of `data/` directly in it, and `logs/` beside them.
23
- * Outside the clone, so a deploy can build a new clone aside and swap it in
24
- * while this one serves. Unset (dev, tests, e2e) = the old in-clone layout,
25
- * `logs/` and `data/` in the package. `state-dir.ts` moves the in-clone copy
26
- * here on the first boot that has it.
27
- */
28
- const STATE_DIR = process.env.CARDTABLE_STATE_DIR ? resolveDir(process.env.CARDTABLE_STATE_DIR) : '';
29
- const LOG_DIR = resolveDir(process.env.CARDTABLE_LOG_DIR || (STATE_DIR ? join(STATE_DIR, 'logs') : 'logs'));
30
- const DATA_DIR = STATE_DIR || resolve(LOG_DIR, '../data');
37
+ const resolveDir = (value) => (isAbsolute(value) ? value : resolve(APP_ROOT, value));
31
38
  /** The in-clone paths a state dir replaces, for the boot move (`state-dir.ts`). */
32
39
  export const LEGACY_STATE = { dataDir: resolve(APP_ROOT, 'data'), logDir: resolve(APP_ROOT, 'logs') };
33
- export const CONFIG = {
34
- /** Port this server listens on. cloudflared points the tunnel hostname here. */
35
- port: parseInt(process.env.CARDTABLE_PORT || '9008', 10),
36
- /**
37
- * Loopback only. The tunnel is the single ingress; binding 0.0.0.0 would put
38
- * this on the LAN with no gate in front of it, because the gate is at the edge.
39
- */
40
- host: process.env.CARDTABLE_HOST || '127.0.0.1',
41
- /**
42
- * The public prefix the BROWSER sees: hadoku.me/cardtable/…
43
- *
44
- * Edge-router stripPrefixes it before forwarding, so THIS process is served
45
- * root paths — but every URL the built bundle emits must still carry the
46
- * prefix, or the browser requests /assets/x.js instead of /cardtable/assets/x.js
47
- * and the page loads blank. assertBasePath() checks that at boot.
48
- */
49
- basePrefix: process.env.CARDTABLE_BASE_PREFIX || '/cardtable',
50
- /**
51
- * The built SPA this server serves off local disk. There is no GitHub-Pages
52
- * shell and no published micro-frontend bundle for a loopback-UI app — this
53
- * directory IS the front end, and `pnpm build` in the child repo produces it.
54
- */
55
- // `../ui/dist` because this repo splits the halves across workspace members:
56
- // apps/ui builds the SPA, apps/server hands it out. The PM2 wrapper passes an
57
- // absolute CARDTABLE_WEB_DIR in production; this default is what makes
58
- // `pnpm --filter @hadoku/server dev` work straight after `pnpm -r build`.
59
- webDir: resolveDir(process.env.CARDTABLE_WEB_DIR || '../ui/dist'),
60
- /**
61
- * Tier floor enforced here as a SECOND seal, independent of route-tiers.ts.
62
- *
63
- * The edge gate is the real one, but it lives in another repo on another
64
- * deploy cadence, and the tunnel hostname is reachable without it. A floor
65
- * here means a route-tiers edit cannot silently widen this app on its own.
66
- */
67
- minTier: process.env.CARDTABLE_MIN_TIER || 'friend',
68
- /**
69
- * Shared secret edge-router stamps as X-Edge-Auth on everything it proxies
70
- * (workers/shared/edgeAuth.ts). Identity headers are believed ONLY when this
71
- * matches. Unset = FAIL CLOSED: every request is degraded to public/anon.
72
- */
73
- edgeAuthSecret: process.env.EDGE_AUTH_SECRET || '',
74
- /**
75
- * Bare-local dev escape hatch. With EDGE_AUTH_SECRET unset this server fails
76
- * closed and strips tier/identity from every request, which locks a local
77
- * browser out of its own app. Never set where the tunnel host is reachable.
78
- */
79
- allowUnverifiedEdge: process.env.CARDTABLE_INSECURE_NO_EDGE_AUTH === '1',
80
- /**
81
- * Identity granted to a header-less caller while allowUnverifiedEdge is on.
82
- * Defaults to the floor, so `pnpm dev` serves the app to a local browser
83
- * instead of 404ing it. Read ONLY on that path — it grants nothing in
84
- * production, where the hatch is off and provenance decides.
85
- */
86
- devTier: process.env.CARDTABLE_DEV_TIER || process.env.CARDTABLE_MIN_TIER || 'friend',
87
- /**
88
- * This server's own service-tier key for the game-stats store and for
89
- * people's prefs rows, from the vault via the PM2 wrapper. Unset = match
90
- * stats are off (logged once), and a music-review read or write is refused
91
- * by prefs-api and answers 502.
92
- */
93
- serviceKey: process.env.CARDTABLE_SERVICE_KEY || '',
94
- /**
95
- * The prefs mount people's own rows are read and written on (`http/musicReviewStore.ts`),
96
- * without `/api/v1`, with the same service key.
97
- */
98
- prefsBaseUrl: process.env.CARDTABLE_PREFS_BASE_URL || 'https://hadoku.me/prefs',
99
- /**
100
- * Where security telemetry is posted (`/health/api/telemetry` under it), with
101
- * the same service key as the stats. Unset key = telemetry is off (logged once).
102
- */
103
- monitoringBaseUrl: process.env.CARDTABLE_MONITORING_BASE_URL || 'https://hadoku.me',
104
- /** Watchparty's origin, whose sprites draw a member's character on a room's link preview (`http/preview.ts`). */
105
- watchpartyBaseUrl: process.env.CARDTABLE_WATCHPARTY_BASE_URL || 'https://hadoku.me/watchparty',
106
- /** Every user id this server has admitted, so `caller-first-seen` fires once per account. */
107
- callersSeenFile: process.env.CARDTABLE_CALLERS_SEEN_FILE ?? join(DATA_DIR, 'callers-seen.json'),
108
- /** The prefs mount the stats are reported to, without `/api/v1`. */
109
- statsBaseUrl: process.env.CARDTABLE_STATS_BASE_URL || 'https://hadoku.me/prefs',
110
- /**
111
- * ArchiveBot's webhook secret for this app, from the vault via the PM2 wrapper. Prod's wrapper
112
- * holds it and PPE's does not, which is what keeps release notes a prod-only post. Unset = the
113
- * boot announcement is skipped (`announce.ts`).
114
- */
115
- archivebotSecret: process.env.ARCHIVEBOT_CARDTABLE_WEBHOOK_SECRET || '',
116
- /** ArchiveBot's webhook server, on loopback beside this one. */
117
- archivebotUrl: process.env.CARDTABLE_ARCHIVEBOT_URL || 'http://127.0.0.1:3004',
118
- /** `CARDTABLE_STATE_DIR`, resolved; empty when unset (the in-clone layout). */
119
- stateDir: STATE_DIR,
120
- /** Structured access log destination (gitignored, created on boot). */
121
- logDir: LOG_DIR,
122
- /**
123
- * The server's persisted state: the state dir itself when one is set, else
124
- * `data/` beside the log directory. `data/` is gitignored, so a `git pull`
125
- * deploy leaves it alone; e2e sets CARDTABLE_LOG_DIR and therefore gets its
126
- * own directory rather than production's.
127
- */
128
- dataDir: DATA_DIR,
129
- /** Every pod that played a round, kept past its room (`CARDTABLE_TOURNAMENTS_FILE`). */
130
- tournamentsFile: process.env.CARDTABLE_TOURNAMENTS_FILE ?? join(DATA_DIR, 'tournaments.json'),
131
- /** The front page's scheduled events (`CARDTABLE_EVENTS_FILE`). */
132
- eventsFile: process.env.CARDTABLE_EVENTS_FILE ?? join(DATA_DIR, 'events.json'),
133
- /** The lobby's rooms, one file each (`CARDTABLE_ROOMS_DIR`). */
134
- roomsDir: process.env.CARDTABLE_ROOMS_DIR ?? join(DATA_DIR, 'rooms'),
135
- /** The sound builder's uploads and assignments (`CARDTABLE_SOUNDS_DIR`). */
136
- soundsDir: process.env.CARDTABLE_SOUNDS_DIR ?? join(DATA_DIR, 'sounds'),
137
- /**
138
- * How long a draft bot takes over a pick (`CARDTABLE_DRAFT_BOT_PICK_MS`): every
139
- * bot holding a pack takes one card per turn. Long enough that bots do not
140
- * drain a pod into the slowest human's pile at once, short enough that a
141
- * quick drafter rarely waits on one.
142
- */
143
- draftBotPickMs: parseInt(process.env.CARDTABLE_DRAFT_BOT_PICK_MS || '1200', 10),
144
- /**
145
- * A CubeCobra draftbot service for the bots' picks (`room/draftbot.ts`), and its
146
- * `X-Internal-Token`. Unset: no draftbot, every bot pick is the heuristic's.
147
- */
148
- draftbotUrl: process.env.CARDTABLE_DRAFTBOT_URL || '',
149
- draftbotToken: process.env.CARDTABLE_DRAFTBOT_TOKEN || '',
150
- /** Each draft's state, so a pod survives a restart (`CARDTABLE_DRAFTS_DIR`). */
151
- draftsDir: process.env.CARDTABLE_DRAFTS_DIR ?? join(DATA_DIR, 'drafts'),
152
- /** A friend's Cube Cobra imports, flat `<id>.json` (`CARDTABLE_CUBES_DIR`). */
153
- cubesDir: process.env.CARDTABLE_CUBES_DIR ?? join(DATA_DIR, 'cubes'),
154
- /** Every match's action log and public stream (`play/recording/`, `CARDTABLE_RECORDINGS_DIR`). */
155
- recordingsDir: process.env.CARDTABLE_RECORDINGS_DIR ?? join(DATA_DIR, 'recordings'),
156
- /** Every game both players walked away from, kept to be resumed (`play/parked.ts`, `CARDTABLE_PARKED_DIR`). */
157
- parkedDir: process.env.CARDTABLE_PARKED_DIR ?? join(DATA_DIR, 'parked'),
158
- /** The card catalog the pools resolve against (`CARDTABLE_CATALOG`). */
159
- catalogPath: process.env.CARDTABLE_CATALOG ?? resolve(homedir(), '.local/share/cardtable/catalog/cards.json'),
160
- /** The art mirror's log (`upload-art`, `CARDTABLE_ART_MIRROR`): which CDN object holds each card image. Missing, every image is Scryfall's. */
161
- artMirrorPath: process.env.CARDTABLE_ART_MIRROR ?? resolve(homedir(), '.local/share/cardtable/art/mirror.jsonl'),
162
- /**
163
- * `CARDTABLE_NEW_ROOM_FORMAT=newest` pins every new room to the newest
164
- * Standard era instead of a random one: the e2e harnesses set it, because
165
- * their specs read a fresh room's pool and a run must not depend on a draw.
166
- */
167
- newRoomFormat: process.env.CARDTABLE_NEW_ROOM_FORMAT,
168
- /**
169
- * Where Forge matches run (`CARDTABLE_PLAY_HOSTS`): `local`, this machine, as always (the
170
- * default until the claw acceptance run passes), or `claws`, placed across the hosting claws'
171
- * agents with this machine as the backstop (`play/placement/`). Anything else is `local`.
172
- */
173
- playHosts: process.env.CARDTABLE_PLAY_HOSTS === 'claws' ? 'claws' : 'local',
174
- /**
175
- * The hosting alerts' Discord webhook, from the vault via the PM2 wrapper
176
- * (`.devvault.json`: `DISCORD_CARDTABLE_ALERT_WEBHOOK`). Unset = alerts are logged, not posted.
177
- */
178
- alertWebhook: process.env.DISCORD_CARDTABLE_ALERT_WEBHOOK || '',
179
- /** How long, past the fencing window, the claws' agents hold their JVMs for the next server on a restart. */
180
- restartGraceMs: parseInt(process.env.CARDTABLE_PLAY_RESTART_GRACE_MS || '90000', 10),
181
- /** The operator's time-boxed force of the backstop host onto the Forge backstop: a JSON file `{"until":"<ISO>"}`. */
182
- backstopForceFile: process.env.CARDTABLE_BACKSTOP_FORCE_FILE ?? join(DATA_DIR, 'backstop-force.json'),
183
- /** `CARDTABLE_PLAY_PROBE=1`: the e2e harness's dev diagnostics — the scenario routes and the frame and stop traces. Never on in production. */
184
- playProbe: process.env.CARDTABLE_PLAY_PROBE === '1',
185
- /**
186
- * `CARDTABLE_PLAY_REJOIN_GRACE_MS`: how long a match nobody is at waits before it is parked
187
- * (`play/socket.ts`'s `PlayDeps.rejoinGraceMs`). Unset is play's own five minutes; a spec that
188
- * parks a game sets it shorter. Never set by the deploy path.
189
- */
190
- playRejoinGraceMs: process.env.CARDTABLE_PLAY_REJOIN_GRACE_MS === undefined ? undefined : parseInt(process.env.CARDTABLE_PLAY_REJOIN_GRACE_MS, 10),
191
- /**
192
- * `CARDTABLE_E2E_UNCHECKED_POOLS=1`: the jar-less e2e stack's own escape
193
- * hatch, wave 73 §A follow-up (CI `check` run 39715510788: a jar-less
194
- * server can never pass a plan's verdict, so `Lobby.startDraft` refused
195
- * `plan-not-ready` forever and `draft.spec`'s "two friends draft a whole
196
- * pod" never dealt).
197
- *
198
- * With it, `room/plan.ts`'s `checkCards` answers OK for a source whose
199
- * cards all resolved (`missingText` still refuses — this is an escape from
200
- * "no jar", never from "no catalog text") instead of refusing with "Forge
201
- * is not available". A source checked WITH a jar is unaffected either way:
202
- * nothing here ever stands in for a real `forge.check`.
203
- *
204
- * Nothing in this repo's own deploy path (the PM2 wrapper, the vault
205
- * broker) ever sets this — `config.test.ts` pins that a config built from
206
- * a bare `process.env` (nothing set) reads `false`. `e2e/harness.ts` sets
207
- * it on its OWN jar-less server only (never `e2e/play/harness.ts`'s,
208
- * which has a real jar and keeps running the real check regardless of
209
- * this flag). `index.ts` logs a boot warning whenever it reads true, the
210
- * same register `EDGE_AUTH_SECRET`'s own dev hatch warns at.
211
- */
212
- testUncheckedPools: process.env.CARDTABLE_E2E_UNCHECKED_POOLS === '1',
213
- /**
214
- * `CARDTABLE_E2E_NO_RATE_LIMITS=1`: both e2e stacks' escape from the
215
- * per-caller limits on making rooms, organizing events and starting matches
216
- * (`http/request.ts`'s `perCallerLimit`). One test identity makes every room
217
- * and starts every match of a whole run, far past any limit a person meets.
218
- * Never set by the deploy path; `config.test.ts` pins it false from a bare
219
- * environment, and `index.ts` warns at boot whenever it reads true.
220
- */
221
- testNoRateLimits: process.env.CARDTABLE_E2E_NO_RATE_LIMITS === '1',
222
- /**
223
- * `CARDTABLE_E2E_PEOPLE_STAND_IN=1`: look people up (`people.ts`) without a
224
- * service key, from the e2e edge's prefs-api stand-in at `prefsBaseUrl`. The
225
- * e2e stacks hold no key, which is what keeps match stats off there, and
226
- * without this no spec could see a look. Never set by the deploy path.
227
- */
228
- testPeopleStandIn: process.env.CARDTABLE_E2E_PEOPLE_STAND_IN === '1',
229
- /**
230
- * `CARDTABLE_CATALOG_REFRESH`: on by default, so production needs no
231
- * cross-repo change to keep its catalog current with Scryfall's daily
232
- * bulk file (`pools/refresh.ts`, wave 74 §G). `index.ts` starts the job
233
- * only when this reads `true`.
234
- *
235
- * Off (`'0'`) is for every server that is NOT production: CI's forge-e2e
236
- * on the claws, every dev/e2e server a session boots, and a lane's own
237
- * manual smoke-boot. Each of those would otherwise run `createCatalogRefresh`
238
- * against `CARDTABLE_SCRYFALL_DIR ?? ~/.local/share/cardtable/scryfall` at
239
- * its own boot — a real Scryfall download, every time, into land.sh's
240
- * SHARED art cache when the default path is in play (`e2e/harness.ts` and
241
- * `e2e/play/harness.ts` set this to `'0'` in the server env they spawn,
242
- * for exactly this reason — one lane's `.partial` file there is what
243
- * found this).
244
- */
245
- catalogRefresh: process.env.CARDTABLE_CATALOG_REFRESH !== '0',
246
- /**
247
- * `CARDTABLE_PLAY_SEED`: fixes Forge's shuffles, the coin toss and the precon
248
- * pick for every match this server starts, or undefined (production) for an
249
- * unseeded one. Read at each start, not at boot, so a test can set it.
250
- */
251
- get playSeed() {
252
- const raw = process.env.CARDTABLE_PLAY_SEED;
253
- const seed = raw === undefined || raw === '' ? Number.NaN : Number(raw);
254
- return Number.isFinite(seed) ? seed : undefined;
255
- },
256
- /** Container n's noVNC port is this plus n (the static bench publishes 127.0.0.1:6080+n). */
257
- streamBasePort: Number(process.env.CARDTABLE_STREAM_PORT ?? 6080),
258
- /** The first host port a room's seat stream may take — see `stream/alloc.ts`. */
259
- roomStreamBasePort: Number(process.env.CARDTABLE_ROOM_STREAM_PORT ?? 6100),
260
- /** The name every room stream container this server owns starts with; `scripts/stream/container.sh` reads the same variable. */
261
- streamNamePrefix: process.env.CARDTABLE_STREAM_NAME_PREFIX ?? 'cardtable-room',
262
- };
40
+ /** Everything a game-server app needs that is not specific to any one game (w119 §C). */
41
+ export function createConfig(options = {}) {
42
+ const prefix = options.envPrefix ?? 'CARDTABLE';
43
+ const env = options.env ?? process.env;
44
+ const read = (name) => env[`${prefix}_${name}`];
45
+ const stateDirRaw = read('STATE_DIR');
46
+ const stateDir = stateDirRaw ? resolveDir(stateDirRaw) : '';
47
+ const logDir = resolveDir(read('LOG_DIR') || (stateDir ? join(stateDir, 'logs') : 'logs'));
48
+ const dataDir = stateDir || resolve(logDir, '../data');
49
+ const minTierRaw = read('MIN_TIER') || 'friend';
50
+ const minTier = kernelAssertFloor(minTierRaw, { envPrefix: prefix, allowPublic: false });
51
+ return {
52
+ port: parseInt(read('PORT') || '9008', 10),
53
+ host: read('HOST') || '127.0.0.1',
54
+ basePrefix: read('BASE_PREFIX') || '/cardtable',
55
+ // `../ui/dist` because this repo splits the halves across workspace members: apps/ui builds
56
+ // the SPA, apps/server hands it out. The PM2 wrapper passes an absolute WEB_DIR in
57
+ // production; this default is what makes `pnpm --filter @hadoku/server dev` work straight
58
+ // after `pnpm -r build`.
59
+ webDir: resolveDir(read('WEB_DIR') || '../ui/dist'),
60
+ minTier,
61
+ edgeAuthSecret: env.EDGE_AUTH_SECRET || '',
62
+ allowUnverifiedEdge: read('INSECURE_NO_EDGE_AUTH') === '1',
63
+ devTier: read('DEV_TIER') || minTierRaw,
64
+ serviceKey: read('SERVICE_KEY') || '',
65
+ prefsBaseUrl: read('PREFS_BASE_URL') || 'https://hadoku.me/prefs',
66
+ monitoringBaseUrl: read('MONITORING_BASE_URL') || 'https://hadoku.me',
67
+ watchpartyBaseUrl: read('WATCHPARTY_BASE_URL') || 'https://hadoku.me/watchparty',
68
+ callersSeenFile: read('CALLERS_SEEN_FILE') ?? join(dataDir, 'callers-seen.json'),
69
+ statsBaseUrl: read('STATS_BASE_URL') || 'https://hadoku.me/prefs',
70
+ stateDir,
71
+ logDir,
72
+ dataDir,
73
+ eventsFile: read('EVENTS_FILE') ?? join(dataDir, 'events.json'),
74
+ roomsDir: read('ROOMS_DIR') ?? join(dataDir, 'rooms'),
75
+ alertWebhook: env[`DISCORD_${prefix}_ALERT_WEBHOOK`] || '',
76
+ backstopForceFile: read('BACKSTOP_FORCE_FILE') ?? join(dataDir, 'backstop-force.json'),
77
+ testNoRateLimits: read('E2E_NO_RATE_LIMITS') === '1',
78
+ testPeopleStandIn: read('E2E_PEOPLE_STAND_IN') === '1',
79
+ };
80
+ }
81
+ /**
82
+ * Cardtable's own instance, built once at this module's first import (every existing
83
+ * `import { CONFIG } from '@wolffm/game-server/config'` keeps working unchanged). Not `as const`:
84
+ * several test suites (`edge-auth.test.ts`) cast this to a mutable mapped type and swap individual
85
+ * fields for a case, then restore them — that only works on a plain object, which this is.
86
+ */
87
+ export const CONFIG = createConfig();
263
88
  /**
264
89
  * Where a Forge match's run directories go (`CARDTABLE_PLAY_WORK_DIR`). Takes the
265
90
  * environment as an argument, as `play/host.ts`'s `jvmHostConfig` does, so a test
266
91
  * can point one host at its own directory.
92
+ *
93
+ * Stays here rather than moving to Magic's config (w119 §C survey calls this Forge-match specific)
94
+ * because `play/local-jvm.ts` — out of this lane's ownership — imports it directly from this
95
+ * module; moving it would break that file's import with no file in this wave's briefs allowed to
96
+ * fix it. `local-jvm.ts` itself is written generic over "any JVM-hosted engine", so this is
97
+ * defensible as the local JVM launcher's own platform-level default, not only Forge's.
267
98
  */
268
99
  export function playWorkDir(env = process.env) {
269
100
  return resolve(env.CARDTABLE_PLAY_WORK_DIR ?? join(tmpdir(), 'cardtable-play'));
@@ -21,6 +21,12 @@ export type { Tier };
21
21
  * (`CARDTABLE_MIN_TIER=member` on a build without `member`) would silently
22
22
  * admit everyone, the direct tunnel hits included. Refusing to boot is the
23
23
  * only safe answer.
24
+ *
25
+ * Kept here for every existing caller (and `edge-auth.test.ts`'s refusal coverage) — the real,
26
+ * fail-closed check now runs inside `config.ts`'s `createConfig` itself (w119 §C.4), at the one
27
+ * deterministic place that builds `CONFIG.minTier`, not as an import-time side effect of this
28
+ * file. `CONFIG.minTier` is therefore already asserted by the time anything reads it; this
29
+ * wrapper just lets a caller (or a test) run the same check against an arbitrary string.
24
30
  */
25
31
  export declare function assertFloor(tier: string): Tier;
26
32
  /** Force a public/anon identity unless edge provenance is proven. */
package/dist/edge-auth.js CHANGED
@@ -12,7 +12,6 @@
12
12
  * the most restrictive identity.
13
13
  */
14
14
  import { TIER_ORDER, assertFloor as kernelAssertFloor, rankOf, tierOf, verifiedOf, verifiedFromHeaders, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, } from '@wolffm/service-kernel/auth';
15
- import { CONFIG } from './config.js';
16
15
  import { ENV_PREFIX, edgeAuth, gate } from './kernel.js';
17
16
  export { TIER_ORDER, rankOf, tierOf, verifiedOf, verifiedFromHeaders, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin };
18
17
  /**
@@ -22,11 +21,16 @@ export { TIER_ORDER, rankOf, tierOf, verifiedOf, verifiedFromHeaders, callerIdOf
22
21
  * (`CARDTABLE_MIN_TIER=member` on a build without `member`) would silently
23
22
  * admit everyone, the direct tunnel hits included. Refusing to boot is the
24
23
  * only safe answer.
24
+ *
25
+ * Kept here for every existing caller (and `edge-auth.test.ts`'s refusal coverage) — the real,
26
+ * fail-closed check now runs inside `config.ts`'s `createConfig` itself (w119 §C.4), at the one
27
+ * deterministic place that builds `CONFIG.minTier`, not as an import-time side effect of this
28
+ * file. `CONFIG.minTier` is therefore already asserted by the time anything reads it; this
29
+ * wrapper just lets a caller (or a test) run the same check against an arbitrary string.
25
30
  */
26
31
  export function assertFloor(tier) {
27
32
  return kernelAssertFloor(tier, { envPrefix: ENV_PREFIX, allowPublic: false });
28
33
  }
29
- assertFloor(CONFIG.minTier);
30
34
  /** Force a public/anon identity unless edge provenance is proven. */
31
35
  export const sanitizeHeaders = edgeAuth.sanitizeHeaders;
32
36
  /**
@@ -138,19 +138,29 @@ export interface HeadlessRules {
138
138
  bestOf: 1 | 3;
139
139
  gameS: number;
140
140
  }
141
- export interface MatchSpec {
142
- /**
143
- * Seat 0 is a human in every match a player sees: the bridge refuses a match with no human seat,
144
- * because Forge watches an AI-against-AI game through a desktop window a headless JVM cannot open.
145
- * Only a bot game ({@link headless}) seats two AIs, and it never opens that window.
146
- */
147
- seats: [SeatSpec & {
148
- ai: false;
149
- }, SeatSpec] | [SeatSpec & {
150
- ai: true;
151
- }, SeatSpec & {
152
- ai: true;
153
- }];
141
+ /**
142
+ * What a match needs to start, generic over the game `G`'s own extra fields (w119 §C). Only
143
+ * `seats` (its length) and {@link MatchSpec.headless} (its presence) are read by this file's own
144
+ * coordinator — everything else below is opaque to it: spread onto `config.json` (`bridgeConfig`)
145
+ * and kept whole in `JvmRecord`, never interpreted here.
146
+ *
147
+ * `G`'s default, `unknown` (so `KnownFields & unknown` simplifies back to `KnownFields`), keeps every existing bare `MatchSpec` (no type
148
+ * argument) call site reading exactly the shape below — every field here was Forge-specific
149
+ * before this wave, and still is; nothing is removed. One thing DID move (w119 §C.3): `seats` is
150
+ * a plain array, not the old 2-tuple with "seat 0 is never AI" encoded in its type (that rule is
151
+ * `socket.ts`'s/the bridge's to enforce, not this type's) — so `runtimes/relay-match.ts`'s
152
+ * pod-sized, no-AI roster no longer needs `as unknown as MatchSpec` to fit it.
153
+ *
154
+ * A fuller split — moving `.dck` text, puzzle scenarios, hand smoothing and coin-toss rigging out
155
+ * of this base into a Magic-only `G` — would need edits to files outside w119 §C's ownership
156
+ * (`packages/game-server/src/play/placement/coordinator.ts`, and most of `games/magic/server/src/
157
+ * play/*`'s own `MatchSpec` readers: `match.ts`, `botgames.ts`, `parked.ts`, `deck-colors.ts`,
158
+ * `table-game.ts`, `art.ts`, `recording/{recorder,rebuild}.ts`, `match/registry.ts`,
159
+ * `http/routes.ts`), so it is deferred; see the wave report.
160
+ */
161
+ export type MatchSpec<G = unknown> = {
162
+ /** Every seat this match starts with. */
163
+ seats: SeatSpec[];
154
164
  /** A bot game ({@link HeadlessRules}); absent for every match a player plays or watches. */
155
165
  headless?: HeadlessRules;
156
166
  /** Seeds Forge's shuffles and the precon pick, for a repeatable test run. Omitted in play. */
@@ -215,7 +225,7 @@ export interface MatchSpec {
215
225
  * Absent: no clock. Inert in the JVM, like `format`.
216
226
  */
217
227
  clockMs?: [number, number];
218
- }
228
+ } & G;
219
229
  /**
220
230
  * The four lines the host and placement read from any engine's own line type `L`; everything else
221
231
  * is the game's own (w103 §H's pinned shape). Forge's full `BridgeLine` (now `bridge-protocol.ts`)
@@ -22,9 +22,11 @@
22
22
  import { HostedMatch } from '../match/hosted.js';
23
23
  import { inProcessHost } from './in-process.js';
24
24
  import { RelaySession } from './relay.js';
25
- /** A `MatchSpec` with `seatCount` seats, none AI. `host.ts`'s own tuple-typed `seats` is Forge's;
26
- * nothing here ever reads a relay match's `spec` back (there is no engine to configure), so the
27
- * cast below is inert and stays local to this one file. */
25
+ /**
26
+ * A `MatchSpec` with `seatCount` seats, none AI. `MatchSpec.seats` is a plain `SeatSpec[]` (w119
27
+ * §C), not the old 2-tuple built for Forge's own "seat 0 is never AI" rule, so a pod-sized roster
28
+ * like this one needs no `as unknown as MatchSpec` to fit it any more.
29
+ */
28
30
  function relaySpec(seatCount) {
29
31
  const seats = Array.from({ length: seatCount }, (_, seat) => ({ ai: false, name: `Seat ${seat}`, deck: null }));
30
32
  return { seats };
@@ -1,11 +1,16 @@
1
1
  /**
2
- * The first host port a room's seat may take.
2
+ * The first host port a room's seat may take, when `createRoomStreams`'s caller does not pass its
3
+ * own `basePort`.
3
4
  *
4
5
  * Deliberately clear of everything else on this host: 6080–6081 are the static
5
6
  * bench, and the e2e harness picks its ports from 20000 up (`e2e/ports.ts`). `container.sh` refuses
6
7
  * anything below 6100 a second time, in case this constant is ever loosened.
8
+ *
9
+ * A literal, not `CONFIG.roomStreamBasePort` (w119 §C): the room-stream ports are Forge/Magic-only
10
+ * (survey §3), so Magic's `MAGIC_CONFIG.roomStreamBasePort` is what `plugins/stream.ts` passes in
11
+ * as `basePort` — this platform file reads no `CARDTABLE_*` env var itself any more.
7
12
  */
8
- export declare const ROOM_STREAM_BASE_PORT: number;
13
+ export declare const ROOM_STREAM_BASE_PORT = 6100;
9
14
  /** Seats in one room. A pod is 8; a constructed table is 2. */
10
15
  export declare const MAX_ROOM_SEATS = 8;
11
16
  /** No websocket attached for this long → the containers go. See the header. */
@@ -42,15 +42,19 @@ import { existsSync } from 'node:fs';
42
42
  import { dirname, join, resolve } from 'node:path';
43
43
  import { fileURLToPath } from 'node:url';
44
44
  import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
45
- import { CONFIG } from '../config.js';
46
45
  /**
47
- * The first host port a room's seat may take.
46
+ * The first host port a room's seat may take, when `createRoomStreams`'s caller does not pass its
47
+ * own `basePort`.
48
48
  *
49
49
  * Deliberately clear of everything else on this host: 6080–6081 are the static
50
50
  * bench, and the e2e harness picks its ports from 20000 up (`e2e/ports.ts`). `container.sh` refuses
51
51
  * anything below 6100 a second time, in case this constant is ever loosened.
52
+ *
53
+ * A literal, not `CONFIG.roomStreamBasePort` (w119 §C): the room-stream ports are Forge/Magic-only
54
+ * (survey §3), so Magic's `MAGIC_CONFIG.roomStreamBasePort` is what `plugins/stream.ts` passes in
55
+ * as `basePort` — this platform file reads no `CARDTABLE_*` env var itself any more.
52
56
  */
53
- export const ROOM_STREAM_BASE_PORT = CONFIG.roomStreamBasePort;
57
+ export const ROOM_STREAM_BASE_PORT = 6100;
54
58
  /**
55
59
  * How many streamed seats may exist on this host AT ONCE, across all rooms.
56
60
  *
@@ -77,8 +81,11 @@ export const IDLE_RECLAIM_MS = 30 * 60_000;
77
81
  * therefore sets its own prefix, and `container.sh` already reads the same
78
82
  * variable, so the script and the server can never disagree about what this
79
83
  * server may touch.
84
+ *
85
+ * A literal default, like {@link ROOM_STREAM_BASE_PORT} — `plugins/stream.ts` passes its own
86
+ * `namePrefix` from `MAGIC_CONFIG.streamNamePrefix` (`CARDTABLE_STREAM_NAME_PREFIX`).
80
87
  */
81
- const CONTAINER_NAME_PREFIX = CONFIG.streamNamePrefix;
88
+ const CONTAINER_NAME_PREFIX = 'cardtable-room';
82
89
  /**
83
90
  * Where `scripts/stream/container.sh` is, found by walking up from this file.
84
91
  *
@@ -45,7 +45,7 @@ export declare function roomStreamPathOf(url: string | undefined): RoomStreamPat
45
45
  * proxy to a port, and guessing here is a port scan. Bounded because an
46
46
  * unbounded count is the same scan with more steps.
47
47
  */
48
- export declare function streamLayout(exists?: (p: string) => boolean, read?: (p: string) => string): {
48
+ export declare function streamLayout(exists?: (p: string) => boolean, read?: (p: string) => string, dir?: string): {
49
49
  streamCount: number;
50
50
  };
51
51
  /**
@@ -84,9 +84,17 @@ export function roomStreamPathOf(url) {
84
84
  const rest = m[3] ?? '/';
85
85
  return { roomKey, seat: Number(m[2]), rest: query === undefined ? rest : `${rest}?${query}` };
86
86
  }
87
- // `CARDTABLE_STREAM_DIR` keeps a second server on the same machine (`pnpm dev`) off this one's containers.
88
- const STREAM_DIR = process.env.CARDTABLE_STREAM_DIR ?? join(homedir(), '.local', 'share', 'cardtable', 'stream');
89
- const STREAMS_FILE = join(STREAM_DIR, 'STREAMS');
87
+ /**
88
+ * Where `STREAMS` lives, if `streamLayout`'s caller passes nothing: `~/.local/share/cardtable/
89
+ * stream`, same as `CARDTABLE_STREAM_DIR`'s old default. A literal, not a `process.env` read (w119
90
+ * §C, same reasoning as `alloc.ts`'s `ROOM_STREAM_BASE_PORT`/`CONTAINER_NAME_PREFIX`): this
91
+ * platform file reads no `CARDTABLE_*` var itself any more. `games/magic/server/src/plugins/
92
+ * stream.ts` passes `MAGIC_CONFIG.streamDir` (`CARDTABLE_STREAM_DIR`, so a second server on the
93
+ * same machine still stays off this one's containers) as `streamLayout`'s `dir`.
94
+ */
95
+ function streamsFile(dir) {
96
+ return join(dir ?? join(homedir(), '.local', 'share', 'cardtable', 'stream'), 'STREAMS');
97
+ }
90
98
  /**
91
99
  * How many containers to expose, read from `STREAMS` on disk.
92
100
  *
@@ -94,9 +102,10 @@ const STREAMS_FILE = join(STREAM_DIR, 'STREAMS');
94
102
  * proxy to a port, and guessing here is a port scan. Bounded because an
95
103
  * unbounded count is the same scan with more steps.
96
104
  */
97
- export function streamLayout(exists = existsSync, read = (f) => readFileSync(f, 'utf8')) {
105
+ export function streamLayout(exists = existsSync, read = (f) => readFileSync(f, 'utf8'), dir) {
106
+ const streamsFilePath = streamsFile(dir);
98
107
  try {
99
- const raw = exists(STREAMS_FILE) ? read(STREAMS_FILE).trim() : '0';
108
+ const raw = exists(streamsFilePath) ? read(streamsFilePath).trim() : '0';
100
109
  const n = Number(raw);
101
110
  return { streamCount: Number.isInteger(n) && n >= 0 && n <= 8 ? n : 0 };
102
111
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.11",
4
- "gitHead": "cff61c64decefe8034fe2c3337997377628bbfb5",
3
+ "version": "0.1.13",
4
+ "gitHead": "169a12a10da47b263ed55a1441cbd01a51d2c95b",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
@@ -16,12 +16,12 @@
16
16
  "play/remote/"
17
17
  ],
18
18
  "dependencies": {
19
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.11",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.11",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.44",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.13",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.13",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.46",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
23
- "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.97",
24
- "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.97",
23
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.98",
24
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.98",
25
25
  "express": "^5.1.0",
26
26
  "socket.io": "^4.8.3",
27
27
  "zod": "4.5.4"