@hadoku/game-server 0.1.19 → 0.1.21

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.
@@ -66,6 +66,10 @@ function seatOpStatus(res, reason) {
66
66
  res.status(400).json({ error: 'not a seat this room has' });
67
67
  return;
68
68
  }
69
+ if (reason === 'no-bot-seat') {
70
+ res.status(409).json({ error: 'this room has no seat the bot can take' });
71
+ return;
72
+ }
69
73
  res.status(400).json({ error: reason });
70
74
  }
71
75
  /** Every one of the leader's three seat ops, per caller: a burst of 10, then one every 10 s — the same shape as a join attempt, spent only by a leader who is actually a member of the room (checked before this is asked). */
@@ -166,6 +166,19 @@ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
166
166
  seatsFixed(room: LobbyRoom<G>): boolean;
167
167
  /** Whether the AI and closed seats are the event's, not anybody's to change. */
168
168
  fieldFixed?(room: LobbyRoom<G>): boolean;
169
+ /**
170
+ * The leader's three atomic ops' fallback seat lineup for a room this type says does NOT
171
+ * `usesSeats` — wave 120 §S2: a 1v1 room's one `RoomTable` IS its seats, so the leader's
172
+ * remove, lower-capacity AND bot-replace reach it too, through the same table `gameSeatsOf`'s
173
+ * own non-pod branch already reads, rather than the room's own (unused, always-empty)
174
+ * `room.seats`. Undefined declines: the plain `not-draft` every other seat op already answers.
175
+ * `botReplacesHuman` still checks the target's own `supportsBot` before it does anything with
176
+ * it — a 1v1 room's table is not offered an AI seat (see `GenericSeatTarget.supportsBot`'s own
177
+ * header), but the route now answers that truthfully (`'no-bot-seat'`), never the `not-draft`
178
+ * that would wrongly say this room does not seat through game seats at all. Not consulted for
179
+ * `sitSeat`/`standSeat`/`aiSeat`/`closeSeat`, which stay gated on `usesSeats` exactly as before.
180
+ */
181
+ extraSeatTarget?(room: LobbyRoom<G>): GenericSeatTarget | undefined;
169
182
  /** The most game seats the room grows to. */
170
183
  seatCeiling(room: LobbyRoom<G>): number;
171
184
  /** The game seats grown to hold `seat`. */
@@ -188,6 +201,23 @@ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
188
201
  */
189
202
  subPlaceOf?(room: LobbyRoom<G>, rest: string): boolean;
190
203
  }
204
+ /**
205
+ * A generic seat lineup the leader's atomic ops can read and write — `room.seats` itself (every
206
+ * room type that `usesSeats`), or, via `RoomTypeHooks.extraSeatTarget`, wherever ELSE a type that
207
+ * does NOT keeps its seating (wave 120 §S2: a 1v1 room's one `RoomTable`).
208
+ */
209
+ export interface GenericSeatTarget {
210
+ read(): GameSeats;
211
+ write(seats: GameSeats): void;
212
+ /**
213
+ * Whether this lineup has an AI-occupies-a-seat idea at all — `botReplacesHuman`'s own gate,
214
+ * checked before it ever picks a seat. `room.seats` always does (`AI_SEAT`). A 1v1 room's one
215
+ * table does not (wave 120 §S2): `false` here is what lets that route answer a truthful,
216
+ * specific refusal (`'no-bot-seat'`) instead of the plain `not-draft` a room that does not seat
217
+ * through game seats AT ALL answers — a 1v1 room now does, for the other two ops.
218
+ */
219
+ supportsBot: boolean;
220
+ }
191
221
  /** The fewest seats a room is left with when its seats are closed: one player and one more. */
192
222
  export declare const MIN_OPEN_SEATS = 2;
