@series-inc/rundot-syncplay 5.23.0-beta.7
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/README.md +610 -0
- package/dist/animation.d.ts +119 -0
- package/dist/animation.js +488 -0
- package/dist/asset-cooking.d.ts +82 -0
- package/dist/asset-cooking.js +364 -0
- package/dist/authority-room.d.ts +217 -0
- package/dist/authority-room.js +701 -0
- package/dist/bot-documents.d.ts +115 -0
- package/dist/bot-documents.js +549 -0
- package/dist/bot-primitives.d.ts +152 -0
- package/dist/bot-primitives.js +472 -0
- package/dist/browser.d.ts +57 -0
- package/dist/browser.js +53 -0
- package/dist/canonical.d.ts +12 -0
- package/dist/canonical.js +288 -0
- package/dist/certification.d.ts +455 -0
- package/dist/certification.js +1855 -0
- package/dist/chaos-certification.d.ts +56 -0
- package/dist/chaos-certification.js +1397 -0
- package/dist/cjs/animation.js +495 -0
- package/dist/cjs/asset-cooking.js +372 -0
- package/dist/cjs/authority-room.js +704 -0
- package/dist/cjs/bot-documents.js +556 -0
- package/dist/cjs/bot-primitives.js +482 -0
- package/dist/cjs/browser.js +96 -0
- package/dist/cjs/canonical.js +299 -0
- package/dist/cjs/certification.js +1860 -0
- package/dist/cjs/chaos-certification.js +1402 -0
- package/dist/cjs/collections.js +36 -0
- package/dist/cjs/collision.js +96 -0
- package/dist/cjs/commands.js +987 -0
- package/dist/cjs/config-bundle.js +491 -0
- package/dist/cjs/creator.js +30 -0
- package/dist/cjs/deterministic-primitives.js +134 -0
- package/dist/cjs/deterministic-session.js +1410 -0
- package/dist/cjs/ecs-lite.js +155 -0
- package/dist/cjs/effects-adapter.js +97 -0
- package/dist/cjs/engine-complete.js +2297 -0
- package/dist/cjs/engine-core-proof.js +70 -0
- package/dist/cjs/engine-parity-matrix.js +874 -0
- package/dist/cjs/engine-parity.js +3183 -0
- package/dist/cjs/engine-runtime.js +3141 -0
- package/dist/cjs/errors.js +22 -0
- package/dist/cjs/events.js +247 -0
- package/dist/cjs/examples/counter-duel.js +157 -0
- package/dist/cjs/examples/fixed-arena.js +368 -0
- package/dist/cjs/index.js +229 -0
- package/dist/cjs/input-authority.js +150 -0
- package/dist/cjs/input-button.js +256 -0
- package/dist/cjs/input-timeline.js +418 -0
- package/dist/cjs/instant-replay.js +66 -0
- package/dist/cjs/lag-compensation3d.js +837 -0
- package/dist/cjs/local-authority-server-runner.js +1121 -0
- package/dist/cjs/local-authority-wire.js +1497 -0
- package/dist/cjs/local-authority.js +817 -0
- package/dist/cjs/local-ws-adapter.js +150 -0
- package/dist/cjs/match-log.js +61 -0
- package/dist/cjs/math.js +157 -0
- package/dist/cjs/mock-network-adapter.js +26 -0
- package/dist/cjs/movement.js +703 -0
- package/dist/cjs/movement3d.js +1246 -0
- package/dist/cjs/multiclient-authority.js +308 -0
- package/dist/cjs/multiplayer-service.js +434 -0
- package/dist/cjs/navigation.js +347 -0
- package/dist/cjs/navmesh.js +1437 -0
- package/dist/cjs/networked-client.js +691 -0
- package/dist/cjs/networked-input-authority.js +443 -0
- package/dist/cjs/node.js +47 -0
- package/dist/cjs/number-lab.js +78 -0
- package/dist/cjs/offline-session.js +370 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/pause-resume.js +43 -0
- package/dist/cjs/physics-cert.js +426 -0
- package/dist/cjs/physics2d.js +751 -0
- package/dist/cjs/physics3d.js +1996 -0
- package/dist/cjs/prediction-culling.js +203 -0
- package/dist/cjs/protocol-lab.js +1299 -0
- package/dist/cjs/r3f-render-adapter.js +209 -0
- package/dist/cjs/random.js +59 -0
- package/dist/cjs/replay-bundle.js +1598 -0
- package/dist/cjs/replay-inspect.js +236 -0
- package/dist/cjs/replay-scoring.js +68 -0
- package/dist/cjs/replay.js +356 -0
- package/dist/cjs/reports.js +181 -0
- package/dist/cjs/rollback-history.js +251 -0
- package/dist/cjs/runtime-guards.js +111 -0
- package/dist/cjs/sample-lab.js +145 -0
- package/dist/cjs/sample-scenes.js +752 -0
- package/dist/cjs/schema-artifacts.js +359 -0
- package/dist/cjs/schema-codegen.js +544 -0
- package/dist/cjs/schema-dsl-binary.js +655 -0
- package/dist/cjs/schema.js +319 -0
- package/dist/cjs/sdk-offline.js +99 -0
- package/dist/cjs/session-promotion.js +74 -0
- package/dist/cjs/session-snapshot.js +265 -0
- package/dist/cjs/session-wire.js +216 -0
- package/dist/cjs/signals.js +103 -0
- package/dist/cjs/sparse-set.js +169 -0
- package/dist/cjs/synctest.js +136 -0
- package/dist/cjs/system-lifecycle.js +286 -0
- package/dist/cjs/timers.js +61 -0
- package/dist/cjs/tools/static-checker.js +1468 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/venus-mp-budget.js +125 -0
- package/dist/cjs/ws-frame.js +255 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11379 -0
- package/dist/collections.d.ts +9 -0
- package/dist/collections.js +30 -0
- package/dist/collision.d.ts +25 -0
- package/dist/collision.js +85 -0
- package/dist/commands.d.ts +137 -0
- package/dist/commands.js +977 -0
- package/dist/config-bundle.d.ts +89 -0
- package/dist/config-bundle.js +483 -0
- package/dist/creator.d.ts +20 -0
- package/dist/creator.js +11 -0
- package/dist/deterministic-primitives.d.ts +59 -0
- package/dist/deterministic-primitives.js +126 -0
- package/dist/deterministic-session.d.ts +197 -0
- package/dist/deterministic-session.js +1401 -0
- package/dist/ecs-lite.d.ts +26 -0
- package/dist/ecs-lite.js +152 -0
- package/dist/effects-adapter.d.ts +21 -0
- package/dist/effects-adapter.js +94 -0
- package/dist/engine-complete.d.ts +45 -0
- package/dist/engine-complete.js +2292 -0
- package/dist/engine-core-proof.d.ts +26 -0
- package/dist/engine-core-proof.js +66 -0
- package/dist/engine-parity-matrix.d.ts +300 -0
- package/dist/engine-parity-matrix.js +869 -0
- package/dist/engine-parity.d.ts +74 -0
- package/dist/engine-parity.js +3178 -0
- package/dist/engine-runtime.d.ts +351 -0
- package/dist/engine-runtime.js +3123 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +17 -0
- package/dist/events.d.ts +45 -0
- package/dist/events.js +242 -0
- package/dist/examples/counter-duel.d.ts +43 -0
- package/dist/examples/counter-duel.js +150 -0
- package/dist/examples/fixed-arena.d.ts +110 -0
- package/dist/examples/fixed-arena.js +356 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +66 -0
- package/dist/input-authority.d.ts +82 -0
- package/dist/input-authority.js +147 -0
- package/dist/input-button.d.ts +36 -0
- package/dist/input-button.js +249 -0
- package/dist/input-timeline.d.ts +65 -0
- package/dist/input-timeline.js +412 -0
- package/dist/instant-replay.d.ts +59 -0
- package/dist/instant-replay.js +62 -0
- package/dist/lag-compensation3d.d.ts +146 -0
- package/dist/lag-compensation3d.js +827 -0
- package/dist/local-authority-server-runner.d.ts +79 -0
- package/dist/local-authority-server-runner.js +1118 -0
- package/dist/local-authority-wire.d.ts +142 -0
- package/dist/local-authority-wire.js +1477 -0
- package/dist/local-authority.d.ts +160 -0
- package/dist/local-authority.js +810 -0
- package/dist/local-ws-adapter.d.ts +14 -0
- package/dist/local-ws-adapter.js +146 -0
- package/dist/match-log.d.ts +74 -0
- package/dist/match-log.js +57 -0
- package/dist/math.d.ts +41 -0
- package/dist/math.js +154 -0
- package/dist/mock-network-adapter.d.ts +13 -0
- package/dist/mock-network-adapter.js +23 -0
- package/dist/movement.d.ts +155 -0
- package/dist/movement.js +694 -0
- package/dist/movement3d.d.ts +195 -0
- package/dist/movement3d.js +1238 -0
- package/dist/multiclient-authority.d.ts +30 -0
- package/dist/multiclient-authority.js +305 -0
- package/dist/multiplayer-service.d.ts +153 -0
- package/dist/multiplayer-service.js +429 -0
- package/dist/navigation.d.ts +91 -0
- package/dist/navigation.js +338 -0
- package/dist/navmesh.d.ts +236 -0
- package/dist/navmesh.js +1423 -0
- package/dist/networked-client.d.ts +124 -0
- package/dist/networked-client.js +688 -0
- package/dist/networked-input-authority.d.ts +51 -0
- package/dist/networked-input-authority.js +439 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +19 -0
- package/dist/number-lab.d.ts +15 -0
- package/dist/number-lab.js +75 -0
- package/dist/offline-session.d.ts +2 -0
- package/dist/offline-session.js +367 -0
- package/dist/pause-resume.d.ts +48 -0
- package/dist/pause-resume.js +40 -0
- package/dist/physics-cert.d.ts +40 -0
- package/dist/physics-cert.js +389 -0
- package/dist/physics2d.d.ts +142 -0
- package/dist/physics2d.js +741 -0
- package/dist/physics3d.d.ts +285 -0
- package/dist/physics3d.js +1979 -0
- package/dist/prediction-culling.d.ts +34 -0
- package/dist/prediction-culling.js +200 -0
- package/dist/protocol-lab.d.ts +115 -0
- package/dist/protocol-lab.js +1295 -0
- package/dist/r3f-render-adapter.d.ts +61 -0
- package/dist/r3f-render-adapter.js +203 -0
- package/dist/random.d.ts +13 -0
- package/dist/random.js +55 -0
- package/dist/replay-bundle.d.ts +150 -0
- package/dist/replay-bundle.js +1586 -0
- package/dist/replay-inspect.d.ts +60 -0
- package/dist/replay-inspect.js +228 -0
- package/dist/replay-scoring.d.ts +28 -0
- package/dist/replay-scoring.js +65 -0
- package/dist/replay.d.ts +17 -0
- package/dist/replay.js +351 -0
- package/dist/reports.d.ts +176 -0
- package/dist/reports.js +174 -0
- package/dist/rollback-history.d.ts +46 -0
- package/dist/rollback-history.js +247 -0
- package/dist/runtime-guards.d.ts +1 -0
- package/dist/runtime-guards.js +108 -0
- package/dist/sample-lab.d.ts +32 -0
- package/dist/sample-lab.js +134 -0
- package/dist/sample-scenes.d.ts +86 -0
- package/dist/sample-scenes.js +745 -0
- package/dist/schema-artifacts.d.ts +49 -0
- package/dist/schema-artifacts.js +356 -0
- package/dist/schema-codegen.d.ts +21 -0
- package/dist/schema-codegen.js +538 -0
- package/dist/schema-dsl-binary.d.ts +75 -0
- package/dist/schema-dsl-binary.js +648 -0
- package/dist/schema.d.ts +87 -0
- package/dist/schema.js +315 -0
- package/dist/sdk-offline.d.ts +34 -0
- package/dist/sdk-offline.js +96 -0
- package/dist/session-promotion.d.ts +26 -0
- package/dist/session-promotion.js +70 -0
- package/dist/session-snapshot.d.ts +95 -0
- package/dist/session-snapshot.js +255 -0
- package/dist/session-wire.d.ts +89 -0
- package/dist/session-wire.js +211 -0
- package/dist/signals.d.ts +31 -0
- package/dist/signals.js +99 -0
- package/dist/sparse-set.d.ts +34 -0
- package/dist/sparse-set.js +165 -0
- package/dist/synctest.d.ts +31 -0
- package/dist/synctest.js +133 -0
- package/dist/system-lifecycle.d.ts +72 -0
- package/dist/system-lifecycle.js +281 -0
- package/dist/timers.d.ts +17 -0
- package/dist/timers.js +53 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/static-checker.d.ts +31 -0
- package/dist/tools/static-checker.js +1462 -0
- package/dist/tools/vite-plugin.d.ts +69 -0
- package/dist/tools/vite-plugin.js +203 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.js +1 -0
- package/dist/venus-mp-budget.d.ts +29 -0
- package/dist/venus-mp-budget.js +122 -0
- package/dist/ws-frame.d.ts +49 -0
- package/dist/ws-frame.js +247 -0
- package/package.json +169 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeterministicAuthorityServer = createDeterministicAuthorityServer;
|
|
4
|
+
exports.createSyncplayClient = createSyncplayClient;
|
|
5
|
+
exports.verifyDeterministicAuthorityCertificationArtifact = verifyDeterministicAuthorityCertificationArtifact;
|
|
6
|
+
const canonical_js_1 = require("./canonical.js");
|
|
7
|
+
const commands_js_1 = require("./commands.js");
|
|
8
|
+
const local_authority_js_1 = require("./local-authority.js");
|
|
9
|
+
const local_authority_wire_js_1 = require("./local-authority-wire.js");
|
|
10
|
+
function createDeterministicAuthorityServer(options) {
|
|
11
|
+
if (!Number.isInteger(options.players) || options.players < 1) {
|
|
12
|
+
throw new Error('Deterministic authority server players must be a positive integer');
|
|
13
|
+
}
|
|
14
|
+
const runtime = (0, local_authority_js_1.createDeterministicLocalAuthorityRuntime)(options.players, options);
|
|
15
|
+
const commandTimeline = createAuthorityCommandTimeline(options);
|
|
16
|
+
const botSlots = new Set();
|
|
17
|
+
const connectedSlots = new Set();
|
|
18
|
+
const inputHistory = [];
|
|
19
|
+
const lifecycleEvents = [];
|
|
20
|
+
let closed = false;
|
|
21
|
+
const server = {
|
|
22
|
+
protocol: local_authority_wire_js_1.deterministicLocalAuthorityWireProtocol,
|
|
23
|
+
players: options.players,
|
|
24
|
+
get botSlots() {
|
|
25
|
+
assertOpen();
|
|
26
|
+
return [...botSlots].sort(compareNumbers);
|
|
27
|
+
},
|
|
28
|
+
get state() {
|
|
29
|
+
assertOpen();
|
|
30
|
+
return runtime.state;
|
|
31
|
+
},
|
|
32
|
+
connectClient(clientOptions) {
|
|
33
|
+
assertOpen();
|
|
34
|
+
assertClientSlot(options.players, clientOptions.slot);
|
|
35
|
+
if (clientOptions.spectator === true && clientOptions.bot === true) {
|
|
36
|
+
throw new Error('Deterministic multiplayer client cannot be both a spectator and a bot');
|
|
37
|
+
}
|
|
38
|
+
const existingClient = runtime.state.clients[clientOptions.slot];
|
|
39
|
+
if (clientOptions.spectator === true && botSlots.has(clientOptions.slot)) {
|
|
40
|
+
throw new Error(`Deterministic multiplayer slot ${clientOptions.slot} is already registered as a bot`);
|
|
41
|
+
}
|
|
42
|
+
if (clientOptions.bot === true && existingClient?.spectator === true) {
|
|
43
|
+
throw new Error(`Deterministic multiplayer slot ${clientOptions.slot} is already registered as a spectator`);
|
|
44
|
+
}
|
|
45
|
+
if (connectedSlots.has(clientOptions.slot)) {
|
|
46
|
+
throw new Error(`Deterministic multiplayer slot ${clientOptions.slot} is already connected`);
|
|
47
|
+
}
|
|
48
|
+
if (clientOptions.lateJoin === true) {
|
|
49
|
+
runtime.lateJoin(clientOptions.slot);
|
|
50
|
+
lifecycleEvents.push({ kind: 'lateJoin', slot: clientOptions.slot, frame: runtime.state.frame });
|
|
51
|
+
}
|
|
52
|
+
if (clientOptions.spectator === true) {
|
|
53
|
+
runtime.addSpectator(clientOptions.slot);
|
|
54
|
+
lifecycleEvents.push({ kind: 'spectator', slot: clientOptions.slot, frame: runtime.state.frame });
|
|
55
|
+
}
|
|
56
|
+
if (clientOptions.bot === true) {
|
|
57
|
+
botSlots.add(clientOptions.slot);
|
|
58
|
+
}
|
|
59
|
+
connectedSlots.add(clientOptions.slot);
|
|
60
|
+
return createLocalClientConnection(runtime, commandTimeline, () => server.botSlots, () => inputHistory, () => lifecycleEvents, (input) => inputHistory.push(input), (event) => lifecycleEvents.push(event), clientOptions.slot, clientRole(clientOptions), assertOpen);
|
|
61
|
+
},
|
|
62
|
+
stepFrames(count) {
|
|
63
|
+
assertOpen();
|
|
64
|
+
if (!Number.isInteger(count) || count < 0) {
|
|
65
|
+
throw new Error('Deterministic authority server step count must be a non-negative integer');
|
|
66
|
+
}
|
|
67
|
+
for (let frame = 0; frame < count; frame += 1) {
|
|
68
|
+
runtime.step();
|
|
69
|
+
commandTimeline?.setCurrentFrame(runtime.state.frame);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
pollCommands(frame, pollOptions = {}) {
|
|
73
|
+
assertOpen();
|
|
74
|
+
return requireCommandTimeline(commandTimeline).poll(frame, pollOptions.slot, pollOptions.channelId);
|
|
75
|
+
},
|
|
76
|
+
commandSnapshot() {
|
|
77
|
+
assertOpen();
|
|
78
|
+
return requireCommandTimeline(commandTimeline).snapshot();
|
|
79
|
+
},
|
|
80
|
+
snapshot() {
|
|
81
|
+
assertOpen();
|
|
82
|
+
return runtime.snapshot();
|
|
83
|
+
},
|
|
84
|
+
checksums() {
|
|
85
|
+
assertOpen();
|
|
86
|
+
return createAuthorityChecksums(runtime, commandTimeline);
|
|
87
|
+
},
|
|
88
|
+
exportCertificationArtifact() {
|
|
89
|
+
assertOpen();
|
|
90
|
+
return createCertificationArtifact(runtime, commandTimeline, server.botSlots, inputHistory, lifecycleEvents);
|
|
91
|
+
},
|
|
92
|
+
close() {
|
|
93
|
+
closed = true;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
function assertOpen() {
|
|
97
|
+
if (closed) {
|
|
98
|
+
throw new Error('Deterministic authority server is closed');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return server;
|
|
102
|
+
}
|
|
103
|
+
function createSyncplayClient(options) {
|
|
104
|
+
const connection = options.connection;
|
|
105
|
+
return {
|
|
106
|
+
slot: connection.slot,
|
|
107
|
+
role: connection.role,
|
|
108
|
+
submitInput(input) {
|
|
109
|
+
return connection.submitInput(input);
|
|
110
|
+
},
|
|
111
|
+
submitCommand(command) {
|
|
112
|
+
return connection.submitCommand(command);
|
|
113
|
+
},
|
|
114
|
+
pollCommands(frame, commandOptions = {}) {
|
|
115
|
+
return connection.pollCommands(frame, commandOptions);
|
|
116
|
+
},
|
|
117
|
+
commandSnapshot() {
|
|
118
|
+
return connection.commandSnapshot();
|
|
119
|
+
},
|
|
120
|
+
lateJoin() {
|
|
121
|
+
return connection.lateJoin();
|
|
122
|
+
},
|
|
123
|
+
disconnect() {
|
|
124
|
+
connection.disconnect();
|
|
125
|
+
},
|
|
126
|
+
reconnect() {
|
|
127
|
+
connection.reconnect();
|
|
128
|
+
},
|
|
129
|
+
snapshot() {
|
|
130
|
+
return connection.snapshot();
|
|
131
|
+
},
|
|
132
|
+
checksums() {
|
|
133
|
+
return connection.checksums();
|
|
134
|
+
},
|
|
135
|
+
exportCertificationArtifact() {
|
|
136
|
+
return connection.exportCertificationArtifact();
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function verifyDeterministicAuthorityCertificationArtifact(artifact) {
|
|
141
|
+
const diagnostics = [];
|
|
142
|
+
if (artifact.schemaVersion !== 1) {
|
|
143
|
+
diagnostics.push('schema-version-mismatch');
|
|
144
|
+
}
|
|
145
|
+
if (artifact.protocol !== local_authority_wire_js_1.deterministicLocalAuthorityWireProtocol) {
|
|
146
|
+
diagnostics.push('protocol-mismatch');
|
|
147
|
+
}
|
|
148
|
+
if (artifact.players !== artifact.snapshot.state.players) {
|
|
149
|
+
diagnostics.push('players-mismatch');
|
|
150
|
+
}
|
|
151
|
+
if (artifact.frame !== artifact.snapshot.state.frame) {
|
|
152
|
+
diagnostics.push('frame-mismatch');
|
|
153
|
+
}
|
|
154
|
+
if (artifact.snapshotChecksum !== (0, canonical_js_1.defaultChecksum)(artifact.snapshot)) {
|
|
155
|
+
diagnostics.push('snapshot-checksum-mismatch');
|
|
156
|
+
}
|
|
157
|
+
if (artifact.checksums.authorityChecksum !== (0, canonical_js_1.defaultChecksum)(artifact.snapshot.state)) {
|
|
158
|
+
diagnostics.push('authority-checksum-mismatch');
|
|
159
|
+
}
|
|
160
|
+
if (artifact.checksums.clientChecksum !== (0, canonical_js_1.defaultChecksum)(artifact.snapshot.clientStateBySlot)) {
|
|
161
|
+
diagnostics.push('client-checksum-mismatch');
|
|
162
|
+
}
|
|
163
|
+
if (artifact.checksums.authorityProjectionChecksum !== (0, canonical_js_1.defaultChecksum)(artifact.snapshot.state.stateBySlot)) {
|
|
164
|
+
diagnostics.push('authority-projection-checksum-mismatch');
|
|
165
|
+
}
|
|
166
|
+
if (artifact.checksums.clientProjectionChecksum !== (0, canonical_js_1.defaultChecksum)(artifact.snapshot.clientStateBySlot)) {
|
|
167
|
+
diagnostics.push('client-projection-checksum-mismatch');
|
|
168
|
+
}
|
|
169
|
+
if (artifact.checksums.commandChecksum !== artifact.snapshot.commandChecksum) {
|
|
170
|
+
diagnostics.push('command-checksum-mismatch');
|
|
171
|
+
}
|
|
172
|
+
if (artifact.checksums.convergence !== (artifact.checksums.authorityProjectionChecksum === artifact.checksums.clientProjectionChecksum)) {
|
|
173
|
+
diagnostics.push('convergence-mismatch');
|
|
174
|
+
}
|
|
175
|
+
if (!sameNumberList(artifact.botSlots, [...artifact.botSlots].sort(compareNumbers))) {
|
|
176
|
+
diagnostics.push('bot-slots-order-mismatch');
|
|
177
|
+
}
|
|
178
|
+
if (!sameNumberList(artifact.lateJoinSlots, artifact.snapshot.lateJoinSlots)) {
|
|
179
|
+
diagnostics.push('late-join-slots-mismatch');
|
|
180
|
+
}
|
|
181
|
+
if (!sameNumberList(artifact.spectatorSlots, artifact.snapshot.spectatorSlots)) {
|
|
182
|
+
diagnostics.push('spectator-slots-mismatch');
|
|
183
|
+
}
|
|
184
|
+
const replay = replayAuthorityCertificationHistory(artifact.players, artifact.frame, artifact.inputHistory, artifact.lifecycleEvents);
|
|
185
|
+
if (artifact.replay.mismatches !== replay.mismatches) {
|
|
186
|
+
diagnostics.push('replay-mismatches-mismatch');
|
|
187
|
+
}
|
|
188
|
+
if (artifact.replay.replayedAuthorityChecksum !== replay.replayedAuthorityChecksum) {
|
|
189
|
+
diagnostics.push('replay-authority-evidence-mismatch');
|
|
190
|
+
}
|
|
191
|
+
if (artifact.replay.replayedProjectionChecksum !== replay.replayedProjectionChecksum) {
|
|
192
|
+
diagnostics.push('replay-projection-evidence-mismatch');
|
|
193
|
+
}
|
|
194
|
+
if (replay.replayedAuthorityChecksum !== artifact.checksums.authorityChecksum) {
|
|
195
|
+
diagnostics.push('replay-authority-checksum-mismatch');
|
|
196
|
+
}
|
|
197
|
+
if (replay.replayedProjectionChecksum !== artifact.checksums.authorityProjectionChecksum) {
|
|
198
|
+
diagnostics.push('replay-projection-checksum-mismatch');
|
|
199
|
+
}
|
|
200
|
+
if (artifact.commandSnapshot === undefined) {
|
|
201
|
+
if (artifact.commandSnapshotChecksum !== undefined || artifact.checksums.commandTimelineChecksum !== undefined) {
|
|
202
|
+
diagnostics.push('command-snapshot-mismatch');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const recomputedCommandSnapshot = (0, commands_js_1.createDeterministicCommandTimelineSnapshot)({
|
|
207
|
+
currentFrame: artifact.commandSnapshot.currentFrame,
|
|
208
|
+
accepted: artifact.commandSnapshot.accepted,
|
|
209
|
+
rejected: artifact.commandSnapshot.rejected,
|
|
210
|
+
});
|
|
211
|
+
if (artifact.commandSnapshotChecksum !== recomputedCommandSnapshot.checksum) {
|
|
212
|
+
diagnostics.push('command-snapshot-checksum-mismatch');
|
|
213
|
+
}
|
|
214
|
+
if (artifact.checksums.commandTimelineChecksum !== (0, canonical_js_1.defaultChecksum)({
|
|
215
|
+
accepted: recomputedCommandSnapshot.accepted,
|
|
216
|
+
rejected: recomputedCommandSnapshot.rejected,
|
|
217
|
+
})) {
|
|
218
|
+
diagnostics.push('command-timeline-checksum-mismatch');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const replayMismatches = replay.mismatches;
|
|
222
|
+
return {
|
|
223
|
+
result: diagnostics.length === 0 ? 'pass' : 'fail',
|
|
224
|
+
diagnostics,
|
|
225
|
+
replayMismatches,
|
|
226
|
+
convergence: artifact.checksums.convergence,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function createLocalClientConnection(runtime, commandTimeline, getBotSlots, getInputHistory, getLifecycleEvents, recordInput, recordLifecycle, slot, role, assertOpen) {
|
|
230
|
+
return {
|
|
231
|
+
slot,
|
|
232
|
+
role,
|
|
233
|
+
submitInput(input) {
|
|
234
|
+
assertOpen();
|
|
235
|
+
const inputMessage = {
|
|
236
|
+
slot,
|
|
237
|
+
senderSlot: slot,
|
|
238
|
+
frame: input.frame,
|
|
239
|
+
value: input.value,
|
|
240
|
+
data: input.data,
|
|
241
|
+
delay: input.delay,
|
|
242
|
+
inputId: input.inputId,
|
|
243
|
+
};
|
|
244
|
+
const accepted = runtime.submitInput(inputMessage);
|
|
245
|
+
recordInput({ accepted, ...inputMessage });
|
|
246
|
+
return { accepted, slot, frame: input.frame };
|
|
247
|
+
},
|
|
248
|
+
submitCommand(command) {
|
|
249
|
+
assertOpen();
|
|
250
|
+
const timeline = requireCommandTimeline(commandTimeline);
|
|
251
|
+
const normalizedCommand = {
|
|
252
|
+
id: command.id,
|
|
253
|
+
slot: command.slot ?? slot,
|
|
254
|
+
frame: command.frame,
|
|
255
|
+
channelId: command.channelId,
|
|
256
|
+
payload: command.payload,
|
|
257
|
+
...(command.predicted === undefined ? {} : { predicted: command.predicted }),
|
|
258
|
+
};
|
|
259
|
+
const rejection = role === 'spectator'
|
|
260
|
+
? timeline.recordFromSlot(-1, normalizedCommand)
|
|
261
|
+
: timeline.recordFromSlot(slot, normalizedCommand);
|
|
262
|
+
return {
|
|
263
|
+
accepted: rejection === undefined,
|
|
264
|
+
slot,
|
|
265
|
+
frame: command.frame,
|
|
266
|
+
commandId: command.id,
|
|
267
|
+
...(rejection === undefined ? {} : { rejectionReason: rejection.reason }),
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
pollCommands(frame, options = {}) {
|
|
271
|
+
assertOpen();
|
|
272
|
+
return requireCommandTimeline(commandTimeline).poll(frame, options.slot, options.channelId);
|
|
273
|
+
},
|
|
274
|
+
commandSnapshot() {
|
|
275
|
+
assertOpen();
|
|
276
|
+
return requireCommandTimeline(commandTimeline).snapshot();
|
|
277
|
+
},
|
|
278
|
+
lateJoin() {
|
|
279
|
+
assertOpen();
|
|
280
|
+
runtime.lateJoin(slot);
|
|
281
|
+
recordLifecycle({ kind: 'lateJoin', slot, frame: runtime.state.frame });
|
|
282
|
+
return { slot, frame: runtime.state.frame };
|
|
283
|
+
},
|
|
284
|
+
disconnect() {
|
|
285
|
+
assertOpen();
|
|
286
|
+
runtime.disconnect(slot);
|
|
287
|
+
recordLifecycle({ kind: 'disconnect', slot, frame: runtime.state.frame });
|
|
288
|
+
},
|
|
289
|
+
reconnect() {
|
|
290
|
+
assertOpen();
|
|
291
|
+
runtime.reconnect(slot);
|
|
292
|
+
recordLifecycle({ kind: 'reconnect', slot, frame: runtime.state.frame });
|
|
293
|
+
},
|
|
294
|
+
snapshot() {
|
|
295
|
+
assertOpen();
|
|
296
|
+
return runtime.snapshot();
|
|
297
|
+
},
|
|
298
|
+
checksums() {
|
|
299
|
+
assertOpen();
|
|
300
|
+
return createAuthorityChecksums(runtime, commandTimeline);
|
|
301
|
+
},
|
|
302
|
+
exportCertificationArtifact() {
|
|
303
|
+
assertOpen();
|
|
304
|
+
return createCertificationArtifact(runtime, commandTimeline, getBotSlots(), getInputHistory(), getLifecycleEvents());
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function createCertificationArtifact(runtime, commandTimeline, botSlots, inputHistory, lifecycleEvents) {
|
|
309
|
+
const snapshot = runtime.snapshot();
|
|
310
|
+
const checksums = createAuthorityChecksums(runtime, commandTimeline);
|
|
311
|
+
const commandSnapshot = commandTimeline?.snapshot();
|
|
312
|
+
const replay = replayAuthorityCertificationHistory(snapshot.state.players, snapshot.state.frame, inputHistory, lifecycleEvents);
|
|
313
|
+
const artifact = {
|
|
314
|
+
schemaVersion: 1,
|
|
315
|
+
result: checksums.convergence ? 'pass' : 'fail',
|
|
316
|
+
protocol: local_authority_wire_js_1.deterministicLocalAuthorityWireProtocol,
|
|
317
|
+
players: snapshot.state.players,
|
|
318
|
+
frame: snapshot.state.frame,
|
|
319
|
+
replayMismatches: checksums.convergence ? 0 : 1,
|
|
320
|
+
botSlots: [...botSlots].sort(compareNumbers),
|
|
321
|
+
lateJoinSlots: snapshot.lateJoinSlots,
|
|
322
|
+
spectatorSlots: snapshot.spectatorSlots,
|
|
323
|
+
inputHistory: inputHistory.map((input) => ({ ...input })),
|
|
324
|
+
lifecycleEvents: lifecycleEvents.map((event) => ({ ...event })),
|
|
325
|
+
replay,
|
|
326
|
+
snapshotChecksum: (0, canonical_js_1.defaultChecksum)(snapshot),
|
|
327
|
+
checksums,
|
|
328
|
+
snapshot,
|
|
329
|
+
...(commandSnapshot === undefined ? {} : {
|
|
330
|
+
commandSnapshotChecksum: commandSnapshot.checksum,
|
|
331
|
+
commandSnapshot,
|
|
332
|
+
}),
|
|
333
|
+
};
|
|
334
|
+
const verification = verifyDeterministicAuthorityCertificationArtifact(artifact);
|
|
335
|
+
return {
|
|
336
|
+
...artifact,
|
|
337
|
+
result: verification.result,
|
|
338
|
+
replayMismatches: verification.replayMismatches,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function createAuthorityCommandTimeline(options) {
|
|
342
|
+
if (options.commandChannels === undefined) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
return (0, commands_js_1.createDeterministicCommandTimeline)({
|
|
346
|
+
playerCount: options.players,
|
|
347
|
+
currentFrame: 0,
|
|
348
|
+
channels: options.commandChannels,
|
|
349
|
+
validAssetRefs: options.validCommandAssetRefs,
|
|
350
|
+
validatePayload: options.validateCommandPayload,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function requireCommandTimeline(commandTimeline) {
|
|
354
|
+
if (commandTimeline === undefined) {
|
|
355
|
+
throw new Error('Deterministic authority server command timeline is not configured');
|
|
356
|
+
}
|
|
357
|
+
return commandTimeline;
|
|
358
|
+
}
|
|
359
|
+
function createAuthorityChecksums(runtime, commandTimeline) {
|
|
360
|
+
const checksums = runtime.checksums();
|
|
361
|
+
return {
|
|
362
|
+
...checksums,
|
|
363
|
+
...(commandTimeline === undefined ? {} : { commandTimelineChecksum: commandTimeline.checksum() }),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function replayAuthorityCertificationHistory(players, targetFrame, inputHistory, lifecycleEvents) {
|
|
367
|
+
const replayRuntime = (0, local_authority_js_1.createDeterministicLocalAuthorityRuntime)(players);
|
|
368
|
+
const orderedEvents = [
|
|
369
|
+
...lifecycleEvents.map((event, index) => ({ kind: 'lifecycle', frame: event.frame, index, event })),
|
|
370
|
+
...inputHistory.map((input, index) => ({ kind: 'input', frame: input.frame, index, input })),
|
|
371
|
+
].sort(compareReplayEvents);
|
|
372
|
+
let mismatches = 0;
|
|
373
|
+
for (const entry of orderedEvents) {
|
|
374
|
+
while (replayRuntime.state.frame < entry.frame) {
|
|
375
|
+
replayRuntime.step();
|
|
376
|
+
}
|
|
377
|
+
if (entry.kind === 'lifecycle') {
|
|
378
|
+
applyReplayLifecycleEvent(replayRuntime, entry.event);
|
|
379
|
+
}
|
|
380
|
+
else if (replayRuntime.submitInput(entry.input) !== entry.input.accepted) {
|
|
381
|
+
mismatches += 1;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
while (replayRuntime.state.frame < targetFrame) {
|
|
385
|
+
replayRuntime.step();
|
|
386
|
+
}
|
|
387
|
+
const checksums = replayRuntime.checksums();
|
|
388
|
+
return {
|
|
389
|
+
mismatches,
|
|
390
|
+
replayedAuthorityChecksum: checksums.authorityChecksum,
|
|
391
|
+
replayedProjectionChecksum: checksums.authorityProjectionChecksum,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function applyReplayLifecycleEvent(replayRuntime, event) {
|
|
395
|
+
if (event.kind === 'lateJoin') {
|
|
396
|
+
replayRuntime.lateJoin(event.slot);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (event.kind === 'spectator') {
|
|
400
|
+
replayRuntime.addSpectator(event.slot);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (event.kind === 'disconnect') {
|
|
404
|
+
replayRuntime.disconnect(event.slot);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
replayRuntime.reconnect(event.slot);
|
|
408
|
+
}
|
|
409
|
+
function clientRole(options) {
|
|
410
|
+
if (options.spectator === true) {
|
|
411
|
+
return 'spectator';
|
|
412
|
+
}
|
|
413
|
+
if (options.bot === true) {
|
|
414
|
+
return 'bot';
|
|
415
|
+
}
|
|
416
|
+
return 'player';
|
|
417
|
+
}
|
|
418
|
+
function compareNumbers(left, right) {
|
|
419
|
+
return left - right;
|
|
420
|
+
}
|
|
421
|
+
function compareReplayEvents(left, right) {
|
|
422
|
+
return left.frame - right.frame || replayEventKindOrder(left.kind) - replayEventKindOrder(right.kind) || left.index - right.index;
|
|
423
|
+
}
|
|
424
|
+
function replayEventKindOrder(kind) {
|
|
425
|
+
return kind === 'lifecycle' ? 0 : 1;
|
|
426
|
+
}
|
|
427
|
+
function sameNumberList(left, right) {
|
|
428
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
429
|
+
}
|
|
430
|
+
function assertClientSlot(players, slot) {
|
|
431
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= players) {
|
|
432
|
+
throw new Error(`Invalid deterministic multiplayer client slot ${slot}`);
|
|
433
|
+
}
|
|
434
|
+
}
|