@hadoku/game-server 0.1.79 → 0.1.80
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/http/room-core.d.ts
CHANGED
|
@@ -203,6 +203,8 @@ export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = n
|
|
|
203
203
|
forfeited?: (roomId: string, tableId: string, loser: string, matches: readonly string[]) => void;
|
|
204
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
205
|
away?: (memberId: string) => number | null | undefined;
|
|
206
|
+
/** Who has a live room connection to `roomId` (`room/serve.ts`'s `here`). Absent, or a room watchparty draws (its roster is watchparty's): no `here` is sent. */
|
|
207
|
+
here?: (roomId: string) => ReadonlySet<string>;
|
|
206
208
|
/** "Reset = Close": runs AFTER `closed`, same as `index.ts`'s own `seedTestingRooms` boot call. */
|
|
207
209
|
reseedTesting?: () => void;
|
|
208
210
|
arrived?: (roomId: string, caller: CallerLike) => void;
|
|
@@ -226,6 +228,8 @@ export type RoomBody<V extends RoomViewCore, G = never> = V & {
|
|
|
226
228
|
tableGames?: Record<string, G>;
|
|
227
229
|
/** 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
230
|
away?: Record<string, string | null>;
|
|
231
|
+
/** The members in the room now: those with a screen open on it, its lobby or any game of it. The spectator row lists only these. Absent where this server cannot say: every member is listed. */
|
|
232
|
+
here?: string[];
|
|
229
233
|
};
|
|
230
234
|
export declare function badRequest(res: Response, error: string): void;
|
|
231
235
|
export declare function noMatch(res: Response): void;
|
package/dist/http/room-core.js
CHANGED
|
@@ -25,7 +25,7 @@ import { MultiRateLimiter } from '@wolffm/rooms-server';
|
|
|
25
25
|
import { isDurableParticipantId } from '@wolffm/rooms-protocol';
|
|
26
26
|
import { isAdmin } from '../edge-auth.js';
|
|
27
27
|
import { bodyErrors, callerOf, parseBody, perCallerLimit } from './request.js';
|
|
28
|
-
import { watchpartyRoomId } from '../room/watchparty-link.js';
|
|
28
|
+
import { isWatchpartyRoomId, watchpartyRoomId } from '../room/watchparty-link.js';
|
|
29
29
|
import { jsonLogger } from '../log.js';
|
|
30
30
|
/** A `BodySchema<T>` with no dependency the way `RoomCoreWire`'s injected ones have — this file imports no zod, no `@hadoku/shared`. */
|
|
31
31
|
function field(check, message) {
|
|
@@ -137,7 +137,15 @@ export function attachRoomCore(api, deps, opts = {}) {
|
|
|
137
137
|
const mine = room.members.find((m) => m.id === callerId);
|
|
138
138
|
const games = deps.tableGames?.(room);
|
|
139
139
|
const away = deps.away === undefined ? undefined : awayOf(room.members, deps.away);
|
|
140
|
-
|
|
140
|
+
const inRoom = isWatchpartyRoomId(room.id) ? undefined : deps.here?.(room.id);
|
|
141
|
+
const here = inRoom === undefined ? undefined : room.members.filter((m) => inRoom.has(m.id)).map((m) => m.id);
|
|
142
|
+
return {
|
|
143
|
+
...room,
|
|
144
|
+
you: { id: callerId, leader: room.leader === callerId, ready: mine?.ready === true },
|
|
145
|
+
...(games === undefined ? {} : { tableGames: games }),
|
|
146
|
+
...(away === undefined ? {} : { away }),
|
|
147
|
+
...(here === undefined ? {} : { here }),
|
|
148
|
+
};
|
|
141
149
|
};
|
|
142
150
|
const rooms = Router();
|
|
143
151
|
rooms.param('id', hideTestingRoomsParam(lobby));
|
package/dist/relay-game.js
CHANGED
|
@@ -161,6 +161,8 @@ export async function startRelayGame(options) {
|
|
|
161
161
|
// The room feed, from the `sockets` phase on: a pending start is no lobby write, so its route
|
|
162
162
|
// pings the room's watchers itself, or every page but the starter's missed the countdown.
|
|
163
163
|
let feedChanged = () => { };
|
|
164
|
+
// The chat's roster by room, once the room socket is up (`socketsPlugin`).
|
|
165
|
+
let roomHere = () => new Set();
|
|
164
166
|
const roomsPlugin = {
|
|
165
167
|
name: 'rooms',
|
|
166
168
|
phase: 'routes',
|
|
@@ -170,6 +172,7 @@ export async function startRelayGame(options) {
|
|
|
170
172
|
lobby,
|
|
171
173
|
wire: relayWire(options.gameType, options.roomIdRe),
|
|
172
174
|
seatRoutes: lobby,
|
|
175
|
+
here: (roomId) => roomHere(roomId),
|
|
173
176
|
arrived: (roomId, caller) => {
|
|
174
177
|
if (caller.userId !== null)
|
|
175
178
|
arrived(roomId, caller.id, caller.userId);
|
|
@@ -260,9 +263,10 @@ export async function startRelayGame(options) {
|
|
|
260
263
|
// The room's own presence: its grace is not the relay seat's hold.
|
|
261
264
|
const presence = new PresenceTracker({ idleMs: 2_000_000_000, graceMs: disconnectGraceMs });
|
|
262
265
|
const roomLog = jsonLogger(`${id}-room`);
|
|
263
|
-
await attachServedRoom(ctx.io, {
|
|
266
|
+
const served = await attachServedRoom(ctx.io, {
|
|
264
267
|
lobby,
|
|
265
268
|
presence,
|
|
269
|
+
onRoster: (roomId) => feedChanged(roomId),
|
|
266
270
|
people: ctx.state.people,
|
|
267
271
|
isMatch: (matchId) => relayMatches.get(matchId) !== undefined,
|
|
268
272
|
minTier: config.minTier,
|
|
@@ -286,6 +290,7 @@ export async function startRelayGame(options) {
|
|
|
286
290
|
});
|
|
287
291
|
const feed = attachRoomFeed(ctx.io, { lobby, log: jsonLogger(`${id}-feed`) });
|
|
288
292
|
feedChanged = (roomId) => feed.changed(roomId);
|
|
293
|
+
roomHere = served.here;
|
|
289
294
|
return {
|
|
290
295
|
shutdown: () => {
|
|
291
296
|
relay.close();
|
package/dist/room/serve.d.ts
CHANGED
|
@@ -41,6 +41,14 @@
|
|
|
41
41
|
* what screens built before 2026-11-11 joined during a game, and is gated as its room is. A
|
|
42
42
|
* refusal sends nothing of the room.
|
|
43
43
|
*
|
|
44
|
+
* ## Who is in a room now
|
|
45
|
+
*
|
|
46
|
+
* `here(roomId)` is the chat's own roster by participant id: everyone with a live room connection to
|
|
47
|
+
* the room, at its lobby, a table of it or a game at one. A member with no screen on the room is a
|
|
48
|
+
* member still (their seat, their sign-up, their place in a locked room) and is not in it. The
|
|
49
|
+
* spectator row reads this (`http/room-core.ts`'s `here`), so it names who is watching, never who
|
|
50
|
+
* once visited (the operator, 2026-11-19). `onRoster` says a room's answer changed.
|
|
51
|
+
*
|
|
44
52
|
* `appId` must agree with the UI's own app id; it is passed in rather than imported, since a
|
|
45
53
|
* server importing UI source is the wrong direction for any app's layering.
|
|
46
54
|
*/
|
|
@@ -120,7 +128,14 @@ export interface ServeDeps<V extends ServeRoomView> {
|
|
|
120
128
|
/** Default `/room`. */
|
|
121
129
|
namespace?: string;
|
|
122
130
|
onEvent?: (level: 'info' | 'warn' | 'debug', event: string, fields: Record<string, unknown>) => void;
|
|
131
|
+
/** A lobby room's `here` changed: someone's room connection opened or closed. */
|
|
132
|
+
onRoster?: (roomId: string) => void;
|
|
133
|
+
}
|
|
134
|
+
/** The served rooms, and who is in each lobby room now. */
|
|
135
|
+
export interface ServedRooms extends ServedRoom<string, RoomChatMessage> {
|
|
136
|
+
/** The participants with a live room connection to `roomId` (see this file's header). */
|
|
137
|
+
here(roomId: string): ReadonlySet<string>;
|
|
123
138
|
}
|
|
124
139
|
/** Mount a game's rooms on `io` (see this file's header). */
|
|
125
|
-
export declare function attachServedRoom<V extends ServeRoomView>(io: SocketIOServer, deps: ServeDeps<V>): Promise<
|
|
140
|
+
export declare function attachServedRoom<V extends ServeRoomView>(io: SocketIOServer, deps: ServeDeps<V>): Promise<ServedRooms>;
|
|
126
141
|
export {};
|
package/dist/room/serve.js
CHANGED
|
@@ -41,6 +41,14 @@
|
|
|
41
41
|
* what screens built before 2026-11-11 joined during a game, and is gated as its room is. A
|
|
42
42
|
* refusal sends nothing of the room.
|
|
43
43
|
*
|
|
44
|
+
* ## Who is in a room now
|
|
45
|
+
*
|
|
46
|
+
* `here(roomId)` is the chat's own roster by participant id: everyone with a live room connection to
|
|
47
|
+
* the room, at its lobby, a table of it or a game at one. A member with no screen on the room is a
|
|
48
|
+
* member still (their seat, their sign-up, their place in a locked room) and is not in it. The
|
|
49
|
+
* spectator row reads this (`http/room-core.ts`'s `here`), so it names who is watching, never who
|
|
50
|
+
* once visited (the operator, 2026-11-19). `onRoster` says a room's answer changed.
|
|
51
|
+
*
|
|
44
52
|
* `appId` must agree with the UI's own app id; it is passed in rather than imported, since a
|
|
45
53
|
* server importing UI source is the wrong direction for any app's layering.
|
|
46
54
|
*/
|
|
@@ -121,6 +129,10 @@ function gateRoomHandshake(namespace, minTier, onEvent) {
|
|
|
121
129
|
/** Mount a game's rooms on `io` (see this file's header). */
|
|
122
130
|
export async function attachServedRoom(io, deps) {
|
|
123
131
|
const { lobby, people } = deps;
|
|
132
|
+
// Each admitted socket's lobby room (a table's and a game's key name their room's), and each
|
|
133
|
+
// lobby room's joined connections by socket id.
|
|
134
|
+
const lobbyRoomOf = new WeakMap();
|
|
135
|
+
const joined = new Map();
|
|
124
136
|
gateRoomHandshake(io.of(deps.namespace ?? '/room'), deps.minTier, deps.onEvent);
|
|
125
137
|
const store = createChatHistoryStore({
|
|
126
138
|
stateDir: deps.stateDir,
|
|
@@ -157,6 +169,8 @@ export async function attachServedRoom(io, deps) {
|
|
|
157
169
|
if (!mayJoin(lobby, place, participantId))
|
|
158
170
|
return refuse('not-member');
|
|
159
171
|
const roomId = place.roomId;
|
|
172
|
+
if (roomId !== null)
|
|
173
|
+
lobbyRoomOf.set(socket, roomId);
|
|
160
174
|
const accountId = accountOfHeaders(headers);
|
|
161
175
|
return {
|
|
162
176
|
roomId: place.served,
|
|
@@ -174,6 +188,25 @@ export async function attachServedRoom(io, deps) {
|
|
|
174
188
|
},
|
|
175
189
|
};
|
|
176
190
|
},
|
|
191
|
+
onJoined(socket, admission) {
|
|
192
|
+
const roomId = lobbyRoomOf.get(socket);
|
|
193
|
+
if (roomId === undefined)
|
|
194
|
+
return;
|
|
195
|
+
let sockets = joined.get(roomId);
|
|
196
|
+
if (sockets === undefined)
|
|
197
|
+
joined.set(roomId, (sockets = new Map()));
|
|
198
|
+
sockets.set(socket.id, admission.key);
|
|
199
|
+
deps.onRoster?.(roomId);
|
|
200
|
+
},
|
|
201
|
+
onLeave(socket) {
|
|
202
|
+
const roomId = lobbyRoomOf.get(socket);
|
|
203
|
+
const sockets = roomId === undefined ? undefined : joined.get(roomId);
|
|
204
|
+
if (roomId === undefined || sockets === undefined || !sockets.delete(socket.id))
|
|
205
|
+
return;
|
|
206
|
+
if (sockets.size === 0)
|
|
207
|
+
joined.delete(roomId);
|
|
208
|
+
deps.onRoster?.(roomId);
|
|
209
|
+
},
|
|
177
210
|
// Always read fresh. serveRoom asks without `fresh` only for a person it holds no copy of (their
|
|
178
211
|
// first join or line since this server started), and people's cache may predate a change they
|
|
179
212
|
// made while their socket was down: a restart's resumed match fills it, and the chrome's
|
|
@@ -197,5 +230,14 @@ export async function attachServedRoom(io, deps) {
|
|
|
197
230
|
if (lobby.get(roomId) === undefined)
|
|
198
231
|
void store.clearRoomChat(roomId);
|
|
199
232
|
});
|
|
200
|
-
return served
|
|
233
|
+
return Object.assign(served, {
|
|
234
|
+
here(roomId) {
|
|
235
|
+
const here = new Set();
|
|
236
|
+
// Live on the tracker too, as the chat's roster reads it: a connection gone silent is not here.
|
|
237
|
+
for (const [socketId, key] of joined.get(roomId) ?? [])
|
|
238
|
+
if (deps.presence.keyOf(socketId) === key)
|
|
239
|
+
here.add(key);
|
|
240
|
+
return here;
|
|
241
|
+
},
|
|
242
|
+
});
|
|
201
243
|
}
|
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function watchpartyRoomId(watchpartyRoom: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Whether `roomId` is one a watchparty room's game slot is bound to. Such a room is drawn inside
|
|
4
|
+
* watchparty's own page, whose chat and roster are watchparty's: nobody at it holds a connection to
|
|
5
|
+
* this server's room socket, so this server cannot say who is in it now.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isWatchpartyRoomId(roomId: string): boolean;
|
|
@@ -15,3 +15,11 @@ import { createHash } from 'node:crypto';
|
|
|
15
15
|
export function watchpartyRoomId(watchpartyRoom) {
|
|
16
16
|
return `wp-${createHash('sha256').update(watchpartyRoom).digest('hex').slice(0, 20)}`;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether `roomId` is one a watchparty room's game slot is bound to. Such a room is drawn inside
|
|
20
|
+
* watchparty's own page, whose chat and roster are watchparty's: nobody at it holds a connection to
|
|
21
|
+
* this server's room socket, so this server cannot say who is in it now.
|
|
22
|
+
*/
|
|
23
|
+
export function isWatchpartyRoomId(roomId) {
|
|
24
|
+
return roomId.startsWith('wp-');
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.80",
|
|
4
|
+
"gitHead": "dd377be610a6dfbc7ae437241d9fdd3b1ef56c57",
|
|
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.
|
|
20
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
21
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
19
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.80",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.80",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.113",
|
|
22
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.31",
|
|
23
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.124",
|
|
24
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.124",
|