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
package/dist/multiplayerDoc.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MULTIPLAYER_DOC = "# Multiplayer, in practice\n\nRead this before writing or changing a server entry or client netcode by hand.\nWritten fresh by the Castle CLI at every serve start; the full API reference is\nthe SDK's own, at `imports/castle.base/sdk/README.md`.\n\n## Reach for a kit first\n\n`castle.multiplayer-2d` and `castle.multiplayer-3d` (both on `castle.real-time`)\nalready do everything below: a server-authoritative world, one snapshot per\ntick, pose interpolation, roster handling, reconnects, ownership of loose\nobjects. `castle.turn-based` does the same for games played in turns, with\nseats, spectators and idle clearing. A deck on one of those kits normally\nwrites nothing against the raw session API, and the right move is usually to\nadd a rule to the deck's own game hooks rather than a message of your own.\n\nHand-roll only when the game genuinely does not fit them -- and then keep the\nshape below, because it is the shape the platform's limits ask for.\n\n## The outbound budget\n\nA session may send about `40 + 40 x connected players` frames per second, with\nroughly two seconds of burst, and about 1 MiB/s of bytes. What a frame costs:\n\n| call | frames |\n|---|---|\n| `session.send(playerId, data)` | 1 |\n| `session.broadcast(data)` | 1, whatever the player count |\n| `session.broadcast(data, { except })` | one per recipient -- it is a loop of sends |\n\nFrames over the budget are **dropped silently**. The session keeps running and\na dropped frame is never retried, so the symptom is not an error: it is a\nclient whose world quietly stops matching everyone else's. Only sustained abuse\nat several times the budget ends a session.\n\nThe arithmetic that matters, at `tickRate: 20`:\n\n- 4 players, one `send` per player per tick: 80 frames/s of a 200 budget --\n before a single hit, join, chat or one-off frame.\n- 8 players, same: 160 of 360. A second per-player message per tick makes it\n 320, and at `tickRate: 30` that is 480 -- over, and frames start dropping.\n- Either, with one `broadcast` per tick: 20 frames/s. The budget stops being\n something you have to think about.\n\nPer-player sends also send the same bytes N times toward the byte budget. The\nlocal serve does not drop anything, but it warns when a 1-second window goes\nover -- `[multiplayer] server sent ...` in `.castle/logs.txt` and in the serve's\nown output (`.castle/serve.log` when it was detached).\n\n## The snapshot pattern\n\nAuthoritative state lives on the server. `onTick` builds ONE snapshot of every\nplayer and broadcasts it once.\n\nEvery client reads EVERY entry in that snapshot, **including its own** -- the\ndifference is only what it does with each:\n\n- **Other players' entries** drive what it draws for them (interpolated between\n snapshots), and are how it learns someone left or went silent.\n- **Its own entry** is the server's verdict on itself. Take hp, alive/wrecked,\n kills, score and the match state from it every tick, exactly as if it were\n someone else's. The one field it does NOT overwrite each tick is its own pose:\n the local player moves on its own input so the game stays responsive, and the\n client only snaps to the server's position when the two have drifted far\n apart. Ignoring the rest of its own entry is how a player ends up alive on\n their own screen and dead on everyone else's.\n\n```js\nconst state = { matchNumber: 1, players: {}, parked: new Map() };\n\nexport default {\n onPlayerJoin(session, player) {\n state.players[player.playerId] = { x: 0, y: 0, hp: 100, kills: 0, alive: true };\n },\n onMessage(session, player, data) {\n if (data.t === 'move') applyMove(state.players[player.playerId], data);\n },\n onTick(session) {\n // One frame per tick, for any number of players.\n session.broadcast({ t: 'snap', n: state.matchNumber, players: state.players });\n },\n};\n```\n\n```js\nconnection.onMessage((msg) => {\n if (msg.t !== 'snap') return;\n match.setNumber(msg.n); // a new match number means: reset, the round moved on\n for (const [id, p] of Object.entries(msg.players)) {\n if (id === connection.playerId) {\n // My own entry: the server owns all of it except where I am right now.\n Object.assign(me, { hp: p.hp, kills: p.kills, alive: p.alive });\n if (Math.hypot(p.x - me.x, p.y - me.y) > SNAP_DISTANCE) {\n me.x = p.x; // drifted too far to argue; the server is right\n me.y = p.y;\n }\n continue;\n }\n remote.set(id, { ...p, seenAt: performance.now() });\n }\n});\n```\n\nDo not build a per-player payload (\"everyone except you\") on the server: the\nclient needs its own entry anyway, and one tailored message per player costs N\nframes where the shared snapshot costs 1.\n\n## One-off events must be self-healing\n\nA dropped or missed event frame is gone for good. So an event may carry an\neffect, never the only copy of a result:\n\n- `{ t: 'hit', target, dmg }` -- fine for a flash, a sound, a particle.\n- The hp it produced, whether the player is alive or wrecked, the kill count,\n the match number: all of that belongs in the periodic snapshot, and the\n client reconciles from the snapshot every tick.\n\nWrite the client so that receiving zero events and only snapshots still\nproduces a correct, playable screen. Then a dropped frame costs one missing\nspark instead of a player who is dead everywhere but on their own device.\n\n## Connection loss has to be visible\n\nTwo independent things can go quiet: the socket, and a player.\n\n```js\nconnection.onStateChange((state, meta) => {\n // 'acquiring' | 'connecting' | 'connected' | 'reconnecting' | 'closed'\n // meta?.type: 'connectionLost' | 'replaced' | 'bye' | 'left' | 'error'\n hud.setConnection(state, meta?.type);\n});\n```\n\n- Show `reconnecting` and `closed` in the deck's own UI. A player staring at a\n frozen game with no explanation assumes the game is broken.\n- On `closed` with `replaced`, call `Multiplayer.join` again: the creator\n published a new server. A `public` join from matchmaking lands on the new\n version; a `named` or `party` room, or a friend's public room the player\n followed, keeps the old one until Castle ends it, about ten minutes after the\n save. That ending, like a kick, arrives as `bye` with a `reason` to show\n the player; don't rejoin a `bye` automatically, or a kicked player comes\n straight back.\n- Expire a remote player whose last snapshot is older than a few seconds\n (`performance.now() - p.seenAt > 3000`) and stop drawing them. This must run\n off the client's own clock, not off an event -- if the server or the socket\n goes silent, no message will ever arrive to tell you, and every remote player\n stays frozen mid-stride forever.\n- The SDK reconnects short drops by itself and `send` is safe to call while the\n socket is down (those messages are dropped), so the client's job is to show\n the state and recover, not to manage the socket.\n\n## Reconnects: park match state, never delete it\n\n`playerId` is stable across a platform reconnect, but the server still sees\n`onPlayerLeave` and then `onPlayerJoin`. A server that deletes the player's row\non leave silently drops a reconnecting player out of the match while their\nclient happily thinks it is still playing.\n\n```js\nonPlayerLeave(session, player) {\n const parked = state.players[player.playerId];\n delete state.players[player.playerId];\n if (parked) state.parked.set(player.playerId, { at: Date.now(), parked }); // or by userId\n},\nonPlayerJoin(session, player) {\n const held = state.parked.get(player.playerId);\n state.parked.delete(player.playerId);\n state.players[player.playerId] =\n held && Date.now() - held.at < 60_000 ? held.parked : freshPlayer();\n session.send(player.playerId, { t: 'full', ...fullState() }); // 1 frame, once\n},\n```\n\nPark for about 60 seconds (the platform's own reconnect window), keyed by\n`playerId`, or by `userId` when the match should survive a genuinely new\nconnection from the same account. Sweep expired entries on a tick.\n\nOn the client, after a state change back to `connected`, ask for full state\nonce and rebuild from the answer rather than assuming the world is as you left\nit.\n\n## The server ignores and tells\n\nWhen the server refuses a message because the player is not in the state the\nclient assumed -- not in the match, already dead, not their turn -- do not just\n`return`. The client believes something false and nothing will correct it.\n\n```js\nonMessage(session, player, data) {\n const me = state.players[player.playerId];\n if (!me || !me.alive) {\n session.send(player.playerId, { t: 'full', ...fullState() }); // authoritative answer\n return;\n }\n ...\n}\n```\n\nOne frame, and the client resyncs instead of arguing with itself. Rate-limit\nthat reply (once per player per second is plenty) so a looping client cannot\nspend the whole budget on corrections.\n\n## Client to server\n\nClient frames are capped at 16 KB and about 30 messages per second; **exceeding\nthe rate closes the socket**, which is much harsher than the server side's\nsilent drop.\n\n- Throttle pose/input sends to a fixed rate. 8-15 per second is plenty when the\n client interpolates between samples (the real-time kit reports at 20). Never\n send once per animation frame -- 60/s closes the connection.\n- Send intent (\"I am holding left\", \"I fired\"), not results. The server decides\n what happened.\n- Coalesce: one message per send tick carrying the latest pose beats three\n messages describing how it got there.\n\n## Testing it\n\n- Open **four or more** tabs, not two. Every budget and roster bug scales with\n the player count, and two tabs is exactly the case that never reproduces one.\n- Reload tabs mid-match to exercise leave/rejoin, and leave one tab idle to see\n what a silent player looks like to everyone else.\n- Kill and restart the serve (or edit the server entry, which restarts it) to\n see the disconnected state the deck shows.\n- Watch the serve log for the `[multiplayer]` budget warning and for dropped\n oversize frames while you play.\n- A published room that crashed or stopped: `castle-web logs` prints its end\n reason, exit code and last server log lines (creator only; `--rooms` lists rooms).\n";
|
|
1
|
+
export declare const MULTIPLAYER_DOC = "# Multiplayer, in practice\n\nRead this before writing or changing a server entry or client netcode by hand.\nWritten fresh by the Castle CLI at every serve start; the full API reference is\nthe SDK's own, at `imports/castle.base/sdk/README.md`.\n\n## Reach for a kit first\n\n`castle.multiplayer-2d` and `castle.multiplayer-3d` (both on `castle.real-time`)\nalready do everything below: a server-authoritative world, one snapshot per\ntick, pose interpolation, roster handling, reconnects, ownership of loose\nobjects. `castle.turn-based` does the same for games played in turns, with\nseats, spectators and idle clearing. A deck on one of those kits normally\nwrites nothing against the raw session API, and the right move is usually to\nadd a rule to the deck's own game hooks rather than a message of your own.\n\nHand-roll only when the game genuinely does not fit them -- and then keep the\nshape below, because it is the shape the platform's limits ask for.\n\n## The outbound budget\n\nA session may send about `40 + 40 x connected players` frames per second, with\nroughly two seconds of burst, and about 1 MiB/s of bytes. What a frame costs:\n\n| call | frames |\n|---|---|\n| `session.send(playerId, data)` | 1 |\n| `session.broadcast(data)` | 1, whatever the player count |\n| `session.broadcast(data, { except })` | one per recipient -- it is a loop of sends |\n\nFrames over the budget are **dropped silently**. The session keeps running and\na dropped frame is never retried, so the symptom is not an error: it is a\nclient whose world quietly stops matching everyone else's. Only sustained abuse\nat several times the budget ends a session.\n\nThe arithmetic that matters, at `tickRate: 20`:\n\n- 4 players, one `send` per player per tick: 80 frames/s of a 200 budget --\n before a single hit, join, chat or one-off frame.\n- 8 players, same: 160 of 360. A second per-player message per tick makes it\n 320, and at `tickRate: 30` that is 480 -- over, and frames start dropping.\n- Either, with one `broadcast` per tick: 20 frames/s. The budget stops being\n something you have to think about.\n\nPer-player sends also send the same bytes N times toward the byte budget. The\nlocal serve does not drop anything, but it warns when a 1-second window goes\nover -- `[multiplayer] server sent ...` in `.castle/logs.txt` and in the serve's\nown output (`.castle/serve.log` when it was detached).\n\n## The snapshot pattern\n\nAuthoritative state lives on the server. `onTick` builds ONE snapshot of every\nplayer and broadcasts it once.\n\nEvery client reads EVERY entry in that snapshot, **including its own** -- the\ndifference is only what it does with each:\n\n- **Other players' entries** drive what it draws for them (interpolated between\n snapshots), and are how it learns someone left or went silent.\n- **Its own entry** is the server's verdict on itself. Take hp, alive/wrecked,\n kills, score and the match state from it every tick, exactly as if it were\n someone else's. The one field it does NOT overwrite each tick is its own pose:\n the local player moves on its own input so the game stays responsive, and the\n client only snaps to the server's position when the two have drifted far\n apart. Ignoring the rest of its own entry is how a player ends up alive on\n their own screen and dead on everyone else's.\n\n```js\nconst state = { matchNumber: 1, players: {}, parked: new Map() };\n\nexport default {\n onPlayerJoin(session, player) {\n state.players[player.playerId] = { x: 0, y: 0, hp: 100, kills: 0, alive: true };\n },\n onMessage(session, player, data) {\n if (data.t === 'move') applyMove(state.players[player.playerId], data);\n },\n onTick(session) {\n // One frame per tick, for any number of players.\n session.broadcast({ t: 'snap', n: state.matchNumber, players: state.players });\n },\n};\n```\n\n```js\nconnection.onMessage((msg) => {\n if (msg.t !== 'snap') return;\n match.setNumber(msg.n); // a new match number means: reset, the round moved on\n for (const [id, p] of Object.entries(msg.players)) {\n if (id === connection.playerId) {\n // My own entry: the server owns all of it except where I am right now.\n Object.assign(me, { hp: p.hp, kills: p.kills, alive: p.alive });\n if (Math.hypot(p.x - me.x, p.y - me.y) > SNAP_DISTANCE) {\n me.x = p.x; // drifted too far to argue; the server is right\n me.y = p.y;\n }\n continue;\n }\n remote.set(id, { ...p, seenAt: performance.now() });\n }\n});\n```\n\nDo not build a per-player payload (\"everyone except you\") on the server: the\nclient needs its own entry anyway, and one tailored message per player costs N\nframes where the shared snapshot costs 1.\n\n## One-off events must be self-healing\n\nA dropped or missed event frame is gone for good. So an event may carry an\neffect, never the only copy of a result:\n\n- `{ t: 'hit', target, dmg }` -- fine for a flash, a sound, a particle.\n- The hp it produced, whether the player is alive or wrecked, the kill count,\n the match number: all of that belongs in the periodic snapshot, and the\n client reconciles from the snapshot every tick.\n\nWrite the client so that receiving zero events and only snapshots still\nproduces a correct, playable screen. Then a dropped frame costs one missing\nspark instead of a player who is dead everywhere but on their own device.\n\n## Connection loss has to be visible\n\nTwo independent things can go quiet: the socket, and a player.\n\n```js\nconnection.onStateChange((state, meta) => {\n // 'acquiring' | 'connecting' | 'connected' | 'reconnecting' | 'closed'\n // meta?.type: 'connectionLost' | 'replaced' | 'bye' | 'left' | 'error'\n hud.setConnection(state, meta?.type);\n});\n```\n\n- Show `reconnecting` and `closed` in the deck's own UI. A player staring at a\n frozen game with no explanation assumes the game is broken.\n- On `closed` with `replaced`, call `Multiplayer.join` again: the creator\n published a new server. A `public` join from matchmaking lands on the new\n version; a `named` or `party` room, or a friend's public room the player\n followed, keeps the old one until Castle ends it, about ten minutes after the\n save. That ending, like a kick, arrives as `bye` with a `reason` to show\n the player; don't rejoin a `bye` automatically, or a kicked player comes\n straight back.\n- Expire a remote player whose last snapshot is older than a few seconds\n (`performance.now() - p.seenAt > 3000`) and stop drawing them. This must run\n off the client's own clock, not off an event -- if the server or the socket\n goes silent, no message will ever arrive to tell you, and every remote player\n stays frozen mid-stride forever.\n- The SDK reconnects short drops by itself and `send` is safe to call while the\n socket is down (those messages are dropped), so the client's job is to show\n the state and recover, not to manage the socket.\n\n## Reconnects: park match state, never delete it\n\n`playerId` is stable across a platform reconnect, but the server still sees\n`onPlayerLeave` and then `onPlayerJoin`. A server that deletes the player's row\non leave silently drops a reconnecting player out of the match while their\nclient happily thinks it is still playing.\n\n```js\nonPlayerLeave(session, player) {\n const parked = state.players[player.playerId];\n delete state.players[player.playerId];\n if (parked) state.parked.set(player.playerId, { at: Date.now(), parked }); // or by userId\n},\nonPlayerJoin(session, player) {\n const held = state.parked.get(player.playerId);\n state.parked.delete(player.playerId);\n state.players[player.playerId] =\n held && Date.now() - held.at < 60_000 ? held.parked : freshPlayer();\n session.send(player.playerId, { t: 'full', ...fullState() }); // 1 frame, once\n},\n```\n\nPark for about 60 seconds (the platform's own reconnect window), keyed by\n`playerId`, or by `userId` when the match should survive a genuinely new\nconnection from the same account. Sweep expired entries on a tick.\n\nOn the client, after a state change back to `connected`, ask for full state\nonce and rebuild from the answer rather than assuming the world is as you left\nit.\n\n## The server ignores and tells\n\nWhen the server refuses a message because the player is not in the state the\nclient assumed -- not in the match, already dead, not their turn -- do not just\n`return`. The client believes something false and nothing will correct it.\n\n```js\nonMessage(session, player, data) {\n const me = state.players[player.playerId];\n if (!me || !me.alive) {\n session.send(player.playerId, { t: 'full', ...fullState() }); // authoritative answer\n return;\n }\n ...\n}\n```\n\nOne frame, and the client resyncs instead of arguing with itself. Rate-limit\nthat reply (once per player per second is plenty) so a looping client cannot\nspend the whole budget on corrections.\n\n## Client to server\n\nClient frames are capped at 16 KB and about 30 messages per second; **exceeding\nthe rate closes the socket**, which is much harsher than the server side's\nsilent drop.\n\n- Throttle pose/input sends to a fixed rate. 8-15 per second is plenty when the\n client interpolates between samples (the real-time kit reports at 20). Never\n send once per animation frame -- 60/s closes the connection.\n- Send intent (\"I am holding left\", \"I fired\"), not results. The server decides\n what happened.\n- Coalesce: one message per send tick carrying the latest pose beats three\n messages describing how it got there.\n\n## Testing it\n\n- Open **four or more** tabs, not two. Every budget and roster bug scales with\n the player count, and two tabs is exactly the case that never reproduces one.\n- Reload tabs mid-match to exercise leave/rejoin, and leave one tab idle to see\n what a silent player looks like to everyone else.\n- Kill and restart the serve (or edit the server entry, which restarts it) to\n see the disconnected state the deck shows.\n- Watch the serve log for the `[multiplayer]` budget warning and for dropped\n oversize frames while you play.\n- A published room that crashed or stopped: `castle-web logs` prints its end\n reason, exit code and last server log lines (creator only; `--rooms` lists rooms).\n The room list and the room view also show how many server messages were dropped\n for being over 64 KB.\n";
|
package/dist/multiplayerDoc.js
CHANGED
|
@@ -234,4 +234,6 @@ silent drop.
|
|
|
234
234
|
oversize frames while you play.
|
|
235
235
|
- A published room that crashed or stopped: \`castle-web logs\` prints its end
|
|
236
236
|
reason, exit code and last server log lines (creator only; \`--rooms\` lists rooms).
|
|
237
|
+
The room list and the room view also show how many server messages were dropped
|
|
238
|
+
for being over 64 KB.
|
|
237
239
|
`;
|
package/dist/platformDoc.js
CHANGED
|
@@ -312,7 +312,7 @@ const COMMON_SECTIONS = `## Imports are read-only
|
|
|
312
312
|
- **Limits worth designing around.** Client→server messages are capped at 16 KB and about 30 per second; server→client messages are capped at 64 KB. These limits apply to both JSON and binary frames and are measured on the frame, so a binary frame's one-byte protocol tag leaves you one byte under the cap for payload. A session may also SEND only about \`40 + 40 × connected players\` frames per second (about two seconds of burst, and about 1 MiB/s of bytes): \`session.send\` costs one frame per call, \`session.broadcast(data)\` costs ONE frame however many players are in the session, and \`session.broadcast(data, { except })\` is a loop of sends, so it costs one frame per recipient. Frames over the budget are dropped silently and never retried — the session keeps running, so the symptom is a client whose world quietly stops matching everyone else's; only sustained abuse at several times the budget ends a session. So send one \`broadcast\` per tick carrying every player's state, rather than a tailored \`send\` per player: every client reads every entry of that snapshot INCLUDING its own — it takes hp, kills and match state from its own entry and only keeps its own position locally predicted.
|
|
313
313
|
- **Binary messages are opt-in per payload.** Pass any typed array, \`DataView\`, or \`ArrayBuffer\` to client \`send\`, server \`send\`, or server \`broadcast\` to send its raw bytes. \`onMessage\` always receives those bytes as a \`Uint8Array\`, while every other payload continues to use JSON. Reconstruct another view type such as \`Float32Array\` on receipt; multi-byte values use the sender platform's byte order.
|
|
314
314
|
- **Test multiplayer locally with no setup.** \`castle-web serve\` runs your server file alongside the deck. Open the shell URL it prints in two tabs, then open the Play panel in each; those play surfaces share a session. If you open the content origin from \`.castle/serve.json\` directly, use \`/index.html?edit=0\`. Its bare origin loads the edit surface, where \`Multiplayer.join\` is not answered. Editing the server entry, anything beside it, or a deck-owned hook under \`server/\` or \`code/server/\` restarts it and clients reconnect, so you exercise your reconnect path constantly. Server \`console.log\` goes to the serve's logs, not the browser console.
|
|
315
|
-
- **A published deck's server rooms have logs too.** \`castle-web logs\` (in the deck folder, signed in as its creator) shows the newest room's state, end reason, exit code, an out-of-memory kill, and its last server log lines; \`--rooms\` lists recent rooms and \`--room <id>\` picks one. Hosts keep the lines for about 30 minutes after a room ends.
|
|
315
|
+
- **A published deck's server rooms have logs too.** \`castle-web logs\` (in the deck folder, signed in as its creator) shows the newest room's state, end reason, exit code, an out-of-memory kill, and its last server log lines; \`--rooms\` lists recent rooms and \`--room <id>\` picks one. Hosts keep the lines for about 30 minutes after a room ends. The room list and the room view also show how many server messages were dropped for being over 64 KB.
|
|
316
316
|
- **Publishing moves players onto the new version; you don't build versioned rooms or a rejoin prompt.** \`save-deck\` bundles and publishes the server entry, and every new session runs it. A session already running keeps the code it started with: its server gets \`onReplaced\`, and each client's connection closes with \`replaced\` metadata. A deck that joins again when the connection closes (the multiplayer kits do) gets the new version at once for a \`public\` join from matchmaking, since new players are not placed in a running public session on the old code; a \`named\` or \`party\` join, or a public one that follows a friend into their room, goes back to that room, which keeps the old code until it ends. About ten minutes after the save Castle ends any ordinary session still on the old code (hub places, persistent worlds and destinations keep their own release handling), closing its connections with \`bye\` and a reason that says the game was updated; its \`onShutdown\` still runs, so a save there lands, and the next join gets the new version.
|
|
317
317
|
`;
|
|
318
318
|
export function platformGuide(deckDir) {
|
package/dist/roomLogs.d.ts
CHANGED
package/dist/roomLogs.js
CHANGED
|
@@ -13,6 +13,9 @@ import { readCastleJson } from './castleJson.js';
|
|
|
13
13
|
import * as config from './config.js';
|
|
14
14
|
const RECENT_ROOMS_LIMIT = 20;
|
|
15
15
|
const ROOM_FIELDS = 'sessionId deckId env startedAt endedAt numPlayers';
|
|
16
|
+
// Selected separately: a Ghost older than the field rejects the whole document, so the
|
|
17
|
+
// query is retried once without it (see query below).
|
|
18
|
+
const OVERSIZE_FIELD = 'oversizeDrops';
|
|
16
19
|
const UNAVAILABLE_REASONS = {
|
|
17
20
|
host_missing: 'the server host that ran this room is gone (hosts are replaced over time), so its logs went with it',
|
|
18
21
|
host_stale: 'the server host that ran this room has stopped reporting in, so its logs cannot be read',
|
|
@@ -31,8 +34,16 @@ const ERROR_CODES = {
|
|
|
31
34
|
};
|
|
32
35
|
export class RoomLogsError extends Error {
|
|
33
36
|
}
|
|
37
|
+
// `document` builds the query with or without oversizeDrops. A Ghost that predates the
|
|
38
|
+
// field fails validation naming it; then the query runs once more without it and every
|
|
39
|
+
// room's count is unknown (null).
|
|
34
40
|
async function query(document, variables, field) {
|
|
35
|
-
|
|
41
|
+
let response = await graphql(document(OVERSIZE_FIELD), variables);
|
|
42
|
+
let withOversize = true;
|
|
43
|
+
if (response.errors?.some((e) => /Cannot query field "oversizeDrops"/.test(e.message ?? ''))) {
|
|
44
|
+
response = await graphql(document(''), variables);
|
|
45
|
+
withOversize = false;
|
|
46
|
+
}
|
|
36
47
|
const error = response.errors?.[0];
|
|
37
48
|
if (error)
|
|
38
49
|
throw new RoomLogsError(describeError(error));
|
|
@@ -40,6 +51,10 @@ async function query(document, variables, field) {
|
|
|
40
51
|
if (value === undefined || value === null) {
|
|
41
52
|
throw new RoomLogsError(`The server returned no ${field}.`);
|
|
42
53
|
}
|
|
54
|
+
if (!withOversize) {
|
|
55
|
+
for (const room of Array.isArray(value) ? value : [value])
|
|
56
|
+
room.oversizeDrops = null;
|
|
57
|
+
}
|
|
43
58
|
return value;
|
|
44
59
|
}
|
|
45
60
|
function describeError(error) {
|
|
@@ -54,16 +69,16 @@ function describeError(error) {
|
|
|
54
69
|
return visible(code ? `${message} [${code}]` : message);
|
|
55
70
|
}
|
|
56
71
|
export function recentRooms(deckId, env, limit = RECENT_ROOMS_LIMIT) {
|
|
57
|
-
return query(`query($deckId: ID!, $env: String, $limit: Int) {
|
|
72
|
+
return query((oversize) => `query($deckId: ID!, $env: String, $limit: Int) {
|
|
58
73
|
cauldronRecentRooms(deckId: $deckId, env: $env, limit: $limit) {
|
|
59
|
-
${ROOM_FIELDS}
|
|
74
|
+
${ROOM_FIELDS} ${oversize}
|
|
60
75
|
}
|
|
61
76
|
}`, { deckId, env, limit }, 'cauldronRecentRooms');
|
|
62
77
|
}
|
|
63
78
|
export function roomLogs(deckId, sessionId, env) {
|
|
64
|
-
return query(`query($deckId: ID!, $sessionId: ID!, $env: String) {
|
|
79
|
+
return query((oversize) => `query($deckId: ID!, $sessionId: ID!, $env: String) {
|
|
65
80
|
cauldronRoomLogs(deckId: $deckId, sessionId: $sessionId, env: $env) {
|
|
66
|
-
${ROOM_FIELDS}
|
|
81
|
+
${ROOM_FIELDS} ${oversize}
|
|
67
82
|
state logsAvailable logsUnavailableReason endReason exitCode oomKilled droppedLines
|
|
68
83
|
lines { at stream text }
|
|
69
84
|
}
|
|
@@ -98,12 +113,16 @@ export function formatRooms(deckId, env, rooms) {
|
|
|
98
113
|
shortTime(room.startedAt),
|
|
99
114
|
room.endedAt ? shortTime(room.endedAt) : 'running',
|
|
100
115
|
String(room.numPlayers),
|
|
116
|
+
hasOversizeDrops(room) ? `${room.oversizeDrops} message${room.oversizeDrops === 1 ? '' : 's'} dropped (over 64 KB)` : '',
|
|
101
117
|
].map((cell) => visible(String(cell))));
|
|
102
|
-
const header = ['ROOM', 'STARTED', 'ENDED', 'PLAYERS'];
|
|
118
|
+
const header = ['ROOM', 'STARTED', 'ENDED', 'PLAYERS', ''];
|
|
103
119
|
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
104
120
|
const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(' ').trimEnd();
|
|
105
121
|
return [`Recent rooms of deck ${deckId} (${env}), newest first:`, line(header), ...rows.map(line)].join('\n');
|
|
106
122
|
}
|
|
123
|
+
function hasOversizeDrops(room) {
|
|
124
|
+
return typeof room.oversizeDrops === 'number' && room.oversizeDrops > 0;
|
|
125
|
+
}
|
|
107
126
|
export function formatRoomLogs(logs) {
|
|
108
127
|
const out = [
|
|
109
128
|
`Room ${logs.sessionId} of deck ${logs.deckId} (${logs.env})`,
|
|
@@ -118,6 +137,11 @@ export function formatRoomLogs(logs) {
|
|
|
118
137
|
out.push(` exit code: ${logs.exitCode}`);
|
|
119
138
|
if (logs.oomKilled)
|
|
120
139
|
out.push(' killed: out of memory');
|
|
140
|
+
if (hasOversizeDrops(logs)) {
|
|
141
|
+
const n = logs.oversizeDrops;
|
|
142
|
+
out.push(` ${n} server message${n === 1 ? ' was' : 's were'} dropped for being over 64 KB. ` +
|
|
143
|
+
'Send smaller messages: split the state, or send only what changed.');
|
|
144
|
+
}
|
|
121
145
|
if (!logs.logsAvailable) {
|
|
122
146
|
const reason = logs.logsUnavailableReason ?? '';
|
|
123
147
|
out.push('', `No log lines: ${UNAVAILABLE_REASONS[reason] ?? `unavailable (${reason || 'no reason given'})`}.`);
|
|
@@ -205,7 +205,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
205
205
|
// scores. A tap on the board, or walking away, closes it. Over the labels,
|
|
206
206
|
// so a pad's words never cut through a row; it is never drawn during a
|
|
207
207
|
// trip, so the door cover needs not hide it.
|
|
208
|
-
const
|
|
208
|
+
const CABINET_CHIP_PAINT = 'rgba(18,14,24,0.92)', CABINET_BOARD_PAINT = 'rgb(18,14,24)';
|
|
209
|
+
const cabinet = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', boxSizing: 'border-box', background: CABINET_CHIP_PAINT, border: '1px solid rgba(255,255,255,0.18)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', font: '600 13px/1.25 system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
|
|
209
210
|
cabinet.dataset.hub = 'cabinet';
|
|
210
211
|
let cabinetKey = '';
|
|
211
212
|
// Whose board this player opened, if any: one at a time (`cabinets.js`).
|
|
@@ -247,7 +248,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
247
248
|
if (!best) {
|
|
248
249
|
return false;
|
|
249
250
|
}
|
|
250
|
-
Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto' });
|
|
251
|
+
Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto', background: CABINET_CHIP_PAINT });
|
|
251
252
|
cabinet.setAttribute('role', 'button');
|
|
252
253
|
cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: show the scores`);
|
|
253
254
|
const line = el('div', { display: 'flex', alignItems: 'center', gap: '7px', fontSize: '12px', whiteSpace: 'nowrap' }, cabinet);
|
|
@@ -260,7 +261,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
260
261
|
}
|
|
261
262
|
function buildCabinetBoard(card, imageOf) {
|
|
262
263
|
cabinet.replaceChildren();
|
|
263
|
-
|
|
264
|
+
// v1.217: opaque, so no plate or area label under it shows through a row.
|
|
265
|
+
Object.assign(cabinet.style, { width: '204px', padding: '10px', borderRadius: '12px', pointerEvents: 'auto', background: CABINET_BOARD_PAINT });
|
|
264
266
|
cabinet.setAttribute('role', 'button');
|
|
265
267
|
cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: hide the scores`);
|
|
266
268
|
const head = el('div', { display: 'flex', gap: '10px', alignItems: 'center' }, cabinet);
|
|
@@ -2262,7 +2264,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2262
2264
|
setPadContext(item) {
|
|
2263
2265
|
const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
|
|
2264
2266
|
!!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
|
|
2265
|
-
externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node))
|
|
2267
|
+
externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node)) ||
|
|
2268
|
+
// v1.217: an open cabinet board is read whole; the plate waits under it.
|
|
2269
|
+
(cabinet.style.display !== 'none' && cabinet.dataset.drawn === 'board');
|
|
2266
2270
|
if (!item || blocked) {
|
|
2267
2271
|
if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
|
|
2268
2272
|
return;
|
|
@@ -15,7 +15,7 @@ export function collectPadCues(actors, hidden) {
|
|
|
15
15
|
const doors = new Map();
|
|
16
16
|
for (const actor of actors) {
|
|
17
17
|
const door = actor.components?.HubDoor;
|
|
18
|
-
if (door) {doors.set(door.id, door
|
|
18
|
+
if (door) {doors.set(door.id, door);}
|
|
19
19
|
}
|
|
20
20
|
const cues = [];
|
|
21
21
|
for (const actor of actors) {
|
|
@@ -27,7 +27,8 @@ export function collectPadCues(actors, hidden) {
|
|
|
27
27
|
const shape = c.Shape;
|
|
28
28
|
cues.push({ id: actor.id, x: c.Transform.x, z: c.Transform.z, radius: spec.radius,
|
|
29
29
|
y: (c.Transform.y ?? 0) + (shape?.kind === 'cylinder' ? (shape.height ?? 1) / 2 : 0) + 0.03,
|
|
30
|
-
title: explicit ? spec.title : doors.get(spec.door), door: !explicit,
|
|
30
|
+
title: explicit ? spec.title : doors.get(spec.door)?.title, door: !explicit,
|
|
31
|
+
cabinet: !explicit && doors.get(spec.door)?.kind === 'cabinet',
|
|
31
32
|
color: shape?.color ?? '#d9a441' });
|
|
32
33
|
}
|
|
33
34
|
return cues;
|
|
@@ -53,9 +54,12 @@ export function selectPadCue(cues, body, current = null) {
|
|
|
53
54
|
return cue ? { cue, on: edge(cue, body) <= 0 } : null;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// v1.217: a guest (signed out, or an anonymous visitor) cannot play a
|
|
58
|
+
// cabinet's classic deck, so its plate says so rather than inviting a step.
|
|
59
|
+
export function padContextText(active, guest = false) {
|
|
60
|
+
if (!active?.cue.title) {return null;}
|
|
61
|
+
const secondary = guest && active.cue.cabinet ? 'Sign in to play' : !active.on && active.cue.door ? 'Step on to join' : '';
|
|
62
|
+
return { id: active.cue.id, title: active.cue.title, secondary };
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
// Called each frame, but unchanged inputs allocate nothing and do not select
|
|
@@ -73,11 +77,11 @@ export function makePadCueTracker() {
|
|
|
73
77
|
const hidden = hiddenNow?.has(actor.id) === true;
|
|
74
78
|
if (!r || r.actor !== actor || !Object.is(r.x, t?.x) || !Object.is(r.y, t?.y) || !Object.is(r.z, t?.z) ||
|
|
75
79
|
!Object.is(r.radius, p?.radius) || r.door !== p?.door || r.explicit !== Object.hasOwn(c, 'HubPadCue') ||
|
|
76
|
-
!Object.is(r.cueRadius, q?.radius) || r.title !== q?.title || r.doorId !== d?.id || r.doorTitle !== d?.title ||
|
|
80
|
+
!Object.is(r.cueRadius, q?.radius) || r.title !== q?.title || r.doorId !== d?.id || r.doorTitle !== d?.title || r.doorKind !== d?.kind ||
|
|
77
81
|
r.kind !== s?.kind || !Object.is(r.height, s?.height) || r.color !== s?.color || r.hidden !== hidden) {
|
|
78
82
|
r = { actor, x: t?.x, y: t?.y, z: t?.z, radius: p?.radius, door: p?.door,
|
|
79
83
|
explicit: Object.hasOwn(c, 'HubPadCue'), cueRadius: q?.radius, title: q?.title, doorId: d?.id,
|
|
80
|
-
doorTitle: d?.title, kind: s?.kind, height: s?.height, color: s?.color, hidden };
|
|
84
|
+
doorTitle: d?.title, doorKind: d?.kind, kind: s?.kind, height: s?.height, color: s?.color, hidden };
|
|
81
85
|
records[count] = r; dirty = true;
|
|
82
86
|
}
|
|
83
87
|
count += 1;
|
|
@@ -8,13 +8,13 @@ export function makePadReadability(engine, options) {
|
|
|
8
8
|
const tracker = engine.hubPadContext === true || engine.hubPadRing === true ? makePadCueTracker() : null;
|
|
9
9
|
const rings = engine.hubPadRing === true || engine.hubSpawnRing === true
|
|
10
10
|
? makePadRings(world, { active: engine.hubPadRing === true, arrival: engine.hubSpawnRing === true ? arrival : null }) : null;
|
|
11
|
-
let previous = null, text = null;
|
|
11
|
+
let previous = null, previousGuest = false, text = null;
|
|
12
12
|
return {
|
|
13
|
-
frame(actors, hidden, body, traveling, captionBlocked = false) {
|
|
13
|
+
frame(actors, hidden, body, traveling, captionBlocked = false, guest = false) {
|
|
14
14
|
const active = tracker?.frame(actors, hidden, body) ?? null;
|
|
15
15
|
rings?.frame(traveling ? null : active?.cue);
|
|
16
16
|
if (engine.hubPadContext === true) {
|
|
17
|
-
if (active !== previous) {text = padContextText(active); previous = active;}
|
|
17
|
+
if (active !== previous || guest !== previousGuest) {text = padContextText(active, guest); previous = active; previousGuest = guest;}
|
|
18
18
|
chrome.setPadContext(traveling || captionBlocked ? null : text);
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -150,6 +150,14 @@ const USER_ID = /^\d{1,20}$/;
|
|
|
150
150
|
// A scene with implicit ground needs it too: that finite floor has an edge.
|
|
151
151
|
const DEFAULT_FALL_Y = -20;
|
|
152
152
|
|
|
153
|
+
// Half the side of the server's ground slab: `ground.half` clamped to 1..200,
|
|
154
|
+
// else 100 (multiplayer-3d world.js `colliderHalf`, whose rule this repeats:
|
|
155
|
+
// that function is not exported).
|
|
156
|
+
function groundHalf(setting) {
|
|
157
|
+
const half = setting?.half;
|
|
158
|
+
return typeof half === 'number' && Number.isFinite(half) ? Math.min(200, Math.max(1, half)) : 100;
|
|
159
|
+
}
|
|
160
|
+
|
|
153
161
|
function hasHook(deckHooks, placeHooks, name) {
|
|
154
162
|
return typeof deckHooks?.[name] === 'function' || Object.values(placeHooks ?? {}).some((hooks) => typeof hooks?.[name] === 'function');
|
|
155
163
|
}
|
|
@@ -308,6 +316,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
308
316
|
delete h.ctx.menu;
|
|
309
317
|
}
|
|
310
318
|
h.noGround = sceneGround(h.place.scene)?.none === true;
|
|
319
|
+
h.groundHalf = h.noGround ? 0 : groundHalf(sceneGround(h.place.scene));
|
|
311
320
|
h.fallY = h.place.fallY ?? DEFAULT_FALL_Y;
|
|
312
321
|
console.log(`[hub] place ${id} (${source}): ${h.place.scene}`);
|
|
313
322
|
return h.place.scene;
|
|
@@ -319,6 +328,25 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
319
328
|
return h.sim === sim && h.place ? standingY(h, at) : at.y;
|
|
320
329
|
},
|
|
321
330
|
|
|
331
|
+
// v1.218: a body admitted with no pose (players.js puts it on the scene
|
|
332
|
+
// spawn, `at`) where another body stands, at the spawn or at the slot its
|
|
333
|
+
// lone arrival would take, starts where that arrival will put it instead,
|
|
334
|
+
// before its WORLD goes out: that snapshot is then the one placement its
|
|
335
|
+
// client makes, at once. That is the arrival slot when it is free, else
|
|
336
|
+
// the free spot beside it the arrival would step off to (`loneSlot`, the
|
|
337
|
+
// search `placeGroup` makes). Null when neither is taken (the arrival
|
|
338
|
+
// places it as before), or when nowhere is free (it shares the spawn, as
|
|
339
|
+
// before v1.218, and the arrival row is its only way off).
|
|
340
|
+
joinSpot(sim, playerId, at) {
|
|
341
|
+
if (h.sim !== sim || !h.place) {return null;}
|
|
342
|
+
const others = othersAt(h, [playerId]);
|
|
343
|
+
const slot = loneSlot(h);
|
|
344
|
+
if (!others.some((p) => takes(h, p, at) || takes(h, p, slot.standing))) {return null;}
|
|
345
|
+
const spot = others.some((p) => takes(h, p, slot.standing)) ? slot.stepOff(others) : slot.standing;
|
|
346
|
+
if (spot) {h.joinedOff.set(playerId, { ...spot });}
|
|
347
|
+
return spot;
|
|
348
|
+
},
|
|
349
|
+
|
|
322
350
|
ready(sim) {
|
|
323
351
|
h.sim = sim;
|
|
324
352
|
h.actors = Scene.readScene(sim.scenePath);
|
|
@@ -931,6 +959,9 @@ function newState(manifest, savedDeckId) {
|
|
|
931
959
|
whereAt: new Map(),
|
|
932
960
|
// playerId -> { at, facing, until }: bodies kept where a jump put them (`settle`)
|
|
933
961
|
settling: new Map(),
|
|
962
|
+
// playerId -> where `joinSpot` put a body that found the spawn taken
|
|
963
|
+
// (v1.218): its WORLD starts it there, and its arrival keeps it there.
|
|
964
|
+
joinedOff: new Map(),
|
|
934
965
|
// playerId -> { at, body, until }: a place's `hub.placeAt` waiting for its
|
|
935
966
|
// client to report from the spot (`stalePose`)
|
|
936
967
|
placed: new Map(),
|
|
@@ -2589,6 +2620,7 @@ function forget(h, playerId) {
|
|
|
2589
2620
|
h.unstuckAt?.delete(playerId);
|
|
2590
2621
|
h.unstuckAskAt?.delete(playerId);
|
|
2591
2622
|
h.settling.delete(playerId);
|
|
2623
|
+
h.joinedOff.delete(playerId);
|
|
2592
2624
|
h.placed.delete(playerId);
|
|
2593
2625
|
Grab.forget(h, playerId);
|
|
2594
2626
|
if (h.manifest.act === true) {Act.forget(h, playerId);}
|
|
@@ -2878,8 +2910,8 @@ function arrivalPoint(h) {
|
|
|
2878
2910
|
return actor?.components.Transform ?? h.sim?.spawn ?? { x: 0, y: 1, z: 0 };
|
|
2879
2911
|
}
|
|
2880
2912
|
|
|
2881
|
-
//
|
|
2882
|
-
function
|
|
2913
|
+
// The arrival point, the way the row faces and the direction it runs.
|
|
2914
|
+
function arrivalRow(h) {
|
|
2883
2915
|
const arrival = h.place.arrival;
|
|
2884
2916
|
const t = arrivalPoint(h);
|
|
2885
2917
|
let facing;
|
|
@@ -2891,29 +2923,93 @@ function placeGroup(h, playerIds) {
|
|
|
2891
2923
|
facing = (t.rotationY ?? 0) * DEG;
|
|
2892
2924
|
}
|
|
2893
2925
|
// Facing f looks along (sin f, cos f); the row runs across it.
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2926
|
+
return { t, facing, across: { x: Math.cos(facing), z: -Math.sin(facing) } };
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
// Whether a body standing at `p` takes the spot `at`: nearer than two radii
|
|
2930
|
+
// across the ground and overlapping it in height. A player on a floor above
|
|
2931
|
+
// or below takes nothing here (v1.218).
|
|
2932
|
+
function takes(h, p, at) {
|
|
2933
|
+
const size = bodySize(h) ?? { radius: BODY_RADIUS_M, halfHeight: BODY_HALF_M };
|
|
2934
|
+
return Math.hypot(p.x - at.x, p.z - at.z) < 2 * size.radius && Math.abs(p.y - at.y) < 2 * size.halfHeight;
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
// The row's slots for `n` players: each authored (`at`, at least 1.2 m up)
|
|
2938
|
+
// and where a body stands there (`standing`), which is what occupancy is
|
|
2939
|
+
// judged at (v1.218: an elevated marker's raw height let an earlier member
|
|
2940
|
+
// stepping off take a later member's slot).
|
|
2941
|
+
function rowSlots(h, n) {
|
|
2942
|
+
const { t, across } = arrivalRow(h);
|
|
2943
|
+
const spread = h.place.arrival.spread;
|
|
2944
|
+
return Array.from({ length: n }, (_, i) => {
|
|
2945
|
+
const offset = (i - (n - 1) / 2) * spread;
|
|
2946
|
+
const at = { x: t.x + across.x * offset, y: Math.max(t.y ?? 1, 1.2), z: t.z + across.z * offset };
|
|
2947
|
+
return { at, standing: { ...at, y: standingY(h, at) } };
|
|
2901
2948
|
});
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
// Where a lone arrival goes (`placeGroup` with one player): the slot, or,
|
|
2952
|
+
// when `occupied` takes it, the free spot beside it (null when none is).
|
|
2953
|
+
// `joinSpot` asks the same, so the two cannot disagree.
|
|
2954
|
+
function loneSlot(h) {
|
|
2955
|
+
const [slot] = rowSlots(h, 1);
|
|
2956
|
+
return { ...slot, stepOff: (occupied) => stepOffSlot(h, slot.at, occupied) };
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
function stepOffSlot(h, at, occupied) {
|
|
2960
|
+
const { across } = arrivalRow(h);
|
|
2961
|
+
const radius = bodySize(h)?.radius ?? BODY_RADIUS_M;
|
|
2962
|
+
return freeArrivalSlot(h, at, across, Math.max(h.place.arrival.spread, 2 * radius + 0.1), radius, occupied, true);
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2965
|
+
// A row at the arrival actor, facing the way the manifest says.
|
|
2966
|
+
function placeGroup(h, ids) {
|
|
2967
|
+
const { t, facing, across } = arrivalRow(h);
|
|
2968
|
+
const occupied = othersAt(h, ids);
|
|
2969
|
+
const off = new Map(ids.filter((id) => h.joinedOff.has(id)).map((id) => [id, h.joinedOff.get(id)]));
|
|
2970
|
+
for (const id of ids) {h.joinedOff.delete(id);}
|
|
2971
|
+
// v1.218: one admitted beside a taken spawn (`joinSpot`) was put there by
|
|
2972
|
+
// its WORLD. Alone, it arrives where it stands while that is still free:
|
|
2973
|
+
// moving it now would reach its client as a clamp, eased a quarter of the
|
|
2974
|
+
// way per update, the glide v1.147 removed. (One whose spot was taken
|
|
2975
|
+
// since, or that moved, is placed as anyone is.)
|
|
2976
|
+
if (ids.length === 1 && off.has(ids[0])) {
|
|
2977
|
+
const body = h.sim.players.get(ids[0]);
|
|
2978
|
+
const kept = off.get(ids[0]);
|
|
2979
|
+
if (body && Math.hypot(body.at.x - kept.x, body.at.z - kept.z) <= HOLD_SLACK && !occupied.some((p) => takes(h, p, body.at))) {
|
|
2980
|
+
placeAt(h, ids[0], { ...body.at }, facing);
|
|
2981
|
+
return;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
// A group with a member admitted beside the spawn takes the row's slots in
|
|
2985
|
+
// the order its members stand along it, so nobody crosses the row.
|
|
2986
|
+
const along = (id) => {
|
|
2987
|
+
const at = h.sim.players.get(id)?.at;
|
|
2988
|
+
return at ? (at.x - t.x) * across.x + (at.z - t.z) * across.z : 0;
|
|
2989
|
+
};
|
|
2990
|
+
const playerIds = off.size ? [...ids].sort((a, b) => along(a) - along(b)) : ids;
|
|
2991
|
+
const slots = rowSlots(h, playerIds.length);
|
|
2902
2992
|
// Where earlier members of this batch were put, and which of them moved: a
|
|
2903
2993
|
// moved member may sit on a later authored slot, which must then move too.
|
|
2904
2994
|
const assigned = [];
|
|
2905
2995
|
const moved = [];
|
|
2906
2996
|
playerIds.forEach((playerId, i) => {
|
|
2907
|
-
const at = slots[i];
|
|
2997
|
+
const { at, standing } = slots[i];
|
|
2908
2998
|
// A lone door visitor may find the owner still at the arrival (a House
|
|
2909
2999
|
// visit from People carries no `near`), and two solid bodies on one spot
|
|
2910
|
-
// wedge.
|
|
2911
|
-
//
|
|
2912
|
-
//
|
|
2913
|
-
//
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
3000
|
+
// wedge. Every place steps off an occupied slot (v1.218). Ground-backed
|
|
3001
|
+
// places (the Town) used to keep the spawn for everyone, so two lone
|
|
3002
|
+
// joiners stood on exactly the same point; each client's physics then
|
|
3003
|
+
// pressed its own capsule into the ground under the other's avatar and
|
|
3004
|
+
// ate every step until one left (Nov 17 Market check). The step-off is
|
|
3005
|
+
// one placement, not the ring's later 1.1 m glide that v1.147 removed
|
|
3006
|
+
// (Oct 17). Empty slots keep their authored placement.
|
|
3007
|
+
// When no spot beside it is free (`freeArrivalSlot` null) the slot
|
|
3008
|
+
// itself is used, shared, as before v1.218. Later members' slots are
|
|
3009
|
+
// held for them where they will stand, as every occupant is judged.
|
|
3010
|
+
const alternate = [...occupied, ...moved].some((p) => takes(h, p, standing))
|
|
3011
|
+
? stepOffSlot(h, at, [...occupied, ...assigned, ...slots.slice(i + 1).map((slot) => slot.standing)]) : null;
|
|
3012
|
+
const spot = alternate ?? standing;
|
|
2917
3013
|
assigned.push(spot);
|
|
2918
3014
|
if (alternate) {moved.push(alternate);}
|
|
2919
3015
|
placeAt(h, playerId, spot, facing);
|
|
@@ -2921,21 +3017,33 @@ function placeGroup(h, playerIds) {
|
|
|
2921
3017
|
}
|
|
2922
3018
|
|
|
2923
3019
|
// Every other body in the place where it stands now, arrived or not: a body
|
|
2924
|
-
// waiting for its group or held is as solid as one that arrived.
|
|
3020
|
+
// waiting for its group or held is as solid as one that arrived. Not one whose
|
|
3021
|
+
// player has left the roster: real-time admits a joiner before it removes the
|
|
3022
|
+
// bodies of players who left that tick (v1.218), and those are going.
|
|
2925
3023
|
function othersAt(h, except) {
|
|
2926
|
-
|
|
3024
|
+
const roster = Array.isArray(h.session?.players) ? new Set(h.session.players.map((p) => p.playerId)) : null;
|
|
3025
|
+
return [...h.sim.players.entries()]
|
|
3026
|
+
.filter(([id]) => !except.includes(id) && (roster === null || roster.has(id)))
|
|
3027
|
+
.map(([, body]) => body.at);
|
|
2927
3028
|
}
|
|
2928
3029
|
|
|
2929
3030
|
// A stored pose (an arrival pose, a durable resumePose, a retained visit)
|
|
2930
3031
|
// puts a returning player back where they stood, but someone may stand there
|
|
2931
|
-
// now.
|
|
2932
|
-
//
|
|
2933
|
-
//
|
|
3032
|
+
// now. One closer than two radii steps off along the row across their
|
|
3033
|
+
// facing, else takes the arrival (Oct 19 QA: a guest's stored House pose was
|
|
3034
|
+
// restored 0.42 m from the owner, and they wedged). On every place since
|
|
3035
|
+
// v1.218, ground-backed ones too: two capsules on one spot wedge there as well
|
|
3036
|
+
// (Nov 17 Market check). A pose nobody stands on is restored exactly.
|
|
2934
3037
|
function restorePose(h, playerId, at, facing) {
|
|
3038
|
+
const body = h.sim.players.get(playerId);
|
|
3039
|
+
const from = body ? { ...body.at } : null;
|
|
3040
|
+
// An arrival hook may already have placed them here; keep its stale-report guard.
|
|
3041
|
+
const guard = h.placed.get(playerId);
|
|
2935
3042
|
const radius = bodySize(h)?.radius ?? BODY_RADIUS_M;
|
|
2936
3043
|
const others = othersAt(h, [playerId]);
|
|
2937
|
-
if (
|
|
3044
|
+
if (!others.some((p) => takes(h, p, at))) {
|
|
2938
3045
|
moveBody(h, playerId, at, facing);
|
|
3046
|
+
guardPlacement(h, playerId, from, guard);
|
|
2939
3047
|
return;
|
|
2940
3048
|
}
|
|
2941
3049
|
const across = { x: Math.cos(facing ?? 0), z: -Math.sin(facing ?? 0) };
|
|
@@ -2945,6 +3053,7 @@ function restorePose(h, playerId, at, facing) {
|
|
|
2945
3053
|
} else {
|
|
2946
3054
|
placeGroup(h, [playerId]);
|
|
2947
3055
|
}
|
|
3056
|
+
guardPlacement(h, playerId, from, guard);
|
|
2948
3057
|
// A hold the player kept across the drop would put them back on the
|
|
2949
3058
|
// occupied spot next tick: it follows them to where they now stand.
|
|
2950
3059
|
const hold = h.held.get(playerId);
|
|
@@ -2957,8 +3066,10 @@ function restorePose(h, playerId, at, facing) {
|
|
|
2957
3066
|
// `around`: when the row has no free slot, also try the eight compass
|
|
2958
3067
|
// directions at the same steps (a narrow floor may run across the row).
|
|
2959
3068
|
function freeArrivalSlot(h, at, across, step, radius, occupied, around = false) {
|
|
2960
|
-
// The
|
|
2961
|
-
|
|
3069
|
+
// The place's own body, as its players are (v1.218: ground-backed places
|
|
3070
|
+
// used the larger legacy envelope, which intersects authored floors under
|
|
3071
|
+
// shorter players).
|
|
3072
|
+
const size = bodySize(h) ?? { radius: BODY_RADIUS_M, halfHeight: BODY_HALF_M };
|
|
2962
3073
|
const dirs = [[across.x, across.z], [-across.x, -across.z]];
|
|
2963
3074
|
if (around) {
|
|
2964
3075
|
for (let i = 0; i < 8; i += 1) {dirs.push([Math.cos(i * Math.PI / 4), Math.sin(i * Math.PI / 4)]);}
|
|
@@ -2969,7 +3080,7 @@ function freeArrivalSlot(h, at, across, step, radius, occupied, around = false)
|
|
|
2969
3080
|
const [dx, dz] = dirs[d];
|
|
2970
3081
|
const candidate = { x: at.x + dx * k * step, y: at.y, z: at.z + dz * k * step };
|
|
2971
3082
|
candidate.y = standingY(h, candidate);
|
|
2972
|
-
if (!occupied.some((p) =>
|
|
3083
|
+
if (!occupied.some((p) => takes(h, p, candidate)) &&
|
|
2973
3084
|
spotClear(h, candidate, size) && padAt(h, candidate, radius) === null) {
|
|
2974
3085
|
return candidate;
|
|
2975
3086
|
}
|
|
@@ -3067,7 +3178,9 @@ function padAt(h, at, margin) {
|
|
|
3067
3178
|
// or a spawned copy (a House's placed furniture), at its live pose -- and on
|
|
3068
3179
|
// a scene with no ground (`fallY`) a solid's top is under its feet.
|
|
3069
3180
|
function spotClear(h, at, { radius, halfHeight }) {
|
|
3070
|
-
|
|
3181
|
+
// The ground slab is finite (`ground.half`, 100 m by default): a spot past
|
|
3182
|
+
// its edge stands only on an authored solid (v1.218).
|
|
3183
|
+
let supported = h.noGround !== true && Math.abs(at.x) <= (h.groundHalf ?? Infinity) && Math.abs(at.z) <= (h.groundHalf ?? Infinity);
|
|
3071
3184
|
for (const { shape, pose } of solids(h)) {
|
|
3072
3185
|
// A tilted solid is judged by its enclosing sphere, as standingY does.
|
|
3073
3186
|
const bound = pose.upright ? null : boundingRadius(shape);
|
|
@@ -3110,7 +3223,7 @@ function moveBody(h, playerId, at, facing) {
|
|
|
3110
3223
|
body.body.setTranslation(body.at, true);
|
|
3111
3224
|
// Any placement is where the player is now, not a `hub.placeAt` still
|
|
3112
3225
|
// waiting for its client (a hold, an arrival, a car, a pose restore, at any
|
|
3113
|
-
// distance; `hub.placeAt`
|
|
3226
|
+
// distance; `hub.placeAt` and pose restores arm theirs again, `guardPlacement`).
|
|
3114
3227
|
h.placed.delete(playerId);
|
|
3115
3228
|
// A leave before the next server step stores where the body was put, not
|
|
3116
3229
|
// where that step's predecessor recorded it (`rememberResumePoses`).
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// on the ring was followed by the arrival row back at the spawn, which the
|
|
8
8
|
// client eased to as a correction: a glide just after the cover lifted (Oct
|
|
9
9
|
// 17, live Town; v1.147). A player waits for their group where their client agrees
|
|
10
|
-
// they are; the arrival row spreads a group out.
|
|
10
|
+
// they are; the arrival row spreads a group out. One who finds another body
|
|
11
|
+
// on the spawn starts beside it instead (v1.218, `hub.joinSpot`).
|
|
11
12
|
import * as Players from '@imports/castle.multiplayer-3d/code/server/players.js';
|
|
12
13
|
import { readPoint } from '@imports/castle.multiplayer-3d/code/server/limits.js';
|
|
13
14
|
|
|
@@ -32,6 +33,10 @@ export function hubPlayers(hub) {
|
|
|
32
33
|
const player = sim.players.get(playerId);
|
|
33
34
|
const at = { ...player.at, x: sim.spawn?.x ?? player.at.x, z: sim.spawn?.z ?? player.at.z };
|
|
34
35
|
player.at = { ...at, y: hub.standingY?.(sim, at) ?? at.y };
|
|
36
|
+
// v1.218: unless another body stands there. Two capsules on exactly
|
|
37
|
+
// one spot wedge each client's own body into the ground under the
|
|
38
|
+
// other's avatar; beside it, this WORLD is still the one placement.
|
|
39
|
+
player.at = hub.joinSpot?.(sim, playerId, player.at) ?? player.at;
|
|
35
40
|
player.body.setTranslation(player.at, true);
|
|
36
41
|
}
|
|
37
42
|
return result;
|
|
@@ -7,9 +7,13 @@ export function standingY(h, at) {
|
|
|
7
7
|
return at.y;
|
|
8
8
|
}
|
|
9
9
|
const { radius, halfHeight } = size;
|
|
10
|
-
|
|
10
|
+
// The ground slab is finite (`ground.half`): past its edge only an authored
|
|
11
|
+
// solid holds a body, as spotClear judges it (v1.218).
|
|
12
|
+
const half = h.groundHalf ?? Infinity;
|
|
13
|
+
const onGround = h.noGround !== true && Math.abs(at.x) <= half && Math.abs(at.z) <= half;
|
|
14
|
+
let support = onGround ? 0 : null;
|
|
11
15
|
const spans = [];
|
|
12
|
-
let centredSupport =
|
|
16
|
+
let centredSupport = onGround;
|
|
13
17
|
for (const { shape, pose, moving } of solids(h)) {
|
|
14
18
|
if (pose.upright && (shape.kind === 'box' || shape.kind === 'cylinder')) {
|
|
15
19
|
if (!footprintHas(shape, pose, at, radius)) {
|
|
@@ -43,7 +47,7 @@ export function standingY(h, at) {
|
|
|
43
47
|
}
|
|
44
48
|
// In a scene without ground, a rim beside the feet does not prove support
|
|
45
49
|
// beneath them. Keep the old drop rather than lower over a hole.
|
|
46
|
-
if (support === null || (
|
|
50
|
+
if (support === null || (!onGround && !centredSupport)) {
|
|
47
51
|
return at.y;
|
|
48
52
|
}
|
|
49
53
|
const y = support + halfHeight + 0.06;
|
|
@@ -4339,8 +4339,9 @@ class HubSystem {
|
|
|
4339
4339
|
this.padReadabilityScope = { data: scene.data, place: Hub.hub.place.id,
|
|
4340
4340
|
context: engine.hubPadContext, ring: engine.hubPadRing, spawn: engine.hubSpawnRing };
|
|
4341
4341
|
}
|
|
4342
|
+
const selfId = scene.multiplayer?.net?.selfId?.();
|
|
4342
4343
|
this.padReadability.frame(scene.actors, Hub.hub.hidden, local?.components.Transform, Boolean(this.trip),
|
|
4343
|
-
this.carded || this.decor?.opened() === true);
|
|
4344
|
+
this.carded || this.decor?.opened() === true, selfId != null && Hub.hub.guests?.has?.(selfId) === true);
|
|
4344
4345
|
}
|
|
4345
4346
|
|
|
4346
4347
|
// A town's world labels under `hub.labels: "near"` (v1.43): the plate and
|