193
223
  export type CreateResult<V> = {
@@ -278,7 +308,7 @@ export type BotReplacesHumanResult<V> = {
278
308
  evicted: string | null;
279
309
  } | {
280
310
  ok: false;
281
- reason: 'no-room' | 'not-member' | 'not-leader' | 'not-draft' | 'not-lobby' | 'historical' | 'bad-seat';
311
+ reason: 'no-room' | 'not-member' | 'not-leader' | 'not-draft' | 'not-lobby' | 'historical' | 'bad-seat' | 'no-bot-seat';
282
312
  };
283
313
  export interface AvatarChange {
284
314
  roomId: string;
@@ -445,10 +475,12 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
445
475
  * Idempotent: a target who holds none is still answered `ok`. Never touches membership — they
446
476
  * stay in the room, watching (this file's own "a player or a spectator, never neither",
447
477
  * 2026-11-02). `targetId` need not be `memberId`; this is the leader acting on someone else,
448
- * which is exactly what `standSeat` (self-service) cannot do. `leaveGameSeat` already IS this
449
- * operation's contract — `@wolffm/rooms-protocol@0.45.95`'s own `removeFromSeat(table,
450
- * participantId)` is `unseatParticipant(table, participantId, { hold: false })`, the same shape —
451
- * so no `seat-eviction.ts` entry exists for this one; see that file's header for the two that do.
478
+ * which is exactly what `standSeat` (self-service) cannot do. Resolved through `#seatOpRoom`
479
+ * (wave 120 §S2), not `#seatRoom`: a room that does not `usesSeats` gets one more chance at
480
+ * `hooks.extraSeatTarget` before the plain `not-draft` — a 1v1 room's one table, for instance.
481
+ * The library's own `removeFromSeat(table, participantId)` is `unseatParticipant(table,
482
+ * participantId, { hold: false })`, the same shape a plain null-out already was, so the target
483
+ * array is mutated directly here rather than through `seat-table-adapter.ts`.
452
484
  */
453
485
  removeFromSeat(roomId: string, memberId: string, targetId: string): RemoveFromSeatResult<V>;
454
486
  /**
@@ -459,11 +491,17 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
459
491
  * default `memberSeats` view reads them as open same as any other non-member string — a room
460
492
  * type that wants its view to tell "AI"/"closed" from "open" gives itself its own `seatsView`
461
493
  * (same as Magic's pod view carries AI through `podAi`, a field of its own, not this one's).
494
+ * Resolved through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header.
462
495
  */
463
496
  lowerSeatCapacity(roomId: string, memberId: string, count: number): LowerSeatCapacityResult<V>;
464
497
  /**
465
498
  * The leader puts the AI in `seat`, evicting whoever holds it first — a human to the spectator
466
- * row — instead of `aiSeat`'s refusal on an occupied seat. Already the AI's: a no-op.
499
+ * row — instead of `aiSeat`'s refusal on an occupied seat. Already the AI's: a no-op. Resolved
500
+ * through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header. A room whose target
501
+ * does not `supportsBot` (a 1v1 room's one table — no AI-occupies-a-seat idea of its own) is
502
+ * refused `'no-bot-seat'`, a truthful, specific reason — never the plain `not-draft`, which
503
+ * would wrongly say this room does not seat through game seats at all (it does, for the other
504
+ * two ops), and never an invented AI seat the table has nowhere to show.
467
505
  */
468
506
  botReplacesHuman(roomId: string, memberId: string, seat: number): BotReplacesHumanResult<V>;
469
507
  /**
@@ -45,7 +45,7 @@ import { addRoomMember, isMemberReady, isRoomMember, passwordAdmits, removeRoomM
45
45
  import { makeSecret, mintRoomId } from "./provisioning.js";
46
46
  import { AI_SEAT, CLOSED_SEAT, leaveGameSeat, memberSeats, setGameSeat, takeGameSeat } from "./record.js";
47
47
  import { isOfferedRoom, isSweepableRoom, NO_BUSY_HOOK, sortRoomsByCreation } from "./room-list.js";
48
- import { lowerCapacity, replaceWithBot } from "./seat-eviction.js";
48
+ import { lowerCapacity, replaceWithBot } from "./seat-table-adapter.js";
49
49
  import { watchpartyRoomId } from "./watchparty-link.js";
50
50
  /** The fewest seats a room is left with when its seats are closed: one player and one more. */
51
51
  export const MIN_OPEN_SEATS = 2;
@@ -606,6 +606,43 @@ export class RoomLobby {
606
606
  #inReach(room, hooks, seat) {
607
607
  return Number.isInteger(seat) && seat >= 0 && seat < hooks.seatCeiling(room) && seat <= room.seats.length;
608
608
  }
609
+ /**
610
+ * `removeFromSeat`/`lowerSeatCapacity`/`botReplacesHuman`'s own resolver (wave 120 §S2) — the
611
+ * same checks as `#seatRoom`, but a room that does NOT `usesSeats` gets one more chance:
612
+ * `hooks.extraSeatTarget`, a type's OWN seat lineup for just these three ops (a 1v1 room's one
613
+ * table). `generic` tells the caller whether `target` IS `room.seats` (so `trimSeats` applies)
614
+ * or the type's own stand-in (which trims nothing — a fixed-size table, never grown or shrunk
615
+ * this way). `room.seats` always `supportsBot` (its `AI_SEAT` marker); a type's own stand-in
616
+ * says for itself.
617
+ */
618
+ #seatOpRoom(roomId, memberId) {
619
+ const room = this.#rooms.get(roomId);
620
+ if (room === undefined)
621
+ return { refused: 'no-room' };
622
+ if (!isRoomMember(room, memberId))
623
+ return { refused: 'not-member' };
624
+ const hooks = this.hooksOf(room);
625
+ if (hooks.usesSeats(room)) {
626
+ if (hooks.seatsFixed(room))
627
+ return { refused: 'not-lobby' };
628
+ return {
629
+ room,
630
+ hooks,
631
+ generic: true,
632
+ target: {
633
+ read: () => room.seats,
634
+ write: (seats) => {
635
+ room.seats = seats;
636
+ },
637
+ supportsBot: true,
638
+ },
639
+ };
640
+ }
641
+ const target = hooks.extraSeatTarget?.(room);
642
+ if (target === undefined)
643
+ return { refused: 'not-draft' };
644
+ return { room, hooks, generic: false, target };
645
+ }
609
646
  /**
610
647
  * Take a game seat. `seat` absent takes the first open one (their own counts as open), growing the
611
648
  * room by one past the last when none is; given, it must be open and in reach. Moves the caller from
@@ -715,10 +752,12 @@ export class RoomLobby {
715
752
  * Idempotent: a target who holds none is still answered `ok`. Never touches membership — they
716
753
  * stay in the room, watching (this file's own "a player or a spectator, never neither",
717
754
  * 2026-11-02). `targetId` need not be `memberId`; this is the leader acting on someone else,
718
- * which is exactly what `standSeat` (self-service) cannot do. `leaveGameSeat` already IS this
719
- * operation's contract — `@wolffm/rooms-protocol@0.45.95`'s own `removeFromSeat(table,
720
- * participantId)` is `unseatParticipant(table, participantId, { hold: false })`, the same shape —
721
- * so no `seat-eviction.ts` entry exists for this one; see that file's header for the two that do.
755
+ * which is exactly what `standSeat` (self-service) cannot do. Resolved through `#seatOpRoom`
756
+ * (wave 120 §S2), not `#seatRoom`: a room that does not `usesSeats` gets one more chance at
757
+ * `hooks.extraSeatTarget` before the plain `not-draft` — a 1v1 room's one table, for instance.
758
+ * The library's own `removeFromSeat(table, participantId)` is `unseatParticipant(table,
759
+ * participantId, { hold: false })`, the same shape a plain null-out already was, so the target
760
+ * array is mutated directly here rather than through `seat-table-adapter.ts`.
722
761
  */
