@hadoku/game-server 0.1.151 → 0.1.152

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.
@@ -11,8 +11,8 @@
11
11
  * them only when the shared secret checks out; otherwise we overwrite them with
12
12
  * the most restrictive identity.
13
13
  */
14
- import { TIER_ORDER, type Tier, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin } from '@wolffm/service-kernel/auth';
15
- export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin };
14
+ import { TIER_ORDER, type Tier, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator } from '@wolffm/service-kernel/auth';
15
+ export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
16
16
  export type { Tier };
17
17
  /**
18
18
  * The floor must be a tier this build knows, and never `public` here —
package/dist/edge-auth.js CHANGED
@@ -11,9 +11,9 @@
11
11
  * them only when the shared secret checks out; otherwise we overwrite them with
12
12
  * the most restrictive identity.
13
13
  */
14
- import { TIER_ORDER, assertFloor as kernelAssertFloor, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, } from '@wolffm/service-kernel/auth';
14
+ import { TIER_ORDER, assertFloor as kernelAssertFloor, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator, } from '@wolffm/service-kernel/auth';
15
15
  import { ENV_PREFIX, edgeAuth, gate } from './kernel.js';
16
- export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin };
16
+ export { TIER_ORDER, rankOf, tierOf, edgeTierOf, callerIdOf, userIdOf, userKeyOf, accountIdOf, userNameOf, isAdmin, isOperator };
17
17
  /**
18
18
  * The floor must be a tier this build knows, and never `public` here —
19
19
  * cardtable admits members and friends, never the public tier. An unknown
@@ -97,14 +97,14 @@ export interface LobbyCore<V extends RoomViewCore, C> {
97
97
  * union: this file never names the real ones (`RemoveFromSeatResult` et al.), only maps whatever
98
98
  * comes back to a status code below.
99
99
  */
