@hadoku/game-server 0.1.201 → 0.1.203

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.
@@ -14,14 +14,12 @@
14
14
  * games-host shipped exactly this: its edge stripPrefix and its backend's base
15
15
  * path are two independent declarations of one fact, and nothing compared them.
16
16
  *
17
- * So: compare them here, once, at boot, and say precisely what to change.
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.
18
19
  */
19
- import { type BasePathVerdict } from '@wolffm/service-kernel/http';
20
20
  /**
21
21
  * The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
22
22
  * emits them, watchparty imports the `.js`. Every other file in the bundle is
23
23
  * content-hashed; these are the only ones whose bytes change under one name.
24
24
  */
25
25
  export declare const EMBED_ENTRIES: readonly ["cardtable-embed.js", "cardtable-embed.css"];
26
- /** The page served in place of a bundle that would render blank, under cardtable's own name. */
27
- export declare function diagnosticPage(verdict: BasePathVerdict, basePrefix: string): string;
package/dist/base-path.js CHANGED
@@ -14,16 +14,12 @@
14
14
  * games-host shipped exactly this: its edge stripPrefix and its backend's base
15
15
  * path are two independent declarations of one fact, and nothing compared them.
16
16
  *
17
- * So: compare them here, once, at boot, and say precisely what to change.
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.
18
19
  */
19
- import { diagnosticPage as kernelDiagnosticPage } from '@wolffm/service-kernel/http';
20
20
  /**
21
21
  * The embed bundle's two fixed-name files (D21): `apps/ui/vite.embed.config.ts`
22
22
  * emits them, watchparty imports the `.js`. Every other file in the bundle is
23
23
  * content-hashed; these are the only ones whose bytes change under one name.
24
24
  */
25
25
  export const EMBED_ENTRIES = ['cardtable-embed.js', 'cardtable-embed.css'];
26
- /** The page served in place of a bundle that would render blank, under cardtable's own name. */
27
- export function diagnosticPage(verdict, basePrefix) {
28
- return kernelDiagnosticPage(verdict, basePrefix, 'Cardtable');
29
- }
@@ -19,6 +19,8 @@ export interface PageDeps {
19
19
  indexHtml: string;
20
20
  basePath: BasePathVerdict;
21
21
  basePrefix: string;
22
+ /** The app's name, as the page that stands in for a bundle that would render blank says it. */
23
+ name: string;
22
24
  /** `null` is no limit (the e2e stacks); omitted is {@link PAGE_LOAD_RATE_LIMIT}. */
23
25
  rateLimit?: RateLimitConfig | null;
24
26
  now?: () => number;
package/dist/http/page.js CHANGED
@@ -11,8 +11,7 @@
11
11
  * eight hours) is refused with a 429 and `rate-limited` telemetry naming it,
12
12
  * while the busiest real caller (20 a minute) never meets the ceiling.
13
13
  */
14
- import { sendIndex } from '@wolffm/service-kernel/http';
15
- import { diagnosticPage } from '../base-path.js';
14
+ import { diagnosticPage, sendIndex } from '@wolffm/service-kernel/http';
16
15
  import { perCallerLimit } from './request.js';
17
16
  export const PAGE_LOAD_RATE_LIMIT = {
18
17
  capacity: 30,
@@ -26,7 +25,7 @@ export function attachPage(app, deps) {
26
25
  });