723
762
  removeFromSeat(roomId, memberId, targetId) {
724
763
  const room = this.#rooms.get(roomId);
@@ -730,13 +769,17 @@ export class RoomLobby {
730
769
  return { ok: false, reason: 'not-leader' };
731
770
  if (!isRoomMember(room, targetId))
732
771
  return { ok: false, reason: 'target-not-member' };
733
- const found = this.#seatRoom(roomId, memberId);
772
+ const found = this.#seatOpRoom(roomId, memberId);
734
773
  if ('refused' in found)
735
774
  return { ok: false, reason: found.refused };
736
- const { room: r, hooks } = found;
737
- if (!leaveGameSeat(r, targetId))
775
+ const { room: r, hooks, target, generic } = found;
776
+ const seats = target.read();
777
+ const at = seats.indexOf(targetId);
778
+ if (at === -1)
738
779
  return { ok: true, room: this.view(r) };
739
- hooks.trimSeats(r);
780
+ target.write(seats.map((s, i) => (i === at ? null : s)));
781
+ if (generic)
782
+ hooks.trimSeats(r);
740
783
  this.persist(r);
741
784
  this.log({ event: 'seat-removed-by-leader', roomId, memberId, targetId });
742
785
  hooks.seatsChanged?.(r);
@@ -750,6 +793,7 @@ export class RoomLobby {
750
793
  * default `memberSeats` view reads them as open same as any other non-member string — a room
751
794
  * type that wants its view to tell "AI"/"closed" from "open" gives itself its own `seatsView`
752
795
  * (same as Magic's pod view carries AI through `podAi`, a field of its own, not this one's).
796
+ * Resolved through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header.
753
797
  */
754
798
  lowerSeatCapacity(roomId, memberId, count) {
755
799
  const room = this.#rooms.get(roomId);
@@ -759,19 +803,21 @@ export class RoomLobby {
759
803
  return { ok: false, reason: 'not-member' };
760
804
  if (room.leader !== memberId)
761
805
  return { ok: false, reason: 'not-leader' };
762
- const found = this.#seatRoom(roomId, memberId);
806
+ const found = this.#seatOpRoom(roomId, memberId);
763
807
  if ('refused' in found)
764
808
  return { ok: false, reason: found.refused };
765
- const { room: r, hooks } = found;
809
+ const { room: r, hooks, target, generic } = found;
766
810
  if (hooks.fieldFixed?.(r) === true)
767
811
  return { ok: false, reason: 'historical' };
768
812
  if (!Number.isInteger(count) || count < MIN_OPEN_SEATS)
769
813
  return { ok: false, reason: 'too-few' };
770
- const { seats, evicted } = lowerCapacity(r.seats, count);
771
- if (evicted.length === 0 && seats.every((s, i) => s === r.seats[i]))
814
+ const before = target.read();
815
+ const { seats, evicted } = lowerCapacity(before, count);
816
+ if (evicted.length === 0 && seats.every((s, i) => s === before[i]))
772
817
  return { ok: true, room: this.view(r), evicted };
773
- r.seats = seats;
774
- hooks.trimSeats(r);
818
+ target.write(seats);
819
+ if (generic)
820
+ hooks.trimSeats(r);
775
821
  this.persist(r);
776
822
  this.log({ event: 'seat-capacity-lowered', roomId, memberId, count, evicted: evicted.length });
777
823
  hooks.seatsChanged?.(r);
@@ -779,7 +825,12 @@ export class RoomLobby {
779
825
  }
780
826
  /**
781
827
  * The leader puts the AI in `seat`, evicting whoever holds it first — a human to the spectator
782
- * row — instead of `aiSeat`'s refusal on an occupied seat. Already the AI's: a no-op.
828
+ * row — instead of `aiSeat`'s refusal on an occupied seat. Already the AI's: a no-op. Resolved
829
+ * through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header. A room whose target
830
+ * does not `supportsBot` (a 1v1 room's one table — no AI-occupies-a-seat idea of its own) is
831
+ * refused `'no-bot-seat'`, a truthful, specific reason — never the plain `not-draft`, which
832
+ * would wrongly say this room does not seat through game seats at all (it does, for the other
833
+ * two ops), and never an invented AI seat the table has nowhere to show.
783
834
  */
784
835
  botReplacesHuman(roomId, memberId, seat) {
785
836
  const room = this.#rooms.get(roomId);
@@ -789,20 +840,24 @@ export class RoomLobby {
789
840
  return { ok: false, reason: 'not-member' };
790
841
  if (room.leader !== memberId)
791
842
  return { ok: false, reason: 'not-leader' };
792
- const found = this.#seatRoom(roomId, memberId);
843
+ const found = this.#seatOpRoom(roomId, memberId);
793
844
  if ('refused' in found)
794
845
  return { ok: false, reason: found.refused };
795
- const { room: r, hooks } = found;
846
+ const { room: r, hooks, target, generic } = found;
796
847
  if (hooks.fieldFixed?.(r) === true)
797
848
  return { ok: false, reason: 'historical' };
849
+ if (!target.supportsBot)
850
+ return { ok: false, reason: 'no-bot-seat' };
798
851
  if (!this.#inReach(r, hooks, seat) || seat >= r.seats.length)
799
852
  return { ok: false, reason: 'bad-seat' };
800
- const { seats, evicted } = replaceWithBot(r.seats, seat);
801
- if (evicted === null && seats[seat] === r.seats[seat])
853
+ const before = target.read();
854
+ const { seats, evicted } = replaceWithBot(before, seat);
855
+ if (evicted === null && seats[seat] === before[seat])
802
856
  return { ok: true, room: this.view(r), evicted: null };
803
- r.seats = seats;
857
+ target.write(seats);
804
858
  hooks.aiSeated?.(r, seat, true);
805
- hooks.trimSeats(r);
859
+ if (generic)
860
+ hooks.trimSeats(r);
806
861
  this.persist(r);
807
862
  this.log({ event: 'seat-bot-replaced-human', roomId, memberId, seat, evicted: evicted !== null });
808
863
  hooks.seatsChanged?.(r);
@@ -0,0 +1,25 @@
1
+ import { type GameSeats } from './record.js';
2
+ /**
3
+ * Close seats from the TOP down until `count` are open, evicting any occupant first (a human —
4
+ * returned, for the caller to tell they are now watching — an AI simply gone). Mirrors the
5
+ * library's own `setSeatCapacity`, which this does NOT call: that function TRUNCATES
6
+ * `seats.length`, while cardtable keeps every seat's index stable (a closed seat stays addressable
7
+ * — P2's op-mapping gap, "composing `closeSeat` plus eviction is the likely fit"). Eviction is
8
+ * always highest seat first, never a caller-chosen one — same reasoning as `setSeatCapacity`'s own
9
+ * doc. A seat already closed is skipped, never counted against `count` twice.
10
+ */
11
+ export declare function lowerCapacity(seats: GameSeats, count: number): {
12
+ seats: GameSeats;
13
+ evicted: readonly string[];
14
+ };
15
+ /**
16
+ * The AI takes `seat`, evicting its human occupant first (returned, for the caller to tell they
17
+ * are now watching). Addressed by SEAT, not by the human's id — cardtable's leader picks a seat,
18
+ * empty or occupied, the same way `aiSeat` always has, and an empty seat has no occupant id to
19
+ * address by. P2's own op mapping: `occupantOf` + `replaceWithBot` for an occupied seat,
20
+ * `seatBot` for an empty one (the library's `replaceWithBot` answers null with nobody to replace).
21
+ */
22
+ export declare function replaceWithBot(seats: GameSeats, seat: number): {
23
+ seats: GameSeats;
24
+ evicted: string | null;
25
+ };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * `GameSeats` (`record.ts`'s plain `(string | null)[]` with `AI_SEAT`/`CLOSED_SEAT` markers in
3
+ * place), as a `@wolffm/rooms-protocol` `SeatTable` the library's own ops can act on — and back.
4
+ * Replaces wave 119 §S's own hand-rolled array code for these two ops, now that
5
+ * `@wolffm/rooms-protocol@0.45.99` (watchparty P2, wave 120) gives `SeatTable` the closed-seat
6
+ * idea cardtable's own array always had:
7
+ * `closeSeat`/`isClosed`, and `Seat.closed?: boolean` that keeps a seat in place — never truncating
8
+ * `seats.length` — exactly the shape `GameSeats` already stores on disk and sends over the wire.
9
+ *
10
+ * Stateless and discarded after each call: a `GameSeats` array has never carried a reservation or
11
+ * a remembered seat (nothing to lose by building a fresh `SeatTable` with `remembered: {}`,
12
+ * `reservations: {}`, `reservationTtlMs: 0` each time), and the round trip back to `GameSeats`
13
+ * drops them again — so `record.ts`'s stored and wire shape is UNCHANGED by this file existing;
14
+ * only the two operations that used to be hand-rolled array code now call the published functions.
15
+ */
16
+ import { closeSeat, isClosed, occupantOf, removeFromSeat, replaceWithBot as libReplaceWithBot, seatBot, unseatBot } from '@wolffm/rooms-protocol';
17
+ import { AI_SEAT, CLOSED_SEAT } from "./record.js";
18
+ function gameSeatsToTable(seats) {
19
+ return {
20
+ capacity: seats.length,
21
+ seats: seats.map((holder, id) => ({
22
+ id,
23
+ occupant: holder === null || holder === CLOSED_SEAT ? null : holder === AI_SEAT ? { kind: 'bot', botId: AI_SEAT } : { kind: 'human', participantId: holder },
24
+ ...(holder === CLOSED_SEAT ? { closed: true } : {}),
25
+ })),
26
+ remembered: {},
27
+ reservations: {},
28
+ reservationTtlMs: 0,
29
+ };
30
+ }
31
+ function tableToGameSeats(table) {
32
+ return table.seats.map((seat) => {
33
+ if (seat.closed === true)
34
+ return CLOSED_SEAT;
35
+ if (seat.occupant === null)
36
+ return null;
37
+ return seat.occupant.kind === 'bot' ? AI_SEAT : seat.occupant.participantId;
38
+ });
39
+ }
40
+ /**
41
+ * Close seats from the TOP down until `count` are open, evicting any occupant first (a human —
42
+ * returned, for the caller to tell they are now watching — an AI simply gone). Mirrors the
43
+ * library's own `setSeatCapacity`, which this does NOT call: that function TRUNCATES
44
+ * `seats.length`, while cardtable keeps every seat's index stable (a closed seat stays addressable
45
+ * — P2's op-mapping gap, "composing `closeSeat` plus eviction is the likely fit"). Eviction is
46
+ * always highest seat first, never a caller-chosen one — same reasoning as `setSeatCapacity`'s own
47
+ * doc. A seat already closed is skipped, never counted against `count` twice.
48
+ */
49
+ export function lowerCapacity(seats, count) {
50
+ const table = gameSeatsToTable(seats);
51
+ const evicted = [];
52
+ let open = table.seats.filter((s) => s.closed !== true).length;
53
+ for (let id = table.seats.length - 1; id >= 0 && open > count; id--) {
54
+ if (isClosed(table, id))
55
+ continue;
56
+ const occupant = occupantOf(table, id);
57
+ if (occupant?.kind === 'human') {
58
+ removeFromSeat(table, occupant.participantId);
59
+ evicted.push(occupant.participantId);
60
+ }
61
+ else if (occupant?.kind === 'bot') {
62
+ unseatBot(table, id);
63
+ }
64
+ closeSeat(table, id);
65
+ open--;
66
+ }
67
+ return { seats: tableToGameSeats(table), evicted };
68
+ }
69
+ /**
70
+ * The AI takes `seat`, evicting its human occupant first (returned, for the caller to tell they
71
+ * are now watching). Addressed by SEAT, not by the human's id — cardtable's leader picks a seat,
72
+ * empty or occupied, the same way `aiSeat` always has, and an empty seat has no occupant id to
73
+ * address by. P2's own op mapping: `occupantOf` + `replaceWithBot` for an occupied seat,
74
+ * `seatBot` for an empty one (the library's `replaceWithBot` answers null with nobody to replace).
75
+ */
76
+ export function replaceWithBot(seats, seat) {
77
+ const table = gameSeatsToTable(seats);
78
+ const occupant = occupantOf(table, seat);
79
+ if (occupant?.kind === 'bot')
80
+ return { seats, evicted: null };
81
+ if (occupant?.kind === 'human') {
82
+ libReplaceWithBot(table, occupant.participantId);
83
+ return { seats: tableToGameSeats(table), evicted: occupant.participantId };
84
+ }
85
+ seatBot(table, seat);
86
+ return { seats: tableToGameSeats(table), evicted: null };
87
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.19",
4
- "gitHead": "3c76466409b427e612cf8a4e773a9ceccc3e2dc1",
3
+ "version": "0.1.21",
4
+ "gitHead": "911b35db8125d3fddfb83455aff3795824470c89",
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,12 +16,12 @@
16
16
  "play/remote/"
17
17
  ],
18
18
  "dependencies": {
19
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.19",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.19",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.52",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.21",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.21",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.54",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
23
- "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.99",
24
- "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.99",
23
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.100",
24
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.100",
25
25
  "express": "^5.1.0",
26
26
  "socket.io": "^4.8.3",
27
27
  "zod": "4.5.4"
@@ -1,54 +0,0 @@
1
- /**
2
- * The leader's three atomic "evict, then act" seat operations (wave 119 §S), isolated here so a
3
- * future swap is a one-file edit.
4
- *
5
- * `@wolffm/rooms-protocol@0.45.95` (watchparty d02dbdfb, published while this lane ran) gives its
6
- * own `SeatTable` the same three operations: `removeFromSeat(table, participantId)`,
7
- * `replaceWithBot(table, participantId)`, and the pre-existing `setSeatCapacity(table, capacity)`
8
- * for "lower capacity under occupants, evicting someone" — its own doc calls that the one and
9
- * only way to do it on a `SeatTable`.
10
- *
11
- * Cardtable's rooms are NOT on `SeatTable`. They are `GameSeats` (`record.ts`): a plain
12
- * `(string | null)[]` with `AI_SEAT`/`CLOSED_SEAT` markers IN PLACE, because a leader can close
13
- * one specific seat (`CLOSED_SEAT`, `closeSeat`) while every seat around it, including a HIGHER
14
- * one, stays open — Magic's draft pods do this (`pods.ts`'s `POD_CLOSED`). `SeatTable.capacity`
15
- * has no such idea: its own `setSeatCapacity` doc says so explicitly — "this table has no concept
16
- * of a specific seat that is closed while a higher one stays open… inventing one would be a
17
- * second notion of capacity." That is not a gap to fix here; it is a different, deliberate design
18
- * for a different shape of room, and reconciling the two (or deciding cardtable keeps its own) is
19
- * a separate, larger item than this wave's (the survey's §7 "two parallel seat implementations"
20
- * open risk).
21
- *
22
- * So this file does not call `@wolffm/rooms-protocol` at all. It gives `GameSeats` the SAME
23
- * contract those three operations have — evict first, in the same call, so there is never a tick
24
- * with a stale seat and a fresh one both claiming the member — against cardtable's own array.
25
- * `room/lobby.ts`'s `removeFromSeat` method needs no function of its own here: `record.ts`'s
26
- * `leaveGameSeat` already IS this contract (vacate one seat, remembered nowhere since `GameSeats`
27
- * has no sticky memory, which is fine — a stood member re-sits through `sitSeat` like anyone
28
- * else). `lowerCapacity` and `replaceWithBot` below are the two that are genuinely new.
29
- *
30
- * If cardtable's seat storage is ever migrated onto `SeatTable` (resolving the `CLOSED_SEAT` gap
31
- * first), THIS file is what gets replaced with calls to the published functions — `room/lobby.ts`'s
32
- * three methods would not need to change at all, since they already call through here.
33
- */
34
- import { type GameSeats } from './record.js';
35
- /**
36
- * Close seats from the TOP down until `count` are open, evicting any occupant first (a human —
37
- * returned, for the caller to tell they are now watching — an AI simply gone). Mirrors
38
- * `@wolffm/rooms-protocol`'s `setSeatCapacity`: eviction is always highest seat first, never a
39
- * caller-chosen one — same reasoning as that function's own doc.
40
- */
41
- export declare function lowerCapacity(seats: GameSeats, count: number): {
42
- seats: GameSeats;
43
- evicted: readonly string[];
44
- };
45
- /**
46
- * The AI takes `seat`, evicting its human occupant first (returned, for the caller to tell they
47
- * are now watching). Addressed by SEAT, not by the human's id (`@wolffm/rooms-protocol`'s
48
- * `replaceWithBot` takes the participant) — cardtable's leader picks a seat, empty or occupied,
49
- * the same way `aiSeat` always has, and an empty seat has no occupant id to address by.
50
- */
51
- export declare function replaceWithBot(seats: GameSeats, seat: number): {
52
- seats: GameSeats;
53
- evicted: string | null;
54
- };
@@ -1,68 +0,0 @@
1
- /**
2
- * The leader's three atomic "evict, then act" seat operations (wave 119 §S), isolated here so a
3
- * future swap is a one-file edit.
4
- *
5
- * `@wolffm/rooms-protocol@0.45.95` (watchparty d02dbdfb, published while this lane ran) gives its
6
- * own `SeatTable` the same three operations: `removeFromSeat(table, participantId)`,
7
- * `replaceWithBot(table, participantId)`, and the pre-existing `setSeatCapacity(table, capacity)`
8
- * for "lower capacity under occupants, evicting someone" — its own doc calls that the one and
9
- * only way to do it on a `SeatTable`.
10
- *
11
- * Cardtable's rooms are NOT on `SeatTable`. They are `GameSeats` (`record.ts`): a plain
12
- * `(string | null)[]` with `AI_SEAT`/`CLOSED_SEAT` markers IN PLACE, because a leader can close
13
- * one specific seat (`CLOSED_SEAT`, `closeSeat`) while every seat around it, including a HIGHER
14
- * one, stays open — Magic's draft pods do this (`pods.ts`'s `POD_CLOSED`). `SeatTable.capacity`
15
- * has no such idea: its own `setSeatCapacity` doc says so explicitly — "this table has no concept
16
- * of a specific seat that is closed while a higher one stays open… inventing one would be a
17
- * second notion of capacity." That is not a gap to fix here; it is a different, deliberate design
18
- * for a different shape of room, and reconciling the two (or deciding cardtable keeps its own) is
19
- * a separate, larger item than this wave's (the survey's §7 "two parallel seat implementations"
20
- * open risk).
21
- *
22
- * So this file does not call `@wolffm/rooms-protocol` at all. It gives `GameSeats` the SAME
23
- * contract those three operations have — evict first, in the same call, so there is never a tick
24
- * with a stale seat and a fresh one both claiming the member — against cardtable's own array.
25
- * `room/lobby.ts`'s `removeFromSeat` method needs no function of its own here: `record.ts`'s
26
- * `leaveGameSeat` already IS this contract (vacate one seat, remembered nowhere since `GameSeats`
27
- * has no sticky memory, which is fine — a stood member re-sits through `sitSeat` like anyone
28
- * else). `lowerCapacity` and `replaceWithBot` below are the two that are genuinely new.
29
- *
30
- * If cardtable's seat storage is ever migrated onto `SeatTable` (resolving the `CLOSED_SEAT` gap
31
- * first), THIS file is what gets replaced with calls to the published functions — `room/lobby.ts`'s
32
- * three methods would not need to change at all, since they already call through here.
33
- */
34
- import { AI_SEAT, CLOSED_SEAT } from "./record.js";
35
- /**
36
- * Close seats from the TOP down until `count` are open, evicting any occupant first (a human —
37
- * returned, for the caller to tell they are now watching — an AI simply gone). Mirrors
38
- * `@wolffm/rooms-protocol`'s `setSeatCapacity`: eviction is always highest seat first, never a
39
- * caller-chosen one — same reasoning as that function's own doc.
40
- */
41
- export function lowerCapacity(seats, count) {
42
- const result = [...seats];
43
- const evicted = [];
44
- let open = result.filter((s) => s !== CLOSED_SEAT).length;
45
- for (let seat = result.length - 1; seat >= 0 && open > count; seat--) {
46
- const holder = result[seat] ?? null;
47
- if (holder === CLOSED_SEAT)
48
- continue;
49
- if (holder !== null && holder !== AI_SEAT)
50
- evicted.push(holder);
51
- result[seat] = CLOSED_SEAT;
52
- open--;
53
- }
54
- return { seats: result, evicted };
55
- }
56
- /**
57
- * The AI takes `seat`, evicting its human occupant first (returned, for the caller to tell they
58
- * are now watching). Addressed by SEAT, not by the human's id (`@wolffm/rooms-protocol`'s
59
- * `replaceWithBot` takes the participant) — cardtable's leader picks a seat, empty or occupied,
60
- * the same way `aiSeat` always has, and an empty seat has no occupant id to address by.
61
- */
62
- export function replaceWithBot(seats, seat) {
63
- const holder = seats[seat] ?? null;
64
- if (holder === AI_SEAT)
65
- return { seats, evicted: null };
66
- const evicted = holder !== null && holder !== CLOSED_SEAT ? holder : null;
67
- return { seats: seats.map((s, i) => (i === seat ? AI_SEAT : s)), evicted };
68
- }