@hadoku/game-server 0.1.178 → 0.1.180

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.
Files changed (43) hide show
  1. package/dist/base-path.d.ts +1 -3
  2. package/dist/base-path.js +1 -2
  3. package/dist/busy.d.ts +0 -1
  4. package/dist/busy.js +0 -1
  5. package/dist/config.d.ts +0 -5
  6. package/dist/config.js +0 -3
  7. package/dist/edge-auth.d.ts +3 -2
  8. package/dist/edge-auth.js +3 -2
  9. package/dist/gate.d.ts +0 -12
  10. package/dist/gate.js +0 -2
  11. package/dist/http/client-events.d.ts +2 -3
  12. package/dist/http/page.d.ts +1 -1
  13. package/dist/http/page.js +2 -1
  14. package/dist/http/room-core.d.ts +5 -5
  15. package/dist/http/room-core.js +33 -12
  16. package/dist/http/usage.d.ts +3 -6
  17. package/dist/http/usage.js +1 -2
  18. package/dist/log.d.ts +0 -8
  19. package/dist/log.js +1 -8
  20. package/dist/play/engine-runtime.d.ts +7 -32
  21. package/dist/play/engine-runtime.js +0 -9
  22. package/dist/play/host.d.ts +7 -6
  23. package/dist/play/host.js +82 -14
  24. package/dist/play/jvm-transport.d.ts +5 -0
  25. package/dist/play/local-jvm.d.ts +5 -6
  26. package/dist/play/local-jvm.js +10 -46
  27. package/dist/play/runtimes/relay-match.d.ts +2 -0
  28. package/dist/play/runtimes/relay-match.js +3 -0
  29. package/dist/play/runtimes/streamed.d.ts +2 -24
  30. package/dist/play/runtimes/streamed.js +2 -37
  31. package/dist/relay-game.d.ts +4 -1
  32. package/dist/relay-game.js +16 -3
  33. package/dist/room/lobby.d.ts +6 -7
  34. package/dist/room/lobby.js +11 -9
  35. package/dist/room/session.d.ts +1 -1
  36. package/dist/room/session.js +1 -1
  37. package/dist/room/watching.d.ts +7 -0
  38. package/dist/room/watching.js +28 -6
  39. package/dist/telemetry.d.ts +6 -6
  40. package/dist/telemetry.js +2 -2
  41. package/package.json +5 -5
  42. package/dist/erase/legacy-ids.d.ts +0 -9
  43. package/dist/erase/legacy-ids.js +0 -33
