@hadoku/game-server 0.1.39 → 0.1.40

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.
@@ -151,7 +151,49 @@ export declare const NO_MATCH: {
151
151
  export declare const JOIN_RATE_LIMIT: RateLimitConfig;
152
152
  /** Rooms made per caller: a burst of 10, then one a minute. `rooms.ts`'s own `/challenge` shares this SAME limiter instance. */
153
153
  export declare const ROOM_CREATE_RATE_LIMIT: RateLimitConfig;
154
+ /**
155
+ * The seat ops every member and the leader take on a room's own game seats (`room/lobby.ts`'s
156
+ * `RoomLobby`): sit, stand, close or open an empty seat, give the AI one or take it back. A game whose
157
+ * room IS its seats (`plainRoomType`) hands its lobby to `RoomCoreDeps.seatRoutes`; Magic seats its
158
+ * pods through routes of its own and does not.
159
+ */
160
+ export interface SeatRouteLobby<V> {
161
+ sitSeat(roomId: string, callerId: string, seat?: number): {
162
+ ok: true;
163
+ room: V;
164
+ } | {
165
+ ok: false;
166
+ reason: string;
167
+ };
168
+ standSeat(roomId: string, callerId: string): {
169
+ ok: true;
170
+ room: V;
171
+ } | {
172
+ ok: false;
173
+ reason: string;
174
+ };
175
+ closeSeat(roomId: string, callerId: string, seat: number, closed: boolean): {
176
+ ok: true;
177
+ room: V;
178
+ } | {
179
+ ok: false;
180
+ reason: string;
181
+ };
182
+ aiSeat(roomId: string, callerId: string, seat: number, on: boolean): {
183
+ ok: true;
184
+ room: V;
185
+ } | {
186
+ ok: false;
187
+ reason: string;
188
+ };
189
+ }
154
190
  export interface RoomCoreDeps<V extends RoomViewCore, C, P extends object, G = never> {
191
+ /**
192
+ * Serve the seat routes on this lobby: `/:id/seats/sit` `{ seat? }`, `/:id/seats/stand` `{}`,
193
+ * `/:id/seats/close` `{ seat, closed }` (the leader's) and `/:id/seats/bot-off` `{ seat }` (the
194
+ * leader's; `/seats/bot` puts one in). Absent: none of the four is registered.
195
+ */
196
+ seatRoutes?: SeatRouteLobby<V>;
155
197
  lobby: LobbyCore<V, C>;
156
198
  wire: RoomCoreWire<C, P>;
157
199
  /** Structured log lines. Never carries a password, hash or salt. */
@@ -39,6 +39,9 @@ function field(check, message) {
39
39
  }
40
40
  const removeFromSeatBody = field((v) => typeof v === 'object' && v !== null && typeof v.memberId === 'string', 'memberId must be a string');
41
41
  const lowerCapacityBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.count), 'count must be an integer');
42
+ const sitSeatBody = field((v) => typeof v === 'object' && v !== null && (v.seat === undefined || (Number.isInteger(v.seat) && (v.seat >= 0))), 'seat must be a non-negative integer, or absent');
43
+ const emptyBody = field((v) => typeof v === 'object' && v !== null && Object.keys(v).length === 0, 'expected an empty body');
44
+ const closeSeatBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.seat) && v.seat >= 0 && typeof v.closed === 'boolean', 'seat must be a non-negative integer and closed a boolean');
42
45
  const botReplacesHumanBody = field((v) => typeof v === 'object' && v !== null && Number.isInteger(v.seat), 'seat must be an integer');
43
46
  /** Every one of the leader's three seat ops' own refusal, mapped to a status. `'no-room'`/`no such room` reuses the create/join answer on purpose: never telling a non-member whether a room id exists. */
44
47
  function seatOpStatus(res, reason) {
@@ -343,6 +346,30 @@ export function attachRoomCore(api, deps, opts = {}) {
343
346
  return seatOpStatus(res, result.reason);
344
347
  res.json({ ...roomBody(result.room, caller.id), evicted: result.evicted });
345
348
  });
349
+ const seats = deps.seatRoutes;
350
+ if (seats !== undefined) {
351
+ // Opted in (`RoomCoreDeps.seatRoutes`): a member sits and stands; the leader closes, opens and takes the AI back out.
352
+ const seatRoute = (path, schema, leaders, run) => {
353
+ rooms.post(`/:id/seats/${path}`, (req, res) => {
354
+ const body = parseBody(schema, req, res);
355
+ // The leader's ops spend the seat-op limit, as `remove`/`capacity`/`bot` do; a member's own sit and stand do not.
356
+ if (body === null || (leaders && !seatOpLimit(req, res)))
357
+ return;
358
+ const caller = callerOf(req);
359
+ const id = String(req.params.id);
360
+ if (!wire.roomIdRe.test(id))
361
+ return noMatch(res);
362
+ const result = run(id, caller.id, body);
363
+ if (!result.ok)
364
+ return seatOpStatus(res, result.reason);
365
+ res.json(roomBody(result.room, caller.id));
366
+ });
367
+ };
368
+ seatRoute('sit', sitSeatBody, false, (id, callerId, body) => seats.sitSeat(id, callerId, body.seat));
369
+ seatRoute('stand', emptyBody, false, (id, callerId) => seats.standSeat(id, callerId));
370
+ seatRoute('close', closeSeatBody, true, (id, callerId, body) => seats.closeSeat(id, callerId, body.seat, body.closed));
371
+ seatRoute('bot-off', botReplacesHumanBody, true, (id, callerId, body) => seats.aiSeat(id, callerId, body.seat, false));
372
+ }
346
373
  // The leader hands the room to another member, seated or watching. Spends the seat-op limit.
347
374
  rooms.post('/:id/leader', (req, res) => {
348
375
  const body = parseBody(removeFromSeatBody, req, res);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.39",
4
- "gitHead": "1f205041f6382de02221007ebda7bd1ba96e417d",
3
+ "version": "0.1.40",
4
+ "gitHead": "01e4b514259bb37d2b1e397ee20e092a53a10848",
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.39",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.39",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.72",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.40",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.40",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.73",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
23
- "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.109",
24
- "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.109",
23
+ "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.110",
24
+ "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.110",
25
25
  "express": "^5.1.0",
26
26
  "socket.io": "^4.8.3",
27
27
  "zod": "4.5.4"