@hadoku/game-server 0.1.210 → 0.1.212
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 +1 -3
- package/dist/config.js +1 -2
- package/dist/play/host.d.ts +1 -0
- package/dist/play/host.js +1 -1
- package/dist/play/local-jvm.d.ts +3 -7
- package/dist/play/local-jvm.js +6 -8
- package/dist/relay-game.js +2 -2
- package/dist/stats/reporter.d.ts +3 -0
- package/dist/stats/reporter.js +4 -0
- package/dist/stream/alloc.d.ts +8 -15
- package/dist/stream/alloc.js +2 -33
- package/dist/stream/index.d.ts +6 -3
- package/dist/stream/index.js +6 -19
- package/dist/telemetry.d.ts +3 -30
- package/dist/telemetry.js +1 -16
- package/package.json +5 -6
- package/dist/base-path.d.ts +0 -25
- package/dist/base-path.js +0 -25
- package/dist/busy.d.ts +0 -39
- package/dist/busy.js +0 -22
- package/dist/capacity.d.ts +0 -9
- package/dist/capacity.js +0 -6
package/dist/config.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* test three hops away that never touches a field — ran the whole factory as a side effect.
|
|
19
19
|
*
|
|
20
20
|
* What is NOT here any more: Magic-only settings (catalog, art mirror, draft bot, tournaments,
|
|
21
|
-
* sounds, draft timing, the Forge-hosting envs, the room-stream envs
|
|
21
|
+
* sounds, draft timing, the Forge-hosting envs, the room-stream envs) moved to
|
|
22
22
|
* `games/magic/server/src/config.ts`'s `createMagicConfig`/`MAGIC_CONFIG` (itself lazy the same
|
|
23
23
|
* way) — a game with no Forge engine has no business reading `CARDTABLE_DRAFT_BOT_PICK_MS`.
|
|
24
24
|
* Cardtable's deployment-only ArchiveBot settings moved to `apps/server/src/plugins/archivebot.ts`
|
|
@@ -128,8 +128,6 @@ export interface GameServerConfig {
|
|
|
128
128
|
readonly watchpartyBaseUrl: string;
|
|
129
129
|
/** Every user id this server has admitted, so `caller-first-seen` fires once per account. */
|
|
130
130
|
readonly callersSeenFile: string;
|
|
131
|
-
/** The prefs mount the stats are reported to, without `/api/v1`. */
|
|
132
|
-
readonly statsBaseUrl: string;
|
|
133
131
|
/** The resolved state dir; empty when unset (the in-clone layout). */
|
|
134
132
|
readonly stateDir: string;
|
|
135
133
|
/** Structured access log destination (gitignored, created on boot). */
|
package/dist/config.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* test three hops away that never touches a field — ran the whole factory as a side effect.
|
|
19
19
|
*
|
|
20
20
|
* What is NOT here any more: Magic-only settings (catalog, art mirror, draft bot, tournaments,
|
|
21
|
-
* sounds, draft timing, the Forge-hosting envs, the room-stream envs
|
|
21
|
+
* sounds, draft timing, the Forge-hosting envs, the room-stream envs) moved to
|
|
22
22
|
* `games/magic/server/src/config.ts`'s `createMagicConfig`/`MAGIC_CONFIG` (itself lazy the same
|
|
23
23
|
* way) — a game with no Forge engine has no business reading `CARDTABLE_DRAFT_BOT_PICK_MS`.
|
|
24
24
|
* Cardtable's deployment-only ArchiveBot settings moved to `apps/server/src/plugins/archivebot.ts`
|
|
@@ -71,7 +71,6 @@ export function createConfig(options = {}) {
|
|
|
71
71
|
monitoringBaseUrl: read('MONITORING_BASE_URL') || 'https://hadoku.me',
|
|
72
72
|
watchpartyBaseUrl: read('WATCHPARTY_BASE_URL') || 'https://hadoku.me/watchparty',
|
|
73
73
|
callersSeenFile: resolveDir(read('CALLERS_SEEN_FILE') ?? join(dataDir, 'callers-seen.json')),
|
|
74
|
-
statsBaseUrl: read('STATS_BASE_URL') || 'https://hadoku.me/prefs',
|
|
75
74
|
stateDir,
|
|
76
75
|
logDir,
|
|
77
76
|
dataDir,
|
package/dist/play/host.d.ts
CHANGED
|
@@ -400,6 +400,7 @@ export declare const ORPHAN_MAX_MS: number;
|
|
|
400
400
|
export declare const ORPHAN_CLAIM_MS = 60000;
|
|
401
401
|
/** A match's stream: every line and command, in order, for a re-attach to replay. */
|
|
402
402
|
export declare function streamFile(dir: string, matchId: string): string;
|
|
403
|
+
export declare const LINE_TYPES: ReadonlySet<string>;
|
|
403
404
|
/**
|
|
404
405
|
* The `bridge.stderr.txt` of the local JVM that hosts `matchId`, found by the `match-placed`
|
|
405
406
|
* line the coordinator logged to that match's log. A JVM's run directory is named for the JVM,
|
package/dist/play/host.js
CHANGED
|
@@ -167,7 +167,7 @@ export function streamFile(dir, matchId) {
|
|
|
167
167
|
function brokenStreamFile(dir, matchId) {
|
|
168
168
|
return join(dir, `${matchId}.broken.jsonl`);
|
|
169
169
|
}
|
|
170
|
-
const LINE_TYPES = new Set(['ready', 'frame', 'probe', 'gameover', 'log', 'fatal', 'rejected', 'stale', 'unsupported', 'pace', 'pace-read', 'resent', 'applied', 'input', 'dropped', 'snapshot', 'impersonated', 'scan-overtaken', 'undo', 'rewind', 'rewound', 'log-truncated']);
|
|
170
|
+
export const LINE_TYPES = new Set(['ready', 'frame', 'probe', 'gameover', 'log', 'fatal', 'rejected', 'stale', 'unsupported', 'pace', 'pace-read', 'resent', 'applied', 'input', 'dropped', 'snapshot', 'impersonated', 'scan-overtaken', 'undo', 'rewind', 'rewound', 'log-truncated']);
|
|
171
171
|
/**
|
|
172
172
|
* The `bridge.stderr.txt` of the local JVM that hosts `matchId`, found by the `match-placed`
|
|
173
173
|
* line the coordinator logged to that match's log. A JVM's run directory is named for the JVM,
|
package/dist/play/local-jvm.d.ts
CHANGED
|
@@ -169,17 +169,13 @@ export type JvmAvailability = {
|
|
|
169
169
|
};
|
|
170
170
|
/** Where compiled bridges are kept, shared by every tree on the host (keyed by `bridgeVersion`). */
|
|
171
171
|
export declare function defaultBridgeCache(env?: NodeJS.ProcessEnv): string;
|
|
172
|
+
/** Where a Forge match's run directories go (`CARDTABLE_PLAY_WORK_DIR`). */
|
|
173
|
+
export declare function playWorkDir(env?: NodeJS.ProcessEnv): string;
|
|
172
174
|
/**
|
|
173
175
|
* Resolve the JVM host's configuration, or say exactly what is missing. `bridgeSource` is the game's
|
|
174
176
|
* own bridge (Magic's is `@hadoku/magic-server/root`'s `BRIDGE_SOURCE`): the platform knows no game's tree.
|
|
175
|
-
*
|
|
176
|
-
* `workDir`, when given, is INJECTED by the caller rather than read here (w120 §K: Magic's own
|
|
177
|
-
* `games/magic/server/src/config.ts` has its own `playWorkDir`, which every Magic caller —
|
|
178
|
-
* `plugins/library.ts`, `play/scenario.ts`, `play/recording/rebuild.ts` — passes through this
|
|
179
|
-
* param). Omitted, this file falls back to its own generic default, unchanged from before this
|
|
180
|
-
* param existed, for every other caller (scripts, the UI's jvm harness) that passes none.
|
|
181
177
|
*/
|
|
182
|
-
export declare function jvmHostConfig(bridgeSource: string, env?: NodeJS.ProcessEnv
|
|
178
|
+
export declare function jvmHostConfig(bridgeSource: string, env?: NodeJS.ProcessEnv): JvmAvailability;
|
|
183
179
|
/**
|
|
184
180
|
* A compiled bridge nobody has launched for this long is removed when the next
|
|
185
181
|
* one is compiled. Far past `ORPHAN_MAX_MS`, so no JVM that could still load a
|
package/dist/play/local-jvm.js
CHANGED
|
@@ -143,17 +143,15 @@ export const JVM_HEAP_MB = 2048;
|
|
|
143
143
|
export function defaultBridgeCache(env = process.env) {
|
|
144
144
|
return resolve(env.CARDTABLE_PLAY_BRIDGE_CACHE ?? join(env.XDG_CACHE_HOME ?? join(homedir(), '.cache'), 'cardtable', 'bridge'));
|
|
145
145
|
}
|
|
146
|
+
/** Where a Forge match's run directories go (`CARDTABLE_PLAY_WORK_DIR`). */
|
|
147
|
+
export function playWorkDir(env = process.env) {
|
|
148
|
+
return resolve(env.CARDTABLE_PLAY_WORK_DIR ?? join(tmpdir(), 'cardtable-play'));
|
|
149
|
+
}
|
|
146
150
|
/**
|
|
147
151
|
* Resolve the JVM host's configuration, or say exactly what is missing. `bridgeSource` is the game's
|
|
148
152
|
* own bridge (Magic's is `@hadoku/magic-server/root`'s `BRIDGE_SOURCE`): the platform knows no game's tree.
|
|
149
|
-
*
|
|
150
|
-
* `workDir`, when given, is INJECTED by the caller rather than read here (w120 §K: Magic's own
|
|
151
|
-
* `games/magic/server/src/config.ts` has its own `playWorkDir`, which every Magic caller —
|
|
152
|
-
* `plugins/library.ts`, `play/scenario.ts`, `play/recording/rebuild.ts` — passes through this
|
|
153
|
-
* param). Omitted, this file falls back to its own generic default, unchanged from before this
|
|
154
|
-
* param existed, for every other caller (scripts, the UI's jvm harness) that passes none.
|
|
155
153
|
*/
|
|
156
|
-
export function jvmHostConfig(bridgeSource, env = process.env
|
|
154
|
+
export function jvmHostConfig(bridgeSource, env = process.env) {
|
|
157
155
|
const jar = env.CARDTABLE_FORGE_JAR ?? '';
|
|
158
156
|
const res = env.CARDTABLE_FORGE_RES ?? '';
|
|
159
157
|
if (jar === '')
|
|
@@ -173,7 +171,7 @@ export function jvmHostConfig(bridgeSource, env = process.env, workDir) {
|
|
|
173
171
|
java: env.CARDTABLE_JAVA ?? defaultJava(env),
|
|
174
172
|
jar: resolve(jar),
|
|
175
173
|
res: resolve(res),
|
|
176
|
-
workDir:
|
|
174
|
+
workDir: playWorkDir(env),
|
|
177
175
|
jvmOpts: (env.CARDTABLE_PLAY_JVM_OPTS ?? '').split(/\s+/).filter((s) => s !== ''),
|
|
178
176
|
bridgeSource,
|
|
179
177
|
bridgeCache: defaultBridgeCache(env),
|
package/dist/relay-game.js
CHANGED
|
@@ -49,7 +49,7 @@ import { MATCH_LIVE, RoomLobby, plainRoomType } from './room/lobby.js';
|
|
|
49
49
|
import { attachServedRoom } from './room/serve.js';
|
|
50
50
|
import { COUNTDOWN_MS, createStarts } from './room/starts.js';
|
|
51
51
|
import { attachRoomFeed } from './room/watching.js';
|
|
52
|
-
import {
|
|
52
|
+
import { statsReporterFor } from './stats/reporter.js';
|
|
53
53
|
import { attachResultRoute } from './stats/relay-results.js';
|
|
54
54
|
/** The lobby a relay game's rooms live in: a room IS its match, and there is one game type. */
|
|
55
55
|
export class RelayLobby extends RoomLobby {
|
|
@@ -192,7 +192,7 @@ export async function startRelayGame(options) {
|
|
|
192
192
|
const results = options.results;
|
|
193
193
|
if (results !== undefined) {
|
|
194
194
|
const statsLog = jsonLogger(`${id}-stats`);
|
|
195
|
-
const stats =
|
|
195
|
+
const stats = statsReporterFor(config, `${envPrefix}_SERVICE_KEY`, id, statsLog);
|
|
196
196
|
attachResultRoute(ctx.api, {
|
|
197
197
|
lobby,
|
|
198
198
|
userKeys: ctx.state.userKeys,
|
package/dist/stats/reporter.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* match twice. Moved here from hadoku-bomberman; any game reporting matches uses it.
|
|
6
6
|
*/
|
|
7
7
|
import { type MatchReport, type RecordMatchOptions, type RecordMatchResult } from '@wolffm/prefs-client/games';
|
|
8
|
+
import type { GameServerConfig } from '../config.js';
|
|
8
9
|
export type RecordMatch = (opts: RecordMatchOptions, report: MatchReport) => Promise<RecordMatchResult>;
|
|
9
10
|
export interface StatsReporterOptions {
|
|
10
11
|
/** The store's game id: `/_games/<gameId>/*`. */
|
|
@@ -40,3 +41,5 @@ export declare const DEFAULT_RETRY_DELAYS_MS: readonly [2000, 10000, 60000];
|
|
|
40
41
|
* round twice.
|
|
41
42
|
*/
|
|
42
43
|
export declare function createStatsReporter(opts: StatsReporterOptions): StatsReporter;
|
|
44
|
+
/** A game's reporter from its server config: its service key, and the prefs mount the store is under. */
|
|
45
|
+
export declare function statsReporterFor({ serviceKey, prefsBaseUrl }: Pick<GameServerConfig, 'serviceKey' | 'prefsBaseUrl'>, serviceKeyEnvVar: string, gameId: string, log: (line: Record<string, unknown>) => void): StatsReporter;
|
package/dist/stats/reporter.js
CHANGED
|
@@ -85,3 +85,7 @@ export function createStatsReporter(opts) {
|
|
|
85
85
|
},
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
+
/** A game's reporter from its server config: its service key, and the prefs mount the store is under. */
|
|
89
|
+
export function statsReporterFor({ serviceKey, prefsBaseUrl }, serviceKeyEnvVar, gameId, log) {
|
|
90
|
+
return createStatsReporter({ gameId, serviceKey, serviceKeyEnvVar, baseUrl: prefsBaseUrl, log });
|
|
91
|
+
}
|
package/dist/stream/alloc.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The first host port a room's seat may take, when `createRoomStreams`'s caller does not pass its
|
|
3
|
-
* own `basePort`.
|
|
4
|
-
*
|
|
5
|
-
* Deliberately clear of everything else on this host: 6080–6081 are the static
|
|
6
|
-
* bench, and the e2e harness picks its ports from 20000 up (`e2e/ports.ts`). `container.sh` refuses
|
|
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.
|
|
12
|
-
*/
|
|
13
|
-
export declare const ROOM_STREAM_BASE_PORT = 6100;
|
|
14
1
|
/** Seats in one room. A pod is 8; a constructed table is 2. */
|
|
15
2
|
export declare const MAX_ROOM_SEATS = 8;
|
|
16
3
|
/** No websocket attached for this long → the containers go. See the header. */
|
|
@@ -62,10 +49,16 @@ export interface RoomStreamsOptions {
|
|
|
62
49
|
script?: ContainerScript;
|
|
63
50
|
/** Injectable so the idle window is tested with a fake clock, not a wait. */
|
|
64
51
|
now?: () => number;
|
|
65
|
-
|
|
52
|
+
/** The first host port a room's seat may take; `container.sh` refuses anything below 6100. */
|
|
53
|
+
basePort: number;
|
|
66
54
|
poolSize?: number;
|
|
67
55
|
idleMs?: number;
|
|
68
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Container names are `<namePrefix>-<roomKey>-<seat>`. The prefix is this server's ownership
|
|
58
|
+
* claim: `sweepOrphans()` destroys every container with it that this process does not own, so
|
|
59
|
+
* two servers on one host (an e2e run beside production) must never share one.
|
|
60
|
+
*/
|
|
61
|
+
namePrefix: string;
|
|
69
62
|
log?: (entry: Record<string, unknown>) => void;
|
|
70
63
|
/**
|
|
71
64
|
* A room's containers actually came down — through `release()`, the idle sweep, or `sweep()`
|
package/dist/stream/alloc.js
CHANGED
|
@@ -42,19 +42,6 @@ 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
|
-
/**
|
|
46
|
-
* The first host port a room's seat may take, when `createRoomStreams`'s caller does not pass its
|
|
47
|
-
* own `basePort`.
|
|
48
|
-
*
|
|
49
|
-
* Deliberately clear of everything else on this host: 6080–6081 are the static
|
|
50
|
-
* bench, and the e2e harness picks its ports from 20000 up (`e2e/ports.ts`). `container.sh` refuses
|
|
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.
|
|
56
|
-
*/
|
|
57
|
-
export const ROOM_STREAM_BASE_PORT = 6100;
|
|
58
45
|
/**
|
|
59
46
|
* How many streamed seats may exist on this host AT ONCE, across all rooms.
|
|
60
47
|
*
|
|
@@ -68,24 +55,6 @@ const ROOM_STREAM_POOL = 8;
|
|
|
68
55
|
export const MAX_ROOM_SEATS = 8;
|
|
69
56
|
/** No websocket attached for this long → the containers go. See the header. */
|
|
70
57
|
export const IDLE_RECLAIM_MS = 30 * 60_000;
|
|
71
|
-
/**
|
|
72
|
-
* Container names: `<prefix>-<roomKey>-<seat>`. `container.sh` enforces it.
|
|
73
|
-
*
|
|
74
|
-
* **Env-settable because the prefix is this server's OWNERSHIP claim, and a
|
|
75
|
-
* host can run more than one cardtable.** `sweepOrphans()` destroys every
|
|
76
|
-
* container matching the prefix that this process's `live` map does not own —
|
|
77
|
-
* which is right for reclaiming what a restart of THIS server left behind, and
|
|
78
|
-
* catastrophic across two servers sharing one name. A `pnpm e2e` run boots a
|
|
79
|
-
* second server on the machine that runs production: with one prefix its boot
|
|
80
|
-
* sweep would delete a real player's containers mid-match. The e2e harness
|
|
81
|
-
* therefore sets its own prefix, and `container.sh` already reads the same
|
|
82
|
-
* variable, so the script and the server can never disagree about what this
|
|
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`).
|
|
87
|
-
*/
|
|
88
|
-
const CONTAINER_NAME_PREFIX = 'cardtable-room';
|
|
89
58
|
/**
|
|
90
59
|
* Where `scripts/stream/container.sh` is, found by walking up from this file.
|
|
91
60
|
*
|
|
@@ -147,10 +116,10 @@ export function isStaticIndexLike(roomKey) {
|
|
|
147
116
|
}
|
|
148
117
|
export function createRoomStreams(options) {
|
|
149
118
|
const now = options.now ?? Date.now;
|
|
150
|
-
const basePort = options.basePort
|
|
119
|
+
const basePort = options.basePort;
|
|
151
120
|
const poolSize = options.poolSize ?? ROOM_STREAM_POOL;
|
|
152
121
|
const idleMs = options.idleMs ?? IDLE_RECLAIM_MS;
|
|
153
|
-
const prefix = options.namePrefix
|
|
122
|
+
const prefix = options.namePrefix;
|
|
154
123
|
const log = options.log ?? (() => { });
|
|
155
124
|
const script = options.script ??
|
|
156
125
|
(() => {
|
package/dist/stream/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
import type { Router } from 'express';
|
|
3
|
+
import type { gateUpgrade } from '../gate.js';
|
|
3
4
|
import { type RoomStreams } from './alloc.js';
|
|
4
5
|
export interface StreamDeps {
|
|
5
6
|
/** The tier floor. `CONFIG.minTier` — never lower, never a new tier. */
|
|
6
7
|
minTier: string;
|
|
8
|
+
/** The floor at the websocket upgrade: `@hadoku/game-server/gate`'s `gateUpgrade`. */
|
|
9
|
+
gateUpgrade: typeof gateUpgrade;
|
|
7
10
|
/** Container n's noVNC port is `streamBasePort + n`. */
|
|
8
11
|
streamBasePort: number;
|
|
9
12
|
/** How many STATIC stream containers to expose. 0 → attach none of them. */
|
|
@@ -39,13 +42,13 @@ export interface RoomStreamPath {
|
|
|
39
42
|
*/
|
|
40
43
|
export declare function roomStreamPathOf(url: string | undefined): RoomStreamPath | null;
|
|
41
44
|
/**
|
|
42
|
-
* How many containers to expose, read from
|
|
45
|
+
* How many containers to expose, read from `<dir>/STREAMS` on disk.
|
|
43
46
|
*
|
|
44
47
|
* A malformed count is zero containers, not a guess — each container is a
|
|
45
48
|
* proxy to a port, and guessing here is a port scan. Bounded because an
|
|
46
49
|
* unbounded count is the same scan with more steps.
|
|
47
50
|
*/
|
|
48
|
-
export declare function streamLayout(exists?: (p: string) => boolean, read?: (p: string) => string
|
|
51
|
+
export declare function streamLayout(dir: string, exists?: (p: string) => boolean, read?: (p: string) => string): {
|
|
49
52
|
streamCount: number;
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
@@ -61,6 +64,6 @@ export declare function attachStreamRoutes(app: Router, deps: StreamDeps): boole
|
|
|
61
64
|
/**
|
|
62
65
|
* The websocket half: noVNC talks RFB over a websocket to websockify.
|
|
63
66
|
* express never sees an `upgrade`, so the tier floor is re-applied here by
|
|
64
|
-
* hand, with
|
|
67
|
+
* hand, with the injected `gateUpgrade`.
|
|
65
68
|
*/
|
|
66
69
|
export declare function attachStream(server: Server, deps: StreamDeps): StreamHandle | null;
|
package/dist/stream/index.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* ## The gate
|
|
38
38
|
*
|
|
39
39
|
* The HTTP half is mounted below `requireMinTier`. The websocket half
|
|
40
|
-
* re-applies the floor itself —
|
|
40
|
+
* re-applies the floor itself — the injected `gateUpgrade` — because an
|
|
41
41
|
* `upgrade` event runs no express middleware.
|
|
42
42
|
*
|
|
43
43
|
* **404, never 403.** A different answer for "exists but you may not" tells
|
|
@@ -46,12 +46,10 @@
|
|
|
46
46
|
* the floor, so it tells a friend the truth and an outsider nothing.
|
|
47
47
|
*/
|
|
48
48
|
import { existsSync, readFileSync } from 'node:fs';
|
|
49
|
-
import { homedir } from 'node:os';
|
|
50
49
|
import { join } from 'node:path';
|
|
51
50
|
import { connect } from 'node:net';
|
|
52
51
|
import { request as httpRequest } from 'node:http';
|
|
53
52
|
import express from 'express';
|
|
54
|
-
import { gateUpgrade } from '../gate.js';
|
|
55
53
|
import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
|
|
56
54
|
import { isStaticIndexLike } from './alloc.js';
|
|
57
55
|
/** `/stream/3/websockify` → 3, or null when the path is not a stream path. */
|
|
@@ -85,25 +83,14 @@ export function roomStreamPathOf(url) {
|
|
|
85
83
|
return { roomKey, seat: Number(m[2]), rest: query === undefined ? rest : `${rest}?${query}` };
|
|
86
84
|
}
|
|
87
85
|
/**
|
|
88
|
-
*
|
|
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
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* How many containers to expose, read from `STREAMS` on disk.
|
|
86
|
+
* How many containers to expose, read from `<dir>/STREAMS` on disk.
|
|
100
87
|
*
|
|
101
88
|
* A malformed count is zero containers, not a guess — each container is a
|
|
102
89
|
* proxy to a port, and guessing here is a port scan. Bounded because an
|
|
103
90
|
* unbounded count is the same scan with more steps.
|
|
104
91
|
*/
|
|
105
|
-
export function streamLayout(exists = existsSync, read = (f) => readFileSync(f, 'utf8')
|
|
106
|
-
const streamsFilePath =
|
|
92
|
+
export function streamLayout(dir, exists = existsSync, read = (f) => readFileSync(f, 'utf8')) {
|
|
93
|
+
const streamsFilePath = join(dir, 'STREAMS');
|
|
107
94
|
try {
|
|
108
95
|
const raw = exists(streamsFilePath) ? read(streamsFilePath).trim() : '0';
|
|
109
96
|
const n = Number(raw);
|
|
@@ -229,7 +216,7 @@ export function attachStreamRoutes(app, deps) {
|
|
|
229
216
|
/**
|
|
230
217
|
* The websocket half: noVNC talks RFB over a websocket to websockify.
|
|
231
218
|
* express never sees an `upgrade`, so the tier floor is re-applied here by
|
|
232
|
-
* hand, with
|
|
219
|
+
* hand, with the injected `gateUpgrade`.
|
|
233
220
|
*/
|
|
234
221
|
export function attachStream(server, deps) {
|
|
235
222
|
const rooms = deps.rooms ?? null;
|
|
@@ -245,7 +232,7 @@ export function attachStream(server, deps) {
|
|
|
245
232
|
refuse(socket, 400, 'expected a version-13 websocket upgrade');
|
|
246
233
|
return;
|
|
247
234
|
}
|
|
248
|
-
const floor = gateUpgrade(req, { minTier: deps.minTier, surface: 'stream' });
|
|
235
|
+
const floor = deps.gateUpgrade(req, { minTier: deps.minTier, surface: 'stream' });
|
|
249
236
|
if (!floor.ok) {
|
|
250
237
|
refuse(socket, 404, 'not found');
|
|
251
238
|
return;
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -1,42 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adapter:
|
|
2
|
+
* Adapter: game-server's binding of `@hadoku/service-kernel/telemetry`.
|
|
3
3
|
*
|
|
4
4
|
* The plain re-exports stay because the published `@wolffm/game-server/telemetry` is a contract:
|
|
5
5
|
* bomberman's server imports `callerContext`, `report`, `installTelemetry` and `Report` from it.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* env var named in the disabled-reason log line (`CARDTABLE_SERVICE_KEY`), and the closed set of
|
|
9
|
-
* surfaces a seal refusal ever names — the kernel's own `reportSealRefused` takes an open string,
|
|
10
|
-
* since it knows no game's surface names.
|
|
6
|
+
* What is its own is the closed set of surfaces a seal refusal ever names — the kernel's own
|
|
7
|
+
* `reportSealRefused` takes an open string, since it knows no game's surface names.
|
|
11
8
|
*/
|
|
12
9
|
import type { Request } from 'express';
|
|
13
|
-
import type { JsonLog } from '@wolffm/service-kernel/log';
|
|
14
10
|
import { callerContext, installTelemetry, report, reportingAlerts, type Level, type Report, type TelemetryContext } from '@wolffm/service-kernel/telemetry';
|
|
15
11
|
export { callerContext, installTelemetry, report, reportingAlerts };
|
|
16
12
|
export type { Level, Report, TelemetryContext };
|
|
17
|
-
/**
|
|
18
|
-
* Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
|
|
19
|
-
* (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
|
|
20
|
-
* prefix names itself.
|
|
21
|
-
*/
|
|
22
|
-
export declare function siteOf(basePrefix: string): string;
|
|
23
|
-
export interface SinkOptions {
|
|
24
|
-
/** `https://hadoku.me` — the telemetry route is `/health/api/telemetry` under it. */
|
|
25
|
-
baseUrl: string;
|
|
26
|
-
serviceKey: string;
|
|
27
|
-
log: JsonLog;
|
|
28
|
-
/** This deployment (`siteOf`), on every event. */
|
|
29
|
-
site: string;
|
|
30
|
-
/** One post per (event, caller, incident key) per this many ms. */
|
|
31
|
-
windowMs?: number;
|
|
32
|
-
now?: () => number;
|
|
33
|
-
fetch?: typeof fetch;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A reporter that posts to monitoring-api. Without a service key it posts
|
|
37
|
-
* nothing and says so once, the way the stats reporter does.
|
|
38
|
-
*/
|
|
39
|
-
export declare function monitoringSink(opts: SinkOptions): Report;
|
|
40
13
|
type Headers = Request['headers'];
|
|
41
14
|
/**
|
|
42
15
|
* A seal below the edge refused a caller. With the edge in front this should
|
package/dist/telemetry.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import { callerContext, installTelemetry,
|
|
1
|
+
import { callerContext, installTelemetry, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, } from '@wolffm/service-kernel/telemetry';
|
|
2
2
|
export { callerContext, installTelemetry, report, reportingAlerts };
|
|
3
|
-
/**
|
|
4
|
-
* Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
|
|
5
|
-
* (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
|
|
6
|
-
* prefix names itself.
|
|
7
|
-
*/
|
|
8
|
-
export function siteOf(basePrefix) {
|
|
9
|
-
return kernelSiteOf(basePrefix, 'cardtable');
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A reporter that posts to monitoring-api. Without a service key it posts
|
|
13
|
-
* nothing and says so once, the way the stats reporter does.
|
|
14
|
-
*/
|
|
15
|
-
export function monitoringSink(opts) {
|
|
16
|
-
return kernelMonitoringSink({ ...opts, service: 'cardtable', serviceKeyEnvVar: 'CARDTABLE_SERVICE_KEY' });
|
|
17
|
-
}
|
|
18
3
|
/**
|
|
19
4
|
* A seal below the edge refused a caller. With the edge in front this should
|
|
20
5
|
* never fire: one means a direct hit on the tunnel host, or an edge rule wider
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.212",
|
|
4
|
+
"gitHead": "a9e2641a46c10f8803503badaf42ec88a15b23e9",
|
|
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.",
|
|
@@ -12,14 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"publishLeaveOut": [
|
|
15
|
-
"announce.ts",
|
|
16
15
|
"play/placement/",
|
|
17
16
|
"play/remote/"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
19
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.212",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.212",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.245",
|
|
23
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
24
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",
|
|
25
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.152",
|
package/dist/base-path.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The base-path contract, checked at boot — cardtable's binding of the
|
|
3
|
-
* platform kernel (`@hadoku/service-kernel/http`).
|
|
4
|
-
*
|
|
5
|
-
* This is the one thing about a loopback-UI app that breaks SILENTLY, so it is
|
|
6
|
-
* the one thing this server refuses to guess about.
|
|
7
|
-
*
|
|
8
|
-
* The edge gives us stripPrefix: hadoku.me/cardtable/assets/x.js arrives here
|
|
9
|
-
* as /assets/x.js, which we serve happily. But the BROWSER is at
|
|
10
|
-
* hadoku.me/cardtable/, so a bundle built with the default base emits
|
|
11
|
-
* `src="/assets/x.js"` — an absolute URL with no prefix. The browser asks the
|
|
12
|
-
* edge for hadoku.me/assets/x.js, which is not this app's route, and the page
|
|
13
|
-
* renders blank with a 404 in the console and a 200 on every server-side probe.
|
|
14
|
-
* games-host shipped exactly this: its edge stripPrefix and its backend's base
|
|
15
|
-
* path are two independent declarations of one fact, and nothing compared them.
|
|
16
|
-
*
|
|
17
|
-
* So the kernel's `checkBundle` compares them once, at boot, and says precisely
|
|
18
|
-
* what to change. What is cardtable's own in that check is here.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
|
|
22
|
-
* emits them, watchparty imports the `.js`. Every other file in the bundle is
|
|
23
|
-
* content-hashed; these are the only ones whose bytes change under one name.
|
|
24
|
-
*/
|
|
25
|
-
export declare const EMBED_ENTRIES: readonly ["cardtable-embed.js", "cardtable-embed.css"];
|
package/dist/base-path.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The base-path contract, checked at boot — cardtable's binding of the
|
|
3
|
-
* platform kernel (`@hadoku/service-kernel/http`).
|
|
4
|
-
*
|
|
5
|
-
* This is the one thing about a loopback-UI app that breaks SILENTLY, so it is
|
|
6
|
-
* the one thing this server refuses to guess about.
|
|
7
|
-
*
|
|
8
|
-
* The edge gives us stripPrefix: hadoku.me/cardtable/assets/x.js arrives here
|
|
9
|
-
* as /assets/x.js, which we serve happily. But the BROWSER is at
|
|
10
|
-
* hadoku.me/cardtable/, so a bundle built with the default base emits
|
|
11
|
-
* `src="/assets/x.js"` — an absolute URL with no prefix. The browser asks the
|
|
12
|
-
* edge for hadoku.me/assets/x.js, which is not this app's route, and the page
|
|
13
|
-
* renders blank with a 404 in the console and a 200 on every server-side probe.
|
|
14
|
-
* games-host shipped exactly this: its edge stripPrefix and its backend's base
|
|
15
|
-
* path are two independent declarations of one fact, and nothing compared them.
|
|
16
|
-
*
|
|
17
|
-
* So the kernel's `checkBundle` compares them once, at boot, and says precisely
|
|
18
|
-
* what to change. What is cardtable's own in that check is here.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
|
|
22
|
-
* emits them, watchparty imports the `.js`. Every other file in the bundle is
|
|
23
|
-
* content-hashed; these are the only ones whose bytes change under one name.
|
|
24
|
-
*/
|
|
25
|
-
export const EMBED_ENTRIES = ['cardtable-embed.js', 'cardtable-embed.css'];
|
package/dist/busy.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapter: cardtable's binding of `@hadoku/service-kernel/lifecycle`'s busy probe (w93-K2).
|
|
3
|
-
*
|
|
4
|
-
* The kernel knows only the report's shape, `isLocalProbe` and the HTTP plumbing (fail-safe on
|
|
5
|
-
* `report`'s own throw, 404 to anything proxied). What counts as cardtable's "destroyable work" —
|
|
6
|
-
* a live match or a drafting pod, never a warm JVM or an idle lobby — stays here, unchanged from
|
|
7
|
-
* before this moved (`docs` below is the same text as always).
|
|
8
|
-
*
|
|
9
|
-
* ## What counts as busy — destroyable work, not connections
|
|
10
|
-
*
|
|
11
|
-
* - a match that is `starting` or `running`: a Forge JVM with players seated;
|
|
12
|
-
* - a draft that is `drafting`: picks made, packs mid-pass, held in memory.
|
|
13
|
-
*
|
|
14
|
-
* NOT counted, deliberately:
|
|
15
|
-
*
|
|
16
|
-
* - a match that is `over`, `failed` or `stopped` — finished, nothing left to lose;
|
|
17
|
-
* - a `complete` draft;
|
|
18
|
-
* - **the warm JVM.** `liveJvmCount()` includes it and would report busy every
|
|
19
|
-
* minute of the day; it is a pre-booted process with nobody in it;
|
|
20
|
-
* - **connected-but-idle clients and open lobbies.** They reconnect fine, they
|
|
21
|
-
* never disconnect on their own, and counting them would make every deploy sit
|
|
22
|
-
* until its deadline — at which point the deadline kills the real match anyway.
|
|
23
|
-
*/
|
|
24
|
-
import type { BusyReport } from '@wolffm/service-kernel/lifecycle';
|
|
25
|
-
export interface BusySources {
|
|
26
|
-
matches(): ReadonlyArray<{
|
|
27
|
-
id: string;
|
|
28
|
-
status: string;
|
|
29
|
-
seats: ReadonlyArray<unknown>;
|
|
30
|
-
anyoneHere?: () => boolean;
|
|
31
|
-
}>;
|
|
32
|
-
drafts(): ReadonlyArray<{
|
|
33
|
-
id: string;
|
|
34
|
-
status: string | undefined;
|
|
35
|
-
packNumber?: number;
|
|
36
|
-
pickNumber?: number;
|
|
37
|
-
}>;
|
|
38
|
-
}
|
|
39
|
-
export declare function busyReport(src: BusySources): BusyReport;
|
package/dist/busy.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const BUSY_MATCH = new Set(['starting', 'running']);
|
|
2
|
-
export function busyReport(src) {
|
|
3
|
-
const runs = [];
|
|
4
|
-
for (const m of src.matches()) {
|
|
5
|
-
if (!BUSY_MATCH.has(m.status))
|
|
6
|
-
continue;
|
|
7
|
-
// A running match whose seats have all gone (past the grace) holds nobody's game:
|
|
8
|
-
// the zombie of m-09487f336215 held every deploy for hours on 2026-10-04.
|
|
9
|
-
if (m.status === 'running' && m.anyoneHere !== undefined && !m.anyoneHere())
|
|
10
|
-
continue;
|
|
11
|
-
runs.push({ id: m.id, kind: 'match', label: `${m.seats.length} seats, ${m.status}` });
|
|
12
|
-
}
|
|
13
|
-
for (const d of src.drafts()) {
|
|
14
|
-
if (d.status !== 'drafting')
|
|
15
|
-
continue;
|
|
16
|
-
const at = d.packNumber !== undefined && d.pickNumber !== undefined
|
|
17
|
-
? `pack ${d.packNumber} pick ${d.pickNumber}`
|
|
18
|
-
: 'in progress';
|
|
19
|
-
runs.push({ id: d.id, kind: 'draft', label: at });
|
|
20
|
-
}
|
|
21
|
-
return { busy: runs.length > 0, count: runs.length, runs };
|
|
22
|
-
}
|
package/dist/capacity.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cardtable's binding of the kernel's capacity sampler: a card image request (`http/card-art.ts`)
|
|
3
|
-
* is a redirect to the art host, one per card a page draws, so it is counted on its own as
|
|
4
|
-
* `artRedirects`, never timed nor logged a line each. `index.ts` hands it to `createGameServer`.
|
|
5
|
-
*/
|
|
6
|
-
export declare const ART_REDIRECTS: {
|
|
7
|
-
path: (path: string) => boolean;
|
|
8
|
-
field: string;
|
|
9
|
-
};
|
package/dist/capacity.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cardtable's binding of the kernel's capacity sampler: a card image request (`http/card-art.ts`)
|
|
3
|
-
* is a redirect to the art host, one per card a page draws, so it is counted on its own as
|
|
4
|
-
* `artRedirects`, never timed nor logged a line each. `index.ts` hands it to `createGameServer`.
|
|
5
|
-
*/
|
|
6
|
-
export const ART_REDIRECTS = { path: (path) => path.startsWith('/api/art/'), field: 'artRedirects' };
|