@hadoku/game-server 0.1.174 → 0.1.175

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.
@@ -481,8 +481,9 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
481
481
  subPlaceOf(roomId: string, rest: string): boolean;
482
482
  gameSeatOf(roomId: string, memberId: string): number | null;
483
483
  /**
484
- * A member steps out. Removed from `members`; their state and Ready go with their row. If they
485
- * led the room, leadership passes to whichever remaining member joined EARLIEST (R16). What it
484
+ * A member steps out. Removed from `members`; their state and Ready go with their row. A leader
485
+ * who leaves still leads (`membership.ts`): only `passLeader` moves the lead, except in a testing
486
+ * room, which its seed leaves at once for whoever comes in (`removeRoomMember`'s `handOn`). What it
486
487
  * costs their game is the type's (`RoomTypeHooks.leaving`). A room left by its last member is not
487
488
  * deleted here (the idle sweep owns deletion) but leaves `offered()` the instant it empties.
488
489
  * `no-room` and `not-member` are both answered the same 404 by the HTTP layer.
@@ -601,14 +602,16 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
601
602
  flushed(): Promise<void>;
602
603
  /**
603
604
  * Account erase: every room that still names one of `ids` names `to` instead, and is saved. Answers
604
- * how many rooms changed. The person leaves first (`leave`), so leadership has passed on.
605
+ * how many rooms changed. The person leaves first (`leave`), which keeps their lead, so a room they
606
+ * led is led by `to` afterwards: nobody, until an operator takes it (`passLeader`'s `override`).
605
607
  */
606
608
  anonymise(ids: ReadonlySet<string>, to: string): number;
607
609
  /**
608
610
  * Account merge: every room that names the merged-away account names the kept one instead, by
609
611
  * `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
610
- * erase sweep that follows (`erase/rooms.ts` has the person leave it first). Each room changed is
611
- * saved. Answers how many changed.
612
+ * erase sweep that follows (`erase/rooms.ts` has the person leave it first). A leave keeps the
613
+ * lead, so a conflict room the merged-away account led is handed to the kept account here, the
614
+ * same person, when it is a member. Each room changed is saved. Answers how many changed.
612
615
  */
613
616
  merge(move: IdMove): number;
614
617
  /** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
@@ -431,8 +431,9 @@ export class RoomLobby {
431
431
  return seat === -1 ? null : seat;
432
432
  }
433
433
  /**
434
- * A member steps out. Removed from `members`; their state and Ready go with their row. If they
435
- * led the room, leadership passes to whichever remaining member joined EARLIEST (R16). What it
434
+ * A member steps out. Removed from `members`; their state and Ready go with their row. A leader
435
+ * who leaves still leads (`membership.ts`): only `passLeader` moves the lead, except in a testing
436
+ * room, which its seed leaves at once for whoever comes in (`removeRoomMember`'s `handOn`). What it
436
437
  * costs their game is the type's (`RoomTypeHooks.leaving`). A room left by its last member is not
437
438
  * deleted here (the idle sweep owns deletion) but leaves `offered()` the instant it empties.
438
439
  * `no-room` and `not-member` are both answered the same 404 by the HTTP layer.
@@ -444,10 +445,9 @@ export class RoomLobby {
444
445
  if (!isRoomMember(room, memberId))
445
446
  return { ok: false, reason: 'not-member' };
446
447
  const cost = this.hooksOf(room).leaving?.(room, memberId) ?? {};
447
- // R16: leadership (whoever remains joined earliest) passes on here if `memberId` held it.
448
- removeRoomMember(room, memberId);
448
+ removeRoomMember(room, memberId, room.testing);
449
449
  this.persist(room);
450
- this.log({ event: 'room-left', roomId, members: room.members.length, newLeader: room.leader });
450
+ this.log({ event: 'room-left', roomId, members: room.members.length, leader: room.leader });
451
451
  return { ok: true, room: this.view(room), ...cost };
452
452
  }
453
453
  /** The floor a room made from `input` would have: its own, or its game type's when that is stricter (`tier-floor.ts`). */
