@hadoku/game-server 0.1.157 → 0.1.159
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 +2 -0
- package/dist/http/room-core.js +5 -1
- package/dist/play/engine-runtime.d.ts +9 -0
- package/dist/play/engine-runtime.js +16 -0
- package/dist/play/host.d.ts +1 -1
- package/dist/play/host.js +1 -1
- package/dist/play/local-jvm.d.ts +19 -7
- package/dist/play/local-jvm.js +20 -8
- package/dist/room/lobby.d.ts +8 -0
- package/dist/room/lobby.js +5 -0
- package/package.json +5 -5
package/dist/http/room-core.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ export interface LobbyCore<V extends RoomViewCore, C> {
|
|
|
69
69
|
} | {
|
|
70
70
|
ok: false;
|
|
71
71
|
};
|
|
72
|
+
/** Whether leaving now drops the caller from the room's event, which only an asked-for leave may do. */
|
|
73
|
+
leaveDrops(roomId: string, callerId: string): boolean;
|
|
72
74
|
close(roomId: string, callerId: string): {
|
|
73
75
|
ok: true;
|
|
74
76
|
matches: readonly string[];
|
package/dist/http/room-core.js
CHANGED
|
@@ -291,7 +291,9 @@ export function attachRoomCore(api, deps, opts = {}) {
|
|
|
291
291
|
return noMatch(res);
|
|
292
292
|
res.json(roomBody(room, caller.id));
|
|
293
293
|
});
|
|
294
|
-
// A member steps out of their own room. A tournament entrant mid-
|
|
294
|
+
// A member steps out of their own room. A tournament entrant mid-event is a drop (`forfeited`), and
|
|
295
|
+
// only when they said so (`?drop=1`, the room's own "Leave tournament"): no page closing, Back or
|
|
296
|
+
// "Main menu" ever drops anyone from a tournament (the operator, 2026-11-28).
|
|
295
297
|
rooms.post('/:id/leave', (req, res) => {
|
|
296
298
|
if (parseBody(wire.emptyBody, req, res) === null)
|
|
297
299
|
return;
|
|
@@ -301,6 +303,8 @@ export function attachRoomCore(api, deps, opts = {}) {
|
|
|
301
303
|
const id = String(req.params.id);
|
|
302
304
|
if (!wire.roomIdRe.test(id))
|
|
303
305
|
return noMatch(res);
|
|
306
|
+
if (req.query.drop !== '1' && lobby.leaveDrops(id, caller.id))
|
|
307
|
+
return res.status(409).json({ error: 'leaving now drops you from the tournament', reason: 'drops' });
|
|
304
308
|
const result = lobby.leave(id, caller.id);
|
|
305
309
|
if (!result.ok)
|
|
306
310
|
return noMatch(res);
|
|
@@ -128,6 +128,15 @@ export declare function pidIsStandingInRun(pid: number, run: string): boolean;
|
|
|
128
128
|
* decides.
|
|
129
129
|
*/
|
|
130
130
|
export declare function pidIsRunning(pid: number): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The work a process has done so far, as `/proc/<pid>/stat` counts it: CPU time (user + system,
|
|
133
|
+
* in clock ticks) and major page faults (pages it waited to read back, from swap or disk). Two
|
|
134
|
+
* readings apart say whether it is getting anywhere; `null` once it has exited, or without `/proc`.
|
|
135
|
+
*/
|
|
136
|
+
export declare function pidWork(pid: number): {
|
|
137
|
+
cpuTicks: number;
|
|
138
|
+
majorFaults: number;
|
|
139
|
+
} | null;
|
|
131
140
|
/** How long a kill will spin waiting for a SIGKILL to land. Measured at 0 ms. */
|
|
132
141
|
export declare const REAP_CONFIRM_MS = 100;
|
|
133
142
|
/** How often an attached process (which is nobody's child, so has no `exit` event) is checked for. */
|
|
@@ -209,6 +209,22 @@ export function pidIsRunning(pid) {
|
|
|
209
209
|
return false; // no /proc entry: it has exited
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* The work a process has done so far, as `/proc/<pid>/stat` counts it: CPU time (user + system,
|
|
214
|
+
* in clock ticks) and major page faults (pages it waited to read back, from swap or disk). Two
|
|
215
|
+
* readings apart say whether it is getting anywhere; `null` once it has exited, or without `/proc`.
|
|
216
|
+
*/
|
|
217
|
+
export function pidWork(pid) {
|
|
218
|
+
try {
|
|
219
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
220
|
+
// After the `(comm)`, fields[0] is field 3 (state): majflt is field 12, utime 14, stime 15.
|
|
221
|
+
const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
222
|
+
return { cpuTicks: Number(fields[11]) + Number(fields[12]), majorFaults: Number(fields[9]) };
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
212
228
|
/** How long a kill will spin waiting for a SIGKILL to land. Measured at 0 ms. */
|
|
213
229
|
export const REAP_CONFIRM_MS = 100;
|
|
214
230
|
/** How often an attached process (which is nobody's child, so has no `exit` event) is checked for. */
|
package/dist/play/host.d.ts
CHANGED
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
export { bridgeDiagnostics } from './diagnostics.js';
|
|
122
122
|
import type { JvmLauncher } from './jvm-transport.js';
|
|
123
123
|
import { type JvmHostConfig } from './local-jvm.js';
|
|
124
|
-
export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, type JvmAvailability, type JvmHostConfig, } from './local-jvm.js';
|
|
124
|
+
export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_JVM_FLAGS, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, type JvmAvailability, type JvmHostConfig, } from './local-jvm.js';
|
|
125
125
|
export interface SeatSpec {
|
|
126
126
|
/** Forge's player name. Shown to both seats, so never an identity. */
|
|
127
127
|
name: string;
|
package/dist/play/host.js
CHANGED
|
@@ -124,7 +124,7 @@ import { join } from 'node:path';
|
|
|
124
124
|
import { jsonLogger } from '@wolffm/service-kernel/log';
|
|
125
125
|
export { bridgeDiagnostics } from './diagnostics.js';
|
|
126
126
|
import { JVM_HEAP_MB, MATCHES_PER_JVM, localJvmLauncher, writeFileAtomic } from './local-jvm.js';
|
|
127
|
-
export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, } from './local-jvm.js';
|
|
127
|
+
export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_JVM_FLAGS, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, } from './local-jvm.js';
|
|
128
128
|
const LIFECYCLE_T = new Set(['ready', 'fatal', 'frame', 'snapshot']);
|
|
129
129
|
/** Narrows any engine's line onto the four the host itself understands. See {@link HostLifecycleLine}. */
|
|
130
130
|
export function isLifecycle(line) {
|
package/dist/play/local-jvm.d.ts
CHANGED
|
@@ -87,12 +87,23 @@ import type { JvmLauncher } from './jvm-transport.js';
|
|
|
87
87
|
*/
|
|
88
88
|
export declare const FORGE_HEARTBEAT_TIMEOUT_S = 86400;
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
90
|
+
* After this long without a GC, an idle JVM's G1 runs one on its own (JEP 346). That returns
|
|
91
|
+
* the committed heap a busy spell left behind, and walks the live set, so a quiet JVM keeps
|
|
92
|
+
* its live set paged in. Measured on the pool JVM, 2026-11-28: 190 MB live in 1.1–1.75 GB
|
|
93
|
+
* committed that was never handed back, and after a quiet spell 1.67 GB of it was in the
|
|
94
|
+
* cgroup's swap; with this, 340 MB committed, and one periodic GC paged 230 MB back from swap.
|
|
95
|
+
* A JVM doing work collects far more often than this, so it never fires there.
|
|
95
96
|
*/
|
|
97
|
+
export declare const JVM_IDLE_GC_MS = 300000;
|
|
98
|
+
/**
|
|
99
|
+
* Flags every Forge JVM gets (match bridges and the pool service), before its heap cap and the
|
|
100
|
+
* operator's `jvmOpts` (so a later flag of theirs wins). `ExitOnOutOfMemoryError`: G1 has no
|
|
101
|
+
* GC-overhead limit, and without this a JVM out of heap never exits — its games die of
|
|
102
|
+
* `OutOfMemoryError` and the JVM limps on (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With
|
|
103
|
+
* it the JVM exits (code 3), which fails everything on it through the exit path.
|
|
104
|
+
*/
|
|
105
|
+
export declare const FORGE_JVM_FLAGS: readonly string[];
|
|
106
|
+
/** {@link FORGE_JVM_FLAGS}, and Forge's client timeout far past any pause. */
|
|
96
107
|
export declare const BRIDGE_JVM_FLAGS: readonly string[];
|
|
97
108
|
export interface JvmHostConfig {
|
|
98
109
|
java: string;
|
|
@@ -145,8 +156,9 @@ export declare const MATCHES_PER_JVM = 25;
|
|
|
145
156
|
/**
|
|
146
157
|
* Each JVM's heap cap: the budget for {@link MATCHES_PER_JVM} matches. A JVM is ~172 MB live idle
|
|
147
158
|
* and ~10 MB per match (Wave 9 lane D; 4–9 MB in hosting-test-plan B3), so 25 matches live in
|
|
148
|
-
* ~420 MB of a 2 GB heap. G1
|
|
149
|
-
* peak: ~2.3 GB with metaspace, code
|
|
159
|
+
* ~420 MB of a 2 GB heap. G1 hands committed heap back only once the JVM is idle
|
|
160
|
+
* ({@link JVM_IDLE_GC_MS}), so a JVM's RSS is budgeted at its peak: ~2.3 GB with metaspace, code
|
|
161
|
+
* cache and Netty.
|
|
150
162
|
*/
|
|
151
163
|
export declare const JVM_HEAP_MB = 2048;
|
|
152
164
|
export type JvmAvailability = {
|
package/dist/play/local-jvm.js
CHANGED
|
@@ -93,13 +93,24 @@ import { CRASH_MARKER, IN_FIFO, JVM_TMP_DIR, OUT_FIFO, PID_POLL_MS, REAP_CONFIRM
|
|
|
93
93
|
*/
|
|
94
94
|
export const FORGE_HEARTBEAT_TIMEOUT_S = 86_400;
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
96
|
+
* After this long without a GC, an idle JVM's G1 runs one on its own (JEP 346). That returns
|
|
97
|
+
* the committed heap a busy spell left behind, and walks the live set, so a quiet JVM keeps
|
|
98
|
+
* its live set paged in. Measured on the pool JVM, 2026-11-28: 190 MB live in 1.1–1.75 GB
|
|
99
|
+
* committed that was never handed back, and after a quiet spell 1.67 GB of it was in the
|
|
100
|
+
* cgroup's swap; with this, 340 MB committed, and one periodic GC paged 230 MB back from swap.
|
|
101
|
+
* A JVM doing work collects far more often than this, so it never fires there.
|
|
101
102
|
*/
|
|
102
|
-
export const
|
|
103
|
+
export const JVM_IDLE_GC_MS = 300_000;
|
|
104
|
+
/**
|
|
105
|
+
* Flags every Forge JVM gets (match bridges and the pool service), before its heap cap and the
|
|
106
|
+
* operator's `jvmOpts` (so a later flag of theirs wins). `ExitOnOutOfMemoryError`: G1 has no
|
|
107
|
+
* GC-overhead limit, and without this a JVM out of heap never exits — its games die of
|
|
108
|
+
* `OutOfMemoryError` and the JVM limps on (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With
|
|
109
|
+
* it the JVM exits (code 3), which fails everything on it through the exit path.
|
|
110
|
+
*/
|
|
111
|
+
export const FORGE_JVM_FLAGS = ['-XX:+ExitOnOutOfMemoryError', `-XX:G1PeriodicGCInterval=${JVM_IDLE_GC_MS}`];
|
|
112
|
+
/** {@link FORGE_JVM_FLAGS}, and Forge's client timeout far past any pause. */
|
|
113
|
+
export const BRIDGE_JVM_FLAGS = [...FORGE_JVM_FLAGS, `-Dforge.net.heartbeatTimeout=${FORGE_HEARTBEAT_TIMEOUT_S}`];
|
|
103
114
|
const AI_FLAT_MC_LEVELS = ['off', 'base', 'lite', 'max'];
|
|
104
115
|
/** `CARDTABLE_AI_FLAT_MC`'s default. See docs/planning/flat-mc-ai.md for the measurement behind it. */
|
|
105
116
|
export const AI_FLAT_MC = 'off';
|
|
@@ -123,8 +134,9 @@ export const MATCHES_PER_JVM = 25;
|
|
|
123
134
|
/**
|
|
124
135
|
* Each JVM's heap cap: the budget for {@link MATCHES_PER_JVM} matches. A JVM is ~172 MB live idle
|
|
125
136
|
* and ~10 MB per match (Wave 9 lane D; 4–9 MB in hosting-test-plan B3), so 25 matches live in
|
|
126
|
-
* ~420 MB of a 2 GB heap. G1
|
|
127
|
-
* peak: ~2.3 GB with metaspace, code
|
|
137
|
+
* ~420 MB of a 2 GB heap. G1 hands committed heap back only once the JVM is idle
|
|
138
|
+
* ({@link JVM_IDLE_GC_MS}), so a JVM's RSS is budgeted at its peak: ~2.3 GB with metaspace, code
|
|
139
|
+
* cache and Netty.
|
|
128
140
|
*/
|
|
129
141
|
export const JVM_HEAP_MB = 2048;
|
|
130
142
|
/** Where compiled bridges are kept, shared by every tree on the host (keyed by `bridgeVersion`). */
|
package/dist/room/lobby.d.ts
CHANGED
|
@@ -171,6 +171,12 @@ export interface RoomTypeHooks<G, I extends RoomCreateInput = RoomCreateInput> {
|
|
|
171
171
|
liveMatches(room: LobbyRoom<G>): string[];
|
|
172
172
|
/** A member is leaving and still in the room: what it costs their game (a match it forfeits). */
|
|
173
173
|
leaving?(room: LobbyRoom<G>, memberId: string): Pick<LeaveOk<never>, 'forfeited'> | void;
|
|
174
|
+
/**
|
|
175
|
+
* Whether leaving now would take the member out of an event under way (a tournament's draft or rounds).
|
|
176
|
+
* Such a leave is only ever asked for, never a side effect: `POST /:id/leave` refuses it unless the
|
|
177
|
+
* caller says so (`?drop=1`). Absent: no leave costs anything.
|
|
178
|
+
*/
|
|
179
|
+
leaveDrops?(room: LobbyRoom<G>, memberId: string): boolean;
|
|
174
180
|
/** A Ready: `'keep'` refuses the change quietly (the room's positions are fixed). Called before it is saved. */
|
|
175
181
|
ready?(room: LobbyRoom<G>, memberId: string, ready: boolean): 'keep' | void;
|
|
176
182
|
/** After a saved change to who sits or who is ready (a tournament's field filling, say). */
|
|
@@ -438,6 +444,8 @@ export declare class RoomLobby<V extends PlatformRoomView, I extends RoomCreateI
|
|
|
438
444
|
get(roomId: string): V | undefined;
|
|
439
445
|
/** Whether `memberId` is a member of `roomId`. False when there is no such room. */
|
|
440
446
|
isMember(roomId: string, memberId: string): boolean;
|
|
447
|
+
/** Whether `memberId` leaving `roomId` now would drop them from its event (`RoomTypeHooks.leaveDrops`). */
|
|
448
|
+
leaveDrops(roomId: string, memberId: string): boolean;
|
|
441
449
|
/**
|
|
442
450
|
* Everyone in a room is a player or a spectator, never neither (the operator, 2026-11-02):
|
|
443
451
|
* `'player'` iff `memberId` holds a game seat, `'spectator'` iff they are a member who holds
|
package/dist/room/lobby.js
CHANGED
|
@@ -324,6 +324,11 @@ export class RoomLobby {
|
|
|
324
324
|
const room = this.#rooms.get(roomId);
|
|
325
325
|
return room !== undefined && isRoomMember(room, memberId);
|
|
326
326
|
}
|
|
327
|
+
/** Whether `memberId` leaving `roomId` now would drop them from its event (`RoomTypeHooks.leaveDrops`). */
|
|
328
|
+
leaveDrops(roomId, memberId) {
|
|
329
|
+
const room = this.#rooms.get(roomId);
|
|
330
|
+
return room !== undefined && isRoomMember(room, memberId) && this.hooksOf(room).leaveDrops?.(room, memberId) === true;
|
|
331
|
+
}
|
|
327
332
|
/**
|
|
328
333
|
* Everyone in a room is a player or a spectator, never neither (the operator, 2026-11-02):
|
|
329
334
|
* `'player'` iff `memberId` holds a game seat, `'spectator'` iff they are a member who holds
|
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.159",
|
|
4
|
+
"gitHead": "57586f6329004b90a6811e9fbea44892db00bc76",
|
|
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.159",
|
|
21
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.159",
|
|
22
|
+
"@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.192",
|
|
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",
|