@hadoku/game-server 0.0.0-stage → 0.1.6

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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/dist/base-path.d.ts +29 -0
  3. package/dist/base-path.js +30 -0
  4. package/dist/busy.d.ts +40 -0
  5. package/dist/busy.js +23 -0
  6. package/dist/capacity.d.ts +9 -0
  7. package/dist/capacity.js +6 -0
  8. package/dist/config.d.ts +247 -0
  9. package/dist/config.js +271 -0
  10. package/dist/edge-auth.d.ts +43 -0
  11. package/dist/edge-auth.js +47 -0
  12. package/dist/erase/anonymise.d.ts +7 -0
  13. package/dist/erase/anonymise.js +7 -0
  14. package/dist/erase/index.d.ts +18 -0
  15. package/dist/erase/index.js +20 -0
  16. package/dist/erase/legacy-ids.d.ts +7 -0
  17. package/dist/erase/legacy-ids.js +24 -0
  18. package/dist/erase/recordings.d.ts +26 -0
  19. package/dist/erase/recordings.js +128 -0
  20. package/dist/erase/rooms.d.ts +63 -0
  21. package/dist/erase/rooms.js +67 -0
  22. package/dist/gate.d.ts +27 -0
  23. package/dist/gate.js +15 -0
  24. package/dist/http/client-events.d.ts +25 -0
  25. package/dist/http/client-events.js +15 -0
  26. package/dist/http/page.d.ts +26 -0
  27. package/dist/http/page.js +35 -0
  28. package/dist/http/prepared.d.ts +14 -0
  29. package/dist/http/prepared.js +16 -0
  30. package/dist/http/request.d.ts +59 -0
  31. package/dist/http/request.js +37 -0
  32. package/dist/http/room-core.d.ts +160 -0
  33. package/dist/http/room-core.js +278 -0
  34. package/dist/http/trim.d.ts +23 -0
  35. package/dist/http/trim.js +76 -0
  36. package/dist/http/usage.d.ts +22 -0
  37. package/dist/http/usage.js +16 -0
  38. package/dist/kernel.d.ts +4 -0
  39. package/dist/kernel.js +26 -0
  40. package/dist/log.d.ts +9 -0
  41. package/dist/log.js +9 -0
  42. package/dist/people.d.ts +105 -0
  43. package/dist/people.js +145 -0
  44. package/dist/play/clock.d.ts +39 -0
  45. package/dist/play/clock.js +81 -0
  46. package/dist/play/diagnostics.d.ts +21 -0
  47. package/dist/play/diagnostics.js +35 -0
  48. package/dist/play/engine-runtime.d.ts +200 -0
  49. package/dist/play/engine-runtime.js +309 -0
  50. package/dist/play/game-adapter.d.ts +158 -0
  51. package/dist/play/game-adapter.js +1 -0
  52. package/dist/play/host.d.ts +482 -0
  53. package/dist/play/host.js +950 -0
  54. package/dist/play/jvm-transport.d.ts +25 -0
  55. package/dist/play/jvm-transport.js +1 -0
  56. package/dist/play/local-jvm.d.ts +325 -0
  57. package/dist/play/local-jvm.js +829 -0
  58. package/dist/play/match/hosted.d.ts +92 -0
  59. package/dist/play/match/hosted.js +151 -0
  60. package/dist/play/match/outcome.d.ts +26 -0
  61. package/dist/play/match/outcome.js +21 -0
  62. package/dist/play/match/shell.d.ts +378 -0
  63. package/dist/play/match/shell.js +613 -0
  64. package/dist/play/recording/retention.d.ts +36 -0
  65. package/dist/play/recording/retention.js +89 -0
  66. package/dist/play/recording/writer.d.ts +185 -0
  67. package/dist/play/recording/writer.js +90 -0
  68. package/dist/play/relay-socket.d.ts +128 -0
  69. package/dist/play/relay-socket.js +194 -0
  70. package/dist/play/runtimes/in-process.d.ts +47 -0
  71. package/dist/play/runtimes/in-process.js +43 -0
  72. package/dist/play/runtimes/relay-match.d.ts +166 -0
  73. package/dist/play/runtimes/relay-match.js +240 -0
  74. package/dist/play/runtimes/relay.d.ts +128 -0
  75. package/dist/play/runtimes/relay.js +183 -0
  76. package/dist/play/runtimes/streamed.d.ts +116 -0
  77. package/dist/play/runtimes/streamed.js +148 -0
  78. package/dist/play/start-queue.d.ts +65 -0
  79. package/dist/play/start-queue.js +187 -0
  80. package/dist/room/avatar.d.ts +1 -0
  81. package/dist/room/avatar.js +28 -0
  82. package/dist/room/caller.d.ts +21 -0
  83. package/dist/room/caller.js +1 -0
  84. package/dist/room/constants.d.ts +27 -0
  85. package/dist/room/constants.js +27 -0
  86. package/dist/room/events.d.ts +59 -0
  87. package/dist/room/events.js +174 -0
  88. package/dist/room/identity.d.ts +89 -0
  89. package/dist/room/identity.js +98 -0
  90. package/dist/room/lobby.d.ts +426 -0
  91. package/dist/room/lobby.js +880 -0
  92. package/dist/room/membership.d.ts +64 -0
  93. package/dist/room/membership.js +76 -0
  94. package/dist/room/provisioning.d.ts +22 -0
  95. package/dist/room/provisioning.js +46 -0
  96. package/dist/room/record.d.ts +63 -0
  97. package/dist/room/record.js +39 -0
  98. package/dist/room/room-list.d.ts +67 -0
  99. package/dist/room/room-list.js +66 -0
  100. package/dist/room/seats.d.ts +39 -0
  101. package/dist/room/seats.js +58 -0
  102. package/dist/room/session.d.ts +91 -0
  103. package/dist/room/session.js +156 -0
  104. package/dist/room/socket-auth.d.ts +2 -0
  105. package/dist/room/socket-auth.js +10 -0
  106. package/dist/room/watching.d.ts +35 -0
  107. package/dist/room/watching.js +72 -0
  108. package/dist/room/watchparty-link.d.ts +1 -0
  109. package/dist/room/watchparty-link.js +17 -0
  110. package/dist/stream/alloc.d.ts +115 -0
  111. package/dist/stream/alloc.js +368 -0
  112. package/dist/stream/index.d.ts +66 -0
  113. package/dist/stream/index.js +293 -0
  114. package/dist/telemetry.d.ts +46 -0
  115. package/dist/telemetry.js +25 -0
  116. package/dist/testPort.d.ts +1 -0
  117. package/dist/testPort.js +28 -0
  118. package/package.json +35 -4
  119. package/README.md +0 -3
