@hadoku/game-server 0.1.235 → 0.1.236

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -21,11 +21,8 @@
21
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
- * Cardtable's deployment-only ArchiveBot settings moved to `apps/server/src/plugins/archivebot.ts`
25
- * (w120 §K): its two readers, `games/magic/server/src/plugins/{listen,routes}.ts`, are in the
26
- * `magic` layer, which may not import `apps/server` (the `site` layer) — see
27
- * `scripts/layers/layers.json`'s allowed directions; the site plugin injects the settings onto
28
- * `ctx.state.archivebot` instead.
24
+ * Cardtable's ArchiveBot settings are the deployment's: the site reads them
25
+ * (`apps/server/src/plugins/archivebot.ts`) onto `ctx.state.archivebot` (`room-site.ts`'s `SiteState`).
29
26
  * Survey: `~/.cache/cardtable-manager/bomberman-survey-2026-11-16.md` §3 has the classification
30
27
  * with the original line numbers.
31
28
  */
package/dist/config.js CHANGED
@@ -21,11 +21,8 @@
21
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
- * Cardtable's deployment-only ArchiveBot settings moved to `apps/server/src/plugins/archivebot.ts`
25
- * (w120 §K): its two readers, `games/magic/server/src/plugins/{listen,routes}.ts`, are in the
26
- * `magic` layer, which may not import `apps/server` (the `site` layer) — see
27
- * `scripts/layers/layers.json`'s allowed directions; the site plugin injects the settings onto
28
- * `ctx.state.archivebot` instead.
24
+ * Cardtable's ArchiveBot settings are the deployment's: the site reads them
25
+ * (`apps/server/src/plugins/archivebot.ts`) onto `ctx.state.archivebot` (`room-site.ts`'s `SiteState`).
29
26
  * Survey: `~/.cache/cardtable-manager/bomberman-survey-2026-11-16.md` §3 has the classification
30
27
  * with the original line numbers.
31
28
  */
@@ -30,7 +30,8 @@ import { type GameAuth } from './auth.js';
30
30
  import { type GameServerConfig } from './config.js';
31
31
  import { type People } from './people.js';
32
32
  import { type AnyRoomSettings } from '@wolffm/platform-wire/room-settings';
33
- import { RoomLobby, type PlainRoomSize, type PlainRoomView, type PlatformRoomView, type RoomCreateInput } from './room/lobby.js';
33
+ import { RoomLobby, type PlatformRoomView, type RoomCreateInput } from './room/lobby.js';
34
+ import { type PlainRoomSize, type PlainRoomView } from './room/room-type.js';
34
35
  import { type Starts } from './room/starts.js';
35
36
  import { type ReportOutcome, type RoundContext } from './stats/relay-results.js';
36
37
  /** A relay room: the platform's view, its bots and, while one is pending, its start. */
@@ -45,7 +45,8 @@ import { leaderSeatOf, wireRelayRooms } from './play/relay-rooms.js';
45
45
  import { relayMatches } from './play/runtimes/relay-match.js';
46
46
  import { configureParticipantIdDomain, identityFromHeaders } from './room/identity.js';
47
47
  import { LIVE } from '@wolffm/platform-wire/room-settings';
48
- import { MATCH_LIVE, RoomLobby, plainRoomType } from './room/lobby.js';
48
+ import { RoomLobby } from './room/lobby.js';
49
+ import { MATCH_LIVE, plainRoomType } from './room/room-type.js';
49
50
  import { attachServedRoom } from './room/serve.js';
50
51
  import { COUNTDOWN_MS, createStarts } from './room/starts.js';
51
52
  import { attachRoomFeed } from './room/watching.js';
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * The lobby core: which rooms exist, who is in them, who leads them and holds which seat, kept on
3
- * disk, for any game type. A game type plugs in through `RoomTypeHooks` (its own part of the record,
4
- * its seat rules, its view, what leaving or a Ready costs it); this file never names a game's field.
5
- * Magic's lobby (`games/magic/server/src/room/lobby.ts`) is this core with Magic's hooks, and a game
6
- * with nothing of its own to keep (bomberman) plays on `plainRoomType`.
3
+ * disk, for any game type. A game type plugs in through `RoomTypeHooks` (`room-type.ts`); this file
4
+ * never names a game's field. Magic's lobby (`games/magic/server/src/room/lobby.ts`) is this core
5
+ * with Magic's hooks, and a game with nothing of its own to keep (bomberman) plays on `plainRoomType`.
7
6
  *
8
7
  * ## Persistence: write-through, through `@wolffm/rooms-server/store`
9
8
  *
@@ -35,14 +34,11 @@
35
34
  */
36
35
  import { FileRoomStore, type RoomCodec } from '@wolffm/rooms-server/store';
37
36
  import { type Look } from '@wolffm/platform-wire/look';
38
- import type { AnyRoomSettings } from '@wolffm/platform-wire/room-settings';
39
- import type { RoomFloorTier } from '@wolffm/platform-wire/tiers';
40
37
  import { type IdMove } from '../erase/anonymise.js';
41
- import { type AiPersona } from './ai-faces.js';
42
38
  import type { Caller } from './caller.js';
43
39
  import { type Secret } from './provisioning.js';
44
40
  import { type GameSeats, type PlatformMember, type PlatformRoomRecord } from './record.js';
45
- import { type RoomBusyHook } from './room-list.js';
41
+ import type { RoomTypeHooks, SetSettingsResult } from './room-type.js';
46
42
  /** A member as the lobby keeps one: the platform's record plus what a view shows of them. */
47
43
  /**
48
44
  * A testing room's stand-in: a `dev:` identity no browser presents, which holds a seeded place until
@@ -117,159 +113,6 @@ export interface StoredRoomApp {
117
113
  }
118
114
  /** Structured, and never carries a password, hash or salt. */
119
115
  export type LobbyLog = (entry: Record<string, unknown>) => void;
120
- /**
121
- * Everything a game type tells the lobby about its rooms. Every hook is called only for a room of
122
- * the type it was registered for, so `G` is that room's own part.
123
- */
124
- export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
125
- /** A new room's game seats and its game part's defaults. */
126
- newGame(input: I, id: string): {
127
- seats: GameSeats;
128
- game: G;
129
- };
130
- /** The game part as stored. */
131
- encode(room: LobbyRoom<G>): unknown;
132
- /**
133
- * The stored `app` read back: its game seats and its game part, as stored. Throws to quarantine the room;
134
- * the message names the field, never a value. `version` is the app blob's own (`ROOM_APP_VERSION` or older).
135
- */
136
- decode(app: Record<string, unknown>, version: number, ctx: {
137
- roomId: string;
138
- }): {
139
- seats: GameSeats;
140
- game: unknown;
141
- };
142
- /**
143
- * The decoded game part made a record's. `dropHolds`: every member comes back with no state and not
144
- * ready (the room is restored as a change to what it plays would leave it). `game` is given the members.
145
- */
146
- restore(app: StoredRoomApp, roomId: string): {
147
- dropHolds: boolean;
148
- game: (members: readonly LobbyMember[]) => G;
149
- };
150
- /** A restored room is installed (boot only). */
151
- restored?(room: LobbyRoom<G>): void;
152
- /** A created room is installed and saved; what the creation log line says of it. */
153
- created?(room: LobbyRoom<G>): Record<string, unknown>;
154
- /** Before every save. */
155
- beforePersist?(room: LobbyRoom<G>): void;
156
- /** The game type's part of the room's view, spread over the platform's. */
157
- view(room: LobbyRoom<G>): object;
158
- /** The game seats as the view and the relay see them (`PlatformRoomView.seats`). Default: `memberSeats`. */
159
- seatsView?(room: LobbyRoom<G>): GameSeats;
160
- /** The members who play, in seat order. Default: the members who hold a game seat. */
161
- players?(room: LobbyRoom<G>): string[];
162
- /**
163
- * Seat a member who just arrived (only when nobody already in the room waits unseated). `'game-seat'`:
164
- * the first open game seat, the platform's own. `true`/`false`: the type seated them itself, or nowhere.
165
- */
166
- autoSeat?(room: LobbyRoom<G>, memberId: string): boolean | 'game-seat';
167
- /** The busy rules the room list and the sweep read (`room-list.ts`). */
168
- busy: RoomBusyHook<LobbyRoom<G>>;
169
- /** The matches the room's games are playing now, which a close lets go of. */
170
- liveMatches(room: LobbyRoom<G>): string[];
171
- /** A member is leaving and still in the room: what it costs their game (a match it forfeits). */
172
- leaving?(room: LobbyRoom<G>, memberId: string): Pick<LeaveOk<never>, 'forfeited'> | void;
173
- /**
174
- * Whether leaving now would take the member out of an event under way (a tournament's draft or rounds).
175
- * Such a leave is only ever asked for, never a side effect: `POST /:id/leave` refuses it unless the
176
- * caller says so (`?drop=1`). Absent: no leave costs anything.
177
- */
178
- leaveDrops?(room: LobbyRoom<G>, memberId: string): boolean;
179
- /** A Ready: `'keep'` refuses the change quietly (the room's positions are fixed). Called before it is saved. */
180
- ready?(room: LobbyRoom<G>, memberId: string, ready: boolean): 'keep' | void;
181
- /** After a saved change to who sits or who is ready (a tournament's field filling, say). */
182
- seatsChanged?(room: LobbyRoom<G>): void;
183
- /** Whether the room seats through its game seats (`sitSeat` and the rest). */
184
- usesSeats(room: LobbyRoom<G>): boolean;
185
- /** Whether nobody may sit, stand, seat an AI or close a seat now (the game started, say). */
186
- seatsFixed(room: LobbyRoom<G>): boolean;
187
- /** Whether the AI and closed seats are the event's, not anybody's to change. */
188
- fieldFixed?(room: LobbyRoom<G>): boolean;
189
- /**
190
- * The leader's three atomic ops' fallback seat lineup for a room this type says does NOT
191
- * `usesSeats` — wave 120 §S2: a 1v1 room's one `RoomTable` IS its seats, so the leader's
192
- * remove, lower-capacity AND bot-replace reach it too, through the same table `gameSeatsOf`'s
193
- * own non-pod branch already reads, rather than the room's own (unused, always-empty)
194
- * `room.seats`. Undefined declines: the plain `not-draft` every other seat op already answers.
195
- * `botReplacesHuman` still checks the target's own `supportsBot` before it does anything with
196
- * it — a 1v1 room's table is not offered an AI seat (see `GenericSeatTarget.supportsBot`'s own
197
- * header), but the route now answers that truthfully (`'no-bot-seat'`), never the `not-draft`
198
- * that would wrongly say this room does not seat through game seats at all. Not consulted for
199
- * `sitSeat`/`standSeat`/`aiSeat`/`closeSeat`, which stay gated on `usesSeats` exactly as before.
200
- */
201
- extraSeatTarget?(room: LobbyRoom<G>): GenericSeatTarget | undefined;
202
- /** The most game seats the room grows to. */
203
- seatCeiling(room: LobbyRoom<G>): number;
204
- /** The game seats grown to hold `seat`. */
205
- growSeats(room: LobbyRoom<G>, seat: number): void;
206
- /** Open seats past the room's own size taken away from the end. */
207
- trimSeats(room: LobbyRoom<G>): void;
208
- /** An AI took `seat` (`on`) or left it; the seat is already marked. */
209
- aiSeated?(room: LobbyRoom<G>, seat: number, on: boolean): void;
210
- /** Every member id `ids` names, in the game part, before the record's ids are replaced (account erase). */
211
- anonymise?(room: LobbyRoom<G>, ids: ReadonlySet<string>): void;
212
- /** A testing room's stand-in gave `to` its place (`#handOver`): the record already names `to`; what the game keeps outside it follows. */
213
- handedOver?(room: LobbyRoom<G>, from: string, to: string): void;
214
- /** The room is about to be forgotten (a close or the sweep): keep what it played, settle what it owes. */
215
- ending?(room: LobbyRoom<G>, why: 'close' | 'sweep' | 'forget'): void;
216
- /** A relay room's match seat count: set for a type whose room IS its match (`onRelayRoomOpened`). */
217
- relaySeats?: number;
218
- /** Every room of this type has at least this tier floor (`tier-floor.ts`), whatever its creator chose. */
219
- minTier?: string;
220
- /**
221
- * Whether `rest` names a sub-place inside this room that the type keeps track of beyond its game
222
- * seats (a table id, a match this room remembers) — `room/serve.ts`'s `placeOfKey`, matching a
223
- * stale table-keyed room-socket join back to its room. Default: never (a type with no such idea,
224
- * `plainRoomType`'s).
225
- */
226
- subPlaceOf?(room: LobbyRoom<G>, rest: string): boolean;
227
- /** The room's settings, which its leader changes (`RoomLobby.setSettings`). Absent: the type has none. */
228
- settings?: RoomTypeSettings<G>;
229
- }
230
- /**
231
- * Where a room type keeps its settings and when they are locked. The fields themselves are the
232
- * game's declaration (`@hadoku/platform-wire/room-settings`); the type only says where they live
233
- * in its game part (it stores them, and its view shows them) and answers each lock by name.
234
- */
235
- export interface RoomTypeSettings<G> {
236
- spec: AnyRoomSettings;
237
- read(room: LobbyRoom<G>): Record<string, unknown>;
238
- /** Called only with a change that passed every lock, before the room is saved. */
239
- write(room: LobbyRoom<G>, next: Record<string, unknown>): void;
240
- /** Why the fields under `lock` cannot change now (the refusal's reason), or null when they can. */
241
- locked(room: LobbyRoom<G>, lock: string): string | null;
242
- }
243
- /**
244
- * `setSettings`' answer. `no-settings`: the room's type declares none. Any other refusal is a lock's
245
- * reason, as the type's `locked` named it (`match-live` for the kit's `LIVE` lock).
246
- */
247
- export type SetSettingsResult<V> = {
248
- ok: true;
249
- room: V;
250
- } | {
251
- ok: false;
252
- reason: string;
253
- };
254
- /** The reason a relay room refuses a `LIVE` setting while its match is live or counting down. */
255
- export declare const MATCH_LIVE = "match-live";
256
- /**
257
- * A generic seat lineup the leader's atomic ops can read and write — `room.seats` itself (every
258
- * room type that `usesSeats`), or, via `RoomTypeHooks.extraSeatTarget`, wherever ELSE a type that
259
- * does NOT keeps its seating (wave 120 §S2: a 1v1 room's one `RoomTable`).
260
- */
261
- export interface GenericSeatTarget {
262
- read(): GameSeats;
263
- write(seats: GameSeats): void;
264
- /**
265
- * Whether this lineup has an AI-occupies-a-seat idea at all — `botReplacesHuman`'s own gate,
266
- * checked before it ever picks a seat. `room.seats` always does (`AI_SEAT`). A 1v1 room's one
267
- * table does not (wave 120 §S2): `false` here is what lets that route answer a truthful,
268
- * specific refusal (`'no-bot-seat'`) instead of the plain `not-draft` a room that does not seat
269
- * through game seats AT ALL answers — a 1v1 room now does, for the other two ops.
270
- */
271
- supportsBot: boolean;
272
- }
273
116
  /** The fewest seats a room is left with when its seats are closed: one player and one more. */
274
117
  export declare const MIN_OPEN_SEATS = 2;
275
118
  export type CreateResult<V> = {
@@ -629,71 +472,4 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
629
472
  */
630
473
  open(): Promise<number>;
631
474
  }
632
- /** How a plain room is sized, and which of the platform's seat behaviours it opts into. */
633
- export interface PlainRoomSize {
634
- /** The seats a new room opens with; trimming never takes it below this. */
635
- seats: number;
636
- /** The most seats it grows to. */
637
- max: number;
638
- /** A relay room's match seat count: set when the room IS its relay match. */
639
- relaySeats?: number;
640
- /**
641
- * Report seats as stored — `AI_SEAT` and `CLOSED_SEAT` included — rather than `memberSeats`'
642
- * reading, which shows both as open. A game whose seat list draws bots and closed seats wants
643
- * this; neither marker is ever a member id, so `gameSeatOf` still only matches a member's own seat.
644
- */
645
- markedSeats?: boolean;
646
- /**
647
- * Keep one seat open: whenever every seat is taken (no open and no closed one), add another,
648
- * up to `max`. The room grows by itself; nobody presses a "+" to make room for the next player,
649
- * and a seat the leader closed is never reopened by it.
650
- */
651
- keepOneOpen?: boolean;
652
- /**
653
- * The game's settings (`@hadoku/platform-wire/room-settings`): kept in the room's game part
654
- * (`app.game.settings`), shown as the view's `settings`, changed by the leader. `locked` answers
655
- * each of the fields' locks by name; absent, nothing is ever locked.
656
- */
657
- settings?: {
658
- spec: AnyRoomSettings;
659
- locked?(room: LobbyRoom<PlainGame>, lock: string): string | null;
660
- };
661
- }
662
- /** A plain room's game part: only its settings, when its game declares any. */
663
- export interface PlainGame {
664
- settings?: Record<string, unknown>;
665
- }
666
- /** What a plain room's view adds to the platform's: the AI at each seat, `seatPersonas`'s draw, and its settings. */
667
- export interface PlainRoomView {
668
- /** In seat order; null where no AI sits. */
669
- aiSeats: (AiPersona | null)[];
670
- /** Present when the game declares settings: every field, at its value now. */
671
- settings?: Record<string, unknown>;
672
- }
673
- /**
674
- * The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
675
- * players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
676
- * closed seat in any open one. `relaySeats` when the room is its own relay match.
677
- *
678
- * A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
679
- * membership, so without it the departed id stayed in the seat for good.
680
- */
681
- export declare function plainRoomType<I extends RoomCreateInput>(size: PlainRoomSize): RoomTypeHooks<PlainGame, I>;
682
- /** What `hostedRoomType` reads of a registered game type: its room's ceiling, its runtime, its match's table, its tier floor. */
683
- export interface HostedRoomSpec {
684
- seats: {
685
- max: number;
686
- };
687
- runtime?: string;
688
- table?: {
689
- seats: number;
690
- };
691
- minTier?: RoomFloorTier;
692
- }
693
- /**
694
- * The room type of a registered game the host does not play itself: `plainRoomType`, opened at eight
695
- * seats (or the game's `max`, if smaller) and growing to `max`. A relay game's room is its match, of
696
- * `table.seats` (every seat, when the game names no table). The game's tier floor is every room's.
697
- */
698
- export declare function hostedRoomType<I extends RoomCreateInput>(spec: HostedRoomSpec): RoomTypeHooks<PlainGame, I>;
699
475
  export {};
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * The lobby core: which rooms exist, who is in them, who leads them and holds which seat, kept on
3
- * disk, for any game type. A game type plugs in through `RoomTypeHooks` (its own part of the record,
4
- * its seat rules, its view, what leaving or a Ready costs it); this file never names a game's field.
5
- * Magic's lobby (`games/magic/server/src/room/lobby.ts`) is this core with Magic's hooks, and a game
6
- * with nothing of its own to keep (bomberman) plays on `plainRoomType`.
3
+ * disk, for any game type. A game type plugs in through `RoomTypeHooks` (`room-type.ts`); this file
4
+ * never names a game's field. Magic's lobby (`games/magic/server/src/room/lobby.ts`) is this core
5
+ * with Magic's hooks, and a game with nothing of its own to keep (bomberman) plays on `plainRoomType`.
7
6
  *
8
7
  * ## Persistence: write-through, through `@wolffm/rooms-server/store`
9
8
  *
@@ -41,13 +40,12 @@ import { seatsOpenAt } from '@wolffm/platform-wire/events';
41
40
  import { sameLook } from '@wolffm/platform-wire/look';
42
41
  import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
43
42
  import { moveIds, namesAny, replaceIds } from "../erase/anonymise.js";
44
- import { seatPersonas } from "./ai-faces.js";
45
43
  import { avatarIdOf } from "./avatar.js";
46
44
  import { ROOM_STALE_MS, UNNAMED } from "./constants.js";
47
45
  import { addRoomMember, isMemberReady, isRoomMember, passRoomLeader, passwordAdmits, removeRoomMember, setMemberReady } from "./membership.js";
48
46
  import { makeSecret, mintRoomId } from "./provisioning.js";
49
47
  import { AI_SEAT, CLOSED_SEAT, leaveGameSeat, memberSeats, setGameSeat, takeGameSeat } from "./record.js";
50
- import { isOfferedRoom, isSweepableRoom, NO_BUSY_HOOK, sortRoomsByCreation } from "./room-list.js";
48
+ import { isOfferedRoom, isSweepableRoom, sortRoomsByCreation } from "./room-list.js";
51
49
  import { lowerCapacity, replaceWithBot } from "./seat-table-adapter.js";
52
50
  import { stricterTier } from "./tier-floor.js";
53
51
  import { watchpartyRoomId } from "./watchparty-link.js";
@@ -57,8 +55,6 @@ import { watchpartyRoomId } from "./watchparty-link.js";
57
55
  * the first person to join takes it over whole (`RoomLobby.join`).
58
56
  */
59
57
  export const TESTING_STAND_IN_ID = 'dev:testing-stand-in';
60
- /** The reason a relay room refuses a `LIVE` setting while its match is live or counting down. */
61
- export const MATCH_LIVE = 'match-live';
62
58
  /** The fewest seats a room is left with when its seats are closed: one player and one more. */
63
59
  export const MIN_OPEN_SEATS = 2;
64
60
  /** The room-level app blob's version. Additive fields never bump it: each reads with a default. */
@@ -1135,91 +1131,3 @@ export class RoomLobby {
1135
1131
  return this.#rooms.size;
1136
1132
  }
1137
1133
  }
