@hadoku/game-server 0.1.225 → 0.1.227

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.
@@ -69,42 +69,24 @@ function seatOpStatus(res, reason) {
69
69
  return noMatch(res);
70
70
  if (reason === 'not-member' || reason === 'target-not-member')
71
71
  return noMatch(res);
72
- if (reason === 'not-leader') {
73
- res.status(403).json({ error: 'only the room leader can do that' });
74
- return;
75
- }
76
- if (reason === 'not-draft' || reason === 'not-lobby') {
77
- res.status(409).json({ error: 'this room does not seat through game seats, or its seats are fixed right now' });
78
- return;
79
- }
80
- if (reason === 'historical') {
81
- res.status(409).json({ error: 'a historical room’s field is the event’s, not the leader’s to change' });
82
- return;
83
- }
84
- if (reason === 'too-few') {
85
- res.status(400).json({ error: `a room always keeps at least ${String(MIN_OPEN_SEATS)} seats open` });
86
- return;
87
- }
88
- if (reason === 'bad-seat') {
89
- res.status(400).json({ error: 'not a seat this room has' });
90
- return;
91
- }
92
- if (reason === 'no-bot-seat') {
93
- res.status(409).json({ error: 'this room has no seat the bot can take' });
94
- return;
95
- }
96
- if (reason === 'seat-taken') {
97
- res.status(409).json({ error: 'that seat is already taken' });
98
- return;
99
- }
100
- if (reason === 'pod-full') {
101
- res.status(409).json({ error: 'every seat is taken' });
102
- return;
103
- }
104
- if (reason === 'not-open') {
105
- res.status(409).json({ error: `seats open ${String(SEATS_OPEN_BEFORE_MS / 60_000)} minutes before the event starts` });
106
- return;
107
- }
72
+ if (reason === 'not-leader')
73
+ return refuse(res, 403, 'only the room leader can do that');
74
+ if (reason === 'not-draft' || reason === 'not-lobby')
75
+ return refuse(res, 409, 'this room does not seat through game seats, or its seats are fixed right now');
76
+ if (reason === 'historical')
77
+ return refuse(res, 409, 'a historical room’s field is the event’s, not the leader’s to change');
78
+ if (reason === 'too-few')
79
+ return refuse(res, 400, `a room always keeps at least ${String(MIN_OPEN_SEATS)} seats open`);
80
+ if (reason === 'bad-seat')
81
+ return refuse(res, 400, 'not a seat this room has');
82
+ if (reason === 'no-bot-seat')
83
+ return refuse(res, 409, 'this room has no seat the bot can take');
84
+ if (reason === 'seat-taken')
85
+ return refuse(res, 409, 'that seat is already taken');
86
+ if (reason === 'pod-full')
87
+ return refuse(res, 409, 'every seat is taken');
88
+ if (reason === 'not-open')
89
+ return refuse(res, 409, `seats open ${String(SEATS_OPEN_BEFORE_MS / 60_000)} minutes before the event starts`);
108
90
  res.status(400).json({ error: reason });
109
91
  }
110
92
  /**
@@ -503,8 +503,6 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
503
503
  * does is checked against its lock, and the first lock that holds refuses the whole patch.
504
504
  */
505
505
  setSettings(roomId: string, callerId: string, patch: Record<string, unknown>): SetSettingsResult<V>;
506
- /** `setSettings` on a room in hand. `write` stands in for the type's own (a game with more to move when a setting does). */
507
- protected changeSettings(room: LobbyRoom, callerId: string, patch: Record<string, unknown>, write?: (room: LobbyRoom, next: Record<string, unknown>) => void): SetSettingsResult<V>;
508
506
  /** Idempotent for an existing member, who needs no password again. */
509
507
  join(roomId: string, caller: Caller, password?: string): JoinResult<V>;