@@ -0,0 +1,293 @@
1
+ /*
2
+ * `/stream/**` — Forge's own desktop UI, streamed from a container.
3
+ *
4
+ * ## What this is
5
+ *
6
+ * The product keeps two game frontends: our React board, and Forge's own UI
7
+ * for whoever wants the full client (operator decision, 2026-09-20: the old
8
+ * UI stays an option). This route serves that second frontend from containers
9
+ * on this host, each running one Forge desktop with websockify, proxied
10
+ * through the app so it sits behind the same edge and the same friend gate as
11
+ * everything else. The noVNC page itself is served by websockify inside the
12
+ * container — nothing here is vendored, and no image bytes pass through this
13
+ * repo.
14
+ *
15
+ * ## Two forms, deliberately disjoint
16
+ *
17
+ * - **`/stream/<n>/`** — the static bench. A fixed set of containers an
18
+ * operator starts by hand; `n` is an index into them. This is the friend
19
+ * demo's link and it keeps working exactly as it did.
20
+ * - **`/stream/<roomKey>/<seat>/`** — a room's own containers, one per seat,
21
+ * provisioned and reclaimed by `alloc.ts` (D19: the client is the ROOM's
22
+ * choice, made at create).
23
+ *
24
+ * The two namespaces cannot collide: a static index is all digits and a room
25
+ * key that is all digits is refused at allocation (`isStaticIndexLike`), so
26
+ * `streamIndexOf` never has to guess and never swallows a room key.
27
+ *
28
+ * ## The switch for the static half is a file, and it is on this host
29
+ *
30
+ * `STREAM_DIR/STREAMS` names how many containers are up. Absent, unreadable
31
+ * or malformed → zero containers → the static half attaches nothing. The PM2
32
+ * wrapper forwards a fixed env set, so a file on disk is the switch an
33
+ * operator can actually flip — and the one an auditor can see in a directory
34
+ * listing. Room-keyed streams do not read it: a room's containers are the
35
+ * room's, and their switch is the room's own mode.
36
+ *
37
+ * ## The gate
38
+ *
39
+ * The HTTP half is mounted below `requireMinTier`. The websocket half
40
+ * re-applies the floor itself — `../gate.ts`'s `gateUpgrade` — because an
41
+ * `upgrade` event runs no express middleware.
42
+ *
43
+ * **404, never 403.** A different answer for "exists but you may not" tells
44
+ * an outsider which paths are real, and this app answers that way everywhere
45
+ * else. A room whose containers were reclaimed answers 410 — but only AFTER
46
+ * the floor, so it tells a friend the truth and an outsider nothing.
47
+ */
48
+ import { existsSync, readFileSync } from 'node:fs';
49
+ import { homedir } from 'node:os';
50
+ import { join } from 'node:path';
51
+ import { connect } from 'node:net';
52
+ import { request as httpRequest } from 'node:http';
53
+ import express from 'express';
54
+ import { gateUpgrade } from '../gate.js';
55
+ import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
56
+ import { isStaticIndexLike } from './alloc.js';
57
+ /** `/stream/3/websockify` → 3, or null when the path is not a stream path. */
58
+ export function streamIndexOf(url, count) {
59
+ if (url === undefined)
60
+ return null;
61
+ const m = /^\/stream\/(\d+)(?:\/|$)/.exec(url.split('?')[0] ?? '');
62
+ if (m === null)
63
+ return null;
64
+ const n = Number(m[1]);
65
+ return Number.isInteger(n) && n >= 0 && n < count ? n : null;
66
+ }
67
+ /**
68
+ * `/stream/kitchen-table/1/vnc.html` → that room's seat 1.
69
+ *
70
+ * Null for anything else — including a key that is all digits, which belongs
71
+ * to the static form and is refused at allocation for exactly this reason.
72
+ * The seat is bounded to two digits because a room has at most eight.
73
+ */
74
+ export function roomStreamPathOf(url) {
75
+ if (url === undefined)
76
+ return null;
77
+ const [path = '', query] = url.split('?');
78
+ const m = /^\/stream\/([^/]+)\/(\d{1,2})(\/.*)?$/.exec(path);
79
+ if (m === null)
80
+ return null;
81
+ const roomKey = m[1] ?? '';
82
+ if (!ROOM_ID_RE.test(roomKey) || isStaticIndexLike(roomKey))
83
+ return null;
84
+ const rest = m[3] ?? '/';
85
+ return { roomKey, seat: Number(m[2]), rest: query === undefined ? rest : `${rest}?${query}` };
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');
90
+ /**
91
+ * How many containers to expose, read from `STREAMS` on disk.
92
+ *
93
+ * A malformed count is zero containers, not a guess — each container is a
94
+ * proxy to a port, and guessing here is a port scan. Bounded because an
95
+ * unbounded count is the same scan with more steps.
96
+ */
97
+ export function streamLayout(exists = existsSync, read = (f) => readFileSync(f, 'utf8')) {
98
+ try {
99
+ const raw = exists(STREAMS_FILE) ? read(STREAMS_FILE).trim() : '0';
100
+ const n = Number(raw);
101
+ return { streamCount: Number.isInteger(n) && n >= 0 && n <= 8 ? n : 0 };
102
+ }
103
+ catch {
104
+ // An unreadable count is not an on switch. Failing closed is the only
105
+ // safe direction for a thing that opens a proxy.
106
+ return { streamCount: 0 };
107
+ }
108
+ }
109
+ /** True only for a version-13 websocket upgrade — the RFC 6455 handshake every websocket upgrade on this server requires. */
110
+ function isWebSocketUpgrade(req) {
111
+ return (String(req.headers.upgrade ?? '').toLowerCase() === 'websocket' &&
112
+ String(req.headers['sec-websocket-version'] ?? '') === '13');
113
+ }
114
+ function refuse(socket, code, why) {
115
+ socket.write(`HTTP/1.1 ${code} ${why}\r\nConnection: close\r\n\r\n`);
116
+ socket.destroy();
117
+ }
118
+ /**
119
+ * One HTTP hop into a container's websockify. Both forms proxy identically.
120
+ *
121
+ * **A parsed hop, not a socket splice.** This wrote the request by hand and
122
+ * piped the upstream SOCKET into `res.socket` — raw status line and headers
123
+ * straight onto the wire, around express. That survives one request on a fresh
124
+ * connection, which is how the static bench is used and why it looked fine.
125
+ * A browser loading noVNC does not do that: it opens keep-alive connections
126
+ * and pulls `app/ui.js`, `core/*.js` and a dozen assets in parallel, and a
127
+ * spliced response leaves express believing the response is still pending, so
128
+ * the next request on that connection is answered with garbage. The visible
129
+ * result was a noVNC page whose JavaScript 502'd, on a container that was
130
+ * healthy — a black seat with no error a player could act on. Found by
131
+ * `e2e/streamed-live.spec.ts`, 2026-09-24.
132
+ *
133
+ * Parsing the upstream response and copying status + headers onto `res` keeps
134
+ * node's own connection handling in charge of both sides, which is what makes
135
+ * concurrent asset loads work.
136
+ */
137
+ function proxyHttp(req, res, port, path) {
138
+ const upstream = httpRequest({
139
+ host: '127.0.0.1',
140
+ port,
141
+ method: req.method ?? 'GET',
142
+ path,
143
+ // The container answers on loopback and does not virtual-host, but a
144
+ // correct Host keeps websockify's own logging honest.
145
+ headers: { ...req.headers, host: `127.0.0.1:${String(port)}` },
146
+ }, (up) => {
147
+ res.status(up.statusCode ?? 502);
148
+ for (const [k, v] of Object.entries(up.headers)) {
149
+ // node re-computes framing headers for our own response; copying
150
+ // them would describe the upstream's body, not ours.
151
+ if (v === undefined || k === 'connection' || k === 'transfer-encoding')
152
+ continue;
153
+ res.setHeader(k, v);
154
+ }
155
+ up.pipe(res);
156
+ });
157
+ upstream.on('error', () => {
158
+ if (!res.headersSent)
159
+ res.status(502).type('text').send(`no stream container on ${String(port)}`);
160
+ });
161
+ res.on('close', () => upstream.destroy());
162
+ req.pipe(upstream);
163
+ }
164
+ /**
165
+ * The HTTP half: noVNC's pages and assets, straight out of websockify.
166
+ *
167
+ * **Must be registered BEFORE the SPA fallback.** Below it, the fallback
168
+ * answers `/stream/0/vnc.html` with index.html and the link renders the
169
+ * cardtable app instead of noVNC — which is exactly what happened to this
170
+ * route's bench predecessor on 2026-09-21, and read like two browsers
171
+ * joining one room.
172
+ */
173
+ export function attachStreamRoutes(app, deps) {
174
+ const rooms = deps.rooms ?? null;
175
+ if (deps.streamCount < 1 && rooms === null)
176
+ return false;
177
+ const log = deps.log ?? (() => { });
178
+ const stream = express.Router();
179
+ // The static bench, first: these paths terminate, so the room-keyed
180
+ // middleware below never sees them.
181
+ for (let n = 0; n < deps.streamCount; n += 1) {
182
+ const port = deps.streamBasePort + n;
183
+ stream.use(`/${String(n)}`, (req, res) => {
184
+ proxyHttp(req, res, port, req.url === '' ? '/' : req.url);
185
+ });
186
+ }
187
+ if (rooms !== null) {
188
+ stream.use((req, res, next) => {
189
+ // `stream` is mounted at /stream, so req.url arrives without it;
190
+ // one parser serves both halves, so put it back.
191
+ const target = roomStreamPathOf(`/stream${req.url}`);
192
+ if (target === null) {
193
+ next();
194
+ return;
195
+ }
196
+ const port = rooms.portOf(target.roomKey, target.seat);
197
+ if (port === null) {
198
+ const status = rooms.statusOf(target.roomKey);
199
+ deps.ensureRoom?.(target.roomKey);
200
+ // Honest, and never a live-looking 502: a reclaimed room says it
201
+ // was reclaimed, a room still booting says it is not up yet.
202
+ if (status.state === 'dead') {
203
+ res
204
+ .status(410)
205
+ .type('text')
206
+ .send(`this room's streams were reclaimed (${status.reason ?? 'unknown'}) — start the room again`);
207
+ }
208
+ else {
209
+ res.status(503).type('text').send('no stream for this seat yet');
210
+ }
211
+ return;
212
+ }
213
+ proxyHttp(req, res, port, target.rest);
214
+ });
215
+ }
216
+ app.use('/stream', stream);
217
+ log({ evt: 'stream-routes', streams: deps.streamCount, rooms: rooms !== null });
218
+ return true;
219
+ }
220
+ /**
221
+ * The websocket half: noVNC talks RFB over a websocket to websockify.
222
+ * express never sees an `upgrade`, so the tier floor is re-applied here by
223
+ * hand, with `../gate.ts`'s `gateUpgrade`.
224
+ */
225
+ export function attachStream(server, deps) {
226
+ const rooms = deps.rooms ?? null;
227
+ if (deps.streamCount < 1 && rooms === null)
228
+ return null;
229
+ const log = deps.log ?? (() => { });
230
+ const onUpgrade = (req, socket, head) => {
231
+ const n = streamIndexOf(req.url, deps.streamCount);
232
+ const roomPath = n === null && rooms !== null ? roomStreamPathOf(req.url) : null;
233
+ if (n === null && roomPath === null)
234
+ return; // not ours — socket.io gets its turn
235
+ if (!isWebSocketUpgrade(req)) {
236
+ refuse(socket, 400, 'expected a version-13 websocket upgrade');
237
+ return;
238
+ }
239
+ const floor = gateUpgrade(req, { minTier: deps.minTier, surface: 'stream' });
240
+ if (!floor.ok) {
241
+ refuse(socket, 404, 'not found');
242
+ return;
243
+ }
244
+ let port;
245
+ let roomKey = null;
246
+ if (roomPath !== null && rooms !== null) {
247
+ const found = rooms.portOf(roomPath.roomKey, roomPath.seat);
248
+ if (found === null) {
249
+ const status = rooms.statusOf(roomPath.roomKey);
250
+ deps.ensureRoom?.(roomPath.roomKey);
251
+ // Post-floor, so this tells a friend the truth and an outsider
252
+ // nothing: they were refused with 404 above.
253
+ refuse(socket, status.state === 'dead' ? 410 : 503, status.state === 'dead' ? 'gone' : 'no stream yet');
254
+ return;
255
+ }
256
+ port = found;
257
+ roomKey = roomPath.roomKey;
258
+ }
259
+ else {
260
+ port = deps.streamBasePort + (n ?? 0);
261
+ }
262
+ const upstream = connect({ host: '127.0.0.1', port }, () => {
263
+ // Replay the handshake verbatim; websockify does its own accept.
264
+ const lines = [`GET ${roomPath === null ? (req.url ?? '/') : roomPath.rest} HTTP/1.1`];
265
+ for (const [k, v] of Object.entries(req.headers)) {
266
+ for (const one of Array.isArray(v) ? v : [v])
267
+ if (one !== undefined)
268
+ lines.push(`${k}: ${one}`);
269
+ }
270
+ upstream.write(`${lines.join('\r\n')}\r\n\r\n`);
271
+ if (head.length > 0)
272
+ upstream.write(head);
273
+ upstream.pipe(socket);
274
+ socket.pipe(upstream);
275
+ if (roomKey !== null && rooms !== null) {
276
+ // Somebody is watching: the idle window is not running.
277
+ rooms.noteAttach(roomKey);
278
+ const key = roomKey;
279
+ socket.once('close', () => rooms.noteDetach(key));
280
+ }
281
+ });
282
+ upstream.on('error', () => refuse(socket, 502, 'no stream container'));
283
+ socket.on('error', () => upstream.destroy());
284
+ log({ evt: 'stream-open', container: n, room: roomKey, seat: roomPath?.seat, tier: floor.tier });
285
+ };
286
+ server.on('upgrade', onUpgrade);
287
+ log({ evt: 'stream-attached', streams: deps.streamCount, rooms: rooms !== null });
288
+ return {
289
+ close() {
290
+ server.off('upgrade', onUpgrade);
291
+ },
292
+ };
293
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Adapter: cardtable's binding of `@hadoku/service-kernel/telemetry` (w93-K3).
3
+ *
4
+ * Every export and signature below is unchanged from before this moved into the kernel:
5
+ * `index.ts`, `gate.ts`, `edge-auth.ts`, `erase/index.ts`, `play/match.ts` and `play/socket.ts`
6
+ * import this path exactly as they did. The cardtable-specific bits are the service id
7
+ * (`cardtable`, stamped on every event's `context.service` and in the posting User-Agent), the
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.
11
+ */
12
+ import type { Request } from 'express';
13
+ import type { JsonLog } from '@wolffm/service-kernel/log';
14
+ import { callerContext, installTelemetry, report, reportingAlerts, userAgentOf, type Level, type Report, type TelemetryContext, type TelemetryValue } from '@wolffm/service-kernel/telemetry';
15
+ export { callerContext, installTelemetry, report, reportingAlerts, userAgentOf };
16
+ export type { Level, Report, TelemetryContext, TelemetryValue };
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
+ type Headers = Request['headers'];
41
+ /**
42
+ * A seal below the edge refused a caller. With the edge in front this should
43
+ * never fire: one means a direct hit on the tunnel host, or an edge rule wider
44
+ * than this server's floor — both worth a look.
45
+ */
46
+ export declare function reportSealRefused(surface: 'http' | 'draft-socket' | 'play-socket' | 'browser' | 'stream', headers: Headers, path: string | null): void;
@@ -0,0 +1,25 @@
1
+ import { callerContext, installTelemetry, monitoringSink as kernelMonitoringSink, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, siteOf as kernelSiteOf, userAgentOf, } from '@wolffm/service-kernel/telemetry';
2
+ export { callerContext, installTelemetry, report, reportingAlerts, userAgentOf };
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
+ /**
19
+ * A seal below the edge refused a caller. With the edge in front this should
20
+ * never fire: one means a direct hit on the tunnel host, or an edge rule wider
21
+ * than this server's floor — both worth a look.
22
+ */
23
+ export function reportSealRefused(surface, headers, path) {
24
+ kernelReportSealRefused(surface, headers, path);
25
+ }
@@ -0,0 +1 @@
1
+ export declare function testPort(): Promise<number>;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * A port for a test to start a real server on.
3
+ *
4
+ * Not `listen(0)`: that hands out a port from the kernel's ephemeral range
5
+ * (32768-60999 here), which it also gives every outgoing connection, and a
6
+ * test that probes one, lets it go and starts a server on it a second later
7
+ * lost it to a connection in between on a busy host (index.test.ts,
8
+ * 2026-10-19: EADDRINUSE on 43357). Below that range only another explicit
9
+ * bind can take it, and the e2e harnesses keep to 19xxx and 29xxx.
10
+ */
11
+ import { createServer } from 'node:net';
12
+ const FROM = 30000;
13
+ const TO = 32767;
14
+ export async function testPort() {
15
+ for (let tries = 0; tries < 50; tries++) {
16
+ const port = FROM + Math.floor(Math.random() * (TO - FROM + 1));
17
+ const probe = createServer();
18
+ const free = await new Promise((resolve) => {
19
+ probe.once('error', () => resolve(false));
20
+ probe.listen(port, '127.0.0.1', () => resolve(true));
21
+ });
22
+ if (!free)
23
+ continue;
24
+ await new Promise((r) => probe.close(() => r()));
25
+ return port;
26
+ }
27
+ throw new Error(`no free port in ${FROM}-${TO} after 50 tries`);
28
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.6",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "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.",
7
+ "exports": {
8
+ "./*": {
9
+ "types": "./dist/*.d.ts",
10
+ "import": "./dist/*.js"
11
+ }
12
+ },
13
+ "publishLeaveOut": [
14
+ "play/placement/",
15
+ "play/remote/"
16
+ ],
17
+ "dependencies": {
18
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.6",
19
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.6",
20
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.39",
21
+ "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
22
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.93",
23
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.93",
24
+ "express": "^5.1.0",
25
+ "socket.io": "^4.8.3",
26
+ "zod": "4.5.4"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "LICENSE"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/WolffM/hadoku-cardtable.git",
35
+ "directory": "packages/game-server"
36
+ }
37
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.