1138
- /** A stored seat list: every seat a holder's id, a marker, or open. */
1139
- function isStoredSeats(v) {
1140
- return Array.isArray(v) && v.every((s) => s === null || typeof s === 'string');
1141
- }
1142
- /**
1143
- * The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
1144
- * players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
1145
- * closed seat in any open one. `relaySeats` when the room is its own relay match.
1146
- *
1147
- * A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
1148
- * membership, so without it the departed id stayed in the seat for good.
1149
- */
1150
- export function plainRoomType(size) {
1151
- const open = () => new Array(size.seats).fill(null);
1152
- const declared = size.settings;
1153
- /** A room's settings as the game part holds them; a room made before its game declared any reads the defaults. */
1154
- const settingsOf = (room) => room.game.settings ?? declared.spec.defaults();
1155
- const game = (settings) => (settings === undefined ? {} : { settings });
1156
- const full = (seats) => !seats.some((s) => s === null || s === CLOSED_SEAT);
1157
- const trim = (room) => {
1158
- while (room.seats.length > size.seats && room.seats.at(-1) === null)
1159
- room.seats = room.seats.slice(0, -1);
1160
- if (size.keepOneOpen === true && room.seats.length < size.max && full(room.seats))
1161
- room.seats = [...room.seats, null];
1162
- };
1163
- return {
1164
- newGame: () => ({ seats: open(), game: game(declared?.spec.defaults()) }),
1165
- encode: (room) => game(room.game.settings),
1166
- decode(app) {
1167
- if (app.seats !== undefined && !isStoredSeats(app.seats))
1168
- throw new Error('app.seats is invalid');
1169
- const raw = typeof app.game === 'object' && app.game !== null ? app.game.settings : undefined;
1170
- // A game that declares no settings ignores whatever a file holds; one that does refuses settings it never declared.
1171
- const settings = declared === undefined ? undefined : declared.spec.readStored(raw);
1172
- if (settings === null)
1173
- throw new Error('app.game.settings is invalid');
1174
- return { seats: app.seats === undefined ? open() : [...app.seats], game: game(settings) };
1175
- },
1176
- restore: (app) => ({ dropHolds: false, game: () => game(app.game.settings) }),
1177
- view: (room) => ({ aiSeats: seatPersonas(room, AI_SEAT), ...(declared === undefined ? {} : { settings: structuredClone(settingsOf(room)) }) }),
1178
- busy: NO_BUSY_HOOK,
1179
- liveMatches: () => [],
1180
- usesSeats: () => true,
1181
- seatsFixed: () => false,
1182
- seatCeiling: () => size.max,
1183
- growSeats(room, seat) {
1184
- while (room.seats.length <= seat)
1185
- room.seats = [...room.seats, null];
1186
- },
1187
- trimSeats: trim,
1188
- leaving(room, memberId) {
1189
- const seat = room.seats.indexOf(memberId);
1190
- if (seat === -1)
1191
- return;
1192
- room.seats = room.seats.map((s, i) => (i === seat ? null : s));
1193
- trim(room);
1194
- },
1195
- ...(size.markedSeats === true ? { seatsView: (room) => room.seats } : {}),
1196
- ...(declared === undefined
1197
- ? {}
1198
- : {
1199
- settings: {
1200
- spec: declared.spec,
1201
- read: settingsOf,
1202
- write(room, next) {
1203
- room.game = { ...room.game, settings: next };
1204
- },
1205
- locked: (room, lock) => declared.locked?.(room, lock) ?? null,
1206
- },
1207
- }),
1208
- ...(size.relaySeats === undefined ? {} : { relaySeats: size.relaySeats }),
1209
- };
1210
- }
1211
- /** The most seats a hosted room opens with; one whose game seats fewer opens at its game's `max`. */
1212
- const HOSTED_OPENING_SEATS = 8;
1213
- /**
1214
- * The room type of a registered game the host does not play itself: `plainRoomType`, opened at eight
1215
- * seats (or the game's `max`, if smaller) and growing to `max`. A relay game's room is its match, of
1216
- * `table.seats` (every seat, when the game names no table). The game's tier floor is every room's.
1217
- */
1218
- export function hostedRoomType(spec) {
1219
- const plain = plainRoomType({
1220
- seats: Math.min(HOSTED_OPENING_SEATS, spec.seats.max),
1221
- max: spec.seats.max,
1222
- ...(spec.runtime === 'relay' ? { relaySeats: spec.table?.seats ?? spec.seats.max } : {}),
1223
- });
1224
- return spec.minTier === undefined ? plain : { ...plain, minTier: spec.minTier };
1225
- }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * What a game type is to the lobby (`RoomTypeHooks`): its own part of a room's record, its seat
3
+ * rules, its view, what leaving or a Ready costs it. `RoomLobby` (`lobby.ts`) runs every room
4
+ * through these hooks and never names a game's field. Two types are the platform's own:
5
+ * `plainRoomType`, for a game that keeps nothing of its own in the room (bomberman), and
6
+ * `hostedRoomType`, for a registered game the host does not play itself.
7
+ */
8
+ import type { AnyRoomSettings } from '@wolffm/platform-wire/room-settings';
9
+ import type { RoomFloorTier } from '@wolffm/platform-wire/tiers';
10
+ import { type AiPersona } from './ai-faces.js';
11
+ import type { LeaveResult, LobbyMember, LobbyRoom, RoomCreateInput, StoredRoomApp } from './lobby.js';
12
+ import { type GameSeats } from './record.js';
13
+ import { type RoomBusyHook } from './room-list.js';
14
+ /**
15
+ * Everything a game type tells the lobby about its rooms. Every hook is called only for a room of
16
+ * the type it was registered for, so `G` is that room's own part.
17
+ */
18
+ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
19
+ /** A new room's game seats and its game part's defaults. */
20
+ newGame(input: I, id: string): {
21
+ seats: GameSeats;
22
+ game: G;
23
+ };
24
+ /** The game part as stored. */
25
+ encode(room: LobbyRoom<G>): unknown;
26
+ /**
27
+ * The stored `app` read back: its game seats and its game part, as stored. Throws to quarantine the room;
28
+ * the message names the field, never a value. `version` is the app blob's own (`ROOM_APP_VERSION` or older).
29
+ */
30
+ decode(app: Record<string, unknown>, version: number, ctx: {
31
+ roomId: string;
32
+ }): {
33
+ seats: GameSeats;
34
+ game: unknown;
35
+ };
36
+ /**
37
+ * The decoded game part made a record's. `dropHolds`: every member comes back with no state and not
38
+ * ready (the room is restored as a change to what it plays would leave it). `game` is given the members.
39
+ */
40
+ restore(app: StoredRoomApp, roomId: string): {
41
+ dropHolds: boolean;
42
+ game: (members: readonly LobbyMember[]) => G;
43
+ };
44
+ /** A restored room is installed (boot only). */
45
+ restored?(room: LobbyRoom<G>): void;
46
+ /** A created room is installed and saved; what the creation log line says of it. */
47
+ created?(room: LobbyRoom<G>): Record<string, unknown>;
48
+ /** Before every save. */
49
+ beforePersist?(room: LobbyRoom<G>): void;
50
+ /** The game type's part of the room's view, spread over the platform's. */
51
+ view(room: LobbyRoom<G>): object;
52
+ /** The game seats as the view and the relay see them (`PlatformRoomView.seats`). Default: `memberSeats`. */
53
+ seatsView?(room: LobbyRoom<G>): GameSeats;
54
+ /** The members who play, in seat order. Default: the members who hold a game seat. */
55
+ players?(room: LobbyRoom<G>): string[];
56
+ /**
57
+ * Seat a member who just arrived (only when nobody already in the room waits unseated). `'game-seat'`:
58
+ * the first open game seat, the platform's own. `true`/`false`: the type seated them itself, or nowhere.
59
+ */
60
+ autoSeat?(room: LobbyRoom<G>, memberId: string): boolean | 'game-seat';
61
+ /** The busy rules the room list and the sweep read (`room-list.ts`). */
62
+ busy: RoomBusyHook<LobbyRoom<G>>;
63
+ /** The matches the room's games are playing now, which a close lets go of. */
64
+ liveMatches(room: LobbyRoom<G>): string[];
65
+ /** A member is leaving and still in the room: what it costs their game (a match it forfeits). */
66
+ leaving?(room: LobbyRoom<G>, memberId: string): Pick<Extract<LeaveResult<never>, {
67
+ ok: true;
68
+ }>, 'forfeited'> | void;
69
+ /**
70
+ * Whether leaving now would take the member out of an event under way (a tournament's draft or rounds).
71
+ * Such a leave is only ever asked for, never a side effect: `POST /:id/leave` refuses it unless the
72
+ * caller says so (`?drop=1`). Absent: no leave costs anything.
73
+ */
74
+ leaveDrops?(room: LobbyRoom<G>, memberId: string): boolean;
75
+ /** A Ready: `'keep'` refuses the change quietly (the room's positions are fixed). Called before it is saved. */
76
+ ready?(room: LobbyRoom<G>, memberId: string, ready: boolean): 'keep' | void;
77
+ /** After a saved change to who sits or who is ready (a tournament's field filling, say). */
78
+ seatsChanged?(room: LobbyRoom<G>): void;
79
+ /** Whether the room seats through its game seats (`sitSeat` and the rest). */
80
+ usesSeats(room: LobbyRoom<G>): boolean;
81
+ /** Whether nobody may sit, stand, seat an AI or close a seat now (the game started, say). */
82
+ seatsFixed(room: LobbyRoom<G>): boolean;
83
+ /** Whether the AI and closed seats are the event's, not anybody's to change. */
84
+ fieldFixed?(room: LobbyRoom<G>): boolean;
85
+ /**
86
+ * Where the leader's remove, lower-capacity and bot-replace find the seats of a room that does not
87
+ * `usesSeats` (a 1v1 room's one table is its seats). Undefined: they answer `not-draft`, as every
88
+ * other seat op does. `sitSeat`, `standSeat`, `aiSeat` and `closeSeat` never read it.
89
+ */
90
+ extraSeatTarget?(room: LobbyRoom<G>): GenericSeatTarget | undefined;
91
+ /** The most game seats the room grows to. */
92
+ seatCeiling(room: LobbyRoom<G>): number;
93
+ /** The game seats grown to hold `seat`. */
94
+ growSeats(room: LobbyRoom<G>, seat: number): void;
95
+ /** Open seats past the room's own size taken away from the end. */
96
+ trimSeats(room: LobbyRoom<G>): void;
97
+ /** An AI took `seat` (`on`) or left it; the seat is already marked. */
98
+ aiSeated?(room: LobbyRoom<G>, seat: number, on: boolean): void;
99
+ /** Every member id `ids` names, in the game part, before the record's ids are replaced (account erase). */
100
+ anonymise?(room: LobbyRoom<G>, ids: ReadonlySet<string>): void;
101
+ /** A testing room's stand-in gave `to` its place (`#handOver`): the record already names `to`; what the game keeps outside it follows. */
102
+ handedOver?(room: LobbyRoom<G>, from: string, to: string): void;
103
+ /** The room is about to be forgotten (a close or the sweep): keep what it played, settle what it owes. */
104
+ ending?(room: LobbyRoom<G>, why: 'close' | 'sweep' | 'forget'): void;
105
+ /** A relay room's match seat count: set for a type whose room IS its match (`onRelayRoomOpened`). */
106
+ relaySeats?: number;
107
+ /** Every room of this type has at least this tier floor (`tier-floor.ts`), whatever its creator chose. */
108
+ minTier?: string;
109
+ /**
110
+ * Whether `rest` names a sub-place inside this room that the type keeps track of beyond its game
111
+ * seats (a table id, a match this room remembers) — `room/serve.ts`'s `placeOfKey`, matching a
112
+ * stale table-keyed room-socket join back to its room. Default: never (a type with no such idea,
113
+ * `plainRoomType`'s).
114
+ */
115
+ subPlaceOf?(room: LobbyRoom<G>, rest: string): boolean;
116
+ /** The room's settings, which its leader changes (`RoomLobby.setSettings`). Absent: the type has none. */
117
+ settings?: RoomTypeSettings<G>;
118
+ }
119
+ /**
120
+ * Where a room type keeps its settings and when they are locked. The fields themselves are the
121
+ * game's declaration (`@hadoku/platform-wire/room-settings`); the type only says where they live
122
+ * in its game part (it stores them, and its view shows them) and answers each lock by name.
123
+ */
124
+ export interface RoomTypeSettings<G> {
125
+ spec: AnyRoomSettings;
126
+ read(room: LobbyRoom<G>): Record<string, unknown>;
127
+ /** Called only with a change that passed every lock, before the room is saved. */
128
+ write(room: LobbyRoom<G>, next: Record<string, unknown>): void;
129
+ /** Why the fields under `lock` cannot change now (the refusal's reason), or null when they can. */
130
+ locked(room: LobbyRoom<G>, lock: string): string | null;
131
+ }
132
+ /**
133
+ * `setSettings`' answer. `no-settings`: the room's type declares none. Any other refusal is a lock's
134
+ * reason, as the type's `locked` named it (`match-live` for the kit's `LIVE` lock).
135
+ */
136
+ export type SetSettingsResult<V> = {
137
+ ok: true;
138
+ room: V;
139
+ } | {
140
+ ok: false;
141
+ reason: string;
142
+ };
143
+ /** The reason a relay room refuses a `LIVE` setting while its match is live or counting down. */
144
+ export declare const MATCH_LIVE = "match-live";
145
+ /**
146
+ * A seat lineup the leader's atomic ops read and write: `room.seats` for a type that `usesSeats`,
147
+ * else wherever the type keeps its seats (`RoomTypeHooks.extraSeatTarget`).
148
+ */
149
+ export interface GenericSeatTarget {
150
+ read(): GameSeats;
151
+ write(seats: GameSeats): void;
152
+ /**
153
+ * Whether an AI may hold one of these seats (`room.seats` always: `AI_SEAT`; a 1v1 room's table
154
+ * never). `botReplacesHuman` reads it first and answers `no-bot-seat` when it is false.
155
+ */
156
+ supportsBot: boolean;
157
+ }
158
+ /** How a plain room is sized, and which of the platform's seat behaviours it opts into. */
159
+ export interface PlainRoomSize {
160
+ /** The seats a new room opens with; trimming never takes it below this. */
161
+ seats: number;
162
+ /** The most seats it grows to. */
163
+ max: number;
164
+ /** A relay room's match seat count: set when the room IS its relay match. */
165
+ relaySeats?: number;
166
+ /**
167
+ * Report seats as stored — `AI_SEAT` and `CLOSED_SEAT` included — rather than `memberSeats`'
168
+ * reading, which shows both as open. A game whose seat list draws bots and closed seats wants
169
+ * this; neither marker is ever a member id, so `gameSeatOf` still only matches a member's own seat.
170
+ */
171
+ markedSeats?: boolean;
172
+ /**
173
+ * Keep one seat open: whenever every seat is taken (no open and no closed one), add another,
174
+ * up to `max`. The room grows by itself; nobody presses a "+" to make room for the next player,
175
+ * and a seat the leader closed is never reopened by it.
176
+ */
177
+ keepOneOpen?: boolean;
178
+ /**
179
+ * The game's settings (`@hadoku/platform-wire/room-settings`): kept in the room's game part
180
+ * (`app.game.settings`), shown as the view's `settings`, changed by the leader. `locked` answers
181
+ * each of the fields' locks by name; absent, nothing is ever locked.
182
+ */
183
+ settings?: {
184
+ spec: AnyRoomSettings;
185
+ locked?(room: LobbyRoom<PlainGame>, lock: string): string | null;
186
+ };
187
+ }
188
+ /** A plain room's game part: only its settings, when its game declares any. */
189
+ export interface PlainGame {
190
+ settings?: Record<string, unknown>;
191
+ }
192
+ /** What a plain room's view adds to the platform's: the AI at each seat, `seatPersonas`'s draw, and its settings. */
193
+ export interface PlainRoomView {
194
+ /** In seat order; null where no AI sits. */
195
+ aiSeats: (AiPersona | null)[];
196
+ /** Present when the game declares settings: every field, at its value now. */
197
+ settings?: Record<string, unknown>;
198
+ }
199
+ /**
200
+ * The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
201
+ * players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
202
+ * closed seat in any open one. `relaySeats` when the room is its own relay match.
203
+ *
204
+ * A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
205
+ * membership, so without it the departed id stayed in the seat for good.
206
+ */
207
+ export declare function plainRoomType<I extends RoomCreateInput>(size: PlainRoomSize): RoomTypeHooks<PlainGame, I>;
208
+ /** What `hostedRoomType` reads of a registered game type: its room's ceiling, its runtime, its match's table, its tier floor. */
209
+ export interface HostedRoomSpec {
210
+ seats: {
211
+ max: number;
212
+ };
213
+ runtime?: string;
214
+ table?: {
215
+ seats: number;
216
+ };
217
+ minTier?: RoomFloorTier;
218
+ }
219
+ /**
220
+ * The room type of a registered game the host does not play itself: `plainRoomType`, opened at eight
221
+ * seats (or the game's `max`, if smaller) and growing to `max`. A relay game's room is its match, of
222
+ * `table.seats` (every seat, when the game names no table). The game's tier floor is every room's.
223
+ */
224
+ export declare function hostedRoomType<I extends RoomCreateInput>(spec: HostedRoomSpec): RoomTypeHooks<PlainGame, I>;
@@ -0,0 +1,93 @@
1
+ import { seatPersonas } from "./ai-faces.js";
2
+ import { AI_SEAT, CLOSED_SEAT } from "./record.js";
3
+ import { NO_BUSY_HOOK } from "./room-list.js";
4
+ /** The reason a relay room refuses a `LIVE` setting while its match is live or counting down. */
5
+ export const MATCH_LIVE = 'match-live';
6
+ /** A stored seat list: every seat a holder's id, a marker, or open. */
7
+ function isStoredSeats(v) {
8
+ return Array.isArray(v) && v.every((s) => s === null || typeof s === 'string');
9
+ }
10
+ /**
11
+ * The room type of a game that keeps nothing of its own in the room (bomberman): no game part, its
12
+ * players in the platform's game seats, opened with `seats` of them and growing to `max`, an AI or a
13
+ * closed seat in any open one. `relaySeats` when the room is its own relay match.
14
+ *
15
+ * A member who leaves the room gives up their seat (`leaving`): `RoomLobby.leave` drops only the
16
+ * membership, so without it the departed id stayed in the seat for good.
17
+ */
18
+ export function plainRoomType(size) {
19
+ const open = () => new Array(size.seats).fill(null);
20
+ const declared = size.settings;
21
+ /** A room's settings as the game part holds them; a room made before its game declared any reads the defaults. */
22
+ const settingsOf = (room) => room.game.settings ?? declared.spec.defaults();
23
+ const game = (settings) => (settings === undefined ? {} : { settings });
24
+ const full = (seats) => !seats.some((s) => s === null || s === CLOSED_SEAT);
25
+ const trim = (room) => {
26
+ while (room.seats.length > size.seats && room.seats.at(-1) === null)
27
+ room.seats = room.seats.slice(0, -1);
28
+ if (size.keepOneOpen === true && room.seats.length < size.max && full(room.seats))
29
+ room.seats = [...room.seats, null];
30
+ };
31
+ return {
32
+ newGame: () => ({ seats: open(), game: game(declared?.spec.defaults()) }),
33
+ encode: (room) => game(room.game.settings),
34
+ decode(app) {
35
+ if (app.seats !== undefined && !isStoredSeats(app.seats))
36
+ throw new Error('app.seats is invalid');
37
+ const raw = typeof app.game === 'object' && app.game !== null ? app.game.settings : undefined;
38
+ // A game that declares no settings ignores whatever a file holds; one that does refuses settings it never declared.
39
+ const settings = declared === undefined ? undefined : declared.spec.readStored(raw);
40
+ if (settings === null)
41
+ throw new Error('app.game.settings is invalid');
42
+ return { seats: app.seats === undefined ? open() : [...app.seats], game: game(settings) };
43
+ },
44
+ restore: (app) => ({ dropHolds: false, game: () => game(app.game.settings) }),
45
+ view: (room) => ({ aiSeats: seatPersonas(room, AI_SEAT), ...(declared === undefined ? {} : { settings: structuredClone(settingsOf(room)) }) }),
46
+ busy: NO_BUSY_HOOK,
47
+ liveMatches: () => [],
48
+ usesSeats: () => true,
49
+ seatsFixed: () => false,
50
+ seatCeiling: () => size.max,
51
+ growSeats(room, seat) {
52
+ while (room.seats.length <= seat)
53
+ room.seats = [...room.seats, null];
54
+ },
55
+ trimSeats: trim,
56
+ leaving(room, memberId) {
57
+ const seat = room.seats.indexOf(memberId);
58
+ if (seat === -1)
59
+ return;
60
+ room.seats = room.seats.map((s, i) => (i === seat ? null : s));
61
+ trim(room);
62
+ },
63
+ ...(size.markedSeats === true ? { seatsView: (room) => room.seats } : {}),
64
+ ...(declared === undefined
65
+ ? {}
66
+ : {
67
+ settings: {
68
+ spec: declared.spec,
69
+ read: settingsOf,
70
+ write(room, next) {
71
+ room.game = { ...room.game, settings: next };
72
+ },
73
+ locked: (room, lock) => declared.locked?.(room, lock) ?? null,
74
+ },
75
+ }),
76
+ ...(size.relaySeats === undefined ? {} : { relaySeats: size.relaySeats }),
77
+ };
78
+ }
79
+ /** The most seats a hosted room opens with; one whose game seats fewer opens at its game's `max`. */
80
+ const HOSTED_OPENING_SEATS = 8;
81
+ /**
82
+ * The room type of a registered game the host does not play itself: `plainRoomType`, opened at eight
83
+ * seats (or the game's `max`, if smaller) and growing to `max`. A relay game's room is its match, of
84
+ * `table.seats` (every seat, when the game names no table). The game's tier floor is every room's.
85
+ */
86
+ export function hostedRoomType(spec) {
87
+ const plain = plainRoomType({
88
+ seats: Math.min(HOSTED_OPENING_SEATS, spec.seats.max),
89
+ max: spec.seats.max,
90
+ ...(spec.runtime === 'relay' ? { relaySeats: spec.table?.seats ?? spec.seats.max } : {}),
91
+ });
92
+ return spec.minTier === undefined ? plain : { ...plain, minTier: spec.minTier };
93
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * What a room site's plugins share whatever its game (`SiteState`). A game's site extends it with
3
+ * its own fields (Magic's `Cardtable`); the site's own plugins are typed on `SiteState` alone
4
+ * (`SitePlugin`), so none of them reaches a game's field.
5
+ */
6
+ import type { JsonLog } from '@wolffm/service-kernel/log';
7
+ import type { GamePlugin } from '@wolffm/service-kernel/server';
8
+ import type { ForgetfulPeople } from './people.js';
9
+ import type { PlatformRoomView, RoomCreateInput, RoomLobby } from './room/lobby.js';
10
+ import type { ServedRooms } from './room/serve.js';
11
+ import type { attachRoomFeed } from './room/watching.js';
12
+ export interface SiteState {
13
+ /** This instance's checkout: prod and PPE each have one. */
14
+ readonly repoRoot: string;
15
+ /** ArchiveBot's settings, the deployment's own integration. With no secret, nothing is sent to it. */
16
+ archivebot: {
17
+ secret: string;
18
+ url: string;
19
+ };
20
+ roomsLog: JsonLog;
21
+ lobby: RoomLobby<PlatformRoomView, RoomCreateInput>;
22
+ people: ForgetfulPeople;
23
+ /** The chrome's room socket: chat, and who is in each room now. */
24
+ servedRoom: ServedRooms;
25
+ roomFeed: ReturnType<typeof attachRoomFeed>;
26
+ roomClosed: (roomId: string, matches: readonly string[]) => void;
27
+ roomForfeited: (roomId: string, tableId: string, loser: string, matches: readonly string[]) => void;
28
+ }
29
+ export type SitePlugin = GamePlugin<Record<never, never>, SiteState>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.235",
4
- "gitHead": "20346b0c6ec2961dfe288dc39f6c3f615c615215",
3
+ "version": "0.1.236",
4
+ "gitHead": "8f448ebdc8024066b07069f72f8e82fc89dc69d7",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
@@ -16,9 +16,9 @@
16
16
  "play/remote/"
17
17
  ],
18
18
  "dependencies": {
19
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.235",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.235",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.268",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.236",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.236",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.269",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
23
23
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",
24
24
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.152",