@chaos-overlords/kernel 0.9.9 → 0.9.11
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/domain/entities.d.ts +11 -0
- package/dist/domain/entities.d.ts.map +1 -1
- package/dist/domain/entities.js +9 -0
- package/dist/domain/entities.js.map +1 -1
- package/dist/logic/turn-logic.d.ts +10 -0
- package/dist/logic/turn-logic.d.ts.map +1 -1
- package/dist/logic/turn-logic.js +20 -0
- package/dist/logic/turn-logic.js.map +1 -1
- package/dist/ports/index.d.ts +1 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +1 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/rateLimits.d.ts +52 -0
- package/dist/ports/rateLimits.d.ts.map +1 -0
- package/dist/ports/rateLimits.js +2 -0
- package/dist/ports/rateLimits.js.map +1 -0
- package/dist/ports/storage.d.ts +28 -8
- package/dist/ports/storage.d.ts.map +1 -1
- package/dist/services/LobbyService.d.ts +15 -1
- package/dist/services/LobbyService.d.ts.map +1 -1
- package/dist/services/LobbyService.js +86 -16
- package/dist/services/LobbyService.js.map +1 -1
- package/dist/services/MatchQueryService.d.ts.map +1 -1
- package/dist/services/MatchQueryService.js +13 -8
- package/dist/services/MatchQueryService.js.map +1 -1
- package/dist/services/RateLimiter.d.ts +97 -21
- package/dist/services/RateLimiter.d.ts.map +1 -1
- package/dist/services/RateLimiter.js +161 -17
- package/dist/services/RateLimiter.js.map +1 -1
- package/dist/services/SnapshotService.d.ts +6 -3
- package/dist/services/SnapshotService.d.ts.map +1 -1
- package/dist/services/SnapshotService.js +12 -7
- package/dist/services/SnapshotService.js.map +1 -1
- package/dist/services/TurnService.d.ts +27 -2
- package/dist/services/TurnService.d.ts.map +1 -1
- package/dist/services/TurnService.js +70 -13
- package/dist/services/TurnService.js.map +1 -1
- package/dist/services/deps.d.ts +7 -0
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/testing/InMemoryStorage.d.ts.map +1 -1
- package/dist/testing/InMemoryStorage.js +30 -11
- package/dist/testing/InMemoryStorage.js.map +1 -1
- package/package.json +2 -2
|
@@ -163,7 +163,18 @@ export interface PublicLobbyRow extends LobbyListing {
|
|
|
163
163
|
export interface MatchSeat {
|
|
164
164
|
matchId: string;
|
|
165
165
|
slot: number;
|
|
166
|
+
/** Whether the computer plays the row's seat, which a late joiner may then claim. */
|
|
167
|
+
computer: boolean;
|
|
168
|
+
/** Whether the row's claim on the seat is over: see `isVacated`. */
|
|
169
|
+
vacated: boolean;
|
|
166
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Whether a player row no longer holds any claim on its seat: the computer plays it and nobody
|
|
173
|
+
* holds a token that could take it back. A late joiner may claim a seat whose every row is
|
|
174
|
+
* computer controlled, and claiming it releases the tokens that are left, which makes those rows
|
|
175
|
+
* vacated. See the 2026-10-06 late-join decision.
|
|
176
|
+
*/
|
|
177
|
+
export declare function isVacated(player: Pick<Player, 'status' | 'tokenHash'>): boolean;
|
|
167
178
|
export type TakeoverDecision = 'computer' | 'wait';
|
|
168
179
|
export interface TakeoverVote {
|
|
169
180
|
matchId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/domain/entities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,oEAAoE;IACpE,eAAe,EAAE,MAAM,CAAA;IACvB;;;;;;;OAOG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,WAAW,CAAA;IACnB,QAAQ,EAAE,aAAa,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,GA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,CAAA;IAC1B,MAAM,EAAE,IAAI,CAAA;CACb;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAA;AAEvC,eAAO,MAAM,aAAa,EAAE,YAAuB,CAAA;AAEnD,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAElE;AAED,yFAAyF;AACzF,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,YAAY,CAI7D,CAAA;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,OAAO,CAE1E;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAEtE;AAED,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,OAAO,CAElE"}
|
package/dist/domain/entities.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a player row no longer holds any claim on its seat: the computer plays it and nobody
|
|
3
|
+
* holds a token that could take it back. A late joiner may claim a seat whose every row is
|
|
4
|
+
* computer controlled, and claiming it releases the tokens that are left, which makes those rows
|
|
5
|
+
* vacated. See the 2026-10-06 late-join decision.
|
|
6
|
+
*/
|
|
7
|
+
export function isVacated(player) {
|
|
8
|
+
return player.status === 'computer' && player.tokenHash === null;
|
|
9
|
+
}
|
|
1
10
|
export const ACTIVE_PLAYER = 'active';
|
|
2
11
|
export function activePlayers(players) {
|
|
3
12
|
return players.filter((player) => player.status === ACTIVE_PLAYER);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/domain/entities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/domain/entities.ts"],"names":[],"mappings":"AAkMA;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,MAA4C;IACpE,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,CAAA;AAClE,CAAC;AAcD,MAAM,CAAC,MAAM,aAAa,GAAiB,QAAQ,CAAA;AAEnD,MAAM,UAAU,aAAa,CAAC,OAA0B;IACtD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,aAAa,CAAC,CAAA;AACpE,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,qBAAqB,GAAgC;IAChE,iBAAiB;IACjB,MAAM;IACN,QAAQ;CACT,CAAA;AAED,kGAAkG;AAClG,MAAM,UAAU,kBAAkB,CAAC,MAA8B;IAC/D,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,KAAK,iBAAiB,CAAA;AAC1E,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,iBAAiB,CAAC,OAA0B;IAC1D,OAAO,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAC3C,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,KAA4B;IACvD,OAAO,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,CAAA;AAClE,CAAC"}
|
|
@@ -49,6 +49,16 @@ export type Consensus = {
|
|
|
49
49
|
* majority's state is right even when the host's own client happens to be the correct one.
|
|
50
50
|
*/
|
|
51
51
|
export declare function authoritativeCandidates(players: readonly Player[], reports: readonly TurnReport[]): string[];
|
|
52
|
+
/**
|
|
53
|
+
* The one player who may break a tie between reported states, or null when there is no tie.
|
|
54
|
+
*
|
|
55
|
+
* The host, when the host's own report is one of the tied hashes; otherwise the lowest-numbered
|
|
56
|
+
* human seat whose report is. A tie has no majority to defer to, so somebody has to be named, and
|
|
57
|
+
* naming the host alone left a match of five or six paused for good whenever the host's report was
|
|
58
|
+
* outside the tie (two reports each for two hashes, the host's alone on a third): the host could
|
|
59
|
+
* not claim a hash it never computed and nobody else was allowed to.
|
|
60
|
+
*/
|
|
61
|
+
export declare function tieBreaker(players: readonly Player[], reports: readonly TurnReport[], candidates: readonly string[], hostPlayerId: string): string | null;
|
|
52
62
|
/**
|
|
53
63
|
* Compare the post-turn state hashes the human seats reported.
|
|
54
64
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-logic.d.ts","sourceRoot":"","sources":["../../src/logic/turn-logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAA;AAE3B;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,MAAM,EAAE,CAKV;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,GAC5D,OAAO,CAMT;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,GAAG,OAAO,CAGrF;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC3D;IACE,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM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C;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAElF"}
|
package/dist/logic/turn-logic.js
CHANGED
|
@@ -62,6 +62,26 @@ export function authoritativeCandidates(players, reports) {
|
|
|
62
62
|
.map(([stateHash]) => stateHash)
|
|
63
63
|
.sort();
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The one player who may break a tie between reported states, or null when there is no tie.
|
|
67
|
+
*
|
|
68
|
+
* The host, when the host's own report is one of the tied hashes; otherwise the lowest-numbered
|
|
69
|
+
* human seat whose report is. A tie has no majority to defer to, so somebody has to be named, and
|
|
70
|
+
* naming the host alone left a match of five or six paused for good whenever the host's report was
|
|
71
|
+
* outside the tie (two reports each for two hashes, the host's alone on a third): the host could
|
|
72
|
+
* not claim a hash it never computed and nobody else was allowed to.
|
|
73
|
+
*/
|
|
74
|
+
export function tieBreaker(players, reports, candidates, hostPlayerId) {
|
|
75
|
+
if (candidates.length < 2)
|
|
76
|
+
return null;
|
|
77
|
+
const tied = new Set(candidates);
|
|
78
|
+
const holders = new Set(reports.filter((report) => tied.has(report.stateHash)).map((report) => report.playerId));
|
|
79
|
+
const eligible = humanParticipants(players).filter((player) => holders.has(player.id));
|
|
80
|
+
if (eligible.some((player) => player.id === hostPlayerId))
|
|
81
|
+
return hostPlayerId;
|
|
82
|
+
const lowest = [...eligible].sort((a, b) => a.slot - b.slot)[0];
|
|
83
|
+
return lowest?.id ?? null;
|
|
84
|
+
}
|
|
65
85
|
/**
|
|
66
86
|
* Compare the post-turn state hashes the human seats reported.
|
|
67
87
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-logic.js","sourceRoot":"","sources":["../../src/logic/turn-logic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GAKnB,MAAM,oBAAoB,CAAA;AAE3B;;;;;;;;;GASG;AACH,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QAAQ,CAAC,OAAO,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC7F,CAAC"}
|
package/dist/ports/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
|
package/dist/ports/index.js
CHANGED
package/dist/ports/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The budget one rate limit enforces: at most `limit` calls per key in a fixed window of
|
|
3
|
+
* `windowMs` that opens on the key's first call.
|
|
4
|
+
*/
|
|
5
|
+
export interface RateLimitPolicy {
|
|
6
|
+
limit: number;
|
|
7
|
+
windowMs: number;
|
|
8
|
+
}
|
|
9
|
+
/** A key's window after a {@link RateLimitStore.consume}. */
|
|
10
|
+
export interface RateLimitWindow {
|
|
11
|
+
/** Whether the call that produced this answer was counted, i.e. the window had room for it. */
|
|
12
|
+
allowed: boolean;
|
|
13
|
+
/** Calls counted in the window, never above the policy's limit. */
|
|
14
|
+
count: number;
|
|
15
|
+
/** When the window opened, in epoch milliseconds. Names the window for a refund. */
|
|
16
|
+
windowStart: number;
|
|
17
|
+
/** When the window rolls, in epoch milliseconds. */
|
|
18
|
+
resetAt: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A fixed-window counter that every instance of a deployment shares.
|
|
22
|
+
*
|
|
23
|
+
* The in-process {@link MemoryRateLimiter} counts what one process or one isolate sees, which is
|
|
24
|
+
* the whole picture for a single self-hosted server and a fraction of it anywhere else: two Node
|
|
25
|
+
* instances behind a load balancer each grant the full budget, and a Cloudflare isolate is one of
|
|
26
|
+
* many. A runtime that runs as more than one instance implements this port in storage every
|
|
27
|
+
* instance reaches (a Postgres table, a Durable Object per key), and the kernel's
|
|
28
|
+
* {@link SharedRateLimiter} keeps the limiter semantics on top of it.
|
|
29
|
+
*
|
|
30
|
+
* Keys arrive already namespaced by limiter, so one store holds every tier. Times are epoch
|
|
31
|
+
* milliseconds from the caller's clock: instances of one deployment agree on the time to well
|
|
32
|
+
* under a second, and a window is a minute or a day.
|
|
33
|
+
*/
|
|
34
|
+
export interface RateLimitStore {
|
|
35
|
+
/**
|
|
36
|
+
* Counts one call against `key` if its window has room, atomically with respect to every other
|
|
37
|
+
* caller. A window that has rolled (its `resetAt` is at or before `now`) is replaced by a fresh
|
|
38
|
+
* one opening at `now`, and the call is counted in that.
|
|
39
|
+
*/
|
|
40
|
+
consume(key: string, policy: RateLimitPolicy, now: number): Promise<RateLimitWindow>;
|
|
41
|
+
/** The live window of `key` at `now`, spending nothing; null when it has rolled or never opened. */
|
|
42
|
+
inspect(key: string, now: number): Promise<{
|
|
43
|
+
count: number;
|
|
44
|
+
resetAt: number;
|
|
45
|
+
} | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Gives back one call counted in the window that opened at `windowStart`. A key whose window has
|
|
48
|
+
* since rolled is left alone, so a late refund never credits a newer window.
|
|
49
|
+
*/
|
|
50
|
+
refund(key: string, windowStart: number): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=rateLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimits.d.ts","sourceRoot":"","sources":["../../src/ports/rateLimits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,+FAA+F;IAC/F,OAAO,EAAE,OAAO,CAAA;IAChB,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAA;IACb,oFAAoF;IACpF,WAAW,EAAE,MAAM,CAAA;IACnB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACpF,oGAAoG;IACpG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;IACrF;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimits.js","sourceRoot":"","sources":["../../src/ports/rateLimits.ts"],"names":[],"mappings":""}
|
package/dist/ports/storage.d.ts
CHANGED
|
@@ -110,13 +110,27 @@ export interface PlayerRepository {
|
|
|
110
110
|
*/
|
|
111
111
|
create(player: Player): Promise<boolean>;
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
113
|
+
* Seats a deterministic-id late member after start and releases the seat's former players, as
|
|
114
|
+
* ONE atomic unit: the insert, and the revocation of the token of every computer-controlled row
|
|
115
|
+
* of the seat, which ends a former player's right to `rejoin` it. Returns the ids it revoked
|
|
116
|
+
* (empty when the seat had none to revoke), or null when it refused, in which case nothing was
|
|
117
|
+
* revoked either.
|
|
114
118
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
* It refuses when the match is not running, when the id is taken, when a row of the seat is not
|
|
120
|
+
* computer controlled (a human holds it, or a former player took it back a moment earlier), and
|
|
121
|
+
* when the match is at `maxPlayers` counting the rows that still hold a claim (see `isVacated`)
|
|
122
|
+
* once the seat's computer rows are released.
|
|
123
|
+
*
|
|
124
|
+
* Capacity is part of the unit because two late joiners taking two different free slots each
|
|
125
|
+
* passed a capacity check the other invalidated, and the match ended up over capacity with a
|
|
126
|
+
* roster the match view's seat schema then refused. The release is part of it because a claim
|
|
127
|
+
* refused after a separate release left the seat with nobody: the former player had lost the
|
|
128
|
+
* right to return and the claimant had not taken it. A `rejoin` racing the claim either lands
|
|
129
|
+
* first, so the claim refuses, or finds its token revoked.
|
|
130
|
+
*/
|
|
131
|
+
createLate(player: Player): Promise<{
|
|
132
|
+
released: string[];
|
|
133
|
+
} | null>;
|
|
120
134
|
get(id: string): Promise<Player | null>;
|
|
121
135
|
/** Never matches a revoked membership, whose token hash is null. */
|
|
122
136
|
getByTokenHash(tokenHash: string): Promise<Player | null>;
|
|
@@ -129,8 +143,14 @@ export interface PlayerRepository {
|
|
|
129
143
|
*/
|
|
130
144
|
listSeats(matchIds: readonly string[]): Promise<MatchSeat[]>;
|
|
131
145
|
setStatus(playerId: string, status: Player['status']): Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Compare-and-swap a player status; exactly one return/takeover race may win. With
|
|
148
|
+
* `holdingToken`, the row must also still hold a token, which is how `rejoin` loses to a late
|
|
149
|
+
* joiner who released the seat after the returning player authenticated.
|
|
150
|
+
*/
|
|
151
|
+
transitionStatus(playerId: string, from: readonly Player['status'][], status: Player['status'], options?: {
|
|
152
|
+
holdingToken?: boolean;
|
|
153
|
+
}): Promise<boolean>;
|
|
134
154
|
/**
|
|
135
155
|
* Replace an active lobby member's name and portrait, in ONE statement conditional on the match
|
|
136
156
|
* still being in the lobby. False when the match has started (or is gone) or the player is not
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/ports/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EACX,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,MAAM,EACN,aAAa,EACb,cAAc,EACd,UAAU,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,UAAU,EACX,MAAM,oBAAoB,CAAA;AAE3B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAe;IAC9B,iGAAiG;IACjG,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACtC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;IACtC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;IACtD;;;;;;;;;OASG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IACpF;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAClD;;;;;;;OAOG;IACH,kBAAkB,CAAC,OAAO,EAAE,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MatchRequest, type JoinMatchRequest, type JoinRunningMatchRequest, type MatchSettings, type MembershipView, type TakeoverVoteRequest, type UpdatePlayerProfileRequest } from '@chaos-overlords/contracts';
|
|
1
|
+
import { type CreateMatchRequest, type JoinMatchRequest, type JoinRunningMatchRequest, type MatchSettings, type MembershipView, type PostChatMessageRequest, type TakeoverVoteRequest, type UpdatePlayerProfileRequest } from '@chaos-overlords/contracts';
|
|
2
2
|
import type { Principal } from './AuthService';
|
|
3
3
|
import type { KernelDeps } from './deps';
|
|
4
4
|
import type { EventPublisher } from './EventPublisher';
|
|
@@ -16,6 +16,7 @@ export declare class LobbyService {
|
|
|
16
16
|
private readonly newId;
|
|
17
17
|
private readonly passwordAttempts;
|
|
18
18
|
private readonly passwordFailures;
|
|
19
|
+
private readonly chatMessages;
|
|
19
20
|
constructor(deps: KernelDeps, publisher: EventPublisher, turns: TurnService, options?: LobbyServiceOptions);
|
|
20
21
|
/**
|
|
21
22
|
* Check a match password, charging two budgets before the hash is computed.
|
|
@@ -53,6 +54,19 @@ export declare class LobbyService {
|
|
|
53
54
|
* every client has generated its city from.
|
|
54
55
|
*/
|
|
55
56
|
updateProfile(principal: Principal, request: UpdatePlayerProfileRequest): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Post a chat message to the lobby, announced to every member as `lobby.chatMessage`.
|
|
59
|
+
*
|
|
60
|
+
* The log is the message's only store, so it is the log that is bounded: a lobby whose log has
|
|
61
|
+
* reached `LIMITS.lobbyChatLogEvents` takes no more chat. The per-player budget is in memory, like
|
|
62
|
+
* every other limiter here, and spares the log from one member's flood long before that. The
|
|
63
|
+
* length check and the publish are separate steps, so posts that arrive together can each pass
|
|
64
|
+
* the check and carry the log a few events past the cap; it bounds the log without being exact.
|
|
65
|
+
* The budget is spent before the length check so a flood never reaches storage. Refused
|
|
66
|
+
* once the match has started, because inside a match the original's Comlink is the channel
|
|
67
|
+
* between players and its rules say who may write to whom.
|
|
68
|
+
*/
|
|
69
|
+
postChat(principal: Principal, request: PostChatMessageRequest): Promise<void>;
|
|
56
70
|
kick(principal: Principal, targetPlayerId: string): Promise<void>;
|
|
57
71
|
/** The player a host or a voter named, refused unless it is a member of the caller's match. */
|
|
58
72
|
private requireTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LobbyService.d.ts","sourceRoot":"","sources":["../../src/services/LobbyService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAGvB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAChC,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"LobbyService.d.ts","sourceRoot":"","sources":["../../src/services/LobbyService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAGvB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAChC,MAAM,4BAA4B,CAAA;AAqBnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAItD,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAyC5D,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,MAAM,CAAA;CACrB;AAED,0EAA0E;AAC1E,qBAAa,YAAY;IAQrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IATxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO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AAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtE;IAED,+FAA+F;YACjF,aAAa;IAQ3B;;;OAGG;IACG,cAAc,CAClB,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAqCf;IAED;;;;;;;OAOG;YACW,iBAAiB;IAgC/B,8EAA8E;YAChE,kBAAkB;IAM1B,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC/C;YAEa,MAAM;IA+HpB;;;;;;;OAOG;YACW,gBAAgB;IAM9B;;;;OAIG;YACW,UAAU;IAWxB;;;OAGG;YACW,qBAAqB;IAOnC;;;OAGG;YACW,MAAM;IAYpB;;;;;;;;;;;;OAYG;YACW,mBAAmB;IAIjC,OAAO,CAAC,gBAAgB;IASxB;;;;OAIG;YACW,YAAY;YAaZ,OAAO;IAcrB;;;;OAIG;YACW,uBAAuB;YAUvB,UAAU;CAQzB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { foldName, GAME_BOUNDS, LIMITS, } from '@chaos-overlords/contracts';
|
|
2
|
-
import { ABSENT_HUMAN_STATUSES, activePlayers, humanParticipants, isInProgress, } from '../domain/entities';
|
|
2
|
+
import { ABSENT_HUMAN_STATUSES, activePlayers, humanParticipants, isInProgress, isVacated, } from '../domain/entities';
|
|
3
3
|
import { ConflictError, ForbiddenError, NotFoundError, RateLimitedError, UnauthorizedError, } from '../domain/errors';
|
|
4
4
|
import { generateJoinCode, generateSeed, generateToken, hashToken } from '../logic/crypto';
|
|
5
5
|
import { hashPassword, verifyPassword } from '../logic/password';
|
|
6
6
|
import { assignSlots } from '../logic/turn-logic';
|
|
7
7
|
import { requireInProgress } from './guards';
|
|
8
8
|
import { MatchQueryService, matchStartedEvent, toPlayerView } from './MatchQueryService';
|
|
9
|
-
import {
|
|
9
|
+
import { memoryRateLimiters } from './RateLimiter';
|
|
10
10
|
import { FIRST_TURN } from './TurnService';
|
|
11
11
|
const JOIN_CODE_LENGTH = LIMITS.joinCodeLength;
|
|
12
12
|
const MIN_PLAYERS_TO_START = LIMITS.minPlayers;
|
|
@@ -43,6 +43,7 @@ const PASSWORD_ATTEMPTS_PER_CALLER = 10;
|
|
|
43
43
|
*/
|
|
44
44
|
const PASSWORD_FAILURES_PER_MATCH = 30;
|
|
45
45
|
const PASSWORD_ATTEMPT_WINDOW_MS = 60_000;
|
|
46
|
+
const CHAT_WINDOW_MS = 60_000;
|
|
46
47
|
/** Match creation, joining, leaving, kicking and the start transition. */
|
|
47
48
|
export class LobbyService {
|
|
48
49
|
deps;
|
|
@@ -52,20 +53,26 @@ export class LobbyService {
|
|
|
52
53
|
newId;
|
|
53
54
|
passwordAttempts;
|
|
54
55
|
passwordFailures;
|
|
56
|
+
chatMessages;
|
|
55
57
|
constructor(deps, publisher, turns, options = {}) {
|
|
56
58
|
this.deps = deps;
|
|
57
59
|
this.publisher = publisher;
|
|
58
60
|
this.turns = turns;
|
|
59
61
|
this.query = new MatchQueryService(deps.storage);
|
|
60
62
|
this.newId = options.newId ?? (() => crypto.randomUUID());
|
|
61
|
-
|
|
63
|
+
const limiters = deps.rateLimits ?? memoryRateLimiters(deps.clock);
|
|
64
|
+
this.passwordAttempts = limiters('passwordAttempts', {
|
|
62
65
|
limit: PASSWORD_ATTEMPTS_PER_CALLER,
|
|
63
66
|
windowMs: PASSWORD_ATTEMPT_WINDOW_MS,
|
|
64
67
|
});
|
|
65
|
-
this.passwordFailures =
|
|
68
|
+
this.passwordFailures = limiters('passwordFailures', {
|
|
66
69
|
limit: PASSWORD_FAILURES_PER_MATCH,
|
|
67
70
|
windowMs: PASSWORD_ATTEMPT_WINDOW_MS,
|
|
68
71
|
});
|
|
72
|
+
this.chatMessages = limiters('chatMessages', {
|
|
73
|
+
limit: LIMITS.chatMessagesPerMinute,
|
|
74
|
+
windowMs: CHAT_WINDOW_MS,
|
|
75
|
+
});
|
|
69
76
|
}
|
|
70
77
|
/**
|
|
71
78
|
* Check a match password, charging two budgets before the hash is computed.
|
|
@@ -89,16 +96,16 @@ export class LobbyService {
|
|
|
89
96
|
throw new UnauthorizedError('This match needs a password', { reason: 'password_required' });
|
|
90
97
|
}
|
|
91
98
|
const callerKey = `${match.id}:${caller ?? 'unattributed'}`;
|
|
92
|
-
const retry = this.passwordAttempts.take(callerKey);
|
|
99
|
+
const retry = await this.passwordAttempts.take(callerKey);
|
|
93
100
|
if (retry !== null)
|
|
94
101
|
throw this.tooManyPasswordAttempts(retry);
|
|
95
|
-
if (this.passwordAttempts.spent(callerKey) > 1) {
|
|
96
|
-
const underAttack = this.passwordFailures.peek(match.id);
|
|
102
|
+
if ((await this.passwordAttempts.spent(callerKey)) > 1) {
|
|
103
|
+
const underAttack = await this.passwordFailures.peek(match.id);
|
|
97
104
|
if (underAttack !== null)
|
|
98
105
|
throw this.tooManyPasswordAttempts(underAttack);
|
|
99
106
|
}
|
|
100
107
|
if (!(await verifyPassword(password, match.passwordHash))) {
|
|
101
|
-
this.passwordFailures.take(match.id);
|
|
108
|
+
await this.passwordFailures.take(match.id);
|
|
102
109
|
throw new UnauthorizedError('Wrong password', { reason: 'wrong_password' });
|
|
103
110
|
}
|
|
104
111
|
}
|
|
@@ -242,20 +249,30 @@ export class LobbyService {
|
|
|
242
249
|
if (humanParticipants(existing).length === 0) {
|
|
243
250
|
throw new ConflictError('Every player has left this match', { reason: 'match_abandoned' });
|
|
244
251
|
}
|
|
245
|
-
|
|
246
|
-
|
|
252
|
+
// Every row that ever held this seat, oldest first. The seat is open when there are none, or
|
|
253
|
+
// when the computer plays every one of them: a takeover vote passed on each human who held it.
|
|
254
|
+
// A seat whose human is merely absent, kicked or late with a turn is still theirs until the
|
|
255
|
+
// players present vote, so it stays reserved.
|
|
256
|
+
const holders = existing.filter((player) => player.slot === request.slot);
|
|
257
|
+
if (holders.some((player) => player.status !== 'computer')) {
|
|
258
|
+
throw new ConflictError('That seat still belongs to a human', {
|
|
247
259
|
reason: 'seat_reserved',
|
|
248
260
|
});
|
|
249
261
|
}
|
|
262
|
+
// The claims that remain once this one releases the seat's former players.
|
|
263
|
+
const claimants = existing.filter((player) => player.slot !== request.slot && !isVacated(player));
|
|
250
264
|
// A courtesy refusal with the right reason before any work is done; `createLate` tests
|
|
251
265
|
// capacity again inside its own insert, which is what actually decides the race between two
|
|
252
266
|
// late joiners taking two different free seats.
|
|
253
|
-
if (
|
|
267
|
+
if (claimants.length >= match.settings.maxPlayers) {
|
|
254
268
|
throw new ConflictError('The match is full', { reason: 'match_full' });
|
|
255
269
|
}
|
|
256
|
-
this.assertNameIsFree(
|
|
270
|
+
this.assertNameIsFree(claimants, request.displayName);
|
|
257
271
|
const token = generateToken();
|
|
258
|
-
|
|
272
|
+
// Deterministic per claim of the seat, so two callers claiming the same seat at once collide
|
|
273
|
+
// on the id as well as on the occupancy test. The first claim keeps the form ids always had.
|
|
274
|
+
const claim = holders.length === 0 ? '' : `:${holders.length}`;
|
|
275
|
+
const seatKey = (await hashToken(`${match.id}:${request.slot}${claim}`)).slice(0, 32);
|
|
259
276
|
// The position is taken before the insert because the port has no transactions to take both
|
|
260
277
|
// in one; a join `createLate` then refuses leaves a gap in the sequence, which only has to be
|
|
261
278
|
// unique and increasing. The checks above refuse the requests that are doomed from the start.
|
|
@@ -268,16 +285,27 @@ export class LobbyService {
|
|
|
268
285
|
slot: request.slot,
|
|
269
286
|
joinOrder,
|
|
270
287
|
displayName: request.displayName,
|
|
271
|
-
|
|
288
|
+
// A seat a human held wears the face it was generated with, which is its first holder's; the
|
|
289
|
+
// match state never changes it, so the roster must not either. A seat nobody held wears the
|
|
290
|
+
// face the host's settings gave it, which is what the client sends.
|
|
291
|
+
portraitId: holders[0]?.portraitId ?? request.portraitId ?? DEFAULT_PORTRAIT_ID,
|
|
272
292
|
tokenHash: await hashToken(token),
|
|
273
293
|
status: 'active',
|
|
274
294
|
joinedAt: this.deps.clock.now(),
|
|
275
295
|
};
|
|
276
|
-
|
|
296
|
+
// The insert and the end of the former players' right to take the seat back are one unit in
|
|
297
|
+
// storage. A former player whose `rejoin` won the seat a moment earlier is no longer computer
|
|
298
|
+
// controlled, so the claim refuses. A claim that loses the seat to another late joiner, the
|
|
299
|
+
// last place under `maxPlayers` to a late joiner on another seat, or the match to its end
|
|
300
|
+
// revokes nothing, and the former players can still return.
|
|
301
|
+
const claimed = await this.deps.storage.players.createLate(player);
|
|
302
|
+
if (!claimed) {
|
|
277
303
|
throw new ConflictError('That seat was claimed by another player, or the match filled up', {
|
|
278
304
|
reason: 'seat_reserved',
|
|
279
305
|
});
|
|
280
306
|
}
|
|
307
|
+
for (const playerId of claimed.released)
|
|
308
|
+
await this.hangUp(match.id, playerId);
|
|
281
309
|
await this.refreshRetention(match.id);
|
|
282
310
|
await this.topUpCurrentTurn(match.id, player.id);
|
|
283
311
|
await this.publisher.publish(match.id, {
|
|
@@ -309,7 +337,15 @@ export class LobbyService {
|
|
|
309
337
|
return;
|
|
310
338
|
}
|
|
311
339
|
const replacedComputer = player.status === 'computer';
|
|
312
|
-
if (!(await this.deps.storage.players.transitionStatus(player.id, ['left', 'takeoverPending', 'computer'], 'active'
|
|
340
|
+
if (!(await this.deps.storage.players.transitionStatus(player.id, ['left', 'takeoverPending', 'computer'], 'active',
|
|
341
|
+
// A late joiner who claims a computer seat revokes its former player's token first. The
|
|
342
|
+
// returning player authenticated before that, so the token is tested again here.
|
|
343
|
+
{ holdingToken: true }))) {
|
|
344
|
+
if ((await this.deps.storage.players.get(player.id))?.tokenHash === null) {
|
|
345
|
+
throw new ForbiddenError('Another player has taken over this seat', {
|
|
346
|
+
reason: 'seat_taken',
|
|
347
|
+
});
|
|
348
|
+
}
|
|
313
349
|
throw new ConflictError('The player seat could not be reclaimed', { reason: 'rejoin_race' });
|
|
314
350
|
}
|
|
315
351
|
await this.topUpCurrentTurn(match.id, player.id);
|
|
@@ -381,6 +417,40 @@ export class LobbyService {
|
|
|
381
417
|
payload: { player: toPlayerView({ ...player, ...profile }, match.hostPlayerId) },
|
|
382
418
|
});
|
|
383
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Post a chat message to the lobby, announced to every member as `lobby.chatMessage`.
|
|
422
|
+
*
|
|
423
|
+
* The log is the message's only store, so it is the log that is bounded: a lobby whose log has
|
|
424
|
+
* reached `LIMITS.lobbyChatLogEvents` takes no more chat. The per-player budget is in memory, like
|
|
425
|
+
* every other limiter here, and spares the log from one member's flood long before that. The
|
|
426
|
+
* length check and the publish are separate steps, so posts that arrive together can each pass
|
|
427
|
+
* the check and carry the log a few events past the cap; it bounds the log without being exact.
|
|
428
|
+
* The budget is spent before the length check so a flood never reaches storage. Refused
|
|
429
|
+
* once the match has started, because inside a match the original's Comlink is the channel
|
|
430
|
+
* between players and its rules say who may write to whom.
|
|
431
|
+
*/
|
|
432
|
+
async postChat(principal, request) {
|
|
433
|
+
const { match, player } = principal;
|
|
434
|
+
if (match.status !== 'lobby') {
|
|
435
|
+
throw new ConflictError('Chat is open only in the lobby', { reason: 'match_not_in_lobby' });
|
|
436
|
+
}
|
|
437
|
+
const retryAfterSeconds = await this.chatMessages.take(`${match.id}:${player.id}`);
|
|
438
|
+
if (retryAfterSeconds !== null) {
|
|
439
|
+
throw new RateLimitedError('Too many chat messages', {
|
|
440
|
+
reason: 'rate_limited',
|
|
441
|
+
retryAfterSeconds,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if ((await this.deps.storage.events.lastSeq(match.id)) >= LIMITS.lobbyChatLogEvents) {
|
|
445
|
+
throw new ConflictError('This lobby has no room for more chat', {
|
|
446
|
+
reason: 'lobby_log_full',
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
await this.publisher.publish(match.id, {
|
|
450
|
+
type: 'lobby.chatMessage',
|
|
451
|
+
payload: { playerId: player.id, text: request.text },
|
|
452
|
+
});
|
|
453
|
+
}
|
|
384
454
|
async kick(principal, targetPlayerId) {
|
|
385
455
|
const { match, player } = principal;
|
|
386
456
|
requireHost(principal);
|