@@ -553,7 +553,6 @@ export class RoomLobby {
553
553
  return { ok: true, room: this.view(room), alreadyMember: false };
554
554
  }
555
555
  const now = this.now();
556
- // An empty ledger's first member becomes its leader (an emptied room's new arrival leads it).
557
556
  addRoomMember(room, { id: caller.id, userId: caller.userId, name: caller.name, joinedAt: now, state: undefined }, now);
558
557
  this.#autoSeat(room, caller.id);
559
558
  this.persist(room);
@@ -1011,7 +1010,8 @@ export class RoomLobby {
1011
1010
  }
1012
1011
  /**
1013
1012
  * Account erase: every room that still names one of `ids` names `to` instead, and is saved. Answers
1014
- * how many rooms changed. The person leaves first (`leave`), so leadership has passed on.
1013
+ * how many rooms changed. The person leaves first (`leave`), which keeps their lead, so a room they
1014
+ * led is led by `to` afterwards: nobody, until an operator takes it (`passLeader`'s `override`).
1015
1015
  */
1016
1016
  anonymise(ids, to) {
1017
1017
  let changed = 0;
@@ -1027,19 +1027,25 @@ export class RoomLobby {
1027
1027
  /**
1028
1028
  * Account merge: every room that names the merged-away account names the kept one instead, by
1029
1029
  * `moveIds` — so a room that already names the kept account is a conflict it wins, left for the
1030
- * erase sweep that follows (`erase/rooms.ts` has the person leave it first). Each room changed is
1031
- * saved. Answers how many changed.
1030
+ * erase sweep that follows (`erase/rooms.ts` has the person leave it first). A leave keeps the
1031
+ * lead, so a conflict room the merged-away account led is handed to the kept account here, the
1032
+ * same person, when it is a member. Each room changed is saved. Answers how many changed.
1032
1033
  */
1033
1034
  merge(move) {
1034
1035
  let changed = 0;
1035
1036
  for (const room of this.#rooms.values()) {
1036
- if (moveIds(room, move) === 0)
1037
+ if (moveIds(room, move) === 0 && !this.#leadToKept(room, move))
1037
1038
  continue;
1038
1039
  changed++;
1039
1040
  this.persist(room);
1040
1041
  }
1041
1042
  return changed;
1042
1043
  }
1044
+ /** A conflict room's lead, held by the merged-away account, to the kept account's member. False when it is not that. */
1045
+ #leadToKept(room, move) {
1046
+ const kept = move.renames.get(room.leader);
1047
+ return kept !== undefined && passRoomLeader(room, kept);
1048
+ }
1043
1049
  /** Does the room's record name any of `ids` anywhere (a member, a seat, a result)? False for no such room. */
1044
1050
  names(roomId, ids) {
1045
1051
  const room = this.#rooms.get(roomId);
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * Split out of `room/lobby.ts`'s `join`/`leave`/`setReady`/`viewOf`/`#persist`.
10
10
  * These wrap `@wolffm/rooms-server`'s `MembershipLedger` functions, which
11
- * already did the real work (leadership succession, readiness) — what moved
12
- * here is the GLUE: adding a member also means maybe inheriting the room's
13
- * leadership (an emptied room's new arrival leads it); removing one also
14
- * means maybe passing it on (whoever remains joined EARLIEST, R16).
11
+ * do the bookkeeping (who is in, readiness). The lead is permanent (the
12
+ * operator, 2026-11-29): whoever leads a room keeps it until they pass it
13
+ * (`passRoomLeader`). Leaving never hands it on, not even out of an emptied
14
+ * room, so the ledger's own succession on a leave is undone here.
15
15
  *
16
16
  * Every mutator mutates in place and returns nothing but what the caller
17
17
  * cannot otherwise observe — the same discipline `lobby.ts`'s own mutators
@@ -34,23 +34,26 @@ export interface MembershipRoom<M extends MemberRow> {
34
34
  /** Whether `id` already holds a seat at the table, so to speak — already a member of the room. */
35
35
  export declare function isRoomMember<M extends MemberRow>(room: Pick<MembershipRoom<M>, 'members'>, id: string): boolean;
36
36
  /**
37
- * Add `member`, and give them the room's leadership exactly when the ledger
38
- * says the room was empty before they joined (`ledger.leaderId`'s own rule —
39
- * an emptied room's new arrival leads it). Mutates `room.members`,
37
+ * Add `member`. They lead only a room whose ledger names no leader (one being
38
+ * made, or a `handOn` room emptied); a leader who left keeps the lead, so an
39
+ * arrival in their absence is a member like any other. Mutates `room.members`,
40
40
  * `room.leader` and `room.ledger`. The caller still owns auto-seating them
41
41
  * and persisting the room.
42
42
  */
43
43
  export declare function addRoomMember<M extends MemberRow>(room: MembershipRoom<M>, member: M, joinedAt: number): void;
44
44
  /**
45
45
  * Remove the member `id` — answers the removed row, or `undefined` when they
46
- * were never a member. If they held the room's leadership, it passes to
47
- * whoever remains joined EARLIEST (`memberLeft`'s own rule, R16); the last
48
- * member out leaves `room.leader` stale, for the caller's sweep to read.
49
- * Mutates `room.members`, `room.leader` and `room.ledger`. The caller still
50
- * owns anything about the leaving member's GAME state (a pod drop, a table
51
- * seat, a series) and persisting the room.
46
+ * were never a member. The room's lead does not move, even when `id` held it
47
+ * or was the last one out: a leader away from the room is still its leader,
48
+ * and leads again the moment they are back. Mutates `room.members` and
49
+ * `room.ledger`. The caller still owns anything about the leaving member's
50
+ * GAME state (a pod drop, a table seat, a series) and persisting the room.
51
+ *
52
+ * `handOn` is for a room no person owns (a seeded testing room, made by a seed
53
+ * that leaves at once): its lead passes to whoever remains joined EARLIEST, and
54
+ * an emptied one's first arrival leads it.
52
55
  */
53
- export declare function removeRoomMember<M extends MemberRow>(room: MembershipRoom<M>, id: string): M | undefined;
56
+ export declare function removeRoomMember<M extends MemberRow>(room: MembershipRoom<M>, id: string, handOn?: boolean): M | undefined;
54
57
  /**
55
58
  * Hand the room's leadership to the member `to`. Answers false, changing nothing, when `to` is not a
56
59
  * member. The caller has checked the hand-off is the current leader's to make, and persists the room.
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * Split out of `room/lobby.ts`'s `join`/`leave`/`setReady`/`viewOf`/`#persist`.
10
10
  * These wrap `@wolffm/rooms-server`'s `MembershipLedger` functions, which
11
- * already did the real work (leadership succession, readiness) — what moved
12
- * here is the GLUE: adding a member also means maybe inheriting the room's
13
- * leadership (an emptied room's new arrival leads it); removing one also
14
- * means maybe passing it on (whoever remains joined EARLIEST, R16).
11
+ * do the bookkeeping (who is in, readiness). The lead is permanent (the
12
+ * operator, 2026-11-29): whoever leads a room keeps it until they pass it
13
+ * (`passRoomLeader`). Leaving never hands it on, not even out of an emptied
14
+ * room, so the ledger's own succession on a leave is undone here.
15
15
  *
16
16
  * Every mutator mutates in place and returns nothing but what the caller
17
17
  * cannot otherwise observe — the same discipline `lobby.ts`'s own mutators
@@ -26,9 +26,9 @@ export function isRoomMember(room, id) {
26
26
  return room.members.some((m) => m.id === id);
27
27
  }
28
28
  /**
29
- * Add `member`, and give them the room's leadership exactly when the ledger
30
- * says the room was empty before they joined (`ledger.leaderId`'s own rule —
31
- * an emptied room's new arrival leads it). Mutates `room.members`,
29
+ * Add `member`. They lead only a room whose ledger names no leader (one being
30
+ * made, or a `handOn` room emptied); a leader who left keeps the lead, so an
31
+ * arrival in their absence is a member like any other. Mutates `room.members`,
32
32
  * `room.leader` and `room.ledger`. The caller still owns auto-seating them
33
33
  * and persisting the room.
34
34
  */
@@ -39,22 +39,27 @@ export function addRoomMember(room, member, joinedAt) {
39
39
  }
40
40
  /**
41
41
  * Remove the member `id` — answers the removed row, or `undefined` when they
42
- * were never a member. If they held the room's leadership, it passes to
43
- * whoever remains joined EARLIEST (`memberLeft`'s own rule, R16); the last
44
- * member out leaves `room.leader` stale, for the caller's sweep to read.
45
- * Mutates `room.members`, `room.leader` and `room.ledger`. The caller still
46
- * owns anything about the leaving member's GAME state (a pod drop, a table
47
- * seat, a series) and persisting the room.
42
+ * were never a member. The room's lead does not move, even when `id` held it
43
+ * or was the last one out: a leader away from the room is still its leader,
44
+ * and leads again the moment they are back. Mutates `room.members` and
45
+ * `room.ledger`. The caller still owns anything about the leaving member's
46
+ * GAME state (a pod drop, a table seat, a series) and persisting the room.
47
+ *
48
+ * `handOn` is for a room no person owns (a seeded testing room, made by a seed
49
+ * that leaves at once): its lead passes to whoever remains joined EARLIEST, and
50
+ * an emptied one's first arrival leads it.
48
51
  */
49
- export function removeRoomMember(room, id) {
52
+ export function removeRoomMember(room, id, handOn = false) {
50
53
  const index = room.members.findIndex((m) => m.id === id);
51
54
  if (index === -1)
52
55
  return undefined;
53
56
  const removed = room.members[index];
54
57
  room.members.splice(index, 1);
55
- const newLeader = memberLeft(room.ledger, id);
56
- if (newLeader !== null)
57
- room.leader = newLeader;
58
+ const next = memberLeft(room.ledger, id);
59
+ if (!handOn)
60
+ room.ledger.leaderId = room.leader;
61
+ else if (next !== null)
62
+ room.leader = next;
58
63
  return removed;
59
64
  }
60
65
  /**
@@ -27,8 +27,12 @@ export interface PlatformMember extends MemberRow {
27
27
  export interface PlatformRoomRecord<G, M extends PlatformMember = PlatformMember> {
28
28
  id: string;
29
29
  name: string;
30
+ /**
31
+ * Whoever made the room, never changed after. Not who leads it: an event a service caller made
32
+ * can name that service's account here, and the lead moves by `passLeader` without it. Read `leader`.
33
+ */
30
34
  creator: string;
31
- /** Mirrors `ledger.leaderId`, kept non-null; it moves when the leader leaves or hands it on (`membership.ts`). */
35
+ /** Mirrors `ledger.leaderId`, kept non-null; it moves only when the leader hands it on (`membership.ts`), never on a leave. */
32
36
  leader: string;
33
37
  gameType: string;
34
38
  /** A seeded, admin-only room: never swept (`room-list.ts`). */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.174",
4
- "gitHead": "e4616550a8324c983a2556965e6c5d5280107e8d",
3
+ "version": "0.1.175",
4
+ "gitHead": "9b2dacac47c9445b2b3059b3a9272269a370607f",
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.174",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.174",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.207",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.175",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.175",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.208",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.145",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.145",