@hadoku/game-server 0.1.73 → 0.1.74

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.
@@ -201,6 +201,8 @@ export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = n
201
201
  closed?: (roomId: string, matches: readonly string[]) => void;
202
202
  /** A tournament entrant's drop (`Lobby.leave`): their match's games to end and its seats' decks to restore. */
203
203
  forfeited?: (roomId: string, tableId: string, loser: string, matches: readonly string[]) => void;
204
+ /** Whether a member has a screen open (`undefined`), or since when they have not (ms, or `null` when not seen since boot). Absent: no `away` is sent. */
205
+ away?: (memberId: string) => number | null | undefined;
204
206
  /** "Reset = Close": runs AFTER `closed`, same as `index.ts`'s own `seedTestingRooms` boot call. */
205
207
  reseedTesting?: () => void;
206
208
  arrived?: (roomId: string, caller: CallerLike) => void;
@@ -222,6 +224,8 @@ export type RoomBody<V extends RoomViewCore, G = never> = V & {
222
224
  ready: boolean;
223
225
  };
224
226
  tableGames?: Record<string, G>;
227
+ /** The members with no screen open now, each with when they were last seen (ISO), or `null` when this server has not seen them since it started. */
228
+ away?: Record<string, string | null>;
225
229
  };
226
230
  export declare function badRequest(res: Response, error: string): void;
227
231
  export declare function noMatch(res: Response): void;
@@ -95,6 +95,16 @@ export const ROOM_CREATE_RATE_LIMIT = {
95
95
  refillAmount: 1,
96
96
  refillIntervalMs: 60_000,
97
97
  };
98
+ /** The members `seen` says have no screen open, each with when they were last seen. */
99
+ function awayOf(members, seen) {
100
+ const away = {};
101
+ for (const m of members) {
102
+ const since = seen(m.id);
103
+ if (since !== undefined)
104
+ away[m.id] = since === null ? null : new Date(since).toISOString();
105
+ }
106
+ return away;
107
+ }
98
108
  export function badRequest(res, error) {
99
109
  res.status(400).json({ error });
100
110
  }
@@ -126,7 +136,8 @@ export function attachRoomCore(api, deps, opts = {}) {
126
136
  const roomBody = (room, callerId) => {
127
137
  const mine = room.members.find((m) => m.id === callerId);
128
138
  const games = deps.tableGames?.(room);
129
- return { ...room, you: { id: callerId, leader: room.leader === callerId, ready: mine?.ready === true }, ...(games === undefined ? {} : { tableGames: games }) };
139
+ const away = deps.away === undefined ? undefined : awayOf(room.members, deps.away);
140
+ return { ...room, you: { id: callerId, leader: room.leader === callerId, ready: mine?.ready === true }, ...(games === undefined ? {} : { tableGames: games }), ...(away === undefined ? {} : { away }) };
130
141
  };
131
142
  const rooms = Router();
132
143
  rooms.param('id', hideTestingRoomsParam(lobby));
@@ -40,6 +40,11 @@ import { type Secret } from './provisioning.js';
40
40
  import { type GameSeats, type PlatformMember, type PlatformRoomRecord } from './record.js';
41
41
  import { type RoomBusyHook } from './room-list.js';
42
42
  /** A member as the lobby keeps one: the platform's record plus what a view shows of them. */
43
+ /**
44
+ * A testing room's stand-in: a `dev:` identity no browser presents, which holds a seeded place until
45
+ * the first person to join takes it over whole (`RoomLobby.join`).
46
+ */
47
+ export declare const TESTING_STAND_IN_ID = "dev:testing-stand-in";
43
48
  export interface LobbyMember extends PlatformMember {
44
49
  /** In memory only, from the member's own requests (`rename`): a saved room keeps no names (R12). Restored `UNNAMED`. */
45
50
  name: string;
@@ -48,6 +48,12 @@ import { AI_SEAT, CLOSED_SEAT, leaveGameSeat, memberSeats, setGameSeat, takeGame
48
48
  import { isOfferedRoom, isSweepableRoom, NO_BUSY_HOOK, sortRoomsByCreation } from "./room-list.js";
49
49
  import { lowerCapacity, replaceWithBot } from "./seat-table-adapter.js";
50
50
  import { watchpartyRoomId } from "./watchparty-link.js";
51
+ /** A member as the lobby keeps one: the platform's record plus what a view shows of them. */
52
+ /**
53
+ * A testing room's stand-in: a `dev:` identity no browser presents, which holds a seeded place until
54
+ * the first person to join takes it over whole (`RoomLobby.join`).
55
+ */
56
+ export const TESTING_STAND_IN_ID = 'dev:testing-stand-in';
51
57
  /** The fewest seats a room is left with when its seats are closed: one player and one more. */
52
58
  export const MIN_OPEN_SEATS = 2;
53
59
  /** The room-level app blob's version. Additive fields never bump it: each reads with a default. */
@@ -484,6 +490,10 @@ export class RoomLobby {
484
490
  return { ok: true, room: this.view(room), alreadyMember: true };
485
491
  if (!passwordAdmits(this.#secrets.get(roomId), password))
486
492
  return { ok: false, reason: 'no-match' };
493
+ if (room.testing && isRoomMember(room, TESTING_STAND_IN_ID)) {
494
+ this.#handOver(room, caller);
495
+ return { ok: true, room: this.view(room), alreadyMember: false };
496
+ }
487
497
  const now = this.now();
488
498
  // An empty ledger's first member becomes its leader (an emptied room's new arrival leads it).
489
499
  addRoomMember(room, { id: caller.id, userId: caller.userId, name: caller.name, joinedAt: now, state: undefined }, now);
@@ -492,6 +502,24 @@ export class RoomLobby {
492
502
  this.log({ event: 'room-joined', roomId, members: room.members.length });
493
503
  return { ok: true, room: this.view(room), alreadyMember: false };
494
504
  }
505
+ /**
506
+ * A testing room's stand-in gives the first person in its whole place: its seat, its deck, its
507
+ * series and its lead, the way an account erase hands a person's place to a tombstone
508
+ * (`anonymise`). So a seeded situation (a series between games, say) is one an admin plays from,
509
+ * not only watches.
510
+ */
511
+ #handOver(room, caller) {
512
+ const ids = new Set([TESTING_STAND_IN_ID]);
513
+ this.hooksOf(room).anonymise?.(room, ids);
514
+ replaceIds(room, ids, caller.id);
515
+ const member = room.members.find((m) => m.id === caller.id);
516
+ if (member !== undefined) {
517
+ member.userId = caller.userId;
518
+ member.name = caller.name;
519
+ }
520
+ this.persist(room);
521
+ this.log({ event: 'room-handed-over', roomId: room.id });
522
+ }
495
523
  /**
496
524
  * Call `caller.id` by `caller.name` in every room they are a member of. The name was copied once, at
497
525
  * join, so a key renamed in the registry kept its first name in every room it had joined
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.73",
4
- "gitHead": "2ada02180afff2e2d5f9e4c28ee9b97be29d3c66",
3
+ "version": "0.1.74",
4
+ "gitHead": "89a57e628dc4c2f07c33ded4f65728dad1ae05c9",
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.73",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.73",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.106",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.74",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.74",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.107",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.30",
23
23
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.122",
24
24
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.122",