@hadoku/game-server 0.1.162 → 0.1.164

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.
@@ -195,6 +195,12 @@ export type MatchSpec<G = unknown> = {
195
195
  * Absent: no clock. Inert in the JVM, like `format`.
196
196
  */
197
197
  clockMs?: [number, number];
198
+ /**
199
+ * When the clock may first run: `'ready'` (absent) as soon as the game waits on a seat, the game
200
+ * itself adding any grace; `'seated'` not before every seat's player has been at the game
201
+ * (`MatchShell.clockSeated`). Inert in the JVM.
202
+ */
203
+ clockStart?: 'ready' | 'seated';
198
204
  } & G;
199
205
  /**
200
206
  * The four lines the host and placement read from any engine's own line type `L`; everything else
@@ -269,6 +275,7 @@ export interface MatchHost<C extends {
269
275
  snapshot?: TurnSnapshot | null;
270
276
  clockMs?: [number, number];
271
277
  clockPaused?: boolean;
278
+ clockSeated?: boolean;
272
279
  }): void;
273
280
  /**
274
281
  * The server is going down and this match is being LEFT RUNNING. Let go of
@@ -315,6 +322,8 @@ export interface MatchRecord extends Pick<Durable, 'owners' | 'checkpoint'> {
315
322
  clockMs?: [number, number];
316
323
  /** The room's leader or an operator had paused the chess clock (`ChessClock.pause`); absent while it may run. */
317
324
  clockPaused?: true;
325
+ /** Every seat's player had been at the game, so a `clockStart: 'seated'` clock may run (`MatchShell.clockSeated`). */
326
+ clockSeated?: true;
318
327
  /** When the server that ran it handed its JVM over. */
319
328
  orphanedAt?: string;
320
329
  }
package/dist/play/host.js CHANGED
@@ -213,6 +213,7 @@ export function readJvmRecord(dir) {
213
213
  spec: m.spec,
214
214
  ...(isClockMs(m.clockMs) ? { clockMs: m.clockMs } : {}),
215
215
  ...(m.clockPaused === true ? { clockPaused: true } : {}),
216
+ ...(m.clockSeated === true ? { clockSeated: true } : {}),
216
217
  })),
217
218
  };
218
219
  }
@@ -691,7 +692,7 @@ export function jvmHostFactory(config, options = {}) {
691
692
  },
692
693
  stop: () => stopMatch(h),
693
694
  remember: (state) => {
694
- const { clockPaused: _was, ...entry } = h.entry;
695
+ const { clockPaused: _was, clockSeated: _seated, ...entry } = h.entry;
695
696
  h.entry = {
696
697
  ...entry,
697
698
  epoch: state.epoch,
@@ -701,6 +702,7 @@ export function jvmHostFactory(config, options = {}) {
701
702
  ...(state.snapshot === undefined ? {} : { snapshot: state.snapshot }),
702
703
  ...(state.clockMs === undefined ? {} : { clockMs: state.clockMs }),
703
704
  ...(state.clockPaused === true ? { clockPaused: true } : {}),
705
+ ...(state.clockSeated === true ? { clockSeated: true } : {}),
704
706
  };
705
707
  writeRecord(h.jvm);
706
708
  },
@@ -55,6 +55,7 @@ export declare abstract class HostedMatch<Line extends {
55
55
  checkpoint?: unknown;
56
56
  clockMs?: [number, number];
57
57
  clockPaused?: boolean;
58
+ clockSeated?: boolean;
58
59
  });
59
60
  /**
60
61
  * The newest `{ t: 'checkpoint' }` line any `onLine` override classified, kept exactly like
@@ -134,6 +134,7 @@ export declare abstract class MatchShell<Line extends {
134
134
  }, Cmd extends {
135
135
  t: string;
136
136
  }> {
137
+ #private;
137
138
  readonly id: string;
138
139
  /** Minted per match-process start: a restart is a new epoch. */
139
140
  readonly epoch: string;