510
508
  /**
@@ -519,10 +519,6 @@ export class RoomLobby {
519
519
  const room = this.#rooms.get(roomId);
520
520
  if (room === undefined)
521
521
  return { ok: false, reason: 'no-room' };
522
- return this.changeSettings(room, callerId, patch);
523
- }
524
- /** `setSettings` on a room in hand. `write` stands in for the type's own (a game with more to move when a setting does). */
525
- changeSettings(room, callerId, patch, write) {
526
522
  const settings = this.hooksOf(room).settings;
527
523
  if (settings === undefined)
528
524
  return { ok: false, reason: 'no-settings' };
@@ -533,7 +529,7 @@ export class RoomLobby {
533
529
  return { ok: false, reason: result.reason };
534
530
  if (result.changed.length === 0)
535
531
  return { ok: true, room: this.view(room) };
536
- (write ?? settings.write)(room, result.next);
532
+ settings.write(room, result.next);
537
533
  this.persist(room);
538
534
  this.log({ event: 'room-settings', roomId: room.id, settings: result.next });
539
535
  return { ok: true, room: this.view(room) };
@@ -7,7 +7,7 @@
7
7
  * offered while dealing; a pod room's default idle window and its post-deal
8
8
  * grace are a tournament's own), reached through `RoomBusyHook` rather than
9
9
  * this file importing pods or drafts itself — the same hook pattern
10
- * `useGameType`/`onRelayRoomOpened` already use. A non-Magic room (bomberman's)
10
+ * `onRelayRoomOpened` already uses. A non-Magic room (bomberman's)
11
11
  * that wires no hook gets `NO_BUSY_HOOK`'s plain rule: no extra reason to stay
12
12
  * offered past staleness, the casual idle window, never spared.
13
13
  *
@@ -7,7 +7,7 @@
7
7
  * offered while dealing; a pod room's default idle window and its post-deal
8
8
  * grace are a tournament's own), reached through `RoomBusyHook` rather than
9
9
  * this file importing pods or drafts itself — the same hook pattern
10
- * `useGameType`/`onRelayRoomOpened` already use. A non-Magic room (bomberman's)
10
+ * `onRelayRoomOpened` already uses. A non-Magic room (bomberman's)
11
11
  * that wires no hook gets `NO_BUSY_HOOK`'s plain rule: no extra reason to stay
12
12
  * offered past staleness, the casual idle window, never spared.
13
13
  *
@@ -24,6 +24,7 @@ import { MATCH_ID_PATTERN } from '@wolffm/prefs-client/games';
24
24
  import { AI_SEAT, CLOSED_SEAT } from '@wolffm/platform-wire/seats';
25
25
  import { participantHandle } from '@wolffm/rooms-protocol';
26
26
  import { callerOf } from '../http/request.js';
27
+ import { refuse } from '../http/room-core.js';
27
28
  /**
28
29
  * Who sits in each occupied seat NOW, in seat order, with a dense `playerId` — the match roster's
29
30
  * own numbering. A human's `clientId` is their full participant id (the roster's); a bot's is
@@ -54,21 +55,15 @@ export function attachResultRoute(api, deps) {
54
55
  api.post('/rooms/:id/result', (req, res) => {
55
56
  const roomId = String(req.params.id);
56
57
  const room = deps.lobby.get(roomId);
57
- if (room === undefined) {
58
- res.status(404).json({ error: 'no such room' });
59
- return;
60
- }
58
+ if (room === undefined)
59
+ return refuse(res, 404, 'no such room');
61
60
  const caller = callerOf(req);
62
- if (room.leader !== caller.id && !room.seats.includes(caller.id)) {
63
- res.status(403).json({ error: 'only a seated player may report a result' });
64
- return;
65
- }
61
+ if (room.leader !== caller.id && !room.seats.includes(caller.id))
62
+ return refuse(res, 403, 'only a seated player may report a result');
66
63
  const body = req.body;
67
64
  const matchId = body?.matchId;
68
- if (typeof matchId !== 'string' || !MATCH_ID_PATTERN.test(matchId)) {
69
- res.status(400).json({ error: "a result needs its round's own matchId" });
70
- return;
71
- }
65
+ if (typeof matchId !== 'string' || !MATCH_ID_PATTERN.test(matchId))
66
+ return refuse(res, 400, "a result needs its round's own matchId");
72
67
  const seats = buildFrozenSeats(room, deps.userKeys, deps.botClientId);
73
68
  const built = deps.toReport(body?.result, { matchId, roomId, endedAt: now(), seats });
74
69
  if (!built.ok) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.225",
4
- "gitHead": "6db2b0d6cae6d1813362faedd2a1a3bef801dcf8",
3
+ "version": "0.1.227",
4
+ "gitHead": "690af2bdc6a23f2433a551e990fb52614ce330b9",
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.225",
20
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.225",
21
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.258",
19
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.227",
20
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.227",
21
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.260",
22
22
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
23
23
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",
24
24
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.152",