castle-web-cli 0.4.240 → 0.4.241
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/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +2 -0
- package/dist/platformDoc.js +1 -1
- package/dist/roomLogs.d.ts +1 -0
- package/dist/roomLogs.js +30 -6
- 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/server/hub.js +141 -28
- 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 +2 -1
- package/kits/hub-game/docs/contract.md +14 -2
- package/kits/hub-game/scripts/test-ballot.mjs +1 -1
- 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/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
|
@@ -378,6 +378,9 @@ Back; nothing is reported and nothing is granted. Web hosts only.
|
|
|
378
378
|
whole board (cover, title, label, every row) and a tap on the board, or
|
|
379
379
|
walking away, closes it; a cabinet with no score draws no chip. A place
|
|
380
380
|
draws none of it and ships no client code for it. The size rules are in §12.
|
|
381
|
+
An open board (v1.217) is drawn opaque and over every plate and area label:
|
|
382
|
+
the pad caption (`engine.hubPadContext`) is hidden while it is open, and a
|
|
383
|
+
world label under it is covered, never seen through it. The chip is as before.
|
|
381
384
|
- On the dev serve there is no ghost, so no board: a cabinet is inert, and a
|
|
382
385
|
place says so on its label. `{ k: 'hub-dev-classic' }` (§12), honoured only
|
|
383
386
|
by a dev session, gives every cabinet door a stand-in board so the card and
|
|
@@ -538,7 +541,13 @@ suppressed. The chip fits within 94vw and its personal line ellipsizes.
|
|
|
538
541
|
A connection that comes back under a new player id (a drop past the place's
|
|
539
542
|
hold, such as 180 s backgrounded) is not an arrival the player made: its
|
|
540
543
|
`hub-arrived` leaves the camera's yaw and the avatar's facing as they were.
|
|
541
|
-
- A late joiner arrives the same way, alone.
|
|
544
|
+
- A late joiner arrives the same way, alone. Two bodies never start on one
|
|
545
|
+
spot (v1.218): a joiner with no pose who finds the spawn or its arrival
|
|
546
|
+
slot taken starts where its arrival puts it, in its first WORLD; a row
|
|
547
|
+
slot or a stored pose being restored that another body on the roster takes
|
|
548
|
+
(nearer than two radii, overlapping it in height) is stepped off along the
|
|
549
|
+
row, else the eight compass directions, on every place (before, only on
|
|
550
|
+
authored floors). A free slot or pose is used exactly.
|
|
542
551
|
- **A line on leaving (v1.52).** `hub.leaving(playerId, text)` says what is waiting
|
|
543
552
|
next visit: on Back, a game's end or a door out of the place (not a classic
|
|
544
553
|
cabinet), the latest line is captured under the trip cover's title and,
|
|
@@ -2524,7 +2533,9 @@ movement over 5 cm or a cue/visibility change, without frame allocations.
|
|
|
2524
2533
|
- `engine.hubPadContext: true`: one noninteractive chrome caption shows the
|
|
2525
2534
|
active title at 16 px, wrapping to at most two lines with ellipsis and the
|
|
2526
2535
|
full accessible title. A nearby door pad adds “Step on to join” at 13 px;
|
|
2527
|
-
explicit cues and standing players get no secondary line.
|
|
2536
|
+
explicit cues and standing players get no secondary line. For a guest (a
|
|
2537
|
+
`hub.guests` id: signed out or an anonymous visitor) a cabinet's pad says
|
|
2538
|
+
“Sign in to play” instead, near it or on it (v1.217). It yields to
|
|
2528
2539
|
final chrome surfaces, the avatar, joystick and host corners, and is omitted
|
|
2529
2540
|
without room. Panels, sheets, chat and travel hide it. It dispatches nothing
|
|
2530
2541
|
and leaves Talk, invites and actions alone.
|
|
@@ -5294,6 +5305,7 @@ a deck written before them remains valid.
|
|
|
5294
5305
|
|
|
5295
5306
|
| date | change |
|
|
5296
5307
|
| --- | --- |
|
|
5308
|
+
| 2026-11-17 (v1.218) | Kit-internal, server only, no deck-facing key or API and no wire change: §5 two bodies never start on one spot. A body admitted with no pose where another body takes the scene spawn or the slot its lone arrival would take starts where that arrival will put it (the arrival slot if free, else the free spot beside it; one helper decides both) before its WORLD goes out, so that WORLD is the one placement its client makes, at once; arriving alone it stays there while the spot is still free, and a group with such a member takes the row's slots in the order its members stand along it. An arrival slot (an arrival, and the arrival a fall or a Stuck? unstick puts a player at) or stored pose (cold `resumePose`, arrival pose, retained visit) that another body takes is likewise stepped off on every place, not only on authored floors (`ground.none: true`); a free slot or pose is used exactly. A body takes a spot when it is nearer than two radii and overlaps it in height (one on a floor above or below does not), and only while its player is on the roster (real-time admits a joiner before it removes the bodies of players who left that tick). A group row's later slots are held where a body would stand in them. The search uses the place's own body size and treats a spot past the ground slab's edge (`ground.half`, 100 m by default) as unsupported unless an authored solid holds it; when every candidate fails the slot is shared, as before. Ground-backed places (the Town) kept the spawn for everyone, so two lone joiners stood on exactly the same point; on each client the two capsules were coaxial, Rapier pushed the local one into the ground under the other's avatar, and it could not walk until one left (Nov 17 Market check, reproduced locally). A stepped-off cold restore still reaches its client as the restore always has. Tests: `test-placeat-server` stepoff, arrivalFree and arrivalTaken (WORLD before hello, reports and corrections on: the client moves once), restoreFree, restoreOccupied; `test-standing` slab edge, floors, a leaver on the same tick and an elevated row, `test-rehello` and `test-stuck` updated; physics-3d `test-coaxial-escape`. |
|
|
5297
5309
|
| 2026-11-10 | `hub.loadingCover` copy and timing: a return's cover (backgrounded 30 s or more, or a dropped connection, after the first load lifted) is plain black, with no title, words or spinner, while hidden and for its first 2.5 s after the page shows; then it says "Reconnecting…" with the spinner. The first load keeps the deck title. The multiplayer-3d kit's return cover is quiet for the same 2.5 s. Most returns are back sooner (measured 2.1-2.4 s past a 180 s app switch). No wire change. Within `hub.contract: 1`. |
|
|
5298
5310
|
| 2026-11-10 | Kit-internal, no deck-facing key or API: a connection that comes back under a new player id on the same page (a drop past the place's hold, such as 180 s backgrounded) keeps the camera yaw and the avatar's facing through the new session's `hub-arrived`, instead of turning to the arrival facing (the Town turned every such return to its spawn bearing). A trip's arrival, the first join and an arrival on another connection face as before. Within `hub.contract: 1`. |
|
|
5299
5311
|
| 2026-11-05 | Kit-internal, no deck-facing key or API: a frame stall is not an away (amends v1.169's rule). The multiplayer resume gate also arms on frames that stopped for over 1 s on a visible page with the socket connected, as a low-memory phone's do while it loads a place. A `hub-go` or tagged `hub-end` met under such a gate now counts as met online, and the trip or end goes as it always did. It still counts as met while away when the connection dropped during the away, the transport is not connected, the page is or was hidden since the away began, or the away has lasted 5 s (`STALL_AWAY_MS`, the multiplayer kit's own line between a frame hitch and an away). The first room split's `hub.go(nux)`, sent about 4 s after the join inside the loading window, was dropped on such phones as 'fired while offline', and the Town's 45 s wait then kept the player in the Town (repro on a moto e22, Nov 5). Limit: an app switch under 5 s on a page that fires no `visibilitychange` and keeps its socket counts as online. Within `hub.contract: 1`. |
|
|
@@ -963,7 +963,7 @@ for (const back of [true, false]) {
|
|
|
963
963
|
'const pickerFree = idle && place !== null && !this.talk.talking() && !this.carded;',
|
|
964
964
|
'scene.data?.engine?.hubInviteRail !== true || Hub.hub.place !== place || Boolean(place.result) || this.talk.talking() || this.carded ||',
|
|
965
965
|
// Optional pad readability only reads the card state to hide its caption.
|
|
966
|
-
'this.carded || this.decor?.opened() === true);',
|
|
966
|
+
'this.carded || this.decor?.opened() === true, selfId != null && Hub.hub.guests?.has?.(selfId) === true);',
|
|
967
967
|
'if (this.ballot) {',
|
|
968
968
|
'this.ballot.dispose();',
|
|
969
969
|
'this.ballot = null;',
|
|
@@ -80,6 +80,22 @@ assert.equal(padContextText({ cue: named, on: true }).secondary, '');
|
|
|
80
80
|
assert.equal(padContextText({ cue: { ...named, door: false }, on: false }).secondary, '');
|
|
81
81
|
assert.equal(padContextText({ cue: { ...named, title: undefined }, on: true }), null);
|
|
82
82
|
assert.equal(padContextText(null), null);
|
|
83
|
+
// v1.217: a guest at a cabinet's pad is told to sign in, near it or on it.
|
|
84
|
+
const cabDoor = actor('cab-actor', { HubDoor: { id: 'cab', title: 'Daily Chicken', kind: 'cabinet' } });
|
|
85
|
+
const cabPad = actor('cab-pad', { Transform: { x: 0, y: 0.1, z: 0 }, HubPad: { door: 'cab', radius: 0.85 } });
|
|
86
|
+
const [cabCue] = cues([cabPad, cabDoor]);
|
|
87
|
+
assert.equal(cabCue.cabinet, true);
|
|
88
|
+
assert.equal(cabCue.title, 'Daily Chicken');
|
|
89
|
+
assert.equal(cues([a, door])[0].cabinet, false, 'an ordinary door is not a cabinet');
|
|
90
|
+
assert.equal(padContextText({ cue: cabCue, on: false }).secondary, 'Step on to join', 'a signed-in player is invited as before');
|
|
91
|
+
assert.equal(padContextText({ cue: cabCue, on: false }, true).secondary, 'Sign in to play');
|
|
92
|
+
assert.equal(padContextText({ cue: cabCue, on: true }, true).secondary, 'Sign in to play');
|
|
93
|
+
assert.equal(padContextText({ cue: named, on: false }, true).secondary, 'Step on to join', 'a guest at an ordinary door is invited as before');
|
|
94
|
+
const kindTracker = makePadCueTracker();
|
|
95
|
+
assert.equal(kindTracker.frame([cabPad, cabDoor], new Set(), body(0)).cue.cabinet, true);
|
|
96
|
+
cabDoor.components.HubDoor.kind = undefined;
|
|
97
|
+
assert.equal(kindTracker.frame([cabPad, cabDoor], new Set(), body(0)).cue.cabinet, false, 'a door kind edit is seen without a new actor');
|
|
98
|
+
cabDoor.components.HubDoor.kind = 'cabinet';
|
|
83
99
|
|
|
84
100
|
// Actual enable gate: even accessing options would create client resources.
|
|
85
101
|
const forbidden = new Proxy({}, { get() {throw new Error('disabled path touched a resource');} });
|
|
@@ -251,6 +267,29 @@ chrome.safeSurface('invite-dialog', panel, 'card');
|
|
|
251
267
|
chrome.setPadContext(text);
|
|
252
268
|
assert.equal(caption.style.visibility, 'hidden', 'any registered open panel hides the caption');
|
|
253
269
|
chrome.safeSurface('invite-dialog', null);
|
|
270
|
+
// v1.217: an open cabinet board hides the caption and is opaque; the chip
|
|
271
|
+
// does neither.
|
|
272
|
+
{
|
|
273
|
+
const cab = dom.made.find((n) => n.dataset.hub === 'cabinet');
|
|
274
|
+
cab.size = { w: 204, h: 275 };
|
|
275
|
+
const item = { id: 'cab', rev: 1, card: { title: 'Batting day', label: 'Daily kills', top: [{ username: 'bo', score: 12 }] }, x: 300, y: 300, opacity: 1 };
|
|
276
|
+
chrome.setCabinet(item, () => null);
|
|
277
|
+
assert.equal(cab.dataset.drawn, 'chip');
|
|
278
|
+
chrome.setPadContext(text);
|
|
279
|
+
assert.equal(caption.style.visibility, '', 'a chip leaves the caption alone');
|
|
280
|
+
assert.equal(cab.style.background, 'rgba(18,14,24,0.92)', 'the chip keeps its paint');
|
|
281
|
+
cab.handlers.pointerdown({ stopPropagation() {} });
|
|
282
|
+
chrome.setCabinet(item, () => null);
|
|
283
|
+
assert.equal(cab.dataset.drawn, 'board');
|
|
284
|
+
chrome.setPadContext(text);
|
|
285
|
+
assert.equal(caption.style.visibility, 'hidden', 'an open board hides the plate');
|
|
286
|
+
assert.equal(cab.style.background, 'rgb(18,14,24)', 'an open board is opaque: no label shows through');
|
|
287
|
+
cab.handlers.pointerdown({ stopPropagation() {} });
|
|
288
|
+
chrome.setCabinet(item, () => null);
|
|
289
|
+
chrome.setPadContext(text);
|
|
290
|
+
assert.equal(caption.style.visibility, '', 'closing the board brings the plate back');
|
|
291
|
+
chrome.setCabinet(null, () => null);
|
|
292
|
+
}
|
|
254
293
|
// Exact phone viewports use the shared final-rectangle placement, including
|
|
255
294
|
// action rails, joystick space, HUD and both host-reserved corners.
|
|
256
295
|
const overlaps = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
|
|
@@ -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
|
}
|