@hadoku/game-server 0.1.24 → 0.1.25
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 +8 -0
- package/dist/http/room-core.js +14 -0
- package/dist/room/lobby.d.ts +19 -2
- package/dist/room/lobby.js +24 -2
- package/dist/room/membership.d.ts +5 -0
- package/dist/room/membership.js +11 -0
- package/dist/room/record.d.ts +1 -1
- package/package.json +5 -5
package/dist/http/room-core.d.ts
CHANGED
|
@@ -116,6 +116,14 @@ export interface LobbyCore<V extends RoomViewCore, C> {
|
|
|
116
116
|
ok: false;
|
|
117
117
|
reason: string;
|
|
118
118
|
};
|
|
119
|
+
/** The leader hands the room's leadership to another member (`room/lobby.ts`'s `passLeader`). */
|
|
120
|
+
passLeader(roomId: string, callerId: string, targetId: string): {
|
|
121
|
+
ok: true;
|
|
122
|
+
room: V;
|
|
123
|
+
} | {
|
|
124
|
+
ok: false;
|
|
125
|
+
reason: string;
|
|
126
|
+
};
|
|
119
127
|
}
|
|
120
128
|
/** Every one of the leader's three seat ops, per caller: a burst of 10, then one every 10 s — the same shape as a join attempt, spent only by a leader who is actually a member of the room (checked before this is asked). */
|
|
121
129
|
export declare const SEAT_OP_RATE_LIMIT: RateLimitConfig;
|
package/dist/http/room-core.js
CHANGED
|
@@ -343,6 +343,20 @@ export function attachRoomCore(api, deps, opts = {}) {
|
|
|
343
343
|
return seatOpStatus(res, result.reason);
|
|
344
344
|
res.json({ ...roomBody(result.room, caller.id), evicted: result.evicted });
|
|
345
345
|
});
|
|
346
|
+
// The leader hands the room to another member, seated or watching. Spends the seat-op limit.
|
|
347
|
+
rooms.post('/:id/leader', (req, res) => {
|
|
348
|
+
const body = parseBody(removeFromSeatBody, req, res);
|
|
349
|
+
if (body === null || !seatOpLimit(req, res))
|
|
350
|
+
return;
|
|
351
|
+
const caller = callerOf(req);
|
|
352
|
+
const id = String(req.params.id);
|
|
353
|
+
if (!wire.roomIdRe.test(id))
|
|
354
|
+
return noMatch(res);
|
|
355
|
+
const result = lobby.passLeader(id, caller.id, body.memberId);
|
|
356
|
+
if (!result.ok)
|
|
357
|
+
return seatOpStatus(res, result.reason);
|
|
358
|
+
res.json(roomBody(result.room, caller.id));
|
|
359
|
+
});
|
|
346
360
|
/**
|
|
347
361
|
* `{ gameType }` is this file's own: the game-type registry is platform.
|
|
348
362
|
* Everything else `P` can be (Magic's `{ format }`/`{ settings }`/`{ mode }`)
|
package/dist/room/lobby.d.ts
CHANGED
|
@@ -263,6 +263,11 @@ export type SitSeatResult<V> = {
|
|
|
263
263
|
ok: false;
|
|
264
264
|
reason: 'no-room' | 'not-member' | 'not-draft' | 'not-lobby' | 'not-open' | 'bad-seat' | 'seat-taken' | 'pod-full' | 'historical';
|
|
265
265
|
};
|
|
266
|
+
/** `aiSeat`'s answer: a seat's answer, or `not-leader` — only the room's leader seats or unseats the AI. */
|
|
267
|
+
export type AiSeatResult<V> = SitSeatResult<V> | {
|
|
268
|
+
ok: false;
|
|
269
|
+
reason: 'not-leader';
|
|
270
|
+
};
|
|
266
271
|
export type CloseSeatResult<V> = {
|
|
267
272
|
ok: true;
|
|
268
273
|
room: V;
|
|
@@ -287,6 +292,13 @@ export type StandSeatResult<V> = {
|
|
|
287
292
|
* never a member acting on themselves. Built against cardtable's own `GameSeats`, not
|
|
288
293
|
* `@wolffm/rooms-protocol`'s `SeatTable` — see `removeFromSeat`'s own doc for why.
|
|
289
294
|
*/
|
|
295
|
+
export type PassLeaderResult<V> = {
|
|
296
|
+
ok: true;
|
|
297
|
+
room: V;
|
|
298
|
+
} | {
|
|
299
|
+
ok: false;
|
|
300
|
+
reason: 'no-room' | 'not-member' | 'not-leader' | 'target-not-member';
|
|
301
|
+
};
|
|
290
302
|
export type RemoveFromSeatResult<V> = {
|
|
291
303
|
ok: true;
|
|
292
304
|
room: V;
|
|
@@ -466,10 +478,15 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
466
478
|
sitSeat(roomId: string, memberId: string, seat?: number): SitSeatResult<V>;
|
|
467
479
|
/** Give up a game seat. Idempotent: not seated is not a failure. */
|
|
468
480
|
standSeat(roomId: string, memberId: string): StandSeatResult<V>;
|
|
469
|
-
/** Put the AI in an open seat (`on`), or take it out.
|
|
470
|
-
aiSeat(roomId: string, memberId: string, seat: number, on: boolean):
|
|
481
|
+
/** Put the AI in an open seat (`on`), or take it out. The leader's. */
|
|
482
|
+
aiSeat(roomId: string, memberId: string, seat: number, on: boolean): AiSeatResult<V>;
|
|
471
483
|
/** Close an empty seat, or open a closed one: the leader's; never fewer than `MIN_OPEN_SEATS` open. */
|
|
472
484
|
closeSeat(roomId: string, memberId: string, seat: number, closed: boolean): CloseSeatResult<V>;
|
|
485
|
+
/**
|
|
486
|
+
* The leader hands the room's leadership to `targetId`, another member, seated or watching.
|
|
487
|
+
* Passing it to yourself is answered `ok` and changes nothing.
|
|
488
|
+
*/
|
|
489
|
+
passLeader(roomId: string, memberId: string, targetId: string): PassLeaderResult<V>;
|
|
473
490
|
/**
|
|
474
491
|
* The leader removes `targetId` from whatever game seat they hold, to the spectator row.
|
|
475
492
|
* Idempotent: a target who holds none is still answered `ok`. Never touches membership — they
|
package/dist/room/lobby.js
CHANGED
|
@@ -41,7 +41,7 @@ import { ROOM_ID_RE } from '@wolffm/platform-wire/room-feed';
|
|
|
41
41
|
import { replaceIds } from "../erase/anonymise.js";
|
|
42
42
|
import { avatarIdOf } from "./avatar.js";
|
|
43
43
|
import { ROOM_STALE_MS, UNNAMED } from "./constants.js";
|
|
44
|
-
import { addRoomMember, isMemberReady, isRoomMember, passwordAdmits, removeRoomMember, setMemberReady } from "./membership.js";
|
|
44
|
+
import { addRoomMember, isMemberReady, isRoomMember, passRoomLeader, passwordAdmits, removeRoomMember, setMemberReady } from "./membership.js";
|
|
45
45
|
import { makeSecret, mintRoomId } from "./provisioning.js";
|
|
46
46
|
import { AI_SEAT, CLOSED_SEAT, leaveGameSeat, memberSeats, setGameSeat, takeGameSeat } from "./record.js";
|
|
47
47
|
import { isOfferedRoom, isSweepableRoom, NO_BUSY_HOOK, sortRoomsByCreation } from "./room-list.js";
|
|
@@ -690,12 +690,14 @@ export class RoomLobby {
|
|
|
690
690
|
hooks.seatsChanged?.(room);
|
|
691
691
|
return { ok: true, room: this.view(room) };
|
|
692
692
|
}
|
|
693
|
-
/** Put the AI in an open seat (`on`), or take it out.
|
|
693
|
+
/** Put the AI in an open seat (`on`), or take it out. The leader's. */
|
|
694
694
|
aiSeat(roomId, memberId, seat, on) {
|
|
695
695
|
const found = this.#seatRoom(roomId, memberId);
|
|
696
696
|
if ('refused' in found)
|
|
697
697
|
return { ok: false, reason: found.refused };
|
|
698
698
|
const { room, hooks } = found;
|
|
699
|
+
if (room.leader !== memberId)
|
|
700
|
+
return { ok: false, reason: 'not-leader' };
|
|
699
701
|
if (hooks.fieldFixed?.(room) === true)
|
|
700
702
|
return { ok: false, reason: 'historical' };
|
|
701
703
|
if (on && this.seatsShut(room) !== null)
|
|
@@ -747,6 +749,26 @@ export class RoomLobby {
|
|
|
747
749
|
this.log({ event: closed ? 'pod-seat-closed' : 'pod-seat-opened', roomId, memberId, seat, size: size() });
|
|
748
750
|
return { ok: true, room: this.view(room) };
|
|
749
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* The leader hands the room's leadership to `targetId`, another member, seated or watching.
|
|
754
|
+
* Passing it to yourself is answered `ok` and changes nothing.
|
|
755
|
+
*/
|
|
756
|
+
passLeader(roomId, memberId, targetId) {
|
|
757
|
+
const room = this.#rooms.get(roomId);
|
|
758
|
+
if (room === undefined)
|
|
759
|
+
return { ok: false, reason: 'no-room' };
|
|
760
|
+
if (!isRoomMember(room, memberId))
|
|
761
|
+
return { ok: false, reason: 'not-member' };
|
|
762
|
+
if (room.leader !== memberId)
|
|
763
|
+
return { ok: false, reason: 'not-leader' };
|
|
764
|
+
if (targetId === memberId)
|
|
765
|
+
return { ok: true, room: this.view(room) };
|
|
766
|
+
if (!passRoomLeader(room, targetId))
|
|
767
|
+
return { ok: false, reason: 'target-not-member' };
|
|
768
|
+
this.persist(room);
|
|
769
|
+
this.log({ event: 'leader-passed', roomId, memberId, targetId });
|
|
770
|
+
return { ok: true, room: this.view(room) };
|
|
771
|
+
}
|
|
750
772
|
/**
|
|
751
773
|
* The leader removes `targetId` from whatever game seat they hold, to the spectator row.
|
|
752
774
|
* Idempotent: a target who holds none is still answered `ok`. Never touches membership — they
|
|
@@ -51,6 +51,11 @@ export declare function addRoomMember<M extends MemberRow>(room: MembershipRoom<
|
|
|
51
51
|
* seat, a series) and persisting the room.
|
|
52
52
|
*/
|
|
53
53
|
export declare function removeRoomMember<M extends MemberRow>(room: MembershipRoom<M>, id: string): M | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Hand the room's leadership to the member `to`. Answers false, changing nothing, when `to` is not a
|
|
56
|
+
* member. The caller has checked the hand-off is the current leader's to make, and persists the room.
|
|
57
|
+
*/
|
|
58
|
+
export declare function passRoomLeader<M extends MemberRow>(room: MembershipRoom<M>, to: string): boolean;
|
|
54
59
|
/** `memberId`'s readiness for whatever the room is about to start. */
|
|
55
60
|
export declare function isMemberReady(room: Pick<MembershipRoom<MemberRow>, 'ledger'>, memberId: string): boolean;
|
|
56
61
|
/** Sets `memberId`'s readiness. The caller still owns every side effect a readiness change has on ITS game (a pod auto-seat, a tournament lock, …) and persisting the room. */
|
package/dist/room/membership.js
CHANGED
|
@@ -57,6 +57,17 @@ export function removeRoomMember(room, id) {
|
|
|
57
57
|
room.leader = newLeader;
|
|
58
58
|
return removed;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Hand the room's leadership to the member `to`. Answers false, changing nothing, when `to` is not a
|
|
62
|
+
* member. The caller has checked the hand-off is the current leader's to make, and persists the room.
|
|
63
|
+
*/
|
|
64
|
+
export function passRoomLeader(room, to) {
|
|
65
|
+
if (!isRoomMember(room, to))
|
|
66
|
+
return false;
|
|
67
|
+
room.ledger.leaderId = to;
|
|
68
|
+
room.leader = to;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
60
71
|
/** `memberId`'s readiness for whatever the room is about to start. */
|
|
61
72
|
export function isMemberReady(room, memberId) {
|
|
62
73
|
return isReady(room.ledger, memberId);
|
package/dist/room/record.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface PlatformRoomRecord<G, M extends PlatformMember = PlatformMember
|
|
|
30
30
|
id: string;
|
|
31
31
|
name: string;
|
|
32
32
|
creator: string;
|
|
33
|
-
/** Mirrors `ledger.leaderId`, kept non-null; it moves
|
|
33
|
+
/** Mirrors `ledger.leaderId`, kept non-null; it moves when the leader leaves or hands it on (`membership.ts`). */
|
|
34
34
|
leader: string;
|
|
35
35
|
gameType: string;
|
|
36
36
|
/** A seeded, admin-only room: never swept (`room-list.ts`). */
|
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.25",
|
|
4
|
+
"gitHead": "7bd6f116fbcfe910127a8ca55b0e23e9b33a84c0",
|
|
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.25",
|
|
20
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.25",
|
|
21
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.58",
|
|
22
22
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
|
|
23
23
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.102",
|
|
24
24
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.102",
|