@hadoku/game-server 0.1.63 → 0.1.65

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.
package/dist/people.d.ts CHANGED
@@ -8,14 +8,15 @@
8
8
  * customizations everywhere."* A person picks all of it in the fleet's avatar
9
9
  * settings, never here; this module only reads it.
10
10
  *
11
- * Resolved with this server's own service key. A failure answers nobody and
12
- * is logged, never thrown: a missing look costs a face its dressing, not a
13
- * join. Cached a minute, so a room's joins share one lookup; a person who has
11
+ * Resolved with this server's own service key, through prefs-client's shared
12
+ * people lookup (`createPeopleLookup`). A failure answers nobody and is logged,
13
+ * never thrown: a missing look costs a face its dressing, not a join. Cached a
14
+ * minute, so a room's joins share one lookup; a person who has
14
15
  * just changed theirs is read `fresh` (the served room's `account`, `room/serve.ts`).
15
16
  * The picture URL is relayed, never fetched: the browser loads it from
16
17
  * Discord, Steam or cdn.hadoku.me, all inside hadoku.me's img-src.
17
18
  */
18
- import { type ResolvedPerson } from '@wolffm/prefs-client/avatar';
19
+ import type { ResolvedPerson } from '@wolffm/prefs-client/avatar';
19
20
  import { type Look, type PersonFace } from '@wolffm/platform-wire/look';
20
21
  /** One person, as a screen shows them. */
21
22
  export interface Person {
@@ -52,7 +53,12 @@ export interface PeopleOptions {
52
53
  }
53
54
  /** What one resolved entry means here. Exported for its test. */
54
55
  export declare function personOf(r: ResolvedPerson | undefined): Person;
55
- /** No key, no lookups: every answer is empty and nothing is called. */
56
+ /**
57
+ * The lookup is prefs-client's (`createPeopleLookup`, the one every hadoku server shows people
58
+ * through: watchparty's too): cached a minute, one lookup per id at a time, a failure answers
59
+ * nobody and is not cached, and no key means no lookups. This adds only cardtable's reading of
60
+ * an answer (`personOf`).
61
+ */
56
62
  export declare function createPeople(opts: PeopleOptions): ForgetfulPeople;
57
63
  /** What a person is written into: the room registry (`room/lobby.ts`'s `Lobby`). */
58
64
  interface PersonRooms {
package/dist/people.js CHANGED
@@ -8,18 +8,18 @@
8
8
  * customizations everywhere."* A person picks all of it in the fleet's avatar
9
9
  * settings, never here; this module only reads it.
10
10
  *
11
- * Resolved with this server's own service key. A failure answers nobody and
12
- * is logged, never thrown: a missing look costs a face its dressing, not a
13
- * join. Cached a minute, so a room's joins share one lookup; a person who has
11
+ * Resolved with this server's own service key, through prefs-client's shared
12
+ * people lookup (`createPeopleLookup`). A failure answers nobody and is logged,
13
+ * never thrown: a missing look costs a face its dressing, not a join. Cached a
14
+ * minute, so a room's joins share one lookup; a person who has
14
15
  * just changed theirs is read `fresh` (the served room's `account`, `room/serve.ts`).
15
16
  * The picture URL is relayed, never fetched: the browser loads it from
16
17
  * Discord, Steam or cdn.hadoku.me, all inside hadoku.me's img-src.
17
18
  */
18
- import { resolveAvatars } from '@wolffm/prefs-client/avatar';
19
+ import { createPeopleLookup } from '@wolffm/prefs-client/people';
19
20
  import { cleanWorn } from '@wolffm/prefs-client/cosmetics';
20
21
  import { AVATAR_ID_MAX, LOOK_PICTURE_MAX, lookOrNone } from '@wolffm/platform-wire/look';
21
22
  const CACHE_TTL_MS = 60_000;
22
- const CACHE_PRUNE_THRESHOLD = 1024;
23
23
  const LOOKUP_TIMEOUT_MS = 5000;
24
24
  /** What one resolved entry means here. Exported for its test. */
25
25
  export function personOf(r) {
@@ -31,65 +31,35 @@ export function personOf(r) {
31
31
  look: lookOrNone({ ...(picture === undefined ? {} : { picture }), ...(cosmetics === undefined ? {} : { cosmetics }) }),
32
32
  };
33
33
  }
34
- /** No key, no lookups: every answer is empty and nothing is called. */
34
+ /**
35
+ * The lookup is prefs-client's (`createPeopleLookup`, the one every hadoku server shows people
36
+ * through: watchparty's too): cached a minute, one lookup per id at a time, a failure answers
37
+ * nobody and is not cached, and no key means no lookups. This adds only cardtable's reading of
38
+ * an answer (`personOf`).
39
+ */
35
40
  export function createPeople(opts) {
36
- const now = opts.now ?? Date.now;
37
- const cache = new Map();
38
- const baseUrl = opts.baseUrl.replace(/\/+$/, '');
39
- // hadoku.me's WAF challenges a bare client user-agent, and a lookup that
40
- // never answers must not hold a join's promise open.
41
- const lookupFetch = (input, init) => (opts.fetch ?? fetch)(input, {
42
- ...init,
43
- headers: { ...init?.headers, 'User-Agent': 'hadoku-cardtable-people/1' },
44
- signal: AbortSignal.timeout(LOOKUP_TIMEOUT_MS),
41
+ const lookup = createPeopleLookup({
42
+ baseUrl: opts.baseUrl,
43
+ serviceKey: opts.serviceKey,
44
+ ...(opts.keyless === true ? { keyless: true } : {}),
45
+ userAgent: 'hadoku-cardtable-people/1',
46
+ ttlMs: CACHE_TTL_MS,
47
+ timeoutMs: LOOKUP_TIMEOUT_MS,
48
+ onError: (err, ids) => opts.log({ evt: 'people-resolve-failed', ids: ids.length, error: err.message }),
49
+ ...(opts.fetch === undefined ? {} : { fetch: opts.fetch }),
50
+ ...(opts.now === undefined ? {} : { now: opts.now }),
45
51
  });
46
- let inflight = Promise.resolve();
47
52
  const peek = (userId) => {
48
- const hit = cache.get(userId);
49
- return hit !== undefined && hit.expiresAt > now() ? hit.person : undefined;
53
+ const hit = lookup.peek(userId);
54
+ return hit === undefined ? undefined : personOf(hit ?? undefined);
50
55
  };
51
56
  return {
52
57
  peek,
53
- forget: (userId) => (cache.delete(userId) ? 1 : 0),
54
- async resolve(userIds, { fresh = false } = {}) {
58
+ forget: (userId) => lookup.forget(userId),
59
+ async resolve(userIds, options = {}) {
55
60
  const out = new Map();
56
- const missing = [];
57
- for (const id of new Set(userIds)) {
58
- const hit = fresh ? undefined : peek(id);
59
- if (hit !== undefined)
60
- out.set(id, hit);
61
- else
62
- missing.push(id);
63
- }
64
- if (missing.length === 0 || (opts.serviceKey === '' && opts.keyless !== true))
65
- return out;
66
- // One lookup at a time: a burst of joins after a restart asks once per
67
- // id rather than once per join.
68
- const run = inflight.then(async () => {
69
- const still = fresh ? missing : missing.filter((id) => peek(id) === undefined);
70
- if (still.length === 0)
71
- return;
72
- try {
73
- const answer = await resolveAvatars({ baseUrl, serviceKey: opts.serviceKey, fetch: lookupFetch }, still);
74
- const at = now();
75
- for (const id of still)
76
- cache.set(id, { person: personOf(answer[id]), expiresAt: at + CACHE_TTL_MS });
77
- if (cache.size > CACHE_PRUNE_THRESHOLD)
78
- for (const [k, e] of cache)
79
- if (e.expiresAt <= at)
80
- cache.delete(k);
81
- }
82
- catch (err) {
83
- opts.log({ evt: 'people-resolve-failed', ids: still.length, error: err.message });
84
- }
85
- });
86
- inflight = run;
87
- await run;
88
- for (const id of missing) {
89
- const hit = cache.get(id);
90
- if (hit !== undefined)
91
- out.set(id, hit.person);
92
- }
61
+ for (const [id, answer] of await lookup.resolve(userIds, options))
62
+ out.set(id, personOf(answer ?? undefined));
93
63
  return out;
94
64
  },
95
65
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.63",
4
- "gitHead": "08474ef960211763cce1fdfab91817e6ec5ea5d6",
3
+ "version": "0.1.65",
4
+ "gitHead": "d69a2feabc856600d3b0e7a0ebedfce43e36c6a6",
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,12 +16,12 @@
16
16
  "play/remote/"
17
17
  ],
18
18
  "dependencies": {
19
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.63",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.63",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.96",
22
- "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.28",
23
- "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.117",
24
- "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.117",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.65",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.65",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.98",
22
+ "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.30",
23
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.119",
24
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.119",
25
25
  "express": "^5.1.0",
26
26
  "socket.io": "^4.8.3",
27
27
  "zod": "4.5.4"