@@ -101,7 +101,8 @@ function isSecret(v) {
101
101
  export function roomAppCodec(typeOf) {
102
102
  const app = {
103
103
  version: ROOM_APP_VERSION,
104
- serialize: (value) => structuredClone(typeOf(value.gameType)?.writes?.(value) ?? value),
104
+ // No copy: the store stringifies the snapshot in the call (`OffLoopRoomStore.saveSync`).
105
+ serialize: (value) => value,
105
106
  deserialize(raw, version, ctx) {
106
107
  if (typeof raw !== 'object' || raw === null)
107
108
  throw new Error('app is not an object');
@@ -230,7 +231,7 @@ export class RoomLobby {
230
231
  lastSeen: m.joinedAt,
231
232
  // Boxed, so a state of `null` survives a restart as `null`, and `ready` rides the same
232
233
  // blob. A member with neither writes `null`.
233
- app: m.state === undefined && !ready ? null : { state: structuredClone(m.state), ready },
234
+ app: m.state === undefined && !ready ? null : { state: m.state, ready },
234
235
  };
235
236
  });
236
237
  const app = {
@@ -274,8 +275,8 @@ export class RoomLobby {
274
275
  }
275
276
  }
276
277
  /**
277
- * Be told every time a room is written, created or forgotten. Every mutation goes through one
278
- * persist, so this is every change a read could see and nothing else: a read (`touch`, `get`,
278
+ * Be told every time a room is written, created or forgotten, or a member's name, avatar or look
279
+ * changes (none of which is written), so this is every change a read could see and nothing else: a read (`touch`, `get`,
279
280
  * `list`) never fires it. Returns the unsubscribe.
280
281
  */
281
282
  onChange(listener) {
@@ -581,7 +582,8 @@ export class RoomLobby {
581
582
  /**
582
583
  * Call `caller.id` by `caller.name` in every room they are a member of. The name was copied once, at
583
584
  * join, so a key renamed in the registry kept its first name in every room it had joined
584
- * (2026-10-26). Writes only the rooms whose copy moved.
585
+ * (2026-10-26). Tells only the rooms whose copy moved, and writes none: a name is never stored (R12),
586
+ * so a rename is not a change to the room and leaves its age alone.
585
587
  */
586
588
  rename(caller) {
587
589
  for (const room of this.#rooms.values()) {
@@ -589,7 +591,7 @@ export class RoomLobby {
589
591
  if (member === undefined || member.name === caller.name)
590
592
  continue;
591
593
  member.name = caller.name;
592
- this.persist(room);
594
+ this.changed(room.id);
593
595
  }
594
596
  }
595
597
  /** false when there is no such room or the caller is not a member. Persisted. */
@@ -610,7 +612,7 @@ export class RoomLobby {
610
612
  * The member's OWN avatar, and nobody else's: `memberId` is always a derived participant id, so a
611
613
  * browser cannot name a row that is not its own. Three states in, two stored: a non-blank string
612
614
  * sets it; `null`, `''`, whitespace, an over-long value and a non-string clear it (`avatarIdOf`).
613
- * `false` only when there is no such room or member. Written only when it changed.
615
+ * `false` only when there is no such room or member. Never written (R12): told to the room when it changed.
614
616
  */
615
617
  setAvatar(roomId, memberId, avatarId) {
616
618
  const room = this.#rooms.get(roomId);
@@ -618,7 +620,7 @@ export class RoomLobby {
618
620
  if (room === undefined || member === undefined)
619
621
  return false;
620
622
  const next = avatarIdOf(avatarId);
621
- // Idempotent, and no write when nothing changed: a member's account is written onto the room
623
+ // Idempotent, and nothing told when nothing changed: a member's account is set on the room
622
624
  // on every arrival and every change to it. `true` either way: the room is in the asked state.
623
625
  if (next === member.avatarId)
624
626
  return true;
@@ -626,7 +628,7 @@ export class RoomLobby {
626
628
  delete member.avatarId;
627
629
  else
628
630
  member.avatarId = next;
629
- this.persist(room);
631
+ this.changed(roomId);
630
632
  this.#announceAvatar(roomId, member.id, member.avatarId ?? null);
631
633
  return true;
632
634
  }
@@ -44,7 +44,7 @@
44
44
  * the holder was live or stale.
45
45
  */
46
46
  import type { Server as SocketIOServer, Socket } from 'socket.io';
47
- import { type JsonLog } from '../log.js';
47
+ import { type JsonLog } from '@wolffm/service-kernel/log';
48
48
  /** How often a holding session socket is asked whether it is alive. */
49
49
  export declare const BEAT_MS = 5000;
50
50
  /** A holder that has answered nothing for this long is stale: two missed beats and change. */
@@ -46,7 +46,7 @@
46
46
  import { SessionClaims } from '@wolffm/rooms-server';
47
47
  import { SESSION_EVENTS, parseSessionClaim } from '@wolffm/rooms-protocol';
48
48
  import { identityFromHeaders } from './identity.js';
49
- import { jsonLogger } from '../log.js';
49
+ import { jsonLogger } from '@wolffm/service-kernel/log';
50
50
  import { callerContext, report } from '../telemetry.js';
51
51
  /** How often a holding session socket is asked whether it is alive. */
52
52
  export const BEAT_MS = 5_000;
@@ -13,6 +13,11 @@
13
13
  * - **Presence.** A hidden screen reads nothing, so the watch itself keeps a room offered on the
14
14
  * front page: every watched room is touched for its member when the watch arrives and every
15
15
  * `FEED_TOUCH_MS` after, for as long as the socket stays.
16
+ * - **A room's other keys.** A watch key that is not a room id names one of the room's facets
17
+ * (`roomOf` says which room): its watcher hears every change of the room, and also what is told
18
+ * for that key alone (`changed(key)`), which the room's own watchers never hear. A game's turn is
19
+ * one: the screen that draws it follows that key, and a screen that only needs the room does not
20
+ * read it again on every turn. Membership and presence are the room's.
16
21
  *
17
22
  * No gate of its own: `attachDraftSocket` and `attachPlay` already put the edge's provenance and the
18
23
  * tier floor in front of every handshake on the default namespace (`room/socket.ts`'s header).
@@ -28,6 +33,8 @@ interface RoomFeedLobby {
28
33
  interface RoomFeedDeps {
29
34
  lobby: RoomFeedLobby;
30
35
  log?: (line: Record<string, unknown>) => void;
36
+ /** The room a watch key names (this file's header). Default: every key is a room id. */
37
+ roomOf?: (key: string) => string;
31
38
  /** Injected for tests. */
32
39
  touchEveryMs?: number;
33
40
  }
@@ -13,6 +13,11 @@
13
13
  * - **Presence.** A hidden screen reads nothing, so the watch itself keeps a room offered on the
14
14
  * front page: every watched room is touched for its member when the watch arrives and every
15
15
  * `FEED_TOUCH_MS` after, for as long as the socket stays.
16
+ * - **A room's other keys.** A watch key that is not a room id names one of the room's facets
17
+ * (`roomOf` says which room): its watcher hears every change of the room, and also what is told
18
+ * for that key alone (`changed(key)`), which the room's own watchers never hear. A game's turn is
19
+ * one: the screen that draws it follows that key, and a screen that only needs the room does not
20
+ * read it again on every turn. Membership and presence are the room's.
16
21
  *
17
22
  * No gate of its own: `attachDraftSocket` and `attachPlay` already put the edge's provenance and the
18
23
  * tier floor in front of every handshake on the default namespace (`room/socket.ts`'s header).
@@ -27,11 +32,27 @@ const FEED_TOUCH_MS = ROOM_STALE_MS / 6;
27
32
  const participantOf = (socket) => identityFromHeaders(socket.request.headers, socket.id);
28
33
  export function attachRoomFeed(io, deps) {
29
34
  const { lobby } = deps;
30
- /** Each watching socket's participant and rooms, for the touch. */
35
+ const roomOf = deps.roomOf ?? ((key) => key);
36
+ /** Each watching socket's participant and keys, for the touch and a room's other keys. */
31
37
  const watching = new Map();
32
38
  const touch = ({ participantId, rooms }) => {
33
- for (const room of rooms)
34
- lobby.touch(room, participantId);
39
+ for (const key of rooms)
40
+ lobby.touch(roomOf(key), participantId);
41
+ };
42
+ /** Every watched key of `roomId`'s other than its id. */
43
+ const otherKeysOf = (roomId) => {
44
+ const keys = new Set();
45
+ for (const { rooms } of watching.values())
46
+ for (const key of rooms)
47
+ if (key !== roomId && roomOf(key) === roomId)
48
+ keys.add(key);
49
+ return keys;
50
+ };
51
+ /** `roomId`'s change, said to its own key and every other key of it. */
52
+ const withOtherKeys = (say) => (roomId) => {
53
+ say(roomId);
54
+ for (const key of otherKeysOf(roomId))
55
+ say(key);
35
56
  };
36
57
  const touching = setInterval(() => {
37
58
  for (const watcher of watching.values())
@@ -56,13 +77,14 @@ export function attachRoomFeed(io, deps) {
56
77
  });
57
78
  const feed = attachRoomBookFeed(io, {
58
79
  wire: { channel: ROOM_FEED_CHANNEL, parseWatch: parseRoomWatch },
59
- onChange: (listener) => lobby.onChange(listener),
60
- isMember: (room, participantId) => lobby.isMember(room, participantId),
80
+ onChange: (listener) => lobby.onChange(withOtherKeys(listener)),
81
+ isMember: (key, participantId) => lobby.isMember(roomOf(key), participantId),
61
82
  participantId: participantOf,
62
83
  log: deps.log ?? jsonLogger('cardtable-feed'),
63
84
  });
85
+ const changedRoom = withOtherKeys(feed.changed);
64
86
  return {
65
- changed: feed.changed,
87
+ changed: (key) => (roomOf(key) === key ? changedRoom(key) : feed.changed(key)),
66
88
  close() {
67
89
  feed.close();
68
90
  clearInterval(touching);
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Adapter: cardtable's binding of `@hadoku/service-kernel/telemetry` (w93-K3).
3
3
  *
4
- * Every export and signature below is unchanged from before this moved into the kernel:
5
- * `index.ts`, `gate.ts`, `edge-auth.ts`, `erase/index.ts`, `play/match.ts` and `play/socket.ts`
6
- * import this path exactly as they did. The cardtable-specific bits are the service id
4
+ * The plain re-exports stay because the published `@wolffm/game-server/telemetry` is a contract:
5
+ * bomberman's server imports `callerContext`, `report`, `installTelemetry` and `Report` from it.
6
+ * The cardtable-specific bits are the service id
7
7
  * (`cardtable`, stamped on every event's `context.service` and in the posting User-Agent), the
8
8
  * env var named in the disabled-reason log line (`CARDTABLE_SERVICE_KEY`), and the closed set of
9
9
  * surfaces a seal refusal ever names — the kernel's own `reportSealRefused` takes an open string,
@@ -11,9 +11,9 @@
11
11
  */
12
12
  import type { Request } from 'express';
13
13
  import type { JsonLog } from '@wolffm/service-kernel/log';
14
- import { callerContext, installTelemetry, report, reportingAlerts, userAgentOf, type Level, type Report, type TelemetryContext, type TelemetryValue } from '@wolffm/service-kernel/telemetry';
15
- export { callerContext, installTelemetry, report, reportingAlerts, userAgentOf };
16
- export type { Level, Report, TelemetryContext, TelemetryValue };
14
+ import { callerContext, installTelemetry, report, reportingAlerts, type Level, type Report, type TelemetryContext } from '@wolffm/service-kernel/telemetry';
15
+ export { callerContext, installTelemetry, report, reportingAlerts };
16
+ export type { Level, Report, TelemetryContext };
17
17
  /**
18
18
  * Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
19
19
  * (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
package/dist/telemetry.js CHANGED
@@ -1,5 +1,5 @@
1
- import { callerContext, installTelemetry, monitoringSink as kernelMonitoringSink, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, siteOf as kernelSiteOf, userAgentOf, } from '@wolffm/service-kernel/telemetry';
2
- export { callerContext, installTelemetry, report, reportingAlerts, userAgentOf };
1
+ import { callerContext, installTelemetry, monitoringSink as kernelMonitoringSink, report, reportingAlerts, reportSealRefused as kernelReportSealRefused, siteOf as kernelSiteOf, } from '@wolffm/service-kernel/telemetry';
2
+ export { callerContext, installTelemetry, report, reportingAlerts };
3
3
  /**
4
4
  * Which deployment a base path is: `/cardtable` is prod, `/cardtable-<site>` that site
5
5
  * (`/cardtable-ppe` is ppe, as the PPE wrapper sets `CARDTABLE_BASE_PREFIX`). Any other
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.178",
4
- "gitHead": "178f9274df3c7083ddec4b5ac1cf9fcb8b880360",
3
+ "version": "0.1.180",
4
+ "gitHead": "08b6dd41a5babb752b2291cdfbc1566758032125",
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.178",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.178",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.211",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.180",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.180",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.213",
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",
@@ -1,9 +0,0 @@
1
- /**
2
- * `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
3
- * prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
4
- * names people by userId, so an erase removes the person's entries from it, and a merge points
5
- * them at the kept account (an old id was that person's, and the person is now the kept account).
6
- * Absent is fine.
7
- */
8
- import type { EraseStep } from './index.js';
9
- export declare function legacyIdsStep(file: string): EraseStep;
@@ -1,33 +0,0 @@
1
- /**
2
- * `legacy-ids.done.json`: the record the R12 identity reset's one-off remap left behind on
3
- * prod (old key-derived id → the userId it was moved to). Nothing reads it any more, but it
4
- * names people by userId, so an erase removes the person's entries from it, and a merge points
5
- * them at the kept account (an old id was that person's, and the person is now the kept account).
6
- * Absent is fine.
7
- */
8
- import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
9
- export function legacyIdsStep(file) {
10
- /** Rewrite every entry that maps to `userId` (`to`: its new userId, or undefined to drop it). Answers how many. */
11
- const rewrite = (userId, to) => {
12
- if (!existsSync(file))
13
- return 0;
14
- const map = JSON.parse(readFileSync(file, 'utf8'));
15
- const theirs = Object.keys(map).filter((old) => map[old] === userId);
16
- if (theirs.length === 0)
17
- return 0;
18
- for (const old of theirs) {
19
- if (to === undefined)
20
- delete map[old];
21
- else
22
- map[old] = to;
23
- }
24
- writeFileSync(`${file}.tmp`, JSON.stringify(map));
25
- renameSync(`${file}.tmp`, file);
26
- return theirs.length;
27
- };
28
- return {
29
- what: 'legacyIds',
30
- erase: ({ userId }) => rewrite(userId, undefined),
31
- merge: ({ from, into }) => rewrite(from.userId, into.userId),
32
- };
33
- }