@hadoku/game-server 0.1.202 → 0.1.204

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,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
+ }
@@ -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.202",
4
- "gitHead": "4ba2350938ced47e5519c9acf331d81ff6f6235c",
3
+ "version": "0.1.204",
4
+ "gitHead": "6212ef2571050bce6d2e17cfccd0bb5d14ef966e",
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.202",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.202",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.235",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.204",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.204",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.237",
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",