@hadoku/game-server 0.1.159 → 0.1.161
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/play/clock.d.ts +16 -1
- package/dist/play/clock.js +27 -3
- package/dist/play/host.d.ts +3 -0
- package/dist/play/host.js +4 -1
- package/dist/play/match/hosted.d.ts +1 -0
- package/dist/play/match/shell.d.ts +12 -0
- package/dist/play/match/shell.js +36 -0
- package/package.json +5 -5
package/dist/play/clock.d.ts
CHANGED
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
* exists. Every game of a series starts from the whole clock.
|
|
15
15
|
*/
|
|
16
16
|
export type Pair<T> = [T, T];
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* One seat's clock as a screen draws it: `ms` left as of the moment it was read, and whether it is running.
|
|
19
|
+
* `paused`: the room's leader (or an operator) has stopped both clocks ({@link ChessClock.pause}); absent otherwise.
|
|
20
|
+
*/
|
|
18
21
|
export interface ClockReading {
|
|
19
22
|
ms: number;
|
|
20
23
|
running: boolean;
|
|
24
|
+
paused?: true;
|
|
21
25
|
}
|
|
22
26
|
export declare class ChessClock {
|
|
23
27
|
#private;
|
|
@@ -30,6 +34,17 @@ export declare class ChessClock {
|
|
|
30
34
|
set(running: readonly [boolean, boolean], now: number): boolean;
|
|
31
35
|
/** Stop both seats: the game is over, or the server is letting go of it. */
|
|
32
36
|
stop(now: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* `ms` more on `seat`'s clock from `now` (the room's leader, or an operator, making good time a
|
|
39
|
+
* crash or a ruling cost a player). A seat at zero that is still running gets the time too.
|
|
40
|
+
*/
|
|
41
|
+
add(seat: 0 | 1, ms: number, now: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Hold both clocks still from `now`, or let them run again. While paused {@link set} runs no seat;
|
|
44
|
+
* the caller's next {@link set} starts the seats the game waits on again once it is let go.
|
|
45
|
+
*/
|
|
46
|
+
pause(paused: boolean, now: number): void;
|
|
47
|
+
get paused(): boolean;
|
|
33
48
|
/** Each seat's time left at `now`. */
|
|
34
49
|
left(now: number): Pair<number>;
|
|
35
50
|
reading(now: number): Pair<ClockReading>;
|
package/dist/play/clock.js
CHANGED
|
@@ -17,6 +17,8 @@ export class ChessClock {
|
|
|
17
17
|
#left;
|
|
18
18
|
/** When each running seat last started (or was last read), null while it is stopped. */
|
|
19
19
|
#since = [null, null];
|
|
20
|
+
/** Both seats held still, whatever the game waits on ({@link pause}). */
|
|
21
|
+
#paused = false;
|
|
20
22
|
constructor(left) {
|
|
21
23
|
this.#left = [Math.max(0, left[0]), Math.max(0, left[1])];
|
|
22
24
|
}
|
|
@@ -39,7 +41,7 @@ export class ChessClock {
|
|
|
39
41
|
this.#settle(now);
|
|
40
42
|
let moved = false;
|
|
41
43
|
for (const seat of [0, 1]) {
|
|
42
|
-
const on = running[seat];
|
|
44
|
+
const on = running[seat] && !this.#paused;
|
|
43
45
|
if (on === (this.#since[seat] !== null))
|
|
44
46
|
continue;
|
|
45
47
|
this.#since[seat] = on ? now : null;
|
|
@@ -51,6 +53,27 @@ export class ChessClock {
|
|
|
51
53
|
stop(now) {
|
|
52
54
|
this.set([false, false], now);
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* `ms` more on `seat`'s clock from `now` (the room's leader, or an operator, making good time a
|
|
58
|
+
* crash or a ruling cost a player). A seat at zero that is still running gets the time too.
|
|
59
|
+
*/
|
|
60
|
+
add(seat, ms, now) {
|
|
61
|
+
this.#settle(now);
|
|
62
|
+
this.#left[seat] += Math.max(0, Math.round(ms));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hold both clocks still from `now`, or let them run again. While paused {@link set} runs no seat;
|
|
66
|
+
* the caller's next {@link set} starts the seats the game waits on again once it is let go.
|
|
67
|
+
*/
|
|
68
|
+
pause(paused, now) {
|
|
69
|
+
this.#settle(now);
|
|
70
|
+
this.#paused = paused;
|
|
71
|
+
if (paused)
|
|
72
|
+
this.#since[0] = this.#since[1] = null;
|
|
73
|
+
}
|
|
74
|
+
get paused() {
|
|
75
|
+
return this.#paused;
|
|
76
|
+
}
|
|
54
77
|
/** Each seat's time left at `now`. */
|
|
55
78
|
left(now) {
|
|
56
79
|
this.#settle(now);
|
|
@@ -58,9 +81,10 @@ export class ChessClock {
|
|
|
58
81
|
}
|
|
59
82
|
reading(now) {
|
|
60
83
|
const left = this.left(now);
|
|
84
|
+
const paused = this.#paused ? { paused: true } : {};
|
|
61
85
|
return [
|
|
62
|
-
{ ms: left[0], running: this.#since[0] !== null },
|
|
63
|
-
{ ms: left[1], running: this.#since[1] !== null },
|
|
86
|
+
{ ms: left[0], running: this.#since[0] !== null, ...paused },
|
|
87
|
+
{ ms: left[1], running: this.#since[1] !== null, ...paused },
|
|
64
88
|
];
|
|
65
89
|
}
|
|
66
90
|
/** The running seat whose time runs out first, and in how long from `now`; null while no seat runs. */
|
package/dist/play/host.d.ts
CHANGED
|
@@ -268,6 +268,7 @@ export interface MatchHost<C extends {
|
|
|
268
268
|
remember?(state: Durable & {
|
|
269
269
|
snapshot?: TurnSnapshot | null;
|
|
270
270
|
clockMs?: [number, number];
|
|
271
|
+
clockPaused?: boolean;
|
|
271
272
|
}): void;
|
|
272
273
|
/**
|
|
273
274
|
* The server is going down and this match is being LEFT RUNNING. Let go of
|
|
@@ -312,6 +313,8 @@ export interface MatchRecord extends Pick<Durable, 'owners' | 'checkpoint'> {
|
|
|
312
313
|
snapshot?: TurnSnapshot | null;
|
|
313
314
|
/** Each seat's chess-clock time left when the match last wrote this record; absent with no clock. */
|
|
314
315
|
clockMs?: [number, number];
|
|
316
|
+
/** The room's leader or an operator had paused the chess clock (`ChessClock.pause`); absent while it may run. */
|
|
317
|
+
clockPaused?: true;
|
|
315
318
|
/** When the server that ran it handed its JVM over. */
|
|
316
319
|
orphanedAt?: string;
|
|
317
320
|
}
|
package/dist/play/host.js
CHANGED
|
@@ -212,6 +212,7 @@ export function readJvmRecord(dir) {
|
|
|
212
212
|
...(isTurnSnapshot(m.snapshot) ? { snapshot: m.snapshot } : {}),
|
|
213
213
|
spec: m.spec,
|
|
214
214
|
...(isClockMs(m.clockMs) ? { clockMs: m.clockMs } : {}),
|
|
215
|
+
...(m.clockPaused === true ? { clockPaused: true } : {}),
|
|
215
216
|
})),
|
|
216
217
|
};
|
|
217
218
|
}
|
|
@@ -690,14 +691,16 @@ export function jvmHostFactory(config, options = {}) {
|
|
|
690
691
|
},
|
|
691
692
|
stop: () => stopMatch(h),
|
|
692
693
|
remember: (state) => {
|
|
694
|
+
const { clockPaused: _was, ...entry } = h.entry;
|
|
693
695
|
h.entry = {
|
|
694
|
-
...
|
|
696
|
+
...entry,
|
|
695
697
|
epoch: state.epoch,
|
|
696
698
|
owners: state.owners,
|
|
697
699
|
// Whatever the caller's own game last had of its `{ t: 'checkpoint' }` line — see `Durable`'s own doc.
|
|
698
700
|
checkpoint: state.checkpoint ?? null,
|
|
699
701
|
...(state.snapshot === undefined ? {} : { snapshot: state.snapshot }),
|
|
700
702
|
...(state.clockMs === undefined ? {} : { clockMs: state.clockMs }),
|
|
703
|
+
...(state.clockPaused === true ? { clockPaused: true } : {}),
|
|
701
704
|
};
|
|
702
705
|
writeRecord(h.jvm);
|
|
703
706
|
},
|
|
@@ -54,6 +54,7 @@ export declare abstract class HostedMatch<Line extends {
|
|
|
54
54
|
snapshot?: TurnSnapshot | null;
|
|
55
55
|
checkpoint?: unknown;
|
|
56
56
|
clockMs?: [number, number];
|
|
57
|
+
clockPaused?: boolean;
|
|
57
58
|
});
|
|
58
59
|
/**
|
|
59
60
|
* The newest `{ t: 'checkpoint' }` line any `onLine` override classified, kept exactly like
|
|
@@ -245,6 +245,17 @@ export declare abstract class MatchShell<Line extends {
|
|
|
245
245
|
* {@link checkWaitingOn}, and every bar {@link send} puts on the wire.
|
|
246
246
|
*/
|
|
247
247
|
syncClock(): void;
|
|
248
|
+
/**
|
|
249
|
+
* `ms` more on `seat`'s chess clock, the room's leader's or an operator's (`table-actions.ts`'s
|
|
250
|
+
* `/clock/add`). False when there is nothing to add to: no clock, or no game running on it.
|
|
251
|
+
*/
|
|
252
|
+
addClockTime(seat: 0 | 1, ms: number): boolean;
|
|
253
|
+
/** Hold both chess clocks still, or let them run again (`table-actions.ts`'s `/clock/pause`). False: no clock, or no game running on it. */
|
|
254
|
+
pauseClock(paused: boolean): boolean;
|
|
255
|
+
/** Whether the chess clock is paused ({@link pauseClock}); false in a game without one. */
|
|
256
|
+
get clockPaused(): boolean;
|
|
257
|
+
/** A clock changed by hand: the flag is timed again, every screen redraws it, and a restore keeps it. */
|
|
258
|
+
private clockChanged;
|
|
248
259
|
/** A seat whose clock a game's own rule holds still while it is waited on. None, unless a game says so. */
|
|
249
260
|
protected clockHeld(_seat: number): boolean;
|
|
250
261
|
/**
|
|
@@ -372,6 +383,7 @@ export declare abstract class MatchShell<Line extends {
|
|
|
372
383
|
snapshot?: TurnSnapshot | null;
|
|
373
384
|
checkpoint?: unknown;
|
|
374
385
|
clockMs?: [number, number];
|
|
386
|
+
clockPaused?: boolean;
|
|
375
387
|
});
|
|
376
388
|
/** One line from the engine, as the composing match reads it: a concede the engine never ends ends here as its game-over would. */
|
|
377
389
|
protected abstract onLine(line: Line): void;
|
package/dist/play/match/shell.js
CHANGED
|
@@ -154,6 +154,7 @@ export class MatchShell {
|
|
|
154
154
|
checkpoint: this.latestCheckpoint,
|
|
155
155
|
snapshot: this.latestSnapshot,
|
|
156
156
|
...(clockMs === null ? {} : { clockMs }),
|
|
157
|
+
...(this.clockPaused ? { clockPaused: true } : {}),
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
/** Each seat's chess-clock time left, or null in a game without one. */
|
|
@@ -178,6 +179,39 @@ export class MatchShell {
|
|
|
178
179
|
this.armFlag(now);
|
|
179
180
|
this.game.tellRoster();
|
|
180
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* `ms` more on `seat`'s chess clock, the room's leader's or an operator's (`table-actions.ts`'s
|
|
184
|
+
* `/clock/add`). False when there is nothing to add to: no clock, or no game running on it.
|
|
185
|
+
*/
|
|
186
|
+
addClockTime(seat, ms) {
|
|
187
|
+
if (this.clock === null || this.status !== 'running' || this.timedOut !== null)
|
|
188
|
+
return false;
|
|
189
|
+
const now = this.now();
|
|
190
|
+
this.clock.add(seat, ms, now);
|
|
191
|
+
this.clockChanged(now);
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
/** Hold both chess clocks still, or let them run again (`table-actions.ts`'s `/clock/pause`). False: no clock, or no game running on it. */
|
|
195
|
+
pauseClock(paused) {
|
|
196
|
+
if (this.clock === null || this.status !== 'running' || this.timedOut !== null)
|
|
197
|
+
return false;
|
|
198
|
+
const now = this.now();
|
|
199
|
+
this.clock.pause(paused, now);
|
|
200
|
+
this.syncClock();
|
|
201
|
+
this.clockChanged(now);
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
/** Whether the chess clock is paused ({@link pauseClock}); false in a game without one. */
|
|
205
|
+
get clockPaused() {
|
|
206
|
+
return this.clock?.paused ?? false;
|
|
207
|
+
}
|
|
208
|
+
/** A clock changed by hand: the flag is timed again, every screen redraws it, and a restore keeps it. */
|
|
209
|
+
clockChanged(now) {
|
|
210
|
+
this.armFlag(now);
|
|
211
|
+
this.game.tellRoster();
|
|
212
|
+
this.remember();
|
|
213
|
+
this.deps.log({ evt: 'clock-changed', matchId: this.id, left: this.clockLeft(), paused: this.clockPaused });
|
|
214
|
+
}
|
|
181
215
|
/** A seat whose clock a game's own rule holds still while it is waited on. None, unless a game says so. */
|
|
182
216
|
clockHeld(_seat) {
|
|
183
217
|
return false;
|
|
@@ -617,6 +651,8 @@ export class MatchShell {
|
|
|
617
651
|
// server was down for is nobody's (`remember`'s callers say how stale that can be).
|
|
618
652
|
const clockMs = restore?.clockMs ?? spec.clockMs;
|
|
619
653
|
this.clock = clockMs === undefined ? null : new ChessClock(clockMs);
|
|
654
|
+
if (restore?.clockPaused === true)
|
|
655
|
+
this.clock?.pause(true, this.now());
|
|
620
656
|
this.startedAt = restore?.startedAt ?? this.now();
|
|
621
657
|
this.epoch = restore?.epoch ?? `${id}:${this.startedAt}`;
|
|
622
658
|
this.latestSnapshot = restore?.snapshot ?? null;
|
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.161",
|
|
4
|
+
"gitHead": "030986f487059f23e2dfd3f37d7597bbb1059f4b",
|
|
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.",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"play/remote/"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.
|
|
21
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
22
|
-
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.
|
|
20
|
+
"@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.161",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.161",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.194",
|
|
23
23
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
|
|
24
24
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.143",
|
|
25
25
|
"@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.143",
|