@@ -245,6 +246,12 @@ export declare abstract class MatchShell<Line extends {
245
246
  * {@link checkWaitingOn}, and every bar {@link send} puts on the wire.
246
247
  */
247
248
  syncClock(): void;
249
+ /** Whether every seat's player has been at the game, so a `clockStart: 'seated'` clock may run ({@link clockWaitsForSeats}). */
250
+ get clockSeated(): boolean;
251
+ /** No clock runs yet, either seat's: a `clockStart: 'seated'` game whose players have not all been at it. */
252
+ clockWaitsForSeats(): boolean;
253
+ /** The last player has come to a `clockStart: 'seated'` game: from now its clock runs. True only on the call that saw it. */
254
+ private seatClock;
248
255
  /**
249
256
  * `ms` more on `seat`'s chess clock, the room's leader's or an operator's (`table-actions.ts`'s
250
257
  * `/clock/add`). False when there is nothing to add to: no clock, or no game running on it.
@@ -384,6 +391,7 @@ export declare abstract class MatchShell<Line extends {
384
391
  checkpoint?: unknown;
385
392
  clockMs?: [number, number];
386
393
  clockPaused?: boolean;
394
+ clockSeated?: boolean;
387
395
  });
388
396
  /** One line from the engine, as the composing match reads it: a concede the engine never ends ends here as its game-over would. */
389
397
  protected abstract onLine(line: Line): void;
@@ -39,6 +39,12 @@ export class MatchShell {
39
39
  * A disconnected seat's keeps running: being away answers nothing.
40
40
  */
41
41
  clock;
42
+ /**
43
+ * Every seat's player has been at this game ({@link entered}): a `clockStart: 'seated'` clock
44
+ * runs no seat before ({@link clockWaitsForSeats}). Once true it stays true — a reload, a long
45
+ * absence, a restore and a restart keep it (`remember`'s `clockSeated`).
46
+ */
47
+ #clockSeated;
42
48
  /** Fires when the running seat with the least time left runs out ({@link syncClock}). */
43
49
  flagTimer = null;
44
50
  /**
@@ -155,6 +161,7 @@ export class MatchShell {
155
161
  snapshot: this.latestSnapshot,
156
162
  ...(clockMs === null ? {} : { clockMs }),
157
163
  ...(this.clockPaused ? { clockPaused: true } : {}),
164
+ ...(this.#clockSeated ? { clockSeated: true } : {}),
158
165
  });
159
166
  }
160
167
  /** Each seat's chess-clock time left, or null in a game without one. */
@@ -172,12 +179,32 @@ export class MatchShell {
172
179
  return;
173
180
  const now = this.now();
174
181
  const running = this.status === 'running' && this.timedOut === null;
175
- const runs = (seat) => running && this.game.waitedOn(seat) && !this.clockHeld(seat);
182
+ const seated = this.seatClock();
183
+ const held = this.clockWaitsForSeats();
184
+ const runs = (seat) => running && !held && this.game.waitedOn(seat) && !this.clockHeld(seat);
176
185
  const moved = this.clock.set([runs(0), runs(1)], now);
177
- if (!moved)
178
- return;
179
- this.armFlag(now);
180
- this.game.tellRoster();
186
+ if (moved)
187
+ this.armFlag(now);
188
+ if (moved || seated)
189
+ this.game.tellRoster();
190
+ if (seated)
191
+ this.remember();
192
+ }
193
+ /** Whether every seat's player has been at the game, so a `clockStart: 'seated'` clock may run ({@link clockWaitsForSeats}). */
194
+ get clockSeated() {
195
+ return this.#clockSeated;
196
+ }
197
+ /** No clock runs yet, either seat's: a `clockStart: 'seated'` game whose players have not all been at it. */
198
+ clockWaitsForSeats() {
199
+ return this.clock !== null && this.spec.clockStart === 'seated' && !this.#clockSeated;
200
+ }
201
+ /** The last player has come to a `clockStart: 'seated'` game: from now its clock runs. True only on the call that saw it. */
202
+ seatClock() {
203
+ if (!this.clockWaitsForSeats() || !this.entered().every(Boolean))
204
+ return false;
205
+ this.#clockSeated = true;
206
+ this.deps.log({ evt: 'clock-seated', matchId: this.id });
207
+ return true;
181
208
  }
182
209
  /**
183
210
  * `ms` more on `seat`'s chess clock, the room's leader's or an operator's (`table-actions.ts`'s
@@ -653,6 +680,7 @@ export class MatchShell {
653
680
  this.clock = clockMs === undefined ? null : new ChessClock(clockMs);
654
681
  if (restore?.clockPaused === true)
655
682
  this.clock?.pause(true, this.now());
683
+ this.#clockSeated = restore?.clockSeated === true;
656
684
  this.startedAt = restore?.startedAt ?? this.now();
657
685
  this.epoch = restore?.epoch ?? `${id}:${this.startedAt}`;
658
686
  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.162",
4
- "gitHead": "d0f773834087c307196eb33c10ab1390f37f57fd",
3
+ "version": "0.1.164",
4
+ "gitHead": "6b64bcbac5f7ac51b132ee706beca28cb07217ec",
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.162",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.162",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.195",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.164",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.164",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.197",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.144",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.144",