castle-web-cli 0.4.240 → 0.4.242
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/bundle.d.ts +9 -1
- package/dist/bundle.js +214 -25
- package/dist/init.js +1 -1
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +2 -0
- package/dist/platformDoc.js +3 -3
- package/dist/playPagePolicy.js +7 -6
- package/dist/roomLogs.d.ts +1 -0
- package/dist/roomLogs.js +30 -6
- package/dist/save-deck.js +20 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +7 -0
- package/kits/base/sdk/context.d.ts +5 -0
- package/kits/base/sdk/debugConsole.d.ts +1 -0
- package/kits/base/sdk/debugConsole.js +87 -14
- package/kits/base/sdk/runtime.js +5 -4
- package/kits/hub-game/code/client/chrome.js +8 -4
- package/kits/hub-game/code/client/padCues.js +11 -7
- package/kits/hub-game/code/client/padReadability.js +3 -3
- package/kits/hub-game/code/client/visibility.js +14 -4
- package/kits/hub-game/code/server/hub.js +146 -30
- package/kits/hub-game/code/server/players.js +6 -1
- package/kits/hub-game/code/server/standing.js +7 -3
- package/kits/hub-game/code/systems/hub.js +11 -3
- package/kits/hub-game/docs/contract.md +25 -4
- package/kits/hub-game/scripts/test-ballot.mjs +1 -1
- package/kits/hub-game/scripts/test-hub-trip.mjs +24 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +259 -6
- package/kits/hub-game/scripts/test-rehello.mjs +5 -3
- package/kits/hub-game/scripts/test-standing.mjs +135 -2
- package/kits/hub-game/scripts/test-stuck.mjs +5 -1
- package/kits/hub-game/scripts/test-visibility.mjs +54 -0
- package/kits/multiplayer-3d/castle.json +1 -1
- package/kits/multiplayer-3d/code/client/resumeGate.js +18 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +41 -7
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +226 -0
- package/kits/physics-3d/castle.json +1 -1
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
- package/kits/physics-3d/systems/physics3d.js +8 -0
- package/package.json +1 -1
|
@@ -13,6 +13,16 @@
|
|
|
13
13
|
// node scripts/test-placeat-server.mjs close
|
|
14
14
|
// A close in the same breath as the placement resumes the account's fresh
|
|
15
15
|
// socket at the placed spot, not where the last server step saw it.
|
|
16
|
+
// node scripts/test-placeat-server.mjs stepoff | restoreFree | restoreOccupied
|
|
17
|
+
// v1.218, on this ground-backed place (as the Town is): a lone joiner who
|
|
18
|
+
// finds someone on the spawn is placed off it; a returner whose stored pose
|
|
19
|
+
// nobody stands on is put back exactly there, and one whose pose is taken
|
|
20
|
+
// steps off it. Each in one server move, never dragged.
|
|
21
|
+
// node scripts/test-placeat-server.mjs arrivalFree | arrivalTaken
|
|
22
|
+
// The same with an arrival actor apart from the scene spawn: a joiner
|
|
23
|
+
// finding the spawn taken but the arrival free starts on the arrival; one
|
|
24
|
+
// finding the arrival taken starts beside it. Either way its first WORLD is
|
|
25
|
+
// the only move its client makes.
|
|
16
26
|
//
|
|
17
27
|
// With no argument both run.
|
|
18
28
|
import assert from 'node:assert/strict';
|
|
@@ -29,8 +39,15 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
29
39
|
const spawn = { x: 0, y: 1, z: 0 };
|
|
30
40
|
const cold = { x: 6, y: 1, z: 8 };
|
|
31
41
|
const user = { userId: '102', username: 'Bo', isAnonymous: false };
|
|
42
|
+
const other = { userId: '103', username: 'Cy', isAnonymous: false };
|
|
43
|
+
// Two capsule radii (the test scene's player has the default 0.35 m shape).
|
|
44
|
+
const TWO_RADII = 0.7;
|
|
45
|
+
// The arrival actor of the arrivalFree/arrivalTaken place: 2.5 m from the
|
|
46
|
+
// scene spawn, under the client's 4 m snap, so an eased correction would show.
|
|
47
|
+
const ARRIVAL = { x: 2, y: 1, z: 1.5 };
|
|
48
|
+
const ARRIVAL_CASES = new Set(['arrivalFree', 'arrivalTaken']);
|
|
32
49
|
const flat = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
|
|
33
|
-
const cases = { reports, close, walk, pinned, held, against };
|
|
50
|
+
const cases = { reports, close, walk, pinned, held, against, restoreReports, restorePreplaced, stepoff, restoreFree, restoreOccupied, arrivalFree, arrivalTaken };
|
|
34
51
|
const chosen = process.argv[2] ? [process.argv[2]] : Object.keys(cases);
|
|
35
52
|
for (const name of chosen) {
|
|
36
53
|
assert.ok(cases[name], `unknown case ${name}`);
|
|
@@ -55,11 +72,13 @@ async function run(name, body) {
|
|
|
55
72
|
await mkdir(path.join(dir, 'scenes'), { recursive: true });
|
|
56
73
|
await writeFile(path.join(dir, 'package.json'), JSON.stringify({ type: 'module', private: true }));
|
|
57
74
|
await writeFile(path.join(dir, 'castle.json'), JSON.stringify({
|
|
58
|
-
hub: { contract: 1, title: 'Resume pose boundary', resumePose: true
|
|
75
|
+
hub: { contract: 1, title: 'Resume pose boundary', resumePose: true,
|
|
76
|
+
...(ARRIVAL_CASES.has(name) ? { arrival: { actor: 'arrival', spread: 1.5, face: 0 } } : {}) },
|
|
59
77
|
server: { main: 'code/server/main.js', tickRate: 20, maxPlayers: 8 },
|
|
60
78
|
}));
|
|
61
79
|
await writeFile(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors: [
|
|
62
80
|
{ id: 'player', components: { Player: {}, Transform: { ...spawn } } },
|
|
81
|
+
...(ARRIVAL_CASES.has(name) ? [{ id: 'arrival', components: { Transform: { ...ARRIVAL } } }] : []),
|
|
63
82
|
] }));
|
|
64
83
|
// Local serve refuses storage to an unsaved deck: the session sees a
|
|
65
84
|
// revision-checked store kept in a file, so it outlives one session process.
|
|
@@ -119,9 +138,22 @@ async function run(name, body) {
|
|
|
119
138
|
const marks = new Map();
|
|
120
139
|
// A Dojo-like place: put the player where they stand, six steps running.
|
|
121
140
|
let pin = null;
|
|
141
|
+
let arrivalAt = null;
|
|
142
|
+
const paths = new Map();
|
|
143
|
+
let arrivalPlaced = 0;
|
|
122
144
|
export default {
|
|
145
|
+
arrive(h, group) {
|
|
146
|
+
if (arrivalAt) for (const p of group) { h.placeAt(p.playerId, arrivalAt, 40); arrivalPlaced++; }
|
|
147
|
+
},
|
|
123
148
|
step(h) {
|
|
124
149
|
steps += 1;
|
|
150
|
+
// Every place each body has stood, a new entry only when it moved.
|
|
151
|
+
for (const [id, body] of h.sim.players) {
|
|
152
|
+
const path = paths.get(id) ?? [];
|
|
153
|
+
const last = path.at(-1);
|
|
154
|
+
if (!last || Math.hypot(body.at.x - last.x, body.at.z - last.z) > 0.01) path.push({ ...body.at });
|
|
155
|
+
paths.set(id, path);
|
|
156
|
+
}
|
|
125
157
|
for (const [id, mark] of marks) {
|
|
126
158
|
const body = h.sim.players.get(id);
|
|
127
159
|
if (body && body.movedAt !== mark.last) { mark.gap = Math.max(mark.gap, body.movedAt - mark.last); mark.last = body.movedAt; }
|
|
@@ -132,6 +164,8 @@ async function run(name, body) {
|
|
|
132
164
|
const id = p.playerId;
|
|
133
165
|
let body = h.sim.players.get(id);
|
|
134
166
|
if (d?.test === 'move') h.placeAt(id, ${JSON.stringify(cold)}, 40);
|
|
167
|
+
if (d?.test === 'prepare-restore') h.placeAt(id, d.at, 40);
|
|
168
|
+
if (d?.test === 'preplace-return') arrivalAt = d.at;
|
|
135
169
|
if (d?.test === 'shove') h.placeAt(id, { ...body.at, z: body.at.z + 1 });
|
|
136
170
|
if (d?.test === 'pin') pin = { id, n: 6 };
|
|
137
171
|
if (d?.test === 'back') h.placeAt(id, { ...body.at, x: body.at.x - 1.4 });
|
|
@@ -141,7 +175,10 @@ async function run(name, body) {
|
|
|
141
175
|
body = h.sim.players.get(id);
|
|
142
176
|
const mark = marks.get(id);
|
|
143
177
|
// clamped: false once the server took a report from where the body stands.
|
|
144
|
-
if (d?.test) h.send(id, { test: d.test, pose: body && { ...body.at }, clamped: body?.clamped, steps,
|
|
178
|
+
if (d?.test) h.send(id, { test: d.test, pose: body && { ...body.at }, facing: body?.facing, clamped: body?.clamped, steps,
|
|
179
|
+
arrivalPlaced, path: paths.get(id) ?? [],
|
|
180
|
+
others: [...h.sim.players].filter(([o]) => o !== id).map(([, b]) => ({ ...b.at })),
|
|
181
|
+
now: h.sim.timeMs, movedAt: body?.movedAt, arrivedAt: h.players().find(p => p.playerId === id)?.arrivedAt,
|
|
145
182
|
gap: mark && body ? Math.max(mark.gap, h.sim.timeMs - mark.last) : null });
|
|
146
183
|
},
|
|
147
184
|
};
|
|
@@ -165,16 +202,16 @@ async function run(name, body) {
|
|
|
165
202
|
|
|
166
203
|
// Arrive at the spawn and wait until the server takes the client's reports
|
|
167
204
|
// there (clamped false), so nothing about the arrival is still settling.
|
|
168
|
-
async function arrive(t) {
|
|
205
|
+
async function arrive(t, who = user, where = spawn) {
|
|
169
206
|
const server = t.server();
|
|
170
|
-
const a = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(
|
|
207
|
+
const a = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(who)}`);
|
|
171
208
|
await a.wait(f => f.t === 'hello');
|
|
172
209
|
a.send({ k: 'hub-hello', avatar: 0, party: 1 });
|
|
173
210
|
a.local = { ...spawn };
|
|
174
211
|
a.reporting = true;
|
|
175
212
|
await a.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
|
|
176
213
|
await world(a);
|
|
177
|
-
const agreed = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose,
|
|
214
|
+
const agreed = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose, where) < 0.3);
|
|
178
215
|
assert.equal(agreed.clamped, false, `server takes the client's reports at the spawn ${JSON.stringify(agreed)}`);
|
|
179
216
|
// One step after that, so the leave has a pose from a step to fall back on.
|
|
180
217
|
await until(a, 'state', {}, s => s.steps > agreed.steps);
|
|
@@ -308,6 +345,210 @@ async function close(t) {
|
|
|
308
345
|
console.log('test-placeat-server close: a leave right after placeAt stores the placed pose');
|
|
309
346
|
}
|
|
310
347
|
|
|
348
|
+
// A correction under 4 m is eased by the browser. A restored cold pose
|
|
349
|
+
// needs the same stale-report guard as placeAt while spawn reports arrive.
|
|
350
|
+
async function restoreReports(t, preplaced = false) {
|
|
351
|
+
const restoredAt = { ...spawn, z: spawn.z + 3.2 };
|
|
352
|
+
const a = await arrive(t);
|
|
353
|
+
a.reporting = false;
|
|
354
|
+
a.local = { ...restoredAt };
|
|
355
|
+
const placed = await query(a, 'prepare-restore', { at: restoredAt });
|
|
356
|
+
await until(a, 'state', {}, s => s.steps > placed.steps);
|
|
357
|
+
if (preplaced) await query(a, 'preplace-return', { at: restoredAt });
|
|
358
|
+
a.socket.close();
|
|
359
|
+
await new Promise(resolve => a.socket.once('close', resolve));
|
|
360
|
+
const rowsFile = path.join(t.dir, 'pose-rows.json');
|
|
361
|
+
const rows = async () => { try { return JSON.parse(await readFile(rowsFile, 'utf8')).rows; } catch { return {}; } };
|
|
362
|
+
for (const end = Date.now() + 10000; !Object.keys(await rows()).length && Date.now() < end;) await sleep(50);
|
|
363
|
+
assert.equal(Object.keys(await rows()).length, 1, 'the near-spawn pose was stored');
|
|
364
|
+
const server = preplaced ? t.server() : await t.restart();
|
|
365
|
+
if (preplaced) server.defaultSession.nextGuest = () => user;
|
|
366
|
+
const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(user)}`);
|
|
367
|
+
await b.wait(f => f.t === 'hello');
|
|
368
|
+
b.local = { ...spawn };
|
|
369
|
+
b.deafUntil = Date.now() + 10000;
|
|
370
|
+
b.send({ k: 'hub-hello', avatar: 0, party: 1 });
|
|
371
|
+
await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
|
|
372
|
+
const restored = await query(b, 'state');
|
|
373
|
+
assert.ok(flat(restored.pose, restoredAt) < 0.05, `cold pose restored 3.2 m from spawn: ${JSON.stringify(restored)}`);
|
|
374
|
+
if (preplaced) assert.equal(restored.arrivalPlaced, 1, 'the arrival hook placed the returner before the cold restore');
|
|
375
|
+
assert.ok(Number.isFinite(restored.arrivedAt), 'arrival and restore share the same simulation tick');
|
|
376
|
+
const report = at => b.send({ k: 'i', p: [at.x, at.y, at.z, 0], c: [], r: [], o: [] });
|
|
377
|
+
for (const z of [spawn.z, spawn.z + 0.1]) {
|
|
378
|
+
report({ ...spawn, z });
|
|
379
|
+
await sleep(50);
|
|
380
|
+
const s = await query(b, 'state');
|
|
381
|
+
assert.ok(s.now - restored.arrivedAt < 500, 'spawn-side reports exercise STALE_FROM_MS');
|
|
382
|
+
assert.ok(flat(s.pose, restoredAt) < 0.05, `stale reports leave the restored body in place: ${JSON.stringify(s)}`);
|
|
383
|
+
assert.equal(s.movedAt, restored.movedAt, 'a stale report is refused outright');
|
|
384
|
+
}
|
|
385
|
+
// A client that applied the correction can walk on immediately.
|
|
386
|
+
const onward = { ...restoredAt, z: restoredAt.z + 0.2 };
|
|
387
|
+
report(onward);
|
|
388
|
+
const walked = await until(b, 'state', {}, s => s.clamped === false && flat(s.pose, onward) < 0.05);
|
|
389
|
+
assert.ok(walked.clamped === false && flat(walked.pose, onward) < 0.05, `a walk from the restored spot is taken: ${JSON.stringify(walked)}`);
|
|
390
|
+
// Once one valid report is taken, even a reachable spawn-side report is
|
|
391
|
+
// ordinary movement. It would still be stale if the guard had survived.
|
|
392
|
+
await sleep(50);
|
|
393
|
+
const before = await query(b, 'state');
|
|
394
|
+
assert.ok(before.now - restored.arrivedAt < 500, 'guard release is tested inside STALE_FROM_MS');
|
|
395
|
+
report({ ...spawn, z: spawn.z + 1.2 });
|
|
396
|
+
const released = await until(b, 'state', {}, s => s.movedAt !== walked.movedAt);
|
|
397
|
+
assert.notEqual(released.movedAt, walked.movedAt, 'the valid walk ended the restore guard');
|
|
398
|
+
assert.ok(released.pose.z < onward.z - 0.1, 'the subsequent report moves the body');
|
|
399
|
+
console.log(`test-placeat-server ${preplaced ? 'restorePreplaced' : 'restoreReports'}: a 3.2 m cold restore${preplaced ? ' preceded by placeAt to the same pose' : ''} rejects stale spawn reports, takes a walk and ends its guard`);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async function restorePreplaced(t) {
|
|
403
|
+
await restoreReports(t, true);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Every point of a path is where it started or where it ended: one move.
|
|
407
|
+
function oneMove(path, label) {
|
|
408
|
+
const [first, last] = [path[0], path.at(-1)];
|
|
409
|
+
const between = path.filter(p => flat(p, first) > 0.05 && flat(p, last) > 0.05);
|
|
410
|
+
assert.equal(between.length, 0, `${label} was moved in one step, not dragged: ${JSON.stringify(path)}`);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// A second lone joiner, as two accounts entering the Town one after the other.
|
|
414
|
+
// Before v1.218 a ground-backed place put both on the very spawn, where each
|
|
415
|
+
// client's capsule wedged under the other's avatar (Nov 17 Market check).
|
|
416
|
+
async function stepoff(t) {
|
|
417
|
+
const a = await arrive(t);
|
|
418
|
+
const server = t.server();
|
|
419
|
+
// The real order: the session sends the joiner's WORLD the tick after it
|
|
420
|
+
// admits them, before their hub-hello is heard. The client reports and takes
|
|
421
|
+
// corrections as the shipped one does (eased under 4 m, a WORLD at once).
|
|
422
|
+
const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(other)}`);
|
|
423
|
+
b.local = { ...spawn };
|
|
424
|
+
b.reporting = true;
|
|
425
|
+
await b.wait(f => f.t === 'hello');
|
|
426
|
+
await world(b);
|
|
427
|
+
b.send({ k: 'hub-hello', avatar: 0, party: 1 });
|
|
428
|
+
await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
|
|
429
|
+
await sleep(600);
|
|
430
|
+
const sb = await query(b, 'state');
|
|
431
|
+
const sa = await query(a, 'state');
|
|
432
|
+
assert.ok(flat(sa.pose, spawn) < 0.3, `the first player stays on the spawn ${JSON.stringify(sa.pose)}`);
|
|
433
|
+
const gap = flat(sb.pose, sa.pose);
|
|
434
|
+
assert.ok(gap >= TWO_RADII, `the joiner is placed off the occupied spawn: ${gap.toFixed(3)} m ${JSON.stringify(sb.pose)}`);
|
|
435
|
+
assert.ok(b.worldAt && flat(b.worldAt, sb.pose) < 0.05, `the joiner's WORLD already put it there: ${JSON.stringify(b.worldAt)} vs ${JSON.stringify(sb.pose)}`);
|
|
436
|
+
// On the client: the scene spawn it started from, then the WORLD spot, and
|
|
437
|
+
// nothing between or after (no eased correction, no glide).
|
|
438
|
+
assert.ok(b.path.length >= 1 && flat(b.path.at(-1), sb.pose) < 0.05 &&
|
|
439
|
+
b.path.every(p => flat(p, spawn) < 0.05 || flat(p, sb.pose) < 0.05), `the client moved once, straight to the spot: ${JSON.stringify(b.path)}`);
|
|
440
|
+
oneMove(sb.path, 'the joiner');
|
|
441
|
+
console.log(`test-placeat-server stepoff: a lone joiner on an occupied spawn starts ${gap.toFixed(2)} m off it with its WORLD, and stays`);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// A second joiner on a place whose arrival actor (ARRIVAL) stands apart from
|
|
445
|
+
// the scene spawn. Reports and corrections on, WORLD before hello.
|
|
446
|
+
async function joinSecond(t) {
|
|
447
|
+
const server = t.server();
|
|
448
|
+
const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(other)}`);
|
|
449
|
+
b.local = { ...spawn };
|
|
450
|
+
b.reporting = true;
|
|
451
|
+
await b.wait(f => f.t === 'hello');
|
|
452
|
+
await world(b);
|
|
453
|
+
b.send({ k: 'hub-hello', avatar: 0, party: 1 });
|
|
454
|
+
await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
|
|
455
|
+
await sleep(600);
|
|
456
|
+
const s = await query(b, 'state');
|
|
457
|
+
assert.ok(b.worldAt && flat(b.worldAt, s.pose) < 0.05, `the joiner's WORLD already put it where it arrived: ${JSON.stringify(b.worldAt)} vs ${JSON.stringify(s.pose)}`);
|
|
458
|
+
assert.ok(flat(b.path.at(-1), s.pose) < 0.05 && b.path.every(p => flat(p, spawn) < 0.05 || flat(p, s.pose) < 0.05),
|
|
459
|
+
`the client moved once, straight to the spot: ${JSON.stringify(b.path)}`);
|
|
460
|
+
oneMove(s.path, 'the joiner');
|
|
461
|
+
return s;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// The scene spawn is taken, the arrival is free: the joiner starts on the
|
|
465
|
+
// arrival, not beside the spawn.
|
|
466
|
+
async function arrivalFree(t) {
|
|
467
|
+
const a = await arrive(t, user, ARRIVAL);
|
|
468
|
+
a.local = { ...spawn };
|
|
469
|
+
await query(a, 'prepare-restore', { at: spawn });
|
|
470
|
+
const there = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose, spawn) < 0.05);
|
|
471
|
+
assert.ok(flat(there.pose, spawn) < 0.05, `the first player stands on the scene spawn ${JSON.stringify(there.pose)}`);
|
|
472
|
+
const s = await joinSecond(t);
|
|
473
|
+
assert.ok(flat(s.pose, ARRIVAL) < 0.01, `the joiner is on the arrival ${JSON.stringify(s.pose)}`);
|
|
474
|
+
console.log('test-placeat-server arrivalFree: spawn taken, arrival free: the joiner starts on the arrival');
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// The arrival is taken, the scene spawn is free: the joiner starts beside the
|
|
478
|
+
// arrival with its WORLD, not on the spawn to be moved later.
|
|
479
|
+
async function arrivalTaken(t) {
|
|
480
|
+
const a = await arrive(t, user, ARRIVAL);
|
|
481
|
+
const sa = await query(a, 'state');
|
|
482
|
+
assert.ok(flat(sa.pose, ARRIVAL) < 0.05, `the first player stands on the arrival ${JSON.stringify(sa.pose)}`);
|
|
483
|
+
const s = await joinSecond(t);
|
|
484
|
+
const gap = flat(s.pose, sa.pose);
|
|
485
|
+
assert.ok(gap >= TWO_RADII && gap <= 1.6, `the joiner is beside the arrival: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
|
|
486
|
+
console.log(`test-placeat-server arrivalTaken: arrival taken, spawn free: the joiner starts ${gap.toFixed(2)} m beside the arrival`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Stores `user`'s pose at `at` (a leave stores it) and starts a fresh session.
|
|
490
|
+
async function storePose(t, at) {
|
|
491
|
+
const a = await arrive(t);
|
|
492
|
+
a.reporting = false;
|
|
493
|
+
a.local = { ...at };
|
|
494
|
+
const placed = await query(a, 'prepare-restore', { at });
|
|
495
|
+
await until(a, 'state', {}, s => s.steps > placed.steps);
|
|
496
|
+
a.socket.close();
|
|
497
|
+
await new Promise(resolve => a.socket.once('close', resolve));
|
|
498
|
+
const rowsFile = path.join(t.dir, 'pose-rows.json');
|
|
499
|
+
const rows = async () => { try { return JSON.parse(await readFile(rowsFile, 'utf8')).rows; } catch { return {}; } };
|
|
500
|
+
for (const end = Date.now() + 10000; !Object.keys(await rows()).length && Date.now() < end;) await sleep(50);
|
|
501
|
+
assert.equal(Object.keys(await rows()).length, 1, 'the pose was stored');
|
|
502
|
+
return t.restart();
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// The returner, deaf so only the server moves its body. The dev server gives
|
|
506
|
+
// the author's identity to the first socket only; a later one is a guest, so
|
|
507
|
+
// the returner is named as that guest (as restorePreplaced does).
|
|
508
|
+
async function rejoin(t, server) {
|
|
509
|
+
server.defaultSession.nextGuest = () => user;
|
|
510
|
+
const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(user)}`);
|
|
511
|
+
await b.wait(f => f.t === 'hello');
|
|
512
|
+
b.local = { ...spawn };
|
|
513
|
+
b.deafUntil = Date.now() + 60000;
|
|
514
|
+
b.send({ k: 'hub-hello', avatar: 0, party: 1 });
|
|
515
|
+
await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
|
|
516
|
+
await sleep(300);
|
|
517
|
+
return query(b, 'state');
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Someone else in the place, but not on the stored pose: it is restored exactly.
|
|
521
|
+
async function restoreFree(t) {
|
|
522
|
+
const at = { ...spawn, x: spawn.x + 2.5, z: spawn.z + 3.2 };
|
|
523
|
+
const server = await storePose(t, at);
|
|
524
|
+
const c = await arrive(t, other);
|
|
525
|
+
const s = await rejoin(t, server);
|
|
526
|
+
assert.ok(flat(s.pose, at) < 0.01 && Math.abs(s.pose.y - at.y) < 0.01, `a free stored pose is restored exactly: ${JSON.stringify(s.pose)} vs ${JSON.stringify(at)}`);
|
|
527
|
+
// prepare-restore's placeAt faced the player 40 degrees.
|
|
528
|
+
assert.ok(Math.abs(s.facing - 40 * Math.PI / 180) < 1e-6, `and its facing: ${s.facing}`);
|
|
529
|
+
assert.ok(flat((await query(c, 'state')).pose, spawn) < 0.3, 'the other player stays on the spawn');
|
|
530
|
+
oneMove(s.path, 'the returner');
|
|
531
|
+
console.log('test-placeat-server restoreFree: a free stored pose on a ground-backed place is restored exactly');
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// Someone standing on the stored pose: the returner steps off it.
|
|
535
|
+
async function restoreOccupied(t) {
|
|
536
|
+
const at = { ...spawn, x: spawn.x + 2.5, z: spawn.z + 3.2 };
|
|
537
|
+
const server = await storePose(t, at);
|
|
538
|
+
const c = await arrive(t, other);
|
|
539
|
+
c.local = { ...at };
|
|
540
|
+
await query(c, 'prepare-restore', { at });
|
|
541
|
+
const there = await until(c, 'state', {}, s => s.clamped === false && flat(s.pose, at) < 0.05);
|
|
542
|
+
assert.ok(flat(there.pose, at) < 0.05, `the other player stands on the stored pose ${JSON.stringify(there.pose)}`);
|
|
543
|
+
const s = await rejoin(t, server);
|
|
544
|
+
const gap = flat(s.pose, there.pose);
|
|
545
|
+
assert.ok(gap >= TWO_RADII, `the returner steps off the occupied pose: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
|
|
546
|
+
assert.ok(gap <= 1, `beside its own pose, not sent back to the spawn: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
|
|
547
|
+
assert.ok(flat(s.pose, spawn) > 2, `not at the spawn ${JSON.stringify(s.pose)}`);
|
|
548
|
+
oneMove(s.path, 'the returner');
|
|
549
|
+
console.log(`test-placeat-server restoreOccupied: a returner whose pose is taken is put ${gap.toFixed(2)} m off it, in one move`);
|
|
550
|
+
}
|
|
551
|
+
|
|
311
552
|
// The client's starting WORLD (the frame that places its body; see connect).
|
|
312
553
|
function world(client) {
|
|
313
554
|
return client.wait(f => f.t === 'm' && [].concat(f.d?.batch ?? f.d).some(d => d?.k === 'w' && !d.again));
|
|
@@ -327,6 +568,11 @@ async function query(client, test, extra = {}) {
|
|
|
327
568
|
client.send({ test, ...extra });
|
|
328
569
|
return (await client.wait(f => f.t === 'm' && f.d?.test === test)).d;
|
|
329
570
|
}
|
|
571
|
+
function trackPath(client) {
|
|
572
|
+
const last = client.path.at(-1);
|
|
573
|
+
if (client.local && (!last || flat(last, client.local) > 0.01)) client.path.push({ ...client.local });
|
|
574
|
+
}
|
|
575
|
+
|
|
330
576
|
async function connect(sockets, url) {
|
|
331
577
|
const socket = new WebSocket(url);
|
|
332
578
|
sockets.push(socket);
|
|
@@ -339,6 +585,10 @@ async function connect(sockets, url) {
|
|
|
339
585
|
deafUntil: 0,
|
|
340
586
|
vel: { x: 0, z: 0 },
|
|
341
587
|
clampedTo: null,
|
|
588
|
+
// Every place the client's body stood (a new entry when it moved over
|
|
589
|
+
// 1 cm), and where its first WORLD put it.
|
|
590
|
+
path: [],
|
|
591
|
+
worldAt: null,
|
|
342
592
|
send: d => socket.send(JSON.stringify({ t: 'm', d })),
|
|
343
593
|
async wait(predicate) {
|
|
344
594
|
const deadline = Date.now() + 10000;
|
|
@@ -359,12 +609,14 @@ async function connect(sockets, url) {
|
|
|
359
609
|
for (const d of frame.t === 'm' ? [].concat(frame.d?.batch ?? frame.d) : []) {
|
|
360
610
|
for (const [id, x, y, z, , clamped] of d?.ps ?? []) {
|
|
361
611
|
// A deaf client stands for one whose frames are still on their way.
|
|
612
|
+
if (id === client.selfId && d.k === 'w' && !d.again && !client.worldAt) client.worldAt = { x, y, z };
|
|
362
613
|
if (Date.now() < client.deafUntil || id !== client.selfId || !client.local) continue;
|
|
363
614
|
if (d.k === 'w' && !d.again) client.local = { x, y, z };
|
|
364
615
|
else if (clamped) client.clampedTo = { x, y, z };
|
|
365
616
|
}
|
|
366
617
|
}
|
|
367
618
|
frames.push(frame);
|
|
619
|
+
trackPath(client);
|
|
368
620
|
});
|
|
369
621
|
// Its frames, as multiplayer-3d's client runs them: walk at `vel`, then take
|
|
370
622
|
// the newest clamped row, at once from over CLAMP_SNAP (4 m) and otherwise
|
|
@@ -382,6 +634,7 @@ async function connect(sockets, url) {
|
|
|
382
634
|
const off = { x: to.x - client.local.x, y: to.y - client.local.y, z: to.z - client.local.z };
|
|
383
635
|
client.local = Math.hypot(off.x, off.y, off.z) > 4 ? { ...to }
|
|
384
636
|
: { x: client.local.x + off.x * 0.25, y: client.local.y + off.y * 0.25, z: client.local.z + off.z * 0.25 };
|
|
637
|
+
trackPath(client);
|
|
385
638
|
}, 16);
|
|
386
639
|
socket.on('close', () => clearInterval(frameTimer));
|
|
387
640
|
const timer = setInterval(() => {
|
|
@@ -1315,7 +1315,9 @@ for (const viaPlace of [false, true]) {
|
|
|
1315
1315
|
});
|
|
1316
1316
|
}
|
|
1317
1317
|
|
|
1318
|
-
|
|
1318
|
+
// v1.218: ground-backed places clear an occupied slot too (two bodies on one
|
|
1319
|
+
// spot wedge on the client); an empty slot keeps its placement.
|
|
1320
|
+
test('a lone door arrival clears an occupied slot on an authored floor and on ground; empty slots keep their placement', () => {
|
|
1319
1321
|
const arrival = { x: 3, y: 1, z: -4 };
|
|
1320
1322
|
const facing = 60 * Math.PI / 180;
|
|
1321
1323
|
const floor = { id: 'floor', components: { Solid: {}, Transform: { x: 0, y: -0.07, z: 0 }, Shape: { kind: 'box', width: 40, height: 0.14, depth: 40 } } };
|
|
@@ -1329,13 +1331,13 @@ test('a lone door arrival onto an authored floor clears an occupied slot; ground
|
|
|
1329
1331
|
r.say('p2', { k: 'hub-hello', avatar: 1, from: 'home-1', party: 1 });
|
|
1330
1332
|
r.tick(2000); r.tick();
|
|
1331
1333
|
const guest = r.world.players.get('p2');
|
|
1332
|
-
if (occupied
|
|
1334
|
+
if (occupied) {
|
|
1333
1335
|
const step = 2 * 0.35 + 0.1;
|
|
1334
1336
|
assert.ok(Math.abs(guest.at.x - arrival.x - Math.cos(facing) * step) < 1e-9, 'first free slot on the positive side');
|
|
1335
1337
|
assert.ok(Math.abs(guest.at.z - arrival.z + Math.sin(facing) * step) < 1e-9, 'stays along the arrival row');
|
|
1336
1338
|
assert.ok(Math.hypot(guest.at.x - arrival.x, guest.at.z - arrival.z) >= 0.7, 'no overlapping players');
|
|
1337
1339
|
} else {
|
|
1338
|
-
assert.deepEqual([guest.at.x, guest.at.z], [arrival.x, arrival.z],
|
|
1340
|
+
assert.deepEqual([guest.at.x, guest.at.z], [arrival.x, arrival.z], 'empty arrival placement is unchanged');
|
|
1339
1341
|
}
|
|
1340
1342
|
assert.equal(guest.facing, facing, 'keeps the arrival facing');
|
|
1341
1343
|
}
|
|
@@ -177,7 +177,10 @@ await test('unreadable resumed pose uses standing spawn', async () => {
|
|
|
177
177
|
// -0.14, +1.09), the client snapped there with WORLD, and the arrival row at
|
|
178
178
|
// the spawn then reached it as a correction under the client's 4 m snap, eased
|
|
179
179
|
// a quarter of the way a frame: a 1.1 m glide after the cover lifted.
|
|
180
|
-
|
|
180
|
+
// v1.218 (Nov 17 Market check): two bodies on exactly one spot wedge, so the
|
|
181
|
+
// second lone joiner starts beside the first, and its WORLD is still the one
|
|
182
|
+
// placement: the arrival row keeps it there.
|
|
183
|
+
await test('joiners wait where WORLD put them, the second beside the first, and the arrival row moves nothing', async () => {
|
|
181
184
|
const town = { id: 'spawn', components: { ...spawn.components, Transform: { x: 0, y: 1, z: 9 } } };
|
|
182
185
|
globalThis.__standingActors = [town, door];
|
|
183
186
|
globalThis.__standingGround = {};
|
|
@@ -194,7 +197,14 @@ await test('joiners wait on the spawn and the arrival row moves nothing', async
|
|
|
194
197
|
for (const id of ['p1', 'p2']) {
|
|
195
198
|
wrapped.addPlayer(sim, id);
|
|
196
199
|
const waiting = { ...sim.players.get(id).at };
|
|
197
|
-
|
|
200
|
+
if (id === 'p1') {
|
|
201
|
+
assert.deepEqual([waiting.x, waiting.z], [0, 9], 'the first joiner waits on the spawn');
|
|
202
|
+
} else {
|
|
203
|
+
const first = sim.players.get('p1').at;
|
|
204
|
+
const gap = Math.hypot(waiting.x - first.x, waiting.z - first.z);
|
|
205
|
+
assert.ok(gap >= 2 * 0.35, `the second joiner waits off the taken spawn, ${gap} m from the first`);
|
|
206
|
+
assert.deepEqual([first.x, first.z], [0, 9], 'the first stays on the spawn');
|
|
207
|
+
}
|
|
198
208
|
h.message(session, { playerId: id }, { k: 'hub-hello', avatar: 1 });
|
|
199
209
|
h.place(sim);
|
|
200
210
|
assert.ok(sent.some(([to, data]) => to === id && data.k === 'hub-arrived'), `${id} arrived`);
|
|
@@ -203,6 +213,129 @@ await test('joiners wait on the spawn and the arrival row moves nothing', async
|
|
|
203
213
|
}
|
|
204
214
|
} finally { sim.world.free(); }
|
|
205
215
|
});
|
|
216
|
+
// v1.218: the step-off stands on the ground slab, which is finite: a spawn
|
|
217
|
+
// 0.4 m inside a 5 m slab's edge, whose row runs outward first (+x), steps
|
|
218
|
+
// inward, not off the edge.
|
|
219
|
+
await test('a joiner beside a taken spawn near the slab edge steps inward', async () => {
|
|
220
|
+
const edge = { id: 'spawn', components: { ...spawn.components, Transform: { x: 4.6, y: 1, z: 0, rotationY: 0 } } };
|
|
221
|
+
globalThis.__standingActors = [edge, door];
|
|
222
|
+
globalThis.__standingGround = { half: 5 };
|
|
223
|
+
const sim = await World.createSimulation();
|
|
224
|
+
sim.spawn = { x: 4.6, y: 1, z: 0 };
|
|
225
|
+
const h = layer(config, {}, {}, () => true, () => ({ half: 5 }), null, engine);
|
|
226
|
+
const session = { sessionId: 'dev:slab', players: [{ playerId: 'p1' }, { playerId: 'p2' }], send() {}, broadcast() {} };
|
|
227
|
+
h.sceneFor(session);
|
|
228
|
+
h.ready(sim);
|
|
229
|
+
const wrapped = hubPlayers(h);
|
|
230
|
+
try {
|
|
231
|
+
wrapped.addPlayer(sim, 'p1');
|
|
232
|
+
wrapped.addPlayer(sim, 'p2');
|
|
233
|
+
const [a, b] = ['p1', 'p2'].map((id) => sim.players.get(id).at);
|
|
234
|
+
assert.ok(Math.hypot(a.x - b.x, a.z - b.z) >= 0.7, `p2 steps off p1 ${JSON.stringify(b)}`);
|
|
235
|
+
assert.ok(Math.abs(b.x) <= 5 && Math.abs(b.z) <= 5, `p2 stands on the slab ${JSON.stringify(b)}`);
|
|
236
|
+
} finally { sim.world.free(); }
|
|
237
|
+
});
|
|
238
|
+
// v1.218: standing height uses the same finite slab as spotClear: past the
|
|
239
|
+
// edge a body stands on an authored platform below the ground plane, or keeps
|
|
240
|
+
// its given height when nothing holds it, never on the slab's plane.
|
|
241
|
+
await test('standing height past the slab edge stands on the platform there', async () => {
|
|
242
|
+
const platform = { id: 'ledge', components: { Transform: { x: 7, y: -1.5, z: 0, rotationY: 0 },
|
|
243
|
+
Shape: { kind: 'box', width: 2, height: 1, depth: 2, solid: true }, Solid: {} } };
|
|
244
|
+
globalThis.__standingActors = [spawn, door, platform];
|
|
245
|
+
globalThis.__standingGround = { half: 5 };
|
|
246
|
+
const sim = await World.createSimulation();
|
|
247
|
+
sim.spawn = { x: 0, y: 1, z: 0 };
|
|
248
|
+
const h = layer(config, {}, {}, () => true, () => ({ half: 5 }), null, engine);
|
|
249
|
+
const session = { sessionId: 'dev:ledge', players: [{ playerId: 'p1' }], send() {}, broadcast() {} };
|
|
250
|
+
h.sceneFor(session);
|
|
251
|
+
h.ready(sim);
|
|
252
|
+
try {
|
|
253
|
+
const onLedge = h.standingY(sim, { x: 7, y: 1, z: 0 });
|
|
254
|
+
assert.ok(onLedge < -0.1 && onLedge > -0.4, `stands on the ledge top (-1), got ${onLedge}`);
|
|
255
|
+
assert.equal(h.standingY(sim, { x: 7, y: 1, z: 4 }), 1, 'nothing holds a body past the slab: keep the given height');
|
|
256
|
+
assert.ok(Math.abs(h.standingY(sim, { x: 4, y: 1, z: 0 }) - 0.76) < 0.05, 'on the slab: the ground');
|
|
257
|
+
} finally { sim.world.free(); }
|
|
258
|
+
});
|
|
259
|
+
// v1.218: a body on a floor above (or below) does not take the spot.
|
|
260
|
+
await test('a body on another floor does not move a joiner off the spawn', async () => {
|
|
261
|
+
globalThis.__standingActors = [spawn, door];
|
|
262
|
+
globalThis.__standingGround = {};
|
|
263
|
+
const sim = await World.createSimulation();
|
|
264
|
+
sim.spawn = { x: 0, y: 1, z: 0 };
|
|
265
|
+
const h = layer(config, {}, {}, () => true, () => ({}), null, engine);
|
|
266
|
+
const session = { sessionId: 'dev:floors', players: [{ playerId: 'p1' }, { playerId: 'p2' }], send() {}, broadcast() {} };
|
|
267
|
+
h.sceneFor(session);
|
|
268
|
+
h.ready(sim);
|
|
269
|
+
const wrapped = hubPlayers(h);
|
|
270
|
+
try {
|
|
271
|
+
wrapped.addPlayer(sim, 'p1');
|
|
272
|
+
const up = sim.players.get('p1');
|
|
273
|
+
up.at = { ...up.at, y: up.at.y + 4 };
|
|
274
|
+
wrapped.addPlayer(sim, 'p2');
|
|
275
|
+
const b = sim.players.get('p2').at;
|
|
276
|
+
assert.deepEqual([b.x, b.z], [0, 0], `p2 keeps the spawn under a body 4 m up ${JSON.stringify(b)}`);
|
|
277
|
+
up.at = { ...up.at, y: up.at.y - 4 };
|
|
278
|
+
wrapped.addPlayer(sim, 'p3');
|
|
279
|
+
const c = sim.players.get('p3').at;
|
|
280
|
+
assert.ok(Math.hypot(c.x, c.z) >= 0.7, `a third, with two on the spawn at its height, steps off ${JSON.stringify(c)}`);
|
|
281
|
+
} finally { sim.world.free(); }
|
|
282
|
+
});
|
|
283
|
+
// v1.218: real-time admits a joiner before it removes the bodies of players
|
|
284
|
+
// who left the roster that tick (session.js reconcilePlayers). Such a body is
|
|
285
|
+
// going, and takes no spot: the joiner lands on the spawn itself.
|
|
286
|
+
await test('a body whose player left the roster this tick does not move a joiner off the spawn', async () => {
|
|
287
|
+
globalThis.__standingActors = [spawn, door];
|
|
288
|
+
globalThis.__standingGround = {};
|
|
289
|
+
const sim = await World.createSimulation();
|
|
290
|
+
sim.spawn = { x: 0, y: 1, z: 0 };
|
|
291
|
+
const h = layer(config, {}, {}, () => true, () => ({}), null, engine);
|
|
292
|
+
const session = { sessionId: 'dev:leaving', players: [{ playerId: 'p1' }], send() {}, broadcast() {} };
|
|
293
|
+
h.sceneFor(session);
|
|
294
|
+
h.ready(sim);
|
|
295
|
+
const wrapped = hubPlayers(h);
|
|
296
|
+
try {
|
|
297
|
+
wrapped.addPlayer(sim, 'p1');
|
|
298
|
+
// p1 leaves and p2 joins on the same tick: the roster has p2 only, and
|
|
299
|
+
// p1's body is still in the simulation while p2 is admitted.
|
|
300
|
+
session.players = [{ playerId: 'p2' }];
|
|
301
|
+
assert.ok(sim.players.has('p1'), 'the leaver\'s body is still there');
|
|
302
|
+
wrapped.addPlayer(sim, 'p2');
|
|
303
|
+
const b = sim.players.get('p2').at;
|
|
304
|
+
assert.deepEqual([b.x, b.z], [0, 0], `p2 lands exactly on the spawn ${JSON.stringify(b)}`);
|
|
305
|
+
} finally { sim.world.free(); }
|
|
306
|
+
});
|
|
307
|
+
// v1.218: a group row whose arrival marker stands 4 m above flat ground. Its
|
|
308
|
+
// slots are judged where a body stands in them: a member stepping off an
|
|
309
|
+
// occupied slot does not take a later member's slot (at the marker's raw
|
|
310
|
+
// height that slot looked free).
|
|
311
|
+
await test('an elevated arrival row: a stepped-off member leaves later members their own slots', async () => {
|
|
312
|
+
const marker = { id: 'arrival', components: { Transform: { x: 0, y: 5, z: 0 } } };
|
|
313
|
+
globalThis.__standingActors = [spawn, door, marker];
|
|
314
|
+
globalThis.__standingGround = {};
|
|
315
|
+
const sim = await World.createSimulation();
|
|
316
|
+
const rowConfig = { ...config, hub: { ...config.hub, arrival: { actor: 'arrival', spread: 1.5, face: 0 } } };
|
|
317
|
+
const h = layer(rowConfig, {}, {}, () => true, () => ({}), null, engine);
|
|
318
|
+
const session = { sessionId: 'dev:row', players: ['p0', 'p1', 'p2'].map((playerId) => ({ playerId })), send() {}, broadcast() {} };
|
|
319
|
+
h.sceneFor(session);
|
|
320
|
+
h.ready(sim);
|
|
321
|
+
try {
|
|
322
|
+
for (const id of ['p0', 'p1', 'p2']) Players.addPlayer(sim, id);
|
|
323
|
+
// Face 0: the row runs along +x, slots at x -0.75 and +0.75. p0 stands
|
|
324
|
+
// in the first.
|
|
325
|
+
const p0 = sim.players.get('p0');
|
|
326
|
+
p0.at = { x: -0.75, y: h.standingY(sim, { x: -0.75, y: 5, z: 0 }), z: 0 };
|
|
327
|
+
p0.body.setTranslation(p0.at, true);
|
|
328
|
+
assert.ok(p0.at.y < 1, `flat ground under the marker ${p0.at.y}`);
|
|
329
|
+
for (const id of ['p1', 'p2']) h.message(session, { playerId: id }, { k: 'hub-hello', avatar: 1, party: 2 });
|
|
330
|
+
h.place(sim);
|
|
331
|
+
const [a, b] = ['p1', 'p2'].map((id) => sim.players.get(id).at);
|
|
332
|
+
assert.ok(Math.abs(b.x - 0.75) < 1e-6 && Math.abs(b.z) < 1e-6, `the later member keeps its own slot ${JSON.stringify(b)}`);
|
|
333
|
+
assert.ok(a.x < -0.75 - 0.7, `the stepped-off member goes the other way ${JSON.stringify(a)}`);
|
|
334
|
+
for (const [u, v] of [[a, b], [a, p0.at], [b, p0.at]]) {
|
|
335
|
+
assert.ok(Math.hypot(u.x - v.x, u.z - v.z) >= 0.7, `distinct spots ${JSON.stringify([u, v])}`);
|
|
336
|
+
}
|
|
337
|
+
} finally { sim.world.free(); }
|
|
338
|
+
});
|
|
206
339
|
await test('other Players exports pass through unchanged', () => {
|
|
207
340
|
const wrapped = hubPlayers({});
|
|
208
341
|
assert.deepEqual(Object.keys(wrapped).sort(), Object.keys(Players).sort());
|
|
@@ -1400,7 +1400,11 @@ test('refused when asked again within 5 s, taken after', () => {
|
|
|
1400
1400
|
assert.deepEqual(b.at('p2'), { x: 6, y: 0.76, z: -9 });
|
|
1401
1401
|
skew += 200;
|
|
1402
1402
|
b.unstick('p1');
|
|
1403
|
-
|
|
1403
|
+
// v1.218: p2 stands on the arrival now, so p1 steps off it along the row
|
|
1404
|
+
// (two bodies on one spot wedge on the client).
|
|
1405
|
+
const p1 = b.at('p1');
|
|
1406
|
+
assert.equal(p1.x, 6);
|
|
1407
|
+
assert.ok(Math.hypot(p1.x - 6, p1.z + 9) >= 0.7, `p1 is put beside p2, not on it: ${JSON.stringify(p1)}`);
|
|
1404
1408
|
assert.equal(b.sent.length, 3);
|
|
1405
1409
|
// It counts as a jump: no door jump within a second of it, and none of it
|
|
1406
1410
|
// within a second of a door jump.
|
|
@@ -131,4 +131,58 @@ assert.deepEqual(mounted, [false, true]);
|
|
|
131
131
|
secondClient.sync(null, null, false);
|
|
132
132
|
shownDoc.visibilityState = 'hidden'; shownDoc.dispatchEvent(new Event('visibilitychange'));
|
|
133
133
|
assert.deepEqual(mounted, [false, true], 'disposed listener cannot send to its old net');
|
|
134
|
+
// v1.219: an app switch kept the socket while hidden; the return's visible
|
|
135
|
+
// went into the dead socket, which still read connected. After the rejoin
|
|
136
|
+
// the client sends its state again.
|
|
137
|
+
{
|
|
138
|
+
const got = [];
|
|
139
|
+
const doc2 = new EventTarget(); doc2.visibilityState = 'visible';
|
|
140
|
+
let state = 'connected', dead = false;
|
|
141
|
+
const net2 = { status: () => ({ state }), send: (data) => { if (!dead) got.push(data.visible); } };
|
|
142
|
+
const v = makeVisibility(doc2, () => ++at);
|
|
143
|
+
v.sync(net2, 'main', true);
|
|
144
|
+
doc2.visibilityState = 'hidden'; doc2.dispatchEvent(new Event('visibilitychange'));
|
|
145
|
+
dead = true; // the socket died while away, unseen
|
|
146
|
+
doc2.visibilityState = 'visible'; doc2.dispatchEvent(new Event('visibilitychange'));
|
|
147
|
+
state = 'reconnecting'; v.sync(net2, 'main', true);
|
|
148
|
+
dead = false; state = 'connected'; v.sync(net2, 'main', true);
|
|
149
|
+
v.sync(net2, 'main', true);
|
|
150
|
+
assert.deepEqual(got, [true, false, true], 'the rejoin sends visible again, once');
|
|
151
|
+
v.sync(null, null, false);
|
|
152
|
+
}
|
|
153
|
+
// v1.219: a rejoin between two frames is never seen as down; the hub's
|
|
154
|
+
// re-admission count says it, and the state is sent again.
|
|
155
|
+
{
|
|
156
|
+
const got = [];
|
|
157
|
+
const doc3 = new EventTarget(); doc3.visibilityState = 'visible';
|
|
158
|
+
let dead = false;
|
|
159
|
+
const net3 = { status: () => ({ state: 'connected' }), send: (data) => { if (!dead) got.push(data.visible); } };
|
|
160
|
+
const v = makeVisibility(doc3, () => ++at);
|
|
161
|
+
v.sync(net3, 'main', true, 0);
|
|
162
|
+
doc3.visibilityState = 'hidden'; doc3.dispatchEvent(new Event('visibilitychange'));
|
|
163
|
+
dead = true;
|
|
164
|
+
doc3.visibilityState = 'visible'; doc3.dispatchEvent(new Event('visibilitychange'));
|
|
165
|
+
dead = false;
|
|
166
|
+
v.sync(net3, 'main', true, 0);
|
|
167
|
+
assert.deepEqual(got, [true, false], 'no rejoin seen yet');
|
|
168
|
+
v.sync(net3, 'main', true, 1);
|
|
169
|
+
v.sync(net3, 'main', true, 1);
|
|
170
|
+
assert.deepEqual(got, [true, false, true], 'the re-admission sends visible again, once');
|
|
171
|
+
v.sync(null, null, false);
|
|
172
|
+
}
|
|
173
|
+
// v1.219: the server takes a rejoin's first signal even when it repeats the
|
|
174
|
+
// kept value, then coalesces again.
|
|
175
|
+
{
|
|
176
|
+
const seen = [];
|
|
177
|
+
const s = boot({ visibility: true }, { hooks: { visibility(hub, info) { seen.push(info.visible); } } });
|
|
178
|
+
s.tick();
|
|
179
|
+
s.say('p1', { k: 'hub-visibility', visible: false, at: 5000 }); s.tick();
|
|
180
|
+
s.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); s.tick();
|
|
181
|
+
s.say('p1', { k: 'hub-visibility', visible: false, at: 5001 }); s.tick();
|
|
182
|
+
s.say('p1', { k: 'hub-visibility', visible: false, at: 5002 }); s.tick();
|
|
183
|
+
assert.deepEqual(seen, [false, false], 'the first after the rejoin is taken, the next repeat is not');
|
|
184
|
+
s.say('p1', { k: 'hub-hello', avatar: 1, again: true }); s.tick();
|
|
185
|
+
s.say('p1', { k: 'hub-visibility', visible: false, at: 5003 }); s.tick();
|
|
186
|
+
assert.deepEqual(seen, [false, false], 'an avatar change is no rejoin');
|
|
187
|
+
}
|
|
134
188
|
console.log('test-visibility: ok');
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"autoUpdateWhenImported": true,
|
|
27
27
|
"deckId": "ZwA_P_-VO-Qh",
|
|
28
28
|
"cardId": "bvRmCzyUpt_a",
|
|
29
|
-
"publishedVersion": "2026-11-
|
|
29
|
+
"publishedVersion": "2026-11-17T22:31:57.174Z",
|
|
30
30
|
"main": "main.jsx",
|
|
31
31
|
"server": {
|
|
32
32
|
"main": "code/server/index.js",
|