27
26
  app.get(/.*/, (req, res, next) => {
28
27
  if (!deps.basePath.ok) {
29
- res.status(503).type('html').send(diagnosticPage(deps.basePath, deps.basePrefix));
28
+ res.status(503).type('html').send(diagnosticPage(deps.basePath, deps.basePrefix, deps.name));
30
29
  return;
31
30
  }
32
31
  if (!limit(req, res))
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A host that stands in for one that does not exist yet, or that may be swapped underneath its
3
+ * match: a queued start's host until its JVM is asked for (`start-queue.ts`), and the host a
4
+ * placed match talks to while a failed start is placed again (`placement/coordinator.ts`).
5
+ */
6
+ import type { MatchHost } from './host.js';
7
+ type Remembered = Parameters<NonNullable<MatchHost<{
8
+ t: string;
9
+ }>['remember']>>[0];
10
+ export declare class DeferredHost<C extends {
11
+ t: string;
12
+ }> implements MatchHost<C> {
13
+ private target;
14
+ private readonly onStopWithoutTarget;
15
+ private readonly held;
16
+ private remembered;
17
+ /** `onStopWithoutTarget`: what `stop` does while there is no target to stop. */
18
+ constructor(target?: MatchHost<C> | null, onStopWithoutTarget?: () => void);
19
+ /** The real host: the latest remembered state goes to it, then every held command, in order. */
20
+ become(target: MatchHost<C>): void;
21
+ send(command: C): void;
22
+ stop(): void;
23
+ remember(state: Remembered): void;
24
+ /** With no target there is no JVM to leave running. */
25
+ handOver(): boolean;
26
+ }
27
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A host that stands in for one that does not exist yet, or that may be swapped underneath its
3
+ * match: a queued start's host until its JVM is asked for (`start-queue.ts`), and the host a
4
+ * placed match talks to while a failed start is placed again (`placement/coordinator.ts`).
5
+ */
6
+ export class DeferredHost {
7
+ target;
8
+ onStopWithoutTarget;
9
+ held = [];
10
+ remembered = null;
11
+ /** `onStopWithoutTarget`: what `stop` does while there is no target to stop. */
12
+ constructor(target = null, onStopWithoutTarget = () => { }) {
13
+ this.target = target;
14
+ this.onStopWithoutTarget = onStopWithoutTarget;
15
+ }
16
+ /** The real host: the latest remembered state goes to it, then every held command, in order. */
17
+ become(target) {
18
+ this.target = target;
19
+ if (this.remembered !== null)
20
+ target.remember?.(this.remembered);
21
+ for (const command of this.held.splice(0))
22
+ target.send(command);
23
+ }
24
+ send(command) {
25
+ if (this.target !== null)
26
+ this.target.send(command);
27
+ else
28
+ this.held.push(command);
29
+ }
30
+ stop() {
31
+ if (this.target !== null)
32
+ this.target.stop();
33
+ else
34
+ this.onStopWithoutTarget();
35
+ }
36
+ remember(state) {
37
+ this.remembered = state;
38
+ this.target?.remember?.(state);
39
+ }
40
+ /** With no target there is no JVM to leave running. */
41
+ handOver() {
42
+ return this.target?.handOver?.() ?? false;
43
+ }
44
+ }
package/dist/play/host.js CHANGED
@@ -123,8 +123,9 @@
123
123
  import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync } from 'node:fs';
124
124
  import { randomBytes } from 'node:crypto';
125
125
  import { join } from 'node:path';
126
+ import { writeFileAtomicSync } from '@wolffm/host-wire';
126
127
  import { jsonLogger } from '@wolffm/service-kernel/log';
127
- import { JVM_HEAP_MB, MATCHES_PER_JVM, RUN_DIR_NAME, localJvmLauncher, writeFileAtomic } from './local-jvm.js';
128
+ import { JVM_HEAP_MB, MATCHES_PER_JVM, RUN_DIR_NAME, localJvmLauncher } from './local-jvm.js';
128
129
  const LIFECYCLE_T = new Set(['ready', 'fatal', 'frame', 'snapshot']);
129
130
  /** Narrows any engine's line onto the four the host itself understands. See {@link HostLifecycleLine}. */
130
131
  export function isLifecycle(line) {
@@ -280,12 +281,12 @@ export function jvmHostFactory(config, options = {}) {
280
281
  matches: hosted.map((h) => recordEntry(h.entry)),
281
282
  };
282
283
  try {
283
- writeFileAtomic(join(jvm.dir, JVM_RECORD_FILE), `${JSON.stringify(record, null, 2)}\n`);
284
+ writeFileAtomicSync(join(jvm.dir, JVM_RECORD_FILE), `${JSON.stringify(record, null, 2)}\n`);
284
285
  for (const h of hosted)
285
286
  h.changed = false;
286
287
  }
287
288
  catch (err) {
288
- // The old record is whole (`writeFileAtomic`), so it names each match as it was. One whose
289
+ // The old record is whole (`writeFileAtomicSync`), so it names each match as it was. One whose
289
290
  // entry changed since cannot be re-attached as it is now, and must not be handed over.
290
291
  poolLog({ evt: 'jvm-record-failed', id: jvm.hostId, error: err.message });
291
292
  for (const h of hosted)
@@ -252,13 +252,6 @@ export declare function bridgeLaunch(config: BridgeConfig, log: (entry: Record<s
252
252
  export declare function bridgeVersion(config: BridgeConfig): string;
253
253
  /** `{hostId, pid, startedAt}`: what a later process finds a running JVM by. Written at launch. */
254
254
  export declare const LAUNCH_RECORD_FILE = "launch.json";
255
- /**
256
- * Write `file` whole or not at all: into a temporary file beside it, then renamed over
257
- * it. `writeFileSync` in place truncates first, so a full disk left `jvm.json` empty and
258
- * its match un-re-attachable (hosting-test-plan C6); here a failed write leaves the old
259
- * file as it was, and throws.
260
- */
261
- export declare function writeFileAtomic(file: string, text: string): void;
262
255
  /**
263
256
  * Forge resolves `res/` against the working directory (`ForgeConstants.RES_DIR`
264
257
  * is "res/" when the version string carries no "git"), and reads its user and
@@ -78,6 +78,7 @@ import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readSync, read
78
78
  import { homedir, tmpdir } from 'node:os';
79
79
  import { basename, dirname, join, resolve } from 'node:path';
80
80
  import { createInterface } from 'node:readline';
81
+ import { writeFileAtomicSync } from '@wolffm/host-wire';
81
82
  import { bridgeDiagnostics } from './diagnostics.js';
82
83
  import { CRASH_MARKER, IN_FIFO, JVM_TMP_DIR, OUT_FIFO, PID_POLL_MS, REAP_CONFIRM_MS, cwdIsUnder, defaultJava, makeFifos, openJvmIo, pidIsRunning, pidIsStandingIn, pidIsStandingInRun, positiveInt, processCwds, pruneCrashRecords, runDirs, sleepSync, wrapChildProcess, } from './engine-runtime.js';
83
84
  /**
@@ -301,23 +302,6 @@ export const LAUNCH_RECORD_FILE = 'launch.json';
301
302
  // under the default `/tmp` every killed match leaked one copy (3,036 of them on the host's
302
303
  // RAM-backed /tmp, 2026-10-10). Inside the run dir it goes wherever the run dir goes: removed on
303
304
  // a clean end, pruned on a crash.
304
- /**
305
- * Write `file` whole or not at all: into a temporary file beside it, then renamed over
306
- * it. `writeFileSync` in place truncates first, so a full disk left `jvm.json` empty and
307
- * its match un-re-attachable (hosting-test-plan C6); here a failed write leaves the old
308
- * file as it was, and throws.
309
- */
310
- export function writeFileAtomic(file, text) {
311
- const tmp = `${file}.tmp-${process.pid}-${randomBytes(4).toString('hex')}`;
312
- try {
313
- writeFileSync(tmp, text);
314
- renameSync(tmp, file);
315
- }
316
- catch (err) {
317
- rmSync(tmp, { force: true });
318
- throw err;
319
- }
320
- }
321
305
  /**
322
306
  * Forge resolves `res/` against the working directory (`ForgeConstants.RES_DIR`
323
307
  * is "res/" when the version string carries no "git"), and reads its user and
@@ -445,7 +429,7 @@ function keepCrashRecord(run, record) {
445
429
  if (!keep.has(entry))
446
430
  rmSync(join(run, entry), { recursive: true, force: true });
447
431
  }
448
- writeFileAtomic(join(run, CRASH_MARKER), `${JSON.stringify(record, null, 2)}\n`);
432
+ writeFileAtomicSync(join(run, CRASH_MARKER), `${JSON.stringify(record, null, 2)}\n`);
449
433
  }
450
434
  /** `<run>/launch.json`, or null when it is missing, unreadable or not one. */
451
435
  export function readLaunchRecord(run) {
@@ -584,7 +568,7 @@ class LocalJvm {
584
568
  this.pid = engineProcess.pid;
585
569
  live.add(this);
586
570
  log({ evt: 'jvm-spawned', id: hostId, pid: this.pid, run, bridge: bridge.how });
587
- writeFileAtomic(join(run, LAUNCH_RECORD_FILE), `${JSON.stringify({ hostId, pid: this.pid, startedAt: new Date().toISOString() })}\n`);
571
+ writeFileAtomicSync(join(run, LAUNCH_RECORD_FILE), `${JSON.stringify({ hostId, pid: this.pid, startedAt: new Date().toISOString() })}\n`);
588
572
  this.read();
589
573
  engineProcess.onError((err) => this.finish(`the JVM could not be started: ${err.message}`, { code: null, signal: null }));
590
574
  engineProcess.onExit((code, signal) => {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A lobby whose rooms are each their own relay match: a room opened puts its match in the registry, a
3
+ * room closed takes it out, and the match socket admits as the room does. What differs per server is passed.
4
+ */
5
+ import type { Server as SocketIOServer } from 'socket.io';
6
+ import type { PlatformRoomView, RoomCreateInput, RoomLobby } from '../room/lobby.js';
7
+ import { type RelayDeps, type RelayHandle } from './relay-socket.js';
8
+ export type RelayRoomsLobby = Pick<RoomLobby<PlatformRoomView, RoomCreateInput>, 'onChange' | 'onRelayRoomOpened' | 'get' | 'isMember' | 'gameSeatOf'>;
9
+ export interface RelayRoomsOptions extends Pick<RelayDeps, 'minTier' | 'gate' | 'onEnded'> {
10
+ log: (entry: Record<string, unknown>) => void;
11
+ /** The seat whose `{ t: 'over' }` ends the room's match, read on every `over`. */
12
+ leaderSeat(roomId: string): number | null;
13
+ /** How long a dropped seat is held, by the room's game type. Absent: never left on its own. */
14
+ seatRejoinGraceMs?(gameType: string): number | undefined;
15
+ }
16
+ /** The seat the room's leader holds, or null. */
17
+ export declare function leaderSeatOf(lobby: Pick<RelayRoomsLobby, 'get' | 'gameSeatOf'>, roomId: string): number | null;
18
+ export declare function wireRelayRooms(lobby: RelayRoomsLobby, io: SocketIOServer, opts: RelayRoomsOptions): RelayHandle;
@@ -0,0 +1,27 @@
1
+ import { roomAdmits } from '../room/tier-floor.js';
2
+ import { attachRelay } from './relay-socket.js';
3
+ import { relayMatches } from './runtimes/relay-match.js';
4
+ /** The seat the room's leader holds, or null. */
5
+ export function leaderSeatOf(lobby, roomId) {
6
+ const leader = lobby.get(roomId)?.leader;
7
+ return leader === undefined ? null : lobby.gameSeatOf(roomId, leader);
8
+ }
9
+ export function wireRelayRooms(lobby, io, opts) {
10
+ lobby.onChange((roomId) => {
11
+ if (lobby.get(roomId) === undefined)
12
+ relayMatches.forget(roomId);
13
+ });
14
+ lobby.onRelayRoomOpened((roomId, seatCount, gameType) => {
15
+ relayMatches.register(roomId, seatCount, {
16
+ log: opts.log,
17
+ roomSeatOf: (participantId) => lobby.gameSeatOf(roomId, participantId),
18
+ leaderSeat: () => opts.leaderSeat(roomId),
19
+ seatRejoinGraceMs: opts.seatRejoinGraceMs?.(gameType),
20
+ });
21
+ });
22
+ return attachRelay(io, {
23
+ ...opts,
24
+ rosterOf: (matchId) => relayMatches.get(matchId),
25
+ admits: (matchId, participantId, tier) => roomAdmits(lobby.get(matchId), lobby.isMember(matchId, participantId), tier),
26
+ });
27
+ }
@@ -26,6 +26,7 @@
26
26
  * everything else on the factory.
27
27
  */
28
28
  import { positiveInt } from './engine-runtime.js';
29
+ import { DeferredHost } from './deferred-host.js';
29
30
  /**
30
31
  * JVMs booting at once before a start that needs another waits. A lone boot on a claw under CI
31
32
  * load took 7.8–10.5 s and ten together ~50 s, so two keeps one well inside the 60 s start timeout
@@ -36,61 +37,6 @@ export const COLD_STARTS = 2;
36
37
  export function coldStartsFrom(env = process.env) {
37
38
  return positiveInt(env.CARDTABLE_PLAY_COLD_STARTS, COLD_STARTS);
38
39
  }
39
- /** A waiting start's host until its JVM is asked for. */
40
- class WaitingHost {
41
- leave;
42
- events;
43
- host = null;
44
- held = [];
45
- remembered = null;
46
- gone = false;
47
- constructor(leave, events) {
48
- this.leave = leave;
49
- this.events = events;
50
- }
51
- /** The real host: everything held goes to it, in order. */
52
- become(host) {
53
- this.host = host;
54
- if (this.remembered !== null)
55
- host.remember?.(this.remembered);
56
- for (const command of this.held.splice(0))
57
- host.send(command);
58
- }
59
- /** Never booted: the queue was dropped (the server is closing or handing over). */
60
- drop(reason) {
61
- if (this.gone)
62
- return;
63
- this.gone = true;
64
- this.events.exit(reason);
65
- }
66
- send(command) {
67
- if (this.host !== null)
68
- this.host.send(command);
69
- else
70
- this.held.push(command);
71
- }
72
- stop() {
73
- if (this.host !== null) {
74
- this.host.stop();
75
- return;
76
- }
77
- if (this.gone)
78
- return;
79
- this.leave();
80
- // A host's exit always comes after `stop` returns; so does this one.
81
- queueMicrotask(() => this.drop('stopped before its JVM started'));
82
- }
83
- remember(state) {
84
- if (this.host !== null)
85
- this.host.remember?.(state);
86
- else
87
- this.remembered = state;
88
- }
89
- /** A start still waiting has no JVM to leave running. */
90
- handOver() {
91
- return this.host?.handOver?.() ?? false;
92
- }
93
- }
94
40
  export function queueColdStarts(factory, limit, log) {
95
41
  const waiting = [];
96
42
  const booting = () => factory.booting?.() ?? 0;
@@ -120,7 +66,7 @@ export function queueColdStarts(factory, limit, log) {
120
66
  }
121
67
  catch (err) {
122
68
  next.events.unstartable?.(err);
123
- next.host.drop(`Forge could not be started: ${err.message}`);
69
+ next.drop(`Forge could not be started: ${err.message}`);
124
70
  continue;
125
71
  }
126
72
  next.host.become(host);
@@ -138,23 +84,35 @@ export function queueColdStarts(factory, limit, log) {
138
84
  }
139
85
  function dropAll(reason) {
140
86
  for (const w of waiting.splice(0))
141
- w.host.drop(reason);
87
+ w.drop(reason);
142
88
  }
143
89
  const queued = ((matchId, spec, events) => {
144
90
  if (waiting.length === 0 && free())
145
91
  return begin(matchId, spec, events, null);
92
+ let gone = false;
93
+ const drop = (reason) => {
94
+ if (gone)
95
+ return;
96
+ gone = true;
97
+ events.exit(reason);
98
+ };
146
99
  const entry = {
147
100
  matchId,
148
101
  spec,
149
102
  events,
103
+ drop,
150
104
  place: 0,
151
105
  since: Date.now(),
152
- host: new WaitingHost(() => {
106
+ host: new DeferredHost(null, () => {
107
+ if (gone)
108
+ return;
153
109
  const i = waiting.indexOf(entry);
154
110
  if (i >= 0)
155
111
  waiting.splice(i, 1);
156
112
  pump();
157
- }, events),
113
+ // A host's exit always comes after `stop` returns; so does this one.
114
+ queueMicrotask(() => drop('stopped before its JVM started'));
115
+ }),
158
116
  };
159
117
  waiting.push(entry);
160
118
  log({ evt: 'start-queued', matchId, place: waiting.length, booting: booting(), limit });
@@ -31,18 +31,17 @@ import express from 'express';
31
31
  import { PresenceTracker } from '@wolffm/rooms-server';
32
32
  import { OffLoopRoomStore } from './room/off-loop-store.js';
33
33
  import { jsonLogger } from '@wolffm/service-kernel/log';
34
- import { diagnosticPage, sendIndex } from '@wolffm/service-kernel/http';
35
34
  import { createGameServer } from '@wolffm/service-kernel/server';
36
35
  import { monitoringSink, siteOf } from '@wolffm/service-kernel/telemetry';
37
36
  import { createGameAuth } from './auth.js';
38
37
  import { createConfig } from './config.js';
39
38
  import { fkOf } from './erase/index.js';
40
39
  import { roomsEraseSteps } from './erase/rooms.js';
40
+ import { attachPage } from './http/page.js';
41
41
  import { attachRoomCore, badRequest, noMatch } from './http/room-core.js';
42
42
  import { callerOf } from './http/request.js';
43
43
  import { attachPeople, createPeople } from './people.js';
44
- import { attachRelay } from './play/relay-socket.js';
45
- import { roomAdmits } from './room/tier-floor.js';
44
+ import { leaderSeatOf, wireRelayRooms } from './play/relay-rooms.js';
46
45
  import { relayMatches } from './play/runtimes/relay-match.js';
47
46
  import { configureParticipantIdDomain, identityFromHeaders } from './room/identity.js';
48
47
  import { LIVE } from '@wolffm/platform-wire/room-settings';
@@ -120,28 +119,8 @@ export async function startRelayGame(options) {
120
119
  ctx.state.lobby = lobby;
121
120
  ctx.gauge('rooms', () => lobby.list().length);
122
121
  lobby.onChange((roomId) => {
123
- if (lobby.get(roomId) !== undefined)
124
- return;
125
- starts.forget(roomId);
126
- relayMatches.forget(roomId);
127
- });
128
- // A room IS its match: one relay match per room, opened as the room is.
129
- lobby.onRelayRoomOpened((roomId, seatCount) => {
130
- relayMatches.register(roomId, seatCount, {
131
- log: relayLog,
132
- roomSeatOf: (participantId) => lobby.gameSeatOf(roomId, participantId),
133
- // A round's end is taken from the HOST of the room's match (whom `starts` named),
134
- // falling back to the leader's seat while nobody hosts or the host left theirs.
135
- leaderSeat: () => {
136
- const host = starts.hostOf(roomId);
137
- const hostSeat = host === null ? null : lobby.gameSeatOf(roomId, host);
138
- if (hostSeat !== null)
139
- return hostSeat;
140
- const leader = lobby.get(roomId)?.leader;
141
- return leader === undefined ? null : lobby.gameSeatOf(roomId, leader);
142
- },
143
- seatRejoinGraceMs: seatHoldMs,
144
- });
122
+ if (lobby.get(roomId) === undefined)
123
+ starts.forget(roomId);
145
124
  });
146
125
  const sweep = setInterval(() => lobby.sweep(roomIdleMs), 60_000);
147
126
  sweep.unref();
@@ -251,12 +230,12 @@ export async function startRelayGame(options) {
251
230
  ctx.app.use('/embed', (_req, res) => {
252
231
  res.status(404).type('text').send('no such embed file');
253
232
  });
254
- ctx.app.get(/.*/, (_req, res, next) => {
255
- if (!ctx.bundle.ok) {
256
- res.status(503).type('html').send(diagnosticPage(ctx.bundle, config.basePrefix, options.name));
257
- return;
258
- }
259
- sendIndex(res, join(config.webDir, 'index.html'), (err) => err && next(err));
233
+ attachPage(ctx.app, {
234
+ indexHtml: join(config.webDir, 'index.html'),
235
+ basePath: ctx.bundle,
236
+ basePrefix: config.basePrefix,
237
+ name: options.name,
238
+ ...(config.testNoRateLimits ? { rateLimit: null } : {}),
260
239
  });
261
240
  },
262
241
  };
@@ -266,12 +245,18 @@ export async function startRelayGame(options) {
266
245
  async setup(ctx) {
267
246
  const lobby = ctx.state.lobby;
268
247
  // The relay first: it installs the engine-wide provenance sanitizer `/room`'s admit relies on.
269
- const relay = attachRelay(ctx.io, {
248
+ // A room IS its match: one relay match per room, opened as the room is.
249
+ const relay = wireRelayRooms(lobby, ctx.io, {
270
250
  minTier: config.minTier,
271
251
  gate: auth.gate,
272
- rosterOf: (matchId) => relayMatches.get(matchId),
273
- admits: (matchId, participantId, tier) => roomAdmits(lobby.get(matchId), lobby.isMember(matchId, participantId), tier),
274
252
  log: relayLog,
253
+ // A round's end is taken from the HOST of the room's match (whom `starts` named),
254
+ // falling back to the leader's seat while nobody hosts or the host left theirs.
255
+ leaderSeat: (roomId) => {
256
+ const host = starts.hostOf(roomId);
257
+ return (host === null ? null : lobby.gameSeatOf(roomId, host)) ?? leaderSeatOf(lobby, roomId);
258
+ },
259
+ seatRejoinGraceMs: () => seatHoldMs,
275
260
  });
276
261
  // The room's own presence: its grace is not the relay seat's hold.
277
262
  const presence = new PresenceTracker({ idleMs: 2_000_000_000, graceMs: disconnectGraceMs });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.201",
4
- "gitHead": "5f99a4b32b35131c69046b111e7ce269ca333b6c",
3
+ "version": "0.1.203",
4
+ "gitHead": "36cbd7078b1199a923f4b09e78a689e6e4d28209",
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.",
@@ -17,9 +17,9 @@
17
17
  "play/remote/"
18
18
  ],
19
19
  "dependencies": {
20
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.201",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.201",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.234",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.203",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.203",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.236",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.150",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.150",