@series-inc/rundot-syncplay 6.0.0-rc.84 → 6.0.0-rc.85
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/core/src/physics/physics-profile-wasm-module.generated.mjs +1 -1
- package/core/src/physics/physics-wasm-module.generated.mjs +1 -1
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +1 -1
- package/dist/authority-room.d.ts +5 -2
- package/dist/authority-room.js +82 -19
- package/dist/run-room-transport.d.ts +14 -0
- package/dist/run-room-transport.js +35 -0
- package/dist/seat-control.d.ts +11 -0
- package/dist/seat-control.js +93 -5
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ export const physicsProfileWasmMetadata = Object.freeze({
|
|
|
36
36
|
"sourceHash": "dac3f2ab1dd7348052bbae1ba83c2ba6c6950e8cb5e86ada6de9a025bc541280",
|
|
37
37
|
"wasmSha256": "f08bddbc71c520ba0d7394b0fc33a38673cbeaffa00a079fe8d960941cd46105",
|
|
38
38
|
"artifact": "profile",
|
|
39
|
-
"packageVersion": "6.0.0-rc.
|
|
39
|
+
"packageVersion": "6.0.0-rc.85",
|
|
40
40
|
"compilerFlags": [
|
|
41
41
|
"-std=c++20",
|
|
42
42
|
"-O3",
|
|
@@ -36,7 +36,7 @@ export const physicsWasmMetadata = Object.freeze({
|
|
|
36
36
|
"sourceHash": "00c81d3088e594a61154d57b39f5f44e0ca42b43822946da0191c7cac27da7a0",
|
|
37
37
|
"wasmSha256": "29f5ee181a1b958577a76211015bd08dbbdfed9c074c15a40cf725430895baae",
|
|
38
38
|
"artifact": "production",
|
|
39
|
-
"packageVersion": "6.0.0-rc.
|
|
39
|
+
"packageVersion": "6.0.0-rc.85",
|
|
40
40
|
"compilerFlags": [
|
|
41
41
|
"-std=c++20",
|
|
42
42
|
"-O3",
|
|
@@ -50,7 +50,7 @@ export const physics2dWasmMetadata = Object.freeze({
|
|
|
50
50
|
"sourceHash": "c982f7b72b0494c8892d40b5fbf1a67ac94a7f20dea1f160abb888f4ccb313c0",
|
|
51
51
|
"wasmSha256": "49cb90541deed40f5fff1015bb578e13ec9a793d51931c1227e3e5a11bbfa3f7",
|
|
52
52
|
"artifact": "production",
|
|
53
|
-
"packageVersion": "6.0.0-rc.
|
|
53
|
+
"packageVersion": "6.0.0-rc.85",
|
|
54
54
|
"compilerFlags": [
|
|
55
55
|
"-std=c++20",
|
|
56
56
|
"-O3",
|
package/dist/authority-room.d.ts
CHANGED
|
@@ -447,9 +447,12 @@ export interface DeterministicAuthorityRoom {
|
|
|
447
447
|
* A player's transport re-attached inside the host's grace window (socket
|
|
448
448
|
* swap; no leave/join fired). Re-unicasts the confirmed-input history so any
|
|
449
449
|
* frames missed while offline are refilled — clients dedupe already-applied
|
|
450
|
-
* ticks, so this is idempotent.
|
|
450
|
+
* ticks, so this is idempotent. Pass `reinitializeSession: true` when a fresh
|
|
451
|
+
* cold-started client took over the seat and needs `session-start` first.
|
|
451
452
|
*/
|
|
452
|
-
onPlayerReconnected(playerId: string
|
|
453
|
+
onPlayerReconnected(playerId: string, options?: {
|
|
454
|
+
readonly reinitializeSession?: boolean;
|
|
455
|
+
}): void;
|
|
453
456
|
/**
|
|
454
457
|
* A player's transport dropped and their seat entered the host's grace
|
|
455
458
|
* window. The slot stays reserved and keeps being substituted, so release
|
package/dist/authority-room.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDetermini
|
|
|
6
6
|
import { DEFAULT_SNAPSHOT_CHUNK_SIZE, createSnapshotTransferCollector, createSnapshotTransferFromBytes, decodeDeterministicStateSnapshot, encodeDeterministicStateSnapshot, deterministicRoomDescriptorHash, } from './session-snapshot.js';
|
|
7
7
|
import { MAX_KINETIX_SESSION_CONFIG_BYTES, MAX_SYNCPLAY_COMMAND_PAYLOAD_BYTES, MAX_SYNCPLAY_EPHEMERAL_PAYLOAD_BYTES, decodeDeterministicSessionMessage, encodeDeterministicSessionMessage, } from './session-wire.js';
|
|
8
8
|
import { createSyncplaySecretAuthority, } from './secret-authority.js';
|
|
9
|
-
import { DEFAULT_SEAT_POLICY, validateSeatPolicy, createInitialSeatControlState, allocatable, findAvailableSeat, applyTransition, createSeatCheckpoint, restoreSeatControlState, } from './seat-control.js';
|
|
9
|
+
import { DEFAULT_SEAT_POLICY, validateSeatPolicy, createInitialSeatControlState, allocatable, findAvailableSeat, applyTransition, expireSeatHolds, createSeatCheckpoint, restoreSeatControlState, } from './seat-control.js';
|
|
10
10
|
const DEFAULT_SESSION_MSG_TYPE = 'rdm';
|
|
11
11
|
const DEFAULT_SECRET_MSG_TYPE = 'rdm-secret';
|
|
12
12
|
/** One hour at 60 Hz — see DeterministicAuthorityRoomConfig.historyRetentionTicks. */
|
|
@@ -106,7 +106,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
106
106
|
let seatControlState = config.restoreFrom?.seatCheckpoint !== undefined
|
|
107
107
|
? restoreSeatControlState(config.restoreFrom.seatCheckpoint)
|
|
108
108
|
: createInitialSeatControlState(config.playerCount, seatPolicy ?? DEFAULT_SEAT_POLICY, config.seatPolicy === undefined ? { legacyBotSlots: [...botSlotSet] } : undefined);
|
|
109
|
-
let hasStartedLobby =
|
|
109
|
+
let hasStartedLobby = (config.restoreFrom?.now ?? -1) >= 0;
|
|
110
110
|
if (config.restoreFrom?.seatCheckpoint !== undefined) {
|
|
111
111
|
for (let slot = 0; slot < config.playerCount; slot++) {
|
|
112
112
|
const seat = seatControlState.seats[slot];
|
|
@@ -998,7 +998,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
998
998
|
if (slot !== undefined)
|
|
999
999
|
authority.neutralizeSlot(slot);
|
|
1000
1000
|
}
|
|
1001
|
-
function onPlayerReconnected(playerId) {
|
|
1001
|
+
function onPlayerReconnected(playerId, options) {
|
|
1002
1002
|
const wasDisconnected = disconnectedPlayers.delete(playerId);
|
|
1003
1003
|
if (wasDisconnected) {
|
|
1004
1004
|
membershipEpoch += 1;
|
|
@@ -1021,15 +1021,16 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1021
1021
|
}
|
|
1022
1022
|
const slot = slotByPlayer.get(playerId);
|
|
1023
1023
|
if (slot === undefined) {
|
|
1024
|
-
|
|
1024
|
+
const hasPriorSeatClaim = reconnectedSlot !== undefined ||
|
|
1025
|
+
(config.seatPolicy !== undefined && seatControlState.rejoinRecords.some((r) => r.playerId === playerId));
|
|
1026
|
+
if (hasPriorSeatClaim) {
|
|
1025
1027
|
onPlayerJoin(playerId);
|
|
1026
1028
|
}
|
|
1027
1029
|
return;
|
|
1028
1030
|
}
|
|
1029
|
-
// Post-restore
|
|
1030
|
-
//
|
|
1031
|
-
|
|
1032
|
-
if (restoredRoom) {
|
|
1031
|
+
// Post-restore or on a cold-start seat takeover, the client's local session
|
|
1032
|
+
// needs a fresh `session-start` before secret proof context and catch-up.
|
|
1033
|
+
if (restoredRoom || options?.reinitializeSession === true) {
|
|
1033
1034
|
sendSessionStart(playerId, slot);
|
|
1034
1035
|
}
|
|
1035
1036
|
// Socket swapped mid-match: refill anything missed while offline. The
|
|
@@ -1282,6 +1283,12 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1282
1283
|
else if (seat.control.kind === "bot") {
|
|
1283
1284
|
const nextEpoch = seat.control.controlEpoch + 1;
|
|
1284
1285
|
const botLeaseId = `lease-${slot}-${nextEpoch}`;
|
|
1286
|
+
const rebasedClaim = seat.retainedClaim?.holdExpiresAtTick !== undefined
|
|
1287
|
+
? {
|
|
1288
|
+
...seat.retainedClaim,
|
|
1289
|
+
holdExpiresAtTick: Math.max(0, seat.retainedClaim.holdExpiresAtTick - Math.max(0, now + 1)),
|
|
1290
|
+
}
|
|
1291
|
+
: seat.retainedClaim;
|
|
1285
1292
|
const updatedSeat = {
|
|
1286
1293
|
...seat,
|
|
1287
1294
|
control: {
|
|
@@ -1289,6 +1296,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1289
1296
|
controlEpoch: nextEpoch,
|
|
1290
1297
|
botLeaseId,
|
|
1291
1298
|
},
|
|
1299
|
+
retainedClaim: rebasedClaim,
|
|
1292
1300
|
};
|
|
1293
1301
|
seatControlState = {
|
|
1294
1302
|
...seatControlState,
|
|
@@ -1305,6 +1313,19 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1305
1313
|
activeBotLeaseBySlot.set(slot, newLease);
|
|
1306
1314
|
lastBotSequenceByLease.set(botLeaseId, 0);
|
|
1307
1315
|
}
|
|
1316
|
+
else if (seat.retainedClaim?.holdExpiresAtTick !== undefined) {
|
|
1317
|
+
const updatedSeat = {
|
|
1318
|
+
...seat,
|
|
1319
|
+
retainedClaim: {
|
|
1320
|
+
...seat.retainedClaim,
|
|
1321
|
+
holdExpiresAtTick: Math.max(0, seat.retainedClaim.holdExpiresAtTick - Math.max(0, now + 1)),
|
|
1322
|
+
},
|
|
1323
|
+
};
|
|
1324
|
+
seatControlState = {
|
|
1325
|
+
...seatControlState,
|
|
1326
|
+
seats: seatControlState.seats.map((s, idx) => (idx === slot ? updatedSeat : s)),
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1308
1329
|
}
|
|
1309
1330
|
}
|
|
1310
1331
|
membershipEpoch += 1;
|
|
@@ -1672,7 +1693,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1672
1693
|
}
|
|
1673
1694
|
authority.neutralizeSlotFrom(slot, effectiveTick);
|
|
1674
1695
|
slotByPlayer.delete(playerId);
|
|
1675
|
-
if (seatPolicy.recycleVacatedSeats) {
|
|
1696
|
+
if (seatPolicy.recycleVacatedSeats && res.nextState.seats[slot].retainedClaim === null) {
|
|
1676
1697
|
everSlotByPlayer.delete(playerId);
|
|
1677
1698
|
}
|
|
1678
1699
|
if (seatPolicy.onHumanLeave === "bot") {
|
|
@@ -1823,19 +1844,61 @@ export function createDeterministicAuthorityRoom(transport, config) {
|
|
|
1823
1844
|
// via the history replay in onPlayerJoin. `assignedSlots` is monotonic, so
|
|
1824
1845
|
// a mid-match leave never re-pauses a started room.
|
|
1825
1846
|
if (config.waitForFullRoom === true && !hasStartedLobby) {
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1847
|
+
const activeCount = config.seatPolicy !== undefined
|
|
1848
|
+
? seatControlState.seats.filter((s) => s.control.kind === "human" || s.control.kind === "bot").length
|
|
1849
|
+
: assignedSlots;
|
|
1850
|
+
if (activeCount < config.playerCount) {
|
|
1851
|
+
if (config.seatPolicy !== undefined && seatControlState.policy.seatHoldTicks !== undefined) {
|
|
1852
|
+
let decayed = false;
|
|
1853
|
+
const decayedSeats = seatControlState.seats.map((seat) => {
|
|
1854
|
+
if (seat.control.kind !== "human" &&
|
|
1855
|
+
seat.retainedClaim?.holdExpiresAtTick !== undefined) {
|
|
1856
|
+
decayed = true;
|
|
1857
|
+
return {
|
|
1858
|
+
...seat,
|
|
1859
|
+
retainedClaim: {
|
|
1860
|
+
...seat.retainedClaim,
|
|
1861
|
+
holdExpiresAtTick: Math.max(0, seat.retainedClaim.holdExpiresAtTick - 1),
|
|
1862
|
+
},
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
return seat;
|
|
1866
|
+
});
|
|
1867
|
+
if (decayed) {
|
|
1868
|
+
seatControlState = { ...seatControlState, seats: decayedSeats };
|
|
1869
|
+
const holdRes = expireSeatHolds(seatControlState, 0);
|
|
1870
|
+
if (holdRes.expired.length > 0) {
|
|
1871
|
+
seatControlState = holdRes.nextState;
|
|
1872
|
+
membershipEpoch += 1;
|
|
1873
|
+
for (const rel of holdRes.expired) {
|
|
1874
|
+
secretAuthority?.onPlayerLeft(rel.playerId, rel.slot, {
|
|
1875
|
+
releaseMode: rel.releaseMode,
|
|
1876
|
+
reason: 'leave',
|
|
1877
|
+
});
|
|
1878
|
+
everSlotByPlayer.delete(rel.playerId);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
return;
|
|
1836
1884
|
}
|
|
1885
|
+
hasStartedLobby = true;
|
|
1837
1886
|
}
|
|
1838
1887
|
now += 1;
|
|
1888
|
+
if (config.seatPolicy !== undefined && seatControlState.policy.seatHoldTicks !== undefined) {
|
|
1889
|
+
const holdRes = expireSeatHolds(seatControlState, now);
|
|
1890
|
+
if (holdRes.expired.length > 0) {
|
|
1891
|
+
seatControlState = holdRes.nextState;
|
|
1892
|
+
membershipEpoch += 1;
|
|
1893
|
+
for (const rel of holdRes.expired) {
|
|
1894
|
+
secretAuthority?.onPlayerLeft(rel.playerId, rel.slot, {
|
|
1895
|
+
releaseMode: rel.releaseMode,
|
|
1896
|
+
reason: 'leave',
|
|
1897
|
+
});
|
|
1898
|
+
everSlotByPlayer.delete(rel.playerId);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1839
1902
|
for (const [schedTick, slots] of scheduledEvacuations.entries()) {
|
|
1840
1903
|
if (schedTick <= now) {
|
|
1841
1904
|
for (const slot of slots) {
|
|
@@ -40,6 +40,15 @@ export interface SyncplayOccupancySnapshot {
|
|
|
40
40
|
readonly full: boolean;
|
|
41
41
|
readonly locked: boolean;
|
|
42
42
|
}
|
|
43
|
+
export interface SyncplaySettlementReport {
|
|
44
|
+
/**
|
|
45
|
+
* Optional per-run identifier (`[A-Za-z0-9._:-]{1,64}`) used by multi-wave or
|
|
46
|
+
* persistent deterministic rooms to settle each run idempotently.
|
|
47
|
+
*/
|
|
48
|
+
readonly runId?: string;
|
|
49
|
+
readonly roomInputs?: Readonly<Record<string, unknown>>;
|
|
50
|
+
readonly playerInputs?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
51
|
+
}
|
|
43
52
|
export interface SyncplayRoomTransport extends NetworkedClientTransport {
|
|
44
53
|
/** The shareable room code (e.g. "HX9KWR"). */
|
|
45
54
|
readonly roomCode: string;
|
|
@@ -59,6 +68,11 @@ export interface SyncplayRoomTransport extends NetworkedClientTransport {
|
|
|
59
68
|
onConnectionEvent(handler: (event: SyncplayConnectionEvent) => void): void;
|
|
60
69
|
onOccupancyChange(handler: (snapshot: SyncplayOccupancySnapshot) => void): () => void;
|
|
61
70
|
setSeatingOpen(open: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Submit a deterministic run-settlement report for quorum agreement across
|
|
73
|
+
* connected peers into `simulationHooks.settleRecipeId`.
|
|
74
|
+
*/
|
|
75
|
+
reportSettlement(report: SyncplaySettlementReport): void;
|
|
62
76
|
}
|
|
63
77
|
/**
|
|
64
78
|
* Join an existing deterministic room by its 6-char code and return a transport
|
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
* carries the session envelope verbatim; the typed-message path would spread a
|
|
13
13
|
* raw string and corrupt it, which is why the raw channel exists.
|
|
14
14
|
*/
|
|
15
|
+
import { canonicalStringify } from './canonical.js';
|
|
15
16
|
import { detectCoarseRegion } from './coarse-region.js';
|
|
16
17
|
import { encodeDeterministicSessionMessage } from './session-wire.js';
|
|
17
18
|
/** Wire envelope msgType the deterministic session protocol travels under. */
|
|
18
19
|
const SESSION_MSG_TYPE = 'rdm';
|
|
19
20
|
const SECRET_MSG_TYPE = 'rdm-secret';
|
|
21
|
+
const SETTLEMENT_MSG_TYPE = 'rdm-settle';
|
|
22
|
+
const RUN_ID_PATTERN = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
20
23
|
/** Room type the platform registers the generic deterministic room under. */
|
|
21
24
|
const SYNCPLAY_ROOM_TYPE = 'deterministic';
|
|
22
25
|
const SYNCPLAY_MAX_PLAYERS_CRITERION = '__syncplay.maxPlayers';
|
|
@@ -28,6 +31,9 @@ function isUint8Array(value) {
|
|
|
28
31
|
return ArrayBuffer.isView(value)
|
|
29
32
|
&& Object.prototype.toString.call(value) === '[object Uint8Array]';
|
|
30
33
|
}
|
|
34
|
+
function isPlainRecord(value) {
|
|
35
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
36
|
+
}
|
|
31
37
|
/**
|
|
32
38
|
* Session traffic buffered between transport creation and the engine attaching
|
|
33
39
|
* its onMessage handler (a game may await asset loads in between). ~4.5 min of
|
|
@@ -166,6 +172,35 @@ function toTransport(room) {
|
|
|
166
172
|
};
|
|
167
173
|
},
|
|
168
174
|
setSeatingOpen: (open) => room.setSeatingOpen(open),
|
|
175
|
+
reportSettlement: (report) => {
|
|
176
|
+
if (!isPlainRecord(report)) {
|
|
177
|
+
throw new TypeError('SyncplaySettlementReport must be a plain object');
|
|
178
|
+
}
|
|
179
|
+
if (report.runId !== undefined && (typeof report.runId !== 'string' || !RUN_ID_PATTERN.test(report.runId))) {
|
|
180
|
+
throw new TypeError('SyncplaySettlementReport.runId must match /^[A-Za-z0-9._:-]{1,64}$/');
|
|
181
|
+
}
|
|
182
|
+
if (report.roomInputs !== undefined && !isPlainRecord(report.roomInputs)) {
|
|
183
|
+
throw new TypeError('SyncplaySettlementReport.roomInputs must be a plain object');
|
|
184
|
+
}
|
|
185
|
+
if (report.playerInputs !== undefined) {
|
|
186
|
+
if (!isPlainRecord(report.playerInputs)) {
|
|
187
|
+
throw new TypeError('SyncplaySettlementReport.playerInputs must be a plain object');
|
|
188
|
+
}
|
|
189
|
+
for (const [profileId, inputs] of Object.entries(report.playerInputs)) {
|
|
190
|
+
if (!profileId || !isPlainRecord(inputs)) {
|
|
191
|
+
throw new TypeError('SyncplaySettlementReport.playerInputs values must be plain objects');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const payload = {};
|
|
196
|
+
if (report.runId !== undefined)
|
|
197
|
+
payload.runId = report.runId;
|
|
198
|
+
if (report.roomInputs !== undefined)
|
|
199
|
+
payload.roomInputs = report.roomInputs;
|
|
200
|
+
if (report.playerInputs !== undefined)
|
|
201
|
+
payload.playerInputs = report.playerInputs;
|
|
202
|
+
room.sendRaw(SETTLEMENT_MSG_TYPE, canonicalStringify(payload));
|
|
203
|
+
},
|
|
169
204
|
};
|
|
170
205
|
}
|
|
171
206
|
/**
|
package/dist/seat-control.d.ts
CHANGED
|
@@ -46,11 +46,18 @@ export interface SeatPolicy {
|
|
|
46
46
|
readonly allowHumanClaimBot: boolean;
|
|
47
47
|
readonly onHumanLeave: 'empty' | 'bot';
|
|
48
48
|
readonly initialBotSlots: readonly SlotIndex[];
|
|
49
|
+
/**
|
|
50
|
+
* Optional tick count to hold a vacated seat exclusively for the departing
|
|
51
|
+
* player before releasing it to `rejoinRecords` for human backfill when
|
|
52
|
+
* `recycleVacatedSeats` is true.
|
|
53
|
+
*/
|
|
54
|
+
readonly seatHoldTicks?: number;
|
|
49
55
|
}
|
|
50
56
|
export interface HumanClaim {
|
|
51
57
|
readonly playerId: PlayerId;
|
|
52
58
|
readonly claimId: HumanClaimId;
|
|
53
59
|
readonly slot: SlotIndex;
|
|
60
|
+
readonly holdExpiresAtTick?: number;
|
|
54
61
|
}
|
|
55
62
|
export interface StagedReservation {
|
|
56
63
|
readonly playerId: PlayerId;
|
|
@@ -135,6 +142,10 @@ export declare function applyTransition(state: SeatControlState, intent: SeatTra
|
|
|
135
142
|
nextState: SeatControlState;
|
|
136
143
|
effects: TransitionEffects;
|
|
137
144
|
};
|
|
145
|
+
export declare function expireSeatHolds(state: SeatControlState, tick: number): {
|
|
146
|
+
readonly nextState: SeatControlState;
|
|
147
|
+
readonly expired: readonly NonNullable<TransitionEffects['secretRelease']>[];
|
|
148
|
+
};
|
|
138
149
|
export interface SeatCheckpoint {
|
|
139
150
|
readonly v: 1;
|
|
140
151
|
readonly playerCount: number;
|
package/dist/seat-control.js
CHANGED
|
@@ -11,7 +11,13 @@ export function validateSeatPolicy(input, playerCount) {
|
|
|
11
11
|
}
|
|
12
12
|
invariant(typeof input === 'object' && input !== null, 'seatPolicy must be an object', 'seat-control.invalid-policy');
|
|
13
13
|
const record = input;
|
|
14
|
-
const allowedKeys = new Set([
|
|
14
|
+
const allowedKeys = new Set([
|
|
15
|
+
'recycleVacatedSeats',
|
|
16
|
+
'allowHumanClaimBot',
|
|
17
|
+
'onHumanLeave',
|
|
18
|
+
'initialBotSlots',
|
|
19
|
+
'seatHoldTicks',
|
|
20
|
+
]);
|
|
15
21
|
for (const key of Object.keys(record)) {
|
|
16
22
|
invariant(allowedKeys.has(key), `seatPolicy contains unknown key: ${key}`, 'seat-control.unknown-key');
|
|
17
23
|
}
|
|
@@ -38,11 +44,17 @@ export function validateSeatPolicy(input, playerCount) {
|
|
|
38
44
|
}
|
|
39
45
|
initialBotSlots = [...seen].sort((a, b) => a - b);
|
|
40
46
|
}
|
|
47
|
+
let seatHoldTicks;
|
|
48
|
+
if (record.seatHoldTicks !== undefined) {
|
|
49
|
+
invariant(typeof record.seatHoldTicks === 'number' && Number.isInteger(record.seatHoldTicks) && record.seatHoldTicks >= 1, 'seatHoldTicks must be an integer >= 1', 'seat-control.invalid-policy');
|
|
50
|
+
seatHoldTicks = record.seatHoldTicks;
|
|
51
|
+
}
|
|
41
52
|
return {
|
|
42
53
|
recycleVacatedSeats,
|
|
43
54
|
allowHumanClaimBot,
|
|
44
55
|
onHumanLeave,
|
|
45
56
|
initialBotSlots,
|
|
57
|
+
...(seatHoldTicks !== undefined ? { seatHoldTicks } : {}),
|
|
46
58
|
};
|
|
47
59
|
}
|
|
48
60
|
export function validateSeatRecord(record) {
|
|
@@ -52,9 +64,13 @@ export function validateSeatRecord(record) {
|
|
|
52
64
|
invariant(record.retainedClaim.playerId === record.control.playerId, 'retainedClaim playerId must match human control playerId', 'seat-control.player-mismatch');
|
|
53
65
|
invariant(record.retainedClaim.claimId === record.control.claimId, 'retainedClaim claimId must match human control claimId', 'seat-control.claim-mismatch');
|
|
54
66
|
invariant(record.retainedClaim.slot === record.slot, 'retainedClaim slot must match seat slot', 'seat-control.slot-mismatch');
|
|
67
|
+
invariant(record.retainedClaim.holdExpiresAtTick === undefined, 'active human control cannot carry holdExpiresAtTick', 'seat-control.invalid-hold-expiry');
|
|
55
68
|
}
|
|
56
69
|
if (record.retainedClaim !== null) {
|
|
57
70
|
invariant(record.retainedClaim.slot === record.slot, 'retainedClaim slot must match seat slot', 'seat-control.slot-mismatch');
|
|
71
|
+
if (record.retainedClaim.holdExpiresAtTick !== undefined) {
|
|
72
|
+
invariant(Number.isInteger(record.retainedClaim.holdExpiresAtTick) && record.retainedClaim.holdExpiresAtTick >= 0, 'holdExpiresAtTick must be a non-negative integer', 'seat-control.invalid-hold-expiry');
|
|
73
|
+
}
|
|
58
74
|
}
|
|
59
75
|
if (record.reservation !== null) {
|
|
60
76
|
invariant(record.reservation.slot === record.slot, 'reservation slot must match seat slot', 'seat-control.slot-mismatch');
|
|
@@ -411,10 +427,11 @@ export function applyTransition(state, intent) {
|
|
|
411
427
|
const departingClaimId = currentSeat.control.claimId;
|
|
412
428
|
const isEvacuation = intent.reason === 'evacuation';
|
|
413
429
|
const isRecycling = state.policy.recycleVacatedSeats;
|
|
430
|
+
const holdTicks = !isEvacuation && isRecycling ? state.policy.seatHoldTicks : undefined;
|
|
414
431
|
if (isEvacuation) {
|
|
415
432
|
nextEvacuatedSlots.add(slot);
|
|
416
433
|
}
|
|
417
|
-
const releaseMode = isEvacuation || isRecycling ? 'retire' : 'retain';
|
|
434
|
+
const releaseMode = isEvacuation || (isRecycling && holdTicks === undefined) ? 'retire' : 'retain';
|
|
418
435
|
secretRelease = {
|
|
419
436
|
playerId: departingPlayerId,
|
|
420
437
|
slot,
|
|
@@ -422,7 +439,15 @@ export function applyTransition(state, intent) {
|
|
|
422
439
|
reason: intent.reason,
|
|
423
440
|
};
|
|
424
441
|
let retainedClaim = currentSeat.retainedClaim;
|
|
425
|
-
if (
|
|
442
|
+
if (holdTicks !== undefined) {
|
|
443
|
+
retainedClaim = {
|
|
444
|
+
playerId: departingPlayerId,
|
|
445
|
+
claimId: departingClaimId,
|
|
446
|
+
slot,
|
|
447
|
+
holdExpiresAtTick: intent.effectiveTick + holdTicks,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
else if (isRecycling || isEvacuation) {
|
|
426
451
|
retainedClaim = null;
|
|
427
452
|
const existingIdx = nextRejoinRecords.findIndex((r) => r.playerId === departingPlayerId);
|
|
428
453
|
const record = {
|
|
@@ -458,10 +483,13 @@ export function applyTransition(state, intent) {
|
|
|
458
483
|
const isEvacuation = intent.reason === 'evacuation';
|
|
459
484
|
const isStagedAbort = intent.reason === 'staged-abort';
|
|
460
485
|
const isRecycling = state.policy.recycleVacatedSeats;
|
|
486
|
+
const holdTicks = !isStagedAbort && !isEvacuation && isRecycling ? state.policy.seatHoldTicks : undefined;
|
|
461
487
|
if (isEvacuation) {
|
|
462
488
|
nextEvacuatedSlots.add(slot);
|
|
463
489
|
}
|
|
464
|
-
const releaseMode = isStagedAbort
|
|
490
|
+
const releaseMode = isStagedAbort
|
|
491
|
+
? 'retain'
|
|
492
|
+
: (isEvacuation || (isRecycling && holdTicks === undefined) ? 'retire' : 'retain');
|
|
465
493
|
secretRelease = {
|
|
466
494
|
playerId: departingPlayerId,
|
|
467
495
|
slot,
|
|
@@ -469,7 +497,15 @@ export function applyTransition(state, intent) {
|
|
|
469
497
|
reason: intent.reason,
|
|
470
498
|
};
|
|
471
499
|
let retainedClaim = currentSeat.retainedClaim;
|
|
472
|
-
if (
|
|
500
|
+
if (holdTicks !== undefined) {
|
|
501
|
+
retainedClaim = {
|
|
502
|
+
playerId: departingPlayerId,
|
|
503
|
+
claimId: departingClaimId,
|
|
504
|
+
slot,
|
|
505
|
+
holdExpiresAtTick: intent.effectiveTick + holdTicks,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
else if (!isStagedAbort && (isRecycling || isEvacuation)) {
|
|
473
509
|
retainedClaim = null;
|
|
474
510
|
const existingIdx = nextRejoinRecords.findIndex((r) => r.playerId === departingPlayerId);
|
|
475
511
|
const record = {
|
|
@@ -514,6 +550,58 @@ export function applyTransition(state, intent) {
|
|
|
514
550
|
},
|
|
515
551
|
};
|
|
516
552
|
}
|
|
553
|
+
export function expireSeatHolds(state, tick) {
|
|
554
|
+
let changed = false;
|
|
555
|
+
const nextSeats = [...state.seats];
|
|
556
|
+
const nextRejoinRecords = [...state.rejoinRecords];
|
|
557
|
+
const expired = [];
|
|
558
|
+
for (let slot = 0; slot < state.playerCount; slot += 1) {
|
|
559
|
+
const seat = state.seats[slot];
|
|
560
|
+
if (seat.control.kind !== 'human' &&
|
|
561
|
+
seat.retainedClaim !== null &&
|
|
562
|
+
seat.retainedClaim.holdExpiresAtTick !== undefined &&
|
|
563
|
+
seat.retainedClaim.holdExpiresAtTick <= tick) {
|
|
564
|
+
changed = true;
|
|
565
|
+
const claim = seat.retainedClaim;
|
|
566
|
+
nextSeats[slot] = {
|
|
567
|
+
...seat,
|
|
568
|
+
retainedClaim: null,
|
|
569
|
+
};
|
|
570
|
+
const existingIdx = nextRejoinRecords.findIndex((r) => r.playerId === claim.playerId);
|
|
571
|
+
const record = {
|
|
572
|
+
playerId: claim.playerId,
|
|
573
|
+
formerSlot: slot,
|
|
574
|
+
formerClaimId: claim.claimId,
|
|
575
|
+
replacedByHuman: false,
|
|
576
|
+
};
|
|
577
|
+
if (existingIdx !== -1) {
|
|
578
|
+
nextRejoinRecords[existingIdx] = record;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
nextRejoinRecords.push(record);
|
|
582
|
+
}
|
|
583
|
+
expired.push({
|
|
584
|
+
playerId: claim.playerId,
|
|
585
|
+
slot,
|
|
586
|
+
releaseMode: 'retire',
|
|
587
|
+
reason: 'hold-expired',
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (!changed) {
|
|
592
|
+
return { nextState: state, expired };
|
|
593
|
+
}
|
|
594
|
+
const nextState = {
|
|
595
|
+
playerCount: state.playerCount,
|
|
596
|
+
policy: state.policy,
|
|
597
|
+
seats: nextSeats,
|
|
598
|
+
rejoinRecords: nextRejoinRecords,
|
|
599
|
+
evacuatedSlots: state.evacuatedSlots,
|
|
600
|
+
legacyBotSlots: state.legacyBotSlots,
|
|
601
|
+
};
|
|
602
|
+
validateInvariants(nextState);
|
|
603
|
+
return { nextState, expired };
|
|
604
|
+
}
|
|
517
605
|
export function createSeatCheckpoint(state, policyDigest) {
|
|
518
606
|
return {
|
|
519
607
|
v: 1,
|
package/package.json
CHANGED