@hadoku/game-server 0.1.167 → 0.1.169

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.
@@ -852,7 +852,8 @@ export class RoomLobby {
852
852
  return { ok: false, reason: 'not-member' };
853
853
  if (!override && room.leader !== memberId)
854
854
  return { ok: false, reason: 'not-leader' };
855
- if (targetId === memberId)
855
+ // Already theirs: nothing to move. An operator naming themselves takes a lead that was someone else's.
856
+ if (targetId === room.leader)
856
857
  return { ok: true, room: this.view(room) };
857
858
  if (!passRoomLeader(room, targetId))
858
859
  return { ok: false, reason: 'target-not-member' };
@@ -58,6 +58,18 @@ import { type RoomChatMessage } from '@wolffm/rooms-server/chat';
58
58
  import { type ServedRoom } from '@wolffm/rooms-server/room';
59
59
  import type { Look } from '@wolffm/platform-wire/look';
60
60
  import { type People } from '../people.js';
61
+ /** A room's chat file is read back for this long after boot; older, it is deleted on sight. */
62
+ export declare const CHAT_RETENTION_MS: number;
63
+ /**
64
+ * The delay the store schedules a CLOSED room's chat wipe at (`roomLifeMs` below). The retention
65
+ * above is what `loadFromDisk` prunes by; this is a timer, and `@hadoku/rooms-server`'s
66
+ * `clearRoomChat` hands it straight to `setTimeout`, which keeps a delay in a 32-bit signed int and
67
+ * clamps anything longer TO 1 MS — so the full 90 days wiped a closed room's chat on the spot and
68
+ * warned `TimeoutOverflowWarning: 7776000000 …` once per room (four or five per boot in prod, and
69
+ * on PPE). Capped (`../timers.ts`), the wipe is late rather than immediate, and boot-time pruning
70
+ * still enforces the 90 days it was asked for.
71
+ */
72
+ export declare const CHAT_WIPE_DELAY_MS: number;
61
73
  /** The minimal room-view shape this file touches, whatever the game. The real `PlatformRoomView` (and Magic's `RoomView`) satisfy it. */
62
74
  export interface ServeRoomView {
63
75
  id: string;
@@ -56,6 +56,7 @@ import { participantHandle } from '@wolffm/rooms-protocol';
56
56
  import { createChatHistoryStore } from '@wolffm/rooms-server/chat';
57
57
  import { serveRoom } from '@wolffm/rooms-server/room';
58
58
  import { rankOf } from '../edge-auth.js';
59
+ import { timerDelay } from '../timers.js';
59
60
  import { applyPerson } from '../people.js';
60
61
  import { handshakeEdgeTier, handshakeTier } from './socket-auth.js';
61
62
  import { roomAdmits } from './tier-floor.js';
@@ -65,7 +66,17 @@ const MAX_MESSAGES_PER_ROOM = 500;
65
66
  const PAGE_LIMIT = 50;
66
67
  const PAGE_LIMIT_MAX = 100;
67
68
  /** A room's chat file is read back for this long after boot; older, it is deleted on sight. */
68
- const CHAT_RETENTION_MS = 90 * 24 * 60 * 60 * 1000;
69
+ export const CHAT_RETENTION_MS = 90 * 24 * 60 * 60 * 1000;
70
+ /**
71
+ * The delay the store schedules a CLOSED room's chat wipe at (`roomLifeMs` below). The retention
72
+ * above is what `loadFromDisk` prunes by; this is a timer, and `@hadoku/rooms-server`'s
73
+ * `clearRoomChat` hands it straight to `setTimeout`, which keeps a delay in a 32-bit signed int and
74
+ * clamps anything longer TO 1 MS — so the full 90 days wiped a closed room's chat on the spot and
75
+ * warned `TimeoutOverflowWarning: 7776000000 …` once per room (four or five per boot in prod, and
76
+ * on PPE). Capped (`../timers.ts`), the wipe is late rather than immediate, and boot-time pruning
77
+ * still enforces the 90 days it was asked for.
78
+ */
79
+ export const CHAT_WIPE_DELAY_MS = timerDelay(CHAT_RETENTION_MS);
69
80
  /**
70
81
  * `<appId>-<id>` → the place it names, or null when it is not one of ours or names nothing live.
71
82
  * A table's key is `<roomId>-<tableId>`, or `<roomId>-<matchId>` when the screen's copy of the
@@ -138,7 +149,7 @@ export async function attachServedRoom(io, deps) {
138
149
  maxMessages: MAX_MESSAGES_PER_ROOM,
139
150
  pageLimit: PAGE_LIMIT,
140
151
  pageLimitMax: PAGE_LIMIT_MAX,
141
- roomLifeMs: () => CHAT_RETENTION_MS,
152
+ roomLifeMs: () => CHAT_WIPE_DELAY_MS,
142
153
  safeRoomId: deps.roomIdRe,
143
154
  onEvent: deps.onEvent === undefined ? undefined : (level, event, roomId, fields) => deps.onEvent?.(level, event, { roomId, ...fields }),
144
155
  });
@@ -0,0 +1,4 @@
1
+ /** The longest delay `setTimeout` keeps as given: 2^31 - 1 ms, a shade under 24.9 days. */
2
+ export declare const MAX_TIMER_DELAY_MS = 2147483647;
3
+ /** `ms` as a delay a timer keeps: never negative, never absent, never past what a 32-bit int holds. */
4
+ export declare function timerDelay(ms: number): number;
package/dist/timers.js ADDED
@@ -0,0 +1,26 @@
1
+ /*
2
+ * A delay any `setTimeout` on this server can actually hold.
3
+ *
4
+ * Node keeps a timer's delay in a 32-bit signed integer. A longer one is not
5
+ * rounded down or refused: it is **clamped to 1 ms**, with a
6
+ * `TimeoutOverflowWarning` on stderr, so a timer meant for weeks away fires on
7
+ * the next tick — the opposite of what the caller asked for. Prod and PPE
8
+ * warned `TimeoutOverflowWarning: 7776000000 does not fit into a 32-bit signed
9
+ * integer. Timeout duration was set to 1.` four or five times per boot, which
10
+ * was a closed room's 90-day chat wipe happening immediately
11
+ * (`room/serve.ts`'s `CHAT_RETENTION_MS` reaching `@hadoku/rooms-server`'s own
12
+ * `setTimeout` through `roomLifeMs`).
13
+ *
14
+ * So every delay computed from a retention, a lifetime or a TTL — anything
15
+ * that can outgrow 24.8 days — goes through `timerDelay` on its way to a
16
+ * timer. Capping it makes the timer LATE at worst; not capping it makes it
17
+ * immediate, which is a different behaviour entirely.
18
+ */
19
+ /** The longest delay `setTimeout` keeps as given: 2^31 - 1 ms, a shade under 24.9 days. */
20
+ export const MAX_TIMER_DELAY_MS = 2_147_483_647;
21
+ /** `ms` as a delay a timer keeps: never negative, never absent, never past what a 32-bit int holds. */
22
+ export function timerDelay(ms) {
23
+ if (!Number.isFinite(ms) || ms <= 0)
24
+ return 0;
25
+ return Math.min(Math.floor(ms), MAX_TIMER_DELAY_MS);
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.167",
4
- "gitHead": "46159021f289942131bbf7685e544208da2cc865",
3
+ "version": "0.1.169",
4
+ "gitHead": "ee9d7f0d7377a77360fab634f97af5deeeb0b642",
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.167",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.167",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.200",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.169",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.169",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.202",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.144",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.144",