@hadoku/game-server 0.1.107 → 0.1.108

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.
@@ -34,6 +34,8 @@ export interface RoomViewCore {
34
34
  ready: boolean;
35
35
  }[];
36
36
  testing?: boolean;
37
+ /** The room's own tier floor (`room/tier-floor.ts`); absent for none. */
38
+ minTier?: string;
37
39
  }
38
40
  /** The slice of `room/lobby.ts`'s `Lobby` this file calls, typed against `V` and `C` alone — never the real types. */
39
41
  export interface LobbyCore<V extends RoomViewCore, C> {
@@ -46,6 +48,8 @@ export interface LobbyCore<V extends RoomViewCore, C> {
46
48
  } | {
47
49
  ok: false;
48
50
  };
51
+ /** The tier floor a room made from `body` would have (`room/lobby.ts`'s `minTierOf`). */
52
+ minTierOf(body: C): string | undefined;
49
53
  join(roomId: string, caller: CallerLike, password?: string): {
50
54
  ok: true;
51
55
  room: V;
@@ -234,8 +238,13 @@ export type RoomBody<V extends RoomViewCore, G = never> = V & {
234
238
  export declare function badRequest(res: Response, error: string): void;
235
239
  export declare function noMatch(res: Response): void;
236
240
  export declare function notDurable(res: Response, verb?: string): void;
237
- /** A testing room, to a non-admin, is as if it did not exist — shared by this file's router and `rooms.ts`'s. */
238
- export declare function hideTestingRoomsParam<V extends RoomViewCore>(lobby: Pick<LobbyCore<V, never>, 'get'>): (req: Request, res: Response, next: NextFunction, id: string) => void;
241
+ /**
242
+ * Whether `req`'s caller may know `room` exists at all: a testing room is an admin's, and a room
243
+ * with a tier floor (`room/tier-floor.ts`) is for that tier and above, by the edge's own name for it.
244
+ */
245
+ export declare function roomVisibleTo(req: Request, room: RoomViewCore): boolean;
246
+ /** A room the caller may not see ({@link roomVisibleTo}) is as if it did not exist — shared by this file's router and `rooms.ts`'s. */
247
+ export declare function hideRoomsParam<V extends RoomViewCore>(lobby: Pick<LobbyCore<V, never>, 'get'>): (req: Request, res: Response, next: NextFunction, id: string) => void;
239
248
  export interface RoomCoreHandle<V extends RoomViewCore, G = never> {
240
249
  router: Router;
241
250
  roomBody(room: V, callerId: string): RoomBody<V, G>;
@@ -23,7 +23,8 @@
23
23
  import { Router } from 'express';
24
24
  import { MultiRateLimiter } from '@wolffm/rooms-server';
25
25
  import { isDurableParticipantId } from '@wolffm/rooms-protocol';
26
- import { isAdmin } from '../edge-auth.js';
26
+ import { edgeTierOf, isAdmin } from '../edge-auth.js';
27
+ import { tierAdmits } from '../room/tier-floor.js';
27
28
  import { bodyErrors, callerOf, parseBody, perCallerLimit } from './request.js';
28
29
  import { isWatchpartyRoomId, watchpartyRoomId } from '../room/watchparty-link.js';
29
30
  import { jsonLogger } from '../log.js';
@@ -118,11 +119,20 @@ export function notDurable(res, verb = 'create or join') {
118
119
  function hasGameType(v) {
119
120
  return 'gameType' in v && typeof v.gameType === 'string';
120
121
  }
121
- /** A testing room, to a non-admin, is as if it did not exist — shared by this file's router and `rooms.ts`'s. */
122
- export function hideTestingRoomsParam(lobby) {
122
+ /**
123
+ * Whether `req`'s caller may know `room` exists at all: a testing room is an admin's, and a room
124
+ * with a tier floor (`room/tier-floor.ts`) is for that tier and above, by the edge's own name for it.
125
+ */
126
+ export function roomVisibleTo(req, room) {
127
+ if (room.testing === true && !isAdmin(req))
128
+ return false;
129
+ return tierAdmits(room.minTier, edgeTierOf(req));
130
+ }
131
+ /** A room the caller may not see ({@link roomVisibleTo}) is as if it did not exist — shared by this file's router and `rooms.ts`'s. */
132
+ export function hideRoomsParam(lobby) {
123
133
  return (req, res, next, id) => {
124
134
  const room = lobby.get(id);
125
- if (room !== undefined && room.testing && !isAdmin(req))
135
+ if (room !== undefined && !roomVisibleTo(req, room))
126
136
  return noMatch(res);
127
137
  next();
128
138
  };
@@ -148,12 +158,11 @@ export function attachRoomCore(api, deps, opts = {}) {
148
158
  };
149
159
  };
150
160
  const rooms = Router();
151
- rooms.param('id', hideTestingRoomsParam(lobby));
161
+ rooms.param('id', hideRoomsParam(lobby));
152
162
  rooms.get('/', (req, res) => {
153
163
  const me = callerOf(req).id;
154
- const admin = isAdmin(req);
155
- // A testing room is never offered to a non-admin.
156
- const offered = lobby.offered().filter((room) => admin || !room.testing);
164
+ // A testing room is never offered to a non-admin, nor a friends-only room below friend.
165
+ const offered = lobby.offered().filter((room) => roomVisibleTo(req, room));
157
166
  const pick = deps.featured?.(me) ?? null;
158
167
  const featured = pick !== null && offered.some((room) => room.id === pick.roomId) ? pick : null;
159
168
  res.json({ rooms: offered.map((room) => roomBody(room, me)), featured });
@@ -165,7 +174,13 @@ export function attachRoomCore(api, deps, opts = {}) {
165
174
  });
166
175
  rooms.post('/', (req, res) => {
167
176
  const body = parseBody(wire.createRoomBody, req, res);
168
- if (body === null || !createLimit(req, res))
177
+ if (body === null)
178
+ return;
179
+ if (!tierAdmits(lobby.minTierOf(body), edgeTierOf(req))) {
180
+ log({ event: 'room-create-refused', reason: 'tier' });
181
+ return res.status(403).json({ error: 'this room needs a higher tier than yours' });
182
+ }
183
+ if (!createLimit(req, res))
169
184
  return;
170
185
  const caller = callerOf(req);
171
186
  const result = lobby.create(caller, body);
@@ -196,7 +211,7 @@ export function attachRoomCore(api, deps, opts = {}) {
196
211
  const matchId = String(req.params.matchId);
197
212
  const room = wire.roomIdRe.test(matchId) ? lobby.roomOfMatch(matchId) : undefined;
198
213
  const me = callerOf(req).id;
199
- if (room === undefined || !lobby.isMember(room.id, me))
214
+ if (room === undefined || !lobby.isMember(room.id, me) || !roomVisibleTo(req, room))
200
215
  return noMatch(res);
201
216
  res.json(roomBody(room, me));
202
217
  });
@@ -36,7 +36,7 @@
36
36
  */
37
37
  import type { Server as SocketIOServer } from 'socket.io';
38
38
  import type { ParticipantId } from '@wolffm/rooms-protocol';
39
- import type { RateLimitConfig } from '@wolffm/rooms-server';
39
+ import { type RateLimitConfig } from '@wolffm/rooms-server';
40
40
  import { type Gate } from '@wolffm/service-kernel/http';
41
41
  import { type RelayOutcome, type RelaySession, type RelaySink } from './runtimes/relay.js';
42
42
  export declare const RELAY_EVENTS: {
@@ -47,6 +47,9 @@ export declare const RELAY_EVENTS: {
47
47
  * the sender of `over` and every watcher included, so the room can show the result. */
48
48
  readonly ended: "relay:ended";
49
49
  };
50
+ /** Messages per sender: four times bomberman's own host, which sends its state at 30 Hz, so no
51
+ * game this relay was built for comes near it, and a bundle that floods its room does. */
52
+ export declare const RELAY_MESSAGE_RATE_LIMIT: RateLimitConfig;
50
53
  /** Joins per caller: a burst of 10, then one every 10 s. A seat opens one
51
54
  * relay connection per tab, so a burst covers a refresh storm without
52
55
  * covering a scan. */
@@ -113,10 +116,18 @@ export interface RelayDeps {
113
116
  gate?: Pick<Gate, 'gateSocketIo'>;
114
117
  /** This match's roster, or `undefined` for a matchId nothing is running — refused as `unknown-match`. */
115
118
  rosterOf(matchId: string): RelayRoster | undefined;
119
+ /**
120
+ * Whether the room holding `matchId` lets `participantId`, of edge tier `tier`, in at all — the
121
+ * same question its chat socket asks (`room/tier-floor.ts`'s `roomAdmits`). Refused as
122
+ * `not-joined`, seat or watcher alike: a watcher hears every seat's message.
123
+ */
124
+ admits(matchId: string, participantId: string, tier: string): boolean;
116
125
  /** The match ended: every seat left (`null`), or the leader's own bundle said `{ t: 'over', winners }`. */
117
126
  onEnded?(matchId: string, outcome: RelayOutcome | null): void;
118
127
  /** Overrides `RELAY_JOIN_RATE_LIMIT`; `null` is none. */
119
128
  joinRateLimit?: RateLimitConfig | null;
129
+ /** Overrides `RELAY_MESSAGE_RATE_LIMIT`; `null` is none. */
130
+ messageRateLimit?: RateLimitConfig | null;
120
131
  log?(entry: Record<string, unknown>): void;
121
132
  }
122
133
  export interface RelayHandle {
@@ -34,9 +34,11 @@
34
34
  * every `relay:ended`): no new event and no reconnect. Until it does, that socket speaks for
35
35
  * nothing — its sends and its disconnect belong to the match it joined, which is over.
36
36
  */
37
+ import { MultiRateLimiter } from '@wolffm/rooms-server';
37
38
  import { createEdgeAuth, rankOf, tierOf } from '@wolffm/service-kernel/auth';
38
39
  import { createGate } from '@wolffm/service-kernel/http';
39
40
  import { identityFromHeaders } from '../room/identity.js';
41
+ import { handshakeEdgeTier } from '../room/socket-auth.js';
40
42
  import { costlyActLimit } from '../http/request.js';
41
43
  export const RELAY_EVENTS = {
42
44
  join: 'relay:join',
@@ -46,6 +48,13 @@ export const RELAY_EVENTS = {
46
48
  * the sender of `over` and every watcher included, so the room can show the result. */
47
49
  ended: 'relay:ended',
48
50
  };
51
+ /** Messages per sender: four times bomberman's own host, which sends its state at 30 Hz, so no
52
+ * game this relay was built for comes near it, and a bundle that floods its room does. */
53
+ export const RELAY_MESSAGE_RATE_LIMIT = {
54
+ capacity: 240,
55
+ refillAmount: 120,
56
+ refillIntervalMs: 1000,
57
+ };
49
58
  /** Joins per caller: a burst of 10, then one every 10 s. A seat opens one
50
59
  * relay connection per tab, so a burst covers a refresh storm without
51
60
  * covering a scan. */
@@ -100,6 +109,10 @@ export function attachRelay(io, deps) {
100
109
  act: 'relay-join',
101
110
  onRefused: () => log({ evt: 'relay-join-refused', reason: 'rate-limited' }),
102
111
  });
112
+ const messageCfg = deps.messageRateLimit === undefined ? RELAY_MESSAGE_RATE_LIMIT : deps.messageRateLimit;
113
+ const messageLimit = messageCfg === null ? null : new MultiRateLimiter(messageCfg);
114
+ /** Senders over their limit now: a refusal is logged once per burst, not once per dropped message. */
115
+ const throttled = new Set();
103
116
  function matchOf(matchId, roster) {
104
117
  const found = live.get(matchId);
105
118
  if (found !== undefined)
@@ -152,7 +165,7 @@ export function attachRelay(io, deps) {
152
165
  reply({ ok: false, error: 'unknown-match' });
153
166
  return;
154
167
  }
155
- const role = roster.roleOf(participantId);
168
+ const role = deps.admits(matchId, participantId, handshakeEdgeTier(socket.request.headers)) ? roster.roleOf(participantId) : undefined;
156
169
  if (role === undefined) {
157
170
  reply({ ok: false, error: 'not-joined' });
158
171
  return;
@@ -188,6 +201,13 @@ export function attachRelay(io, deps) {
188
201
  log({ evt: 'relay-send-refused', matchId: joined.matchId, reason: 'watcher' });
189
202
  return;
190
203
  }
204
+ if (messageLimit !== null && !messageLimit.allow(participantId)) {
205
+ if (!throttled.has(participantId))
206
+ log({ evt: 'relay-send-refused', matchId: joined.matchId, reason: 'rate-limited' });
207
+ throttled.add(participantId);
208
+ return;
209
+ }
210
+ throttled.delete(participantId);
191
211
  match.session.fromSeat(joined.seat, msg);
192
212
  });
193
213
  socket.on('disconnect', () => {
@@ -218,6 +238,7 @@ export function attachRelay(io, deps) {
218
238
  for (const { session } of live.values())
219
239
  session.ended('server-stopping');
220
240
  live.clear();
241
+ messageLimit?.deregister();
221
242
  },
222
243
  };
223
244
  }
@@ -39,6 +39,7 @@ import { attachRoomCore, badRequest, noMatch } from './http/room-core.js';
39
39
  import { callerOf } from './http/request.js';
40
40
  import { attachPeople, createPeople } from './people.js';
41
41
  import { attachRelay } from './play/relay-socket.js';
42
+ import { roomAdmits } from './room/tier-floor.js';
42
43
  import { relayMatches } from './play/runtimes/relay-match.js';
43
44
  import { configureParticipantIdDomain, identityFromHeaders } from './room/identity.js';
44
45
  import { RoomLobby, plainRoomType } from './room/lobby.js';
@@ -258,6 +259,7 @@ export async function startRelayGame(options) {
258
259
  minTier: config.minTier,
259
260
  gate: auth.gate,
260
261
  rosterOf: (matchId) => relayMatches.get(matchId),
262
+ admits: (matchId, participantId, tier) => roomAdmits(lobby.get(matchId), lobby.isMember(matchId, participantId), tier),
261
263
  log: relayLog,
262
264
  });
263
265
  // The room's own presence: its grace is not the relay seat's hold.
@@ -65,6 +65,8 @@ export interface RoomCreateInput {
65
65
  testing?: boolean;
66
66
  /** When the room's event starts, in ms (`events.ts`). Set by the events route, never by a client body. */
67
67
  scheduledFor?: number;
68
+ /** The room's own tier floor (`tier-floor.ts`): Create room's friends-only switch. The game type's own floor, if stricter, wins. */
69
+ minTier?: string;
68
70
  }
69
71
  /** A member as every room's view names them. */
70
72
  export interface LobbyMemberView {
@@ -90,6 +92,8 @@ export interface PlatformRoomView {
90
92
  createdAt: string;
91
93
  testing: boolean;
92
94
  scheduledFor: string | null;
95
+ /** The room's own tier floor (`tier-floor.ts`); absent for a room anyone at the app's floor may see. */
96
+ minTier?: string;
93
97
  }
94
98
  /** The room-level `app` blob as the store keeps it: the platform's fields, the game seats, and the game's own part under `game`. */
95
99
  export interface StoredRoomApp {
@@ -101,6 +105,8 @@ export interface StoredRoomApp {
101
105
  testing?: boolean;
102
106
  /** Absent for a room no event made. */
103
107
  scheduledFor?: number;
108
+ /** Absent for a room with no floor of its own. */
109
+ minTier?: string;
104
110
  secret: Secret | null;
105
111
  seats: GameSeats;
106
112
  /** The game type's part as it stores it (`RoomTypeHooks.encode`/`decode`). */
@@ -202,6 +208,8 @@ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
202
208
  ending?(room: LobbyRoom<G>, why: 'close' | 'sweep' | 'forget'): void;
203
209
  /** A relay room's match seat count: set for a type whose room IS its match (`onRelayRoomOpened`). */
204
210
  relaySeats?: number;
211
+ /** Every room of this type has at least this tier floor (`tier-floor.ts`), whatever its creator chose. */
212
+ minTier?: string;
205
213
  /**
206
214
  * Whether `rest` names a sub-place inside this room that the type keeps track of beyond its game
207
215
  * seats (a table id, a match this room remembers) — `room/serve.ts`'s `placeOfKey`, matching a
@@ -442,6 +450,8 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
442
450
  * `no-room` and `not-member` are both answered the same 404 by the HTTP layer.
443
451
  */
444
452
  leave(roomId: string, memberId: string): LeaveResult<V>;
453
+ /** The floor a room made from `input` would have: its own, or its game type's when that is stricter (`tier-floor.ts`). */
454
+ minTierOf(input: Pick<I, 'gameType' | 'minTier'>): string | undefined;
445
455
  create(caller: Caller, input: I): CreateResult<V>;
446
456
  /**
447
457
  * The room a watchparty room's game slot binds to (D21): `wp-` plus a digest of the watchparty
@@ -47,6 +47,7 @@ import { makeSecret, mintRoomId } from "./provisioning.js";
47
47
  import { AI_SEAT, CLOSED_SEAT, leaveGameSeat, memberSeats, setGameSeat, takeGameSeat } from "./record.js";
48
48
  import { isOfferedRoom, isSweepableRoom, NO_BUSY_HOOK, sortRoomsByCreation } from "./room-list.js";
49
49
  import { lowerCapacity, replaceWithBot } from "./seat-table-adapter.js";
50
+ import { stricterTier } from "./tier-floor.js";
50
51
  import { watchpartyRoomId } from "./watchparty-link.js";
51
52
  /** A member as the lobby keeps one: the platform's record plus what a view shows of them. */
52
53
  /**
@@ -81,6 +82,8 @@ function platformView(room, locked, seats) {
81
82
  createdAt: new Date(room.createdAt).toISOString(),
82
83
  testing: room.testing,
83
84
  scheduledFor: room.scheduledFor === undefined ? null : new Date(room.scheduledFor).toISOString(),
85
+ // Spread: the key is ABSENT for a room with no floor, as `avatarId` is for a member with no character.
86
+ ...(room.minTier === undefined ? {} : { minTier: room.minTier }),
84
87
  };
85
88
  }
86
89
  function isSecret(v) {
@@ -114,6 +117,8 @@ export function roomAppCodec(typeOf) {
114
117
  throw new Error('app.testing is invalid');
115
118
  if (a.scheduledFor !== undefined && typeof a.scheduledFor !== 'number')
116
119
  throw new Error('app.scheduledFor is invalid');
120
+ if (a.minTier !== undefined && typeof a.minTier !== 'string')
121
+ throw new Error('app.minTier is invalid');
117
122
  if (a.secret !== null && !isSecret(a.secret))
118
123
  throw new Error('app.secret is invalid');
119
124
  const { seats, game } = hooks.decode(a, version, { roomId: ctx.roomId });
@@ -124,6 +129,7 @@ export function roomAppCodec(typeOf) {
124
129
  gameType: a.gameType,
125
130
  testing: a.testing === true,
126
131
  ...(a.scheduledFor === undefined ? {} : { scheduledFor: a.scheduledFor }),
132
+ ...(a.minTier === undefined ? {} : { minTier: a.minTier }),
127
133
  secret: a.secret === null ? null : { salt: a.secret.salt, hash: a.secret.hash },
128
134
  seats,
129
135
  game,
@@ -230,6 +236,7 @@ export class RoomLobby {
230
236
  gameType: room.gameType,
231
237
  testing: room.testing,
232
238
  ...(room.scheduledFor === undefined ? {} : { scheduledFor: room.scheduledFor }),
239
+ ...(room.minTier === undefined ? {} : { minTier: room.minTier }),
233
240
  secret: this.#secrets.get(room.id) ?? null,
234
241
  seats: [...room.seats],
235
242
  game: hooks.encode(room),
@@ -426,6 +433,10 @@ export class RoomLobby {
426
433
  this.log({ event: 'room-left', roomId, members: room.members.length, newLeader: room.leader });
427
434
  return { ok: true, room: this.view(room), ...cost };
428
435
  }
436
+ /** The floor a room made from `input` would have: its own, or its game type's when that is stricter (`tier-floor.ts`). */
437
+ minTierOf(input) {
438
+ return stricterTier(input.minTier, this.#typeOf(input.gameType)?.minTier);
439
+ }
429
440
  create(caller, input) {
430
441
  if (!isDurableParticipantId(caller.id))
431
442
  return { ok: false, reason: 'not-durable' };
@@ -451,6 +462,7 @@ export class RoomLobby {
451
462
  const hooks = this.#typeOf(input.gameType);
452
463
  if (hooks === undefined)
453
464
  throw new Error(`no room type ${input.gameType}`);
465
+ const minTier = this.minTierOf(input);
454
466
  const now = Math.max(this.now(), this.#lastCreatedAt + 1);
455
467
  this.#lastCreatedAt = now;
456
468
  const ledger = createMembershipLedger();
@@ -463,6 +475,7 @@ export class RoomLobby {
463
475
  gameType: input.gameType,
464
476
  testing: input.testing === true,
465
477
  ...(input.scheduledFor === undefined ? {} : { scheduledFor: input.scheduledFor }),
478
+ ...(minTier === undefined ? {} : { minTier }),
466
479
  ...hooks.newGame(input, id),
467
480
  createdAt: now,
468
481
  updatedAt: now,
@@ -1072,6 +1085,7 @@ export class RoomLobby {
1072
1085
  gameType: app.gameType,
1073
1086
  testing: app.testing === true,
1074
1087
  ...(app.scheduledFor === undefined ? {} : { scheduledFor: app.scheduledFor }),
1088
+ ...(app.minTier === undefined ? {} : { minTier: app.minTier }),
1075
1089
  seats: app.seats,
1076
1090
  game: game(members),
1077
1091
  createdAt: decoded.createdAt,
@@ -35,6 +35,8 @@ export interface PlatformRoomRecord<G, M extends PlatformMember = PlatformMember
35
35
  testing: boolean;
36
36
  /** When its event starts (`events.ts`). Absent for a room no event made. */
37
37
  scheduledFor?: number;
38
+ /** The room's own tier floor above the app's (`tier-floor.ts`); absent for a room anyone at the app's floor may see. */
39
+ minTier?: string;
38
40
  createdAt: number;
39
41
  /** Last mutation, in ms. What the sweep ages a room out on. */
40
42
  updatedAt: number;
@@ -62,6 +62,8 @@ import { type People } from '../people.js';
62
62
  export interface ServeRoomView {
63
63
  id: string;
64
64
  locked: boolean;
65
+ /** The room's own tier floor (`./tier-floor.ts`); absent for none. */
66
+ minTier?: string;
65
67
  members: readonly {
66
68
  id: string;
67
69
  name: string;
@@ -57,7 +57,8 @@ 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
59
  import { applyPerson } from '../people.js';
60
- import { handshakeTier } from './socket-auth.js';
60
+ import { handshakeEdgeTier, handshakeTier } from './socket-auth.js';
61
+ import { roomAdmits } from './tier-floor.js';
61
62
  import { identityFromHeaders } from './identity.js';
62
63
  /** In memory per room, and the default/max page a `GET …/chat` page asks for. */
63
64
  const MAX_MESSAGES_PER_ROOM = 500;
@@ -92,13 +93,11 @@ export function placeOfKey(lobby, isMatch, appId, roomKey, roomIdRe) {
92
93
  }
93
94
  return isMatch(id) ? { served: id, roomId: null, kind: 'match' } : null;
94
95
  }
95
- /** Whether `participantId` may be in `place`: a room's (or its table's) members, or anyone while the room has no password; anyone at a match. */
96
- function mayJoin(lobby, place, participantId) {
96
+ /** Whether `participantId`, of edge tier `tier`, may be in `place`: as its room admits them (`./tier-floor.ts`'s `roomAdmits`); anyone at a match. */
97
+ function mayJoin(lobby, place, participantId, tier) {
97
98
  if (place.roomId === null)
98
99
  return true;
99
- if (lobby.isMember(place.roomId, participantId))
100
- return true;
101
- return lobby.get(place.roomId)?.locked === false;
100
+ return roomAdmits(lobby.get(place.roomId), lobby.isMember(place.roomId, participantId), tier);
102
101
  }
103
102
  function accountOfHeaders(headers) {
104
103
  const id = headers['x-user-id'];
@@ -166,7 +165,7 @@ export async function attachServedRoom(io, deps) {
166
165
  if (place === null)
167
166
  return refuse('no-place');
168
167
  const participantId = identityFromHeaders(headers, socket.id);
169
- if (!mayJoin(lobby, place, participantId))
168
+ if (!mayJoin(lobby, place, participantId, handshakeEdgeTier(headers)))
170
169
  return refuse('not-member');
171
170
  const roomId = place.roomId;
172
171
  if (roomId !== null)
@@ -1,2 +1,4 @@
1
1
  import type { IncomingHttpHeaders } from 'node:http';
2
2
  export declare function handshakeTier(headers: IncomingHttpHeaders): string;
3
+ /** `edgeTierOf` over the same handshake: the tier exactly as the edge named it (`./tier-floor.ts`'s room floors read this). */
4
+ export declare function handshakeEdgeTier(headers: IncomingHttpHeaders): string;
@@ -1,4 +1,4 @@
1
- import { tierOf } from '../edge-auth.js';
1
+ import { edgeTierOf, tierOf } from '../edge-auth.js';
2
2
  export function handshakeTier(headers) {
3
3
  // `tierOf` reads exactly one header off `req.headers`, but it is typed for an
4
4
  // express `Request` and a handshake carries a bare `IncomingMessage`. The
@@ -8,3 +8,7 @@ export function handshakeTier(headers) {
8
8
  // is written about.
9
9
  return tierOf({ headers });
10
10
  }
11
+ /** `edgeTierOf` over the same handshake: the tier exactly as the edge named it (`./tier-floor.ts`'s room floors read this). */
12
+ export function handshakeEdgeTier(headers) {
13
+ return edgeTierOf({ headers });
14
+ }
@@ -0,0 +1,13 @@
1
+ /** The stricter of two floors; undefined when neither is set. */
2
+ export declare function stricterTier(a: string | undefined, b: string | undefined): string | undefined;
3
+ /** Whether a caller of `tier` (the edge's own name for it) may see a room whose floor is `minTier`. */
4
+ export declare function tierAdmits(minTier: string | undefined, tier: string): boolean;
5
+ /**
6
+ * Whether a room lets someone in at all — its chat socket (`./serve.ts`) and its relay match's socket
7
+ * (`../play/relay-socket.ts`) ask the same question: never below the room's own floor; its members;
8
+ * and anyone else only while it has no password.
9
+ */
10
+ export declare function roomAdmits(room: {
11
+ minTier?: string;
12
+ locked: boolean;
13
+ } | undefined, isMember: boolean, tier: string): boolean;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A room's own tier floor, above the app's: a room made friends-only (`minTier: 'friend'`) is, to
3
+ * anyone below that tier, as if it did not exist — absent from the list, 404 on every route, refused
4
+ * on the room and relay sockets. The app's floor (`CONFIG.minTier`) still applies first; this only
5
+ * ever narrows it.
6
+ *
7
+ * Read against the edge's tier EXACTLY as the edge named it (`edgeTierOf`), never `tierOf`, which
8
+ * promotes a member to friend for cardtable's own gates: a friends-only room means the fleet's
9
+ * friend tier and above, and a verified member is not that.
10
+ */
11
+ import { rankOf } from '../edge-auth.js';
12
+ /** The stricter of two floors; undefined when neither is set. */
13
+ export function stricterTier(a, b) {
14
+ if (a === undefined)
15
+ return b;
16
+ if (b === undefined)
17
+ return a;
18
+ return rankOf(b) > rankOf(a) ? b : a;
19
+ }
20
+ /** Whether a caller of `tier` (the edge's own name for it) may see a room whose floor is `minTier`. */
21
+ export function tierAdmits(minTier, tier) {
22
+ return minTier === undefined || rankOf(tier) >= rankOf(minTier);
23
+ }
24
+ /**
25
+ * Whether a room lets someone in at all — its chat socket (`./serve.ts`) and its relay match's socket
26
+ * (`../play/relay-socket.ts`) ask the same question: never below the room's own floor; its members;
27
+ * and anyone else only while it has no password.
28
+ */
29
+ export function roomAdmits(room, isMember, tier) {
30
+ if (room === undefined || !tierAdmits(room.minTier, tier))
31
+ return false;
32
+ return isMember || !room.locked;
33
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.107",
4
- "gitHead": "37dbbaf58dbc0bbf0bf38fa438d0eee421301227",
3
+ "version": "0.1.108",
4
+ "gitHead": "a51b8e0343f7a8b2b27db981541bca211c75fd4f",
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.107",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.107",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.140",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.108",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.108",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.141",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.32",
23
- "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.130",
24
- "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.130",
23
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.131",
24
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.131",
25
25
  "express": "^5.1.0",
26
26
  "socket.io": "^4.8.3",
27
27
  "zod": "4.5.4"