100
- removeFromSeat(roomId: string, callerId: string, targetId: string): {
100
+ removeFromSeat(roomId: string, callerId: string, targetId: string, override?: boolean): {
101
101
  ok: true;
102
102
  room: V;
103
103
  } | {
104
104
  ok: false;
105
105
  reason: string;
106
106
  };
107
- lowerSeatCapacity(roomId: string, callerId: string, count: number): {
107
+ lowerSeatCapacity(roomId: string, callerId: string, count: number, override?: boolean): {
108
108
  ok: true;
109
109
  room: V;
110
110
  evicted: readonly string[];
@@ -112,7 +112,7 @@ export interface LobbyCore<V extends RoomViewCore, C> {
112
112
  ok: false;
113
113
  reason: string;
114
114
  };
115
- botReplacesHuman(roomId: string, callerId: string, seat: number): {
115
+ botReplacesHuman(roomId: string, callerId: string, seat: number, override?: boolean): {
116
116
  ok: true;
117
117
  room: V;
118
118
  evicted: string | null;
@@ -121,7 +121,7 @@ export interface LobbyCore<V extends RoomViewCore, C> {
121
121
  reason: string;
122
122
  };
123
123
  /** The leader hands the room's leadership to another member (`room/lobby.ts`'s `passLeader`). */
124
- passLeader(roomId: string, callerId: string, targetId: string): {
124
+ passLeader(roomId: string, callerId: string, targetId: string, override?: boolean): {
125
125
  ok: true;
126
126
  room: V;
127
127
  } | {
@@ -198,14 +198,14 @@ export interface SeatRouteLobby<V> {
198
198
  ok: false;
199
199
  reason: string;
200
200
  };
201
- closeSeat(roomId: string, callerId: string, seat: number, closed: boolean): {
201
+ closeSeat(roomId: string, callerId: string, seat: number, closed: boolean, override?: boolean): {
202
202
  ok: true;
203
203
  room: V;
204
204
  } | {
205
205
  ok: false;
206
206
  reason: string;
207
207
  };
208
- aiSeat(roomId: string, callerId: string, seat: number, on: boolean): {
208
+ aiSeat(roomId: string, callerId: string, seat: number, on: boolean, override?: boolean): {
209
209
  ok: true;
210
210
  room: V;
211
211
  } | {
@@ -220,6 +220,12 @@ export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = n
220
220
  * leader's; `/seats/bot` puts one in). Absent: none of the four is registered.
221
221
  */
222
222
  seatRoutes?: SeatRouteLobby<V>;
223
+ /**
224
+ * Whether this caller has the leader's reach in every room (the game's operators: cardtable's are
225
+ * the edge's wife and admin, `isOperator`): the leader's seat ops are theirs too, member or not.
226
+ * Absent: only the leader.
227
+ */
228
+ operator?: (req: Request) => boolean;
223
229
  lobby: LobbyCore<V, C>;
224
230
  wire: RoomCoreWire<C, P>;
225
231
  /** Structured log lines. Never carries a password, hash or salt. */
@@ -364,7 +364,7 @@ export function attachRoomCore(api, deps, opts = {}) {
364
364
  const id = String(req.params.id);
365
365
  if (!wire.roomIdRe.test(id))
366
366
  return noMatch(res);
367
- const result = lobby.removeFromSeat(id, caller.id, body.memberId);
367
+ const result = lobby.removeFromSeat(id, caller.id, body.memberId, deps.operator?.(req) === true);
368
368
  if (!result.ok)
369
369
  return seatOpStatus(res, result.reason);
370
370
  res.json(roomBody(result.room, caller.id));
@@ -378,7 +378,7 @@ export function attachRoomCore(api, deps, opts = {}) {
378
378
  const id = String(req.params.id);
379
379
  if (!wire.roomIdRe.test(id))
380
380
  return noMatch(res);
381
- const result = lobby.lowerSeatCapacity(id, caller.id, body.count);
381
+ const result = lobby.lowerSeatCapacity(id, caller.id, body.count, deps.operator?.(req) === true);
382
382
  if (!result.ok)
383
383
  return seatOpStatus(res, result.reason);
384
384
  res.json({ ...roomBody(result.room, caller.id), evicted: result.evicted });
@@ -392,7 +392,7 @@ export function attachRoomCore(api, deps, opts = {}) {
392
392
  const id = String(req.params.id);
393
393
  if (!wire.roomIdRe.test(id))
394
394
  return noMatch(res);
395
- const result = lobby.botReplacesHuman(id, caller.id, body.seat);
395
+ const result = lobby.botReplacesHuman(id, caller.id, body.seat, deps.operator?.(req) === true);
396
396
  if (!result.ok)
397
397
  return seatOpStatus(res, result.reason);
398
398
  res.json({ ...roomBody(result.room, caller.id), evicted: result.evicted });
@@ -410,7 +410,7 @@ export function attachRoomCore(api, deps, opts = {}) {
410
410
  const id = String(req.params.id);
411
411
  if (!wire.roomIdRe.test(id))
412
412
  return noMatch(res);
413
- const result = run(id, caller.id, body);
413
+ const result = run(id, caller.id, body, leaders && deps.operator?.(req) === true);
414
414
  if (!result.ok)
415
415
  return seatOpStatus(res, result.reason);
416
416
  res.json(roomBody(result.room, caller.id));
@@ -418,8 +418,8 @@ export function attachRoomCore(api, deps, opts = {}) {
418
418
  };
419
419
  seatRoute('sit', sitSeatBody, false, (id, callerId, body) => seats.sitSeat(id, callerId, body.seat));
420
420
  seatRoute('stand', emptyBody, false, (id, callerId) => seats.standSeat(id, callerId));
421
- seatRoute('close', closeSeatBody, true, (id, callerId, body) => seats.closeSeat(id, callerId, body.seat, body.closed));
422
- seatRoute('bot-off', botReplacesHumanBody, true, (id, callerId, body) => seats.aiSeat(id, callerId, body.seat, false));
421
+ seatRoute('close', closeSeatBody, true, (id, callerId, body, override) => seats.closeSeat(id, callerId, body.seat, body.closed, override));
422
+ seatRoute('bot-off', botReplacesHumanBody, true, (id, callerId, body, override) => seats.aiSeat(id, callerId, body.seat, false, override));
423
423
  }
424
424
  // The leader hands the room to another member, seated or watching. Spends the seat-op limit.
425
425
  rooms.post('/:id/leader', (req, res) => {
@@ -430,7 +430,7 @@ export function attachRoomCore(api, deps, opts = {}) {
430
430
  const id = String(req.params.id);
431
431
  if (!wire.roomIdRe.test(id))
432
432
  return noMatch(res);
433
- const result = lobby.passLeader(id, caller.id, body.memberId);
433
+ const result = lobby.passLeader(id, caller.id, body.memberId, deps.operator?.(req) === true);
434
434
  if (!result.ok)
435
435
  return seatOpStatus(res, result.reason);
436
436
  res.json(roomBody(result.room, caller.id));
@@ -173,7 +173,13 @@ export interface MatchRecordingWriter {
173
173
  * Never throws; a failed write is one `log` line, not a rejection. Resolves
174
174
  * once both attempts (success or failure) are done.
175
175
  */
176
- finish(actionsEnd: Omit<ActionsEndLine, 't'>, publicEnd: Omit<PublicEndLine, 't'>): Promise<void>;
176
+ /**
177
+ * `aside`: this is an earlier epoch whose match already plays on under a new one (`MatchRegistry.restore`),
178
+ * so it is written straight to the first free `<matchId>-e<N>`, never over the match's own name.
179
+ */
180
+ finish(actionsEnd: Omit<ActionsEndLine, 't'>, publicEnd: Omit<PublicEndLine, 't'>, opts?: {
181
+ aside?: boolean;
182
+ }): Promise<void>;
177
183
  }
178
184
  export interface MatchRecordingWriterDeps {
179
185
  dir: string;
@@ -182,4 +188,7 @@ export interface MatchRecordingWriterDeps {
182
188
  publicHeader: Omit<PublicHeader, 't' | 'v'>;
183
189
  log?: JsonLog;
184
190
  }
191
+ export declare function keepEarlierEpoch(dir: string, matchId: string, log: JsonLog): void;
192
+ /** The recordings a match's earlier epochs left (`keepEarlierEpoch`), oldest first, by the id each is served under. */
193
+ export declare function earlierEpochs(dir: string, matchId: string): string[];
185
194
  export declare function createMatchRecordingWriter(deps: MatchRecordingWriterDeps): MatchRecordingWriter;
@@ -17,7 +17,7 @@
17
17
  * Nothing here may fail a match. Every public method swallows its own errors
18
18
  * into `log`; `finish` resolves even when the disk write failed.
19
19
  */
20
- import { mkdirSync } from 'node:fs';
20
+ import { existsSync, mkdirSync, readdirSync, renameSync } from 'node:fs';
21
21
  import { rename, writeFile } from 'node:fs/promises';
22
22
  import { randomUUID } from 'node:crypto';
23
23
  import { join } from 'node:path';
@@ -49,6 +49,57 @@ async function flush(path, lines, log, which) {
49
49
  log({ evt: 'recording-write-failed', which, path, error: err.message });
50
50
  }
51
51
  }
52
+ /**
53
+ * A match restored on a new JVM (`MatchRegistry.restore`: a lost JVM, an agreed restart, an operator's
54
+ * restore) keeps its id, so each of its epochs finishes onto the same two files. The one already there
55
+ * is an earlier epoch: it moves aside to the first free `<matchId>-e<N>` before the new one is written,
56
+ * the latest staying under the match's own id. A recording like any other under that name — retention
57
+ * ages it, an erase rewrites it, and `/replays/<matchId>-e<N>` serves it — so the game as it was before
58
+ * the restore survives for a dispute.
59
+ */
60
+ const epochPaths = (dir, id) => [join(dir, `${id}${ACTIONS_SUFFIX}`), join(dir, `${id}${PUBLIC_SUFFIX}`)];
61
+ /** The first `<matchId>-e<N>` no recording holds yet. */
62
+ function freeEpoch(dir, matchId) {
63
+ let n = 1;
64
+ while (epochPaths(dir, `${matchId}-e${String(n)}`).some((p) => existsSync(p)))
65
+ n += 1;
66
+ return n;
67
+ }
68
+ export function keepEarlierEpoch(dir, matchId, log) {
69
+ const current = epochPaths(dir, matchId);
70
+ if (!current.some((p) => existsSync(p)))
71
+ return;
72
+ const n = freeEpoch(dir, matchId);
73
+ const aside = epochPaths(dir, `${matchId}-e${String(n)}`);
74
+ try {
75
+ current.forEach((p, i) => {
76
+ if (existsSync(p))
77
+ renameSync(p, aside[i]);
78
+ });
79
+ log({ evt: 'recording-epoch-kept', matchId, epoch: n });
80
+ }
81
+ catch (err) {
82
+ log({ evt: 'recording-epoch-keep-failed', matchId, epoch: n, error: err.message });
83
+ }
84
+ }
85
+ /** The recordings a match's earlier epochs left (`keepEarlierEpoch`), oldest first, by the id each is served under. */
86
+ export function earlierEpochs(dir, matchId) {
87
+ let names;
88
+ try {
89
+ names = readdirSync(dir);
90
+ }
91
+ catch {
92
+ return [];
93
+ }
94
+ const epoch = new RegExp(`^${matchId.replace(/[^A-Za-z0-9_-]/g, '')}-e(\\d+)${PUBLIC_SUFFIX.replace(/\./g, '\\.')}$`);
95
+ return names
96
+ .flatMap((n) => {
97
+ const m = epoch.exec(n);
98
+ return m === null ? [] : [Number(m[1])];
99
+ })
100
+ .sort((a, b) => a - b)
101
+ .map((n) => `${matchId}-e${String(n)}`);
102
+ }
52
103
  export function createMatchRecordingWriter(deps) {
53
104
  const log = deps.log ?? (() => undefined);
54
105
  try {
@@ -78,12 +129,19 @@ export function createMatchRecordingWriter(deps) {
78
129
  actionsHeader.roomId = roomId;
79
130
  publicHeader.roomId = roomId;
80
131
  },
81
- async finish(actionsEnd, publicEnd) {
132
+ async finish(actionsEnd, publicEnd, opts = {}) {
82
133
  actionLines.push({ t: 'end', ...actionsEnd });
83
134
  publicLines.push({ t: 'end', ...publicEnd });
135
+ let id = deps.matchId;
136
+ if (opts.aside === true) {
137
+ id = `${deps.matchId}-e${String(freeEpoch(deps.dir, deps.matchId))}`;
138
+ log({ evt: 'recording-epoch-kept', matchId: deps.matchId, epoch: id });
139
+ }
140
+ else
141
+ keepEarlierEpoch(deps.dir, deps.matchId, log);
84
142
  await Promise.all([
85
- flush(join(deps.dir, `${deps.matchId}${ACTIONS_SUFFIX}`), actionLines, log, 'actions'),
86
- flush(join(deps.dir, `${deps.matchId}${PUBLIC_SUFFIX}`), publicLines, log, 'public'),
143
+ flush(join(deps.dir, `${id}${ACTIONS_SUFFIX}`), actionLines, log, 'actions'),
144
+ flush(join(deps.dir, `${id}${PUBLIC_SUFFIX}`), publicLines, log, 'public'),
87
145
  ]);
88
146
  },
89
147
  };
@@ -535,15 +535,15 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
535
535
  sitSeat(roomId: string, memberId: string, seat?: number): SitSeatResult<V>;
536
536
  /** Give up a game seat. Idempotent: not seated is not a failure. */
537
537
  standSeat(roomId: string, memberId: string): StandSeatResult<V>;
538
- /** Put the AI in an open seat (`on`), or take it out. The leader's. */
539
- aiSeat(roomId: string, memberId: string, seat: number, on: boolean): AiSeatResult<V>;
540
- /** Close an empty seat, or open a closed one: the leader's; never fewer than `MIN_OPEN_SEATS` open. */
541
- closeSeat(roomId: string, memberId: string, seat: number, closed: boolean): CloseSeatResult<V>;
538
+ /** Put the AI in an open seat (`on`), or take it out. The leader's, or `override`'s (see `removeFromSeat`). */
539
+ aiSeat(roomId: string, memberId: string, seat: number, on: boolean, override?: boolean): AiSeatResult<V>;
540
+ /** Close an empty seat, or open a closed one: the leader's, or `override`'s (see `removeFromSeat`); never fewer than `MIN_OPEN_SEATS` open. */
541
+ closeSeat(roomId: string, memberId: string, seat: number, closed: boolean, override?: boolean): CloseSeatResult<V>;
542
542
  /**
543
543
  * The leader hands the room's leadership to `targetId`, another member, seated or watching.
544
544
  * Passing it to yourself is answered `ok` and changes nothing.
545
545
  */
546
- passLeader(roomId: string, memberId: string, targetId: string): PassLeaderResult<V>;
546
+ passLeader(roomId: string, memberId: string, targetId: string, override?: boolean): PassLeaderResult<V>;
547
547
  /**
548
548
  * The leader removes `targetId` from whatever game seat they hold, to the spectator row.
549
549
  * Idempotent: a target who holds none is still answered `ok`. Never touches membership — they
@@ -555,8 +555,10 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
555
555
  * The library's own `removeFromSeat(table, participantId)` is `unseatParticipant(table,
556
556
  * participantId, { hold: false })`, the same shape a plain null-out already was, so the target
557
557
  * array is mutated directly here rather than through `seat-table-adapter.ts`.
558
+ * `override`: the caller acts with an operator's reach (a wife or admin tier, checked by the route),
559
+ * needing to be neither the leader nor a member.
558
560
  */
559
- removeFromSeat(roomId: string, memberId: string, targetId: string): RemoveFromSeatResult<V>;
561
+ removeFromSeat(roomId: string, memberId: string, targetId: string, override?: boolean): RemoveFromSeatResult<V>;
560
562
  /**
561
563
  * The leader closes seats from the TOP down until `count` are open, evicting any occupant
562
564
  * first — a human to the spectator row, an AI simply removed — instead of `closeSeat`'s refusal
@@ -567,7 +569,7 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
567
569
  * (same as Magic's pod view carries AI through `podAi`, a field of its own, not this one's).
568
570
  * Resolved through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header.
569
571
  */
570
- lowerSeatCapacity(roomId: string, memberId: string, count: number): LowerSeatCapacityResult<V>;
572
+ lowerSeatCapacity(roomId: string, memberId: string, count: number, override?: boolean): LowerSeatCapacityResult<V>;
571
573
  /**
572
574
  * The leader puts the AI in `seat`, evicting whoever holds it first — a human to the spectator
573
575
  * row — instead of `aiSeat`'s refusal on an occupied seat. Already the AI's: a no-op. Resolved
@@ -576,8 +578,10 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
576
578
  * refused `'no-bot-seat'`, a truthful, specific reason — never the plain `not-draft`, which
577
579
  * would wrongly say this room does not seat through game seats at all (it does, for the other
578
580
  * two ops), and never an invented AI seat the table has nowhere to show.
581
+ * `override`: the caller acts with an operator's reach (a wife or admin tier, checked by the route),
582
+ * needing to be neither the leader nor a member.
579
583
  */
580
- botReplacesHuman(roomId: string, memberId: string, seat: number): BotReplacesHumanResult<V>;
584
+ botReplacesHuman(roomId: string, memberId: string, seat: number, override?: boolean): BotReplacesHumanResult<V>;
581
585
  /**
582
586
  * Forget every room untouched for longer than `idleMs` (or its type's own idle window), on disk as
583
587
  * well as in memory. Never a room with a live game, never one its type spares. Returns the ids dropped.
@@ -674,11 +674,11 @@ export class RoomLobby {
674
674
  };
675
675
  }
676
676
  /** The room by id when it seats through its game seats, with the refusal every seat op shares otherwise. */
677
- #seatRoom(roomId, memberId) {
677
+ #seatRoom(roomId, memberId, override = false) {
678
678
  const room = this.#rooms.get(roomId);
679
679
  if (room === undefined)
680
680
  return { refused: 'no-room' };
681
- if (!isRoomMember(room, memberId))
681
+ if (!override && !isRoomMember(room, memberId))
682
682
  return { refused: 'not-member' };
683
683
  const hooks = this.hooksOf(room);
684
684
  // `not-draft`, the wire's name for a room that does not seat through its game seats.
@@ -701,11 +701,11 @@ export class RoomLobby {
701
701
  * this way). `room.seats` always `supportsBot` (its `AI_SEAT` marker); a type's own stand-in
702
702
  * says for itself.
703
703
  */
704
- #seatOpRoom(roomId, memberId) {
704
+ #seatOpRoom(roomId, memberId, override = false) {
705
705
  const room = this.#rooms.get(roomId);
706
706
  if (room === undefined)
707
707
  return { refused: 'no-room' };
708
- if (!isRoomMember(room, memberId))
708
+ if (!override && !isRoomMember(room, memberId))
709
709
  return { refused: 'not-member' };
710
710
  const hooks = this.hooksOf(room);
711
711
  if (hooks.usesSeats(room)) {
@@ -776,13 +776,13 @@ export class RoomLobby {
776
776
  hooks.seatsChanged?.(room);
777
777
  return { ok: true, room: this.view(room) };
778
778
  }
779
- /** Put the AI in an open seat (`on`), or take it out. The leader's. */
780
- aiSeat(roomId, memberId, seat, on) {
781
- const found = this.#seatRoom(roomId, memberId);
779
+ /** Put the AI in an open seat (`on`), or take it out. The leader's, or `override`'s (see `removeFromSeat`). */
780
+ aiSeat(roomId, memberId, seat, on, override = false) {
781
+ const found = this.#seatRoom(roomId, memberId, override);
782
782
  if ('refused' in found)
783
783
  return { ok: false, reason: found.refused };
784
784
  const { room, hooks } = found;
785
- if (room.leader !== memberId)
785
+ if (!override && room.leader !== memberId)
786
786
  return { ok: false, reason: 'not-leader' };
787
787
  if (hooks.fieldFixed?.(room) === true)
788
788
  return { ok: false, reason: 'historical' };
@@ -804,16 +804,16 @@ export class RoomLobby {
804
804
  hooks.seatsChanged?.(room);
805
805
  return { ok: true, room: this.view(room) };
806
806
  }
807
- /** Close an empty seat, or open a closed one: the leader's; never fewer than `MIN_OPEN_SEATS` open. */
808
- closeSeat(roomId, memberId, seat, closed) {
807
+ /** Close an empty seat, or open a closed one: the leader's, or `override`'s (see `removeFromSeat`); never fewer than `MIN_OPEN_SEATS` open. */
808
+ closeSeat(roomId, memberId, seat, closed, override = false) {
809
809
  const room = this.#rooms.get(roomId);
810
810
  if (room === undefined)
811
811
  return { ok: false, reason: 'no-room' };
812
- if (!isRoomMember(room, memberId))
812
+ if (!override && !isRoomMember(room, memberId))
813
813
  return { ok: false, reason: 'not-member' };
814
- if (room.leader !== memberId)
814
+ if (!override && room.leader !== memberId)
815
815
  return { ok: false, reason: 'not-leader' };
816
- const found = this.#seatRoom(roomId, memberId);
816
+ const found = this.#seatRoom(roomId, memberId, override);
817
817
  if ('refused' in found)
818
818
  return { ok: false, reason: found.refused };
819
819
  const { hooks } = found;
@@ -839,13 +839,13 @@ export class RoomLobby {
839
839
  * The leader hands the room's leadership to `targetId`, another member, seated or watching.
840
840
  * Passing it to yourself is answered `ok` and changes nothing.
841
841
  */
842
- passLeader(roomId, memberId, targetId) {
842
+ passLeader(roomId, memberId, targetId, override = false) {
843
843
  const room = this.#rooms.get(roomId);
844
844
  if (room === undefined)
845
845
  return { ok: false, reason: 'no-room' };
846
- if (!isRoomMember(room, memberId))
846
+ if (!override && !isRoomMember(room, memberId))
847
847
  return { ok: false, reason: 'not-member' };
848
- if (room.leader !== memberId)
848
+ if (!override && room.leader !== memberId)
849
849
  return { ok: false, reason: 'not-leader' };
850
850
  if (targetId === memberId)
851
851
  return { ok: true, room: this.view(room) };
@@ -866,18 +866,20 @@ export class RoomLobby {
866
866
  * The library's own `removeFromSeat(table, participantId)` is `unseatParticipant(table,
867
867
  * participantId, { hold: false })`, the same shape a plain null-out already was, so the target
868
868
  * array is mutated directly here rather than through `seat-table-adapter.ts`.
869
+ * `override`: the caller acts with an operator's reach (a wife or admin tier, checked by the route),
870
+ * needing to be neither the leader nor a member.
869
871
  */
870
- removeFromSeat(roomId, memberId, targetId) {
872
+ removeFromSeat(roomId, memberId, targetId, override = false) {
871
873
  const room = this.#rooms.get(roomId);
872
874
  if (room === undefined)
873
875
  return { ok: false, reason: 'no-room' };
874
- if (!isRoomMember(room, memberId))
876
+ if (!override && !isRoomMember(room, memberId))
875
877
  return { ok: false, reason: 'not-member' };
876
- if (room.leader !== memberId)
878
+ if (!override && room.leader !== memberId)
877
879
  return { ok: false, reason: 'not-leader' };
878
880
  if (!isRoomMember(room, targetId))
879
881
  return { ok: false, reason: 'target-not-member' };
880
- const found = this.#seatOpRoom(roomId, memberId);
882
+ const found = this.#seatOpRoom(roomId, memberId, override);
881
883
  if ('refused' in found)
882
884
  return { ok: false, reason: found.refused };
883
885
  const { room: r, hooks, target, generic } = found;
@@ -903,15 +905,15 @@ export class RoomLobby {
903
905
  * (same as Magic's pod view carries AI through `podAi`, a field of its own, not this one's).
904
906
  * Resolved through `#seatOpRoom` (wave 120 §S2): see `removeFromSeat`'s header.
905
907
  */
906
- lowerSeatCapacity(roomId, memberId, count) {
908
+ lowerSeatCapacity(roomId, memberId, count, override = false) {
907
909
  const room = this.#rooms.get(roomId);
908
910
  if (room === undefined)
909
911
  return { ok: false, reason: 'no-room' };
910
- if (!isRoomMember(room, memberId))
912
+ if (!override && !isRoomMember(room, memberId))
911
913
  return { ok: false, reason: 'not-member' };
912
- if (room.leader !== memberId)
914
+ if (!override && room.leader !== memberId)
913
915
  return { ok: false, reason: 'not-leader' };
914
- const found = this.#seatOpRoom(roomId, memberId);
916
+ const found = this.#seatOpRoom(roomId, memberId, override);
915
917
  if ('refused' in found)
916
918
  return { ok: false, reason: found.refused };
917
919
  const { room: r, hooks, target, generic } = found;
@@ -939,16 +941,18 @@ export class RoomLobby {
939
941
  * refused `'no-bot-seat'`, a truthful, specific reason — never the plain `not-draft`, which
940
942
  * would wrongly say this room does not seat through game seats at all (it does, for the other
941
943
  * two ops), and never an invented AI seat the table has nowhere to show.
944
+ * `override`: the caller acts with an operator's reach (a wife or admin tier, checked by the route),
945
+ * needing to be neither the leader nor a member.
942
946
  */
943
- botReplacesHuman(roomId, memberId, seat) {
947
+ botReplacesHuman(roomId, memberId, seat, override = false) {
944
948
  const room = this.#rooms.get(roomId);
945
949
  if (room === undefined)
946
950
  return { ok: false, reason: 'no-room' };
947
- if (!isRoomMember(room, memberId))
951
+ if (!override && !isRoomMember(room, memberId))
948
952
  return { ok: false, reason: 'not-member' };
949
- if (room.leader !== memberId)
953
+ if (!override && room.leader !== memberId)
950
954
  return { ok: false, reason: 'not-leader' };
951
- const found = this.#seatOpRoom(roomId, memberId);
955
+ const found = this.#seatOpRoom(roomId, memberId, override);
952
956
  if ('refused' in found)
953
957
  return { ok: false, reason: found.refused };
954
958
  const { room: r, hooks, target, generic } = found;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.151",
4
- "gitHead": "deeadc58080e22f1d16dbff80069bb9c844d6765",
3
+ "version": "0.1.152",
4
+ "gitHead": "6a384c4363e40e9f65aea9c1c5f2ecb719434aa1",
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.151",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.151",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.184",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.152",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.152",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.185",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.143",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.143",