castle-web-cli 0.4.239 → 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/agent.js +5 -1
- package/dist/api.d.ts +20 -0
- package/dist/api.js +57 -0
- package/dist/bundle.d.ts +38 -1
- package/dist/bundle.js +309 -13
- package/dist/castle-host/host.js +163 -11
- package/dist/castleJson.d.ts +10 -0
- package/dist/castleJson.js +46 -2
- package/dist/check.js +5 -2
- package/dist/devSessionServer.js +4 -1
- package/dist/devSessionStorage.d.ts +1 -0
- package/dist/devSessionStorage.js +32 -7
- package/dist/importOrder.d.ts +2 -0
- package/dist/importOrder.js +29 -0
- package/dist/index.js +6 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +2 -0
- package/dist/platformDoc.js +3 -2
- package/dist/playPagePolicy.js +5 -1
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +1 -0
- package/dist/roomLogs.js +30 -6
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +174 -6
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +5 -1
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +48 -0
- package/kits/base/sdk/commands.js +1 -0
- package/kits/base/sdk/debugConsole.d.ts +17 -0
- package/kits/base/sdk/debugConsole.js +154 -0
- package/kits/base/sdk/experiments.js +24 -1
- package/kits/base/sdk/hostRetry.d.ts +7 -0
- package/kits/base/sdk/hostRetry.js +57 -0
- package/kits/base/sdk/hub.d.ts +20 -2
- package/kits/base/sdk/hub.js +99 -13
- package/kits/base/sdk/multiplayer.d.ts +2 -0
- package/kits/base/sdk/multiplayer.js +168 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- package/kits/base/sdk/runtime.js +36 -19
- package/kits/base/sdk/server/hub.d.ts +19 -0
- package/kits/base/sdk/server/hub.js +12 -0
- package/kits/base/sdk/server/platformHandle.d.ts +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +1 -1
- package/kits/base/sdk/server/wrapper.js +26 -1
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +35 -0
- package/kits/hub-game/CLAUDE.md +66 -19
- package/kits/hub-game/code/client/act.js +9 -6
- package/kits/hub-game/code/client/actCore.js +26 -6
- package/kits/hub-game/code/client/actGateLog.js +36 -0
- package/kits/hub-game/code/client/actionOverflow.js +29 -8
- package/kits/hub-game/code/client/actionRailSurface.js +186 -0
- package/kits/hub-game/code/client/actionRailTree.js +173 -0
- package/kits/hub-game/code/client/askSurface.js +85 -0
- package/kits/hub-game/code/client/askTree.js +51 -0
- package/kits/hub-game/code/client/attention.js +31 -6
- package/kits/hub-game/code/client/ballot.js +42 -5
- package/kits/hub-game/code/client/ballotSurface.js +115 -0
- package/kits/hub-game/code/client/ballotTree.js +180 -0
- package/kits/hub-game/code/client/catchingUp.js +19 -0
- package/kits/hub-game/code/client/celebrate.js +66 -0
- package/kits/hub-game/code/client/chrome.js +481 -57
- package/kits/hub-game/code/client/companion.js +93 -23
- package/kits/hub-game/code/client/companionDress.js +1 -1
- package/kits/hub-game/code/client/cornerSurface.js +106 -0
- package/kits/hub-game/code/client/cornerTree.js +83 -0
- package/kits/hub-game/code/client/decor.js +20 -11
- package/kits/hub-game/code/client/deviceStorage.js +121 -0
- package/kits/hub-game/code/client/disguise.js +23 -0
- package/kits/hub-game/code/client/disguiseDraw.js +87 -0
- package/kits/hub-game/code/client/dockSurface.js +206 -0
- package/kits/hub-game/code/client/dockTree.js +232 -0
- package/kits/hub-game/code/client/earned.js +29 -0
- package/kits/hub-game/code/client/emoteSurface.js +188 -0
- package/kits/hub-game/code/client/emoteTree.js +264 -0
- package/kits/hub-game/code/client/farAvatars.js +4 -3
- package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
- package/kits/hub-game/code/client/grab.js +121 -50
- package/kits/hub-game/code/client/holdShow.js +19 -0
- package/kits/hub-game/code/client/hookLayer.js +96 -12
- package/kits/hub-game/code/client/hubControls.js +7 -1
- package/kits/hub-game/code/client/hudSurface.js +11 -3
- package/kits/hub-game/code/client/hudTree.js +7 -4
- package/kits/hub-game/code/client/idle.js +21 -3
- package/kits/hub-game/code/client/invites.js +24 -3
- package/kits/hub-game/code/client/keys.js +15 -0
- package/kits/hub-game/code/client/labelsNear.js +8 -1
- package/kits/hub-game/code/client/layoutCache.js +57 -8
- package/kits/hub-game/code/client/loadingCover.js +53 -4
- package/kits/hub-game/code/client/menuIcons.js +15 -0
- package/kits/hub-game/code/client/menuSurface.js +102 -0
- package/kits/hub-game/code/client/menuTree.js +135 -0
- package/kits/hub-game/code/client/modelLook.js +41 -0
- package/kits/hub-game/code/client/padCues.js +11 -7
- package/kits/hub-game/code/client/padReadability.js +3 -3
- package/kits/hub-game/code/client/pickerSurface.js +152 -0
- package/kits/hub-game/code/client/pickerTree.js +163 -0
- package/kits/hub-game/code/client/pushVisit.js +4 -2
- package/kits/hub-game/code/client/quality.js +188 -29
- package/kits/hub-game/code/client/qualityEntry.js +10 -1
- package/kits/hub-game/code/client/quickChatSurface.js +222 -0
- package/kits/hub-game/code/client/quickChatTree.js +201 -0
- package/kits/hub-game/code/client/rehello.js +75 -0
- package/kits/hub-game/code/client/renderVisibility.js +17 -0
- package/kits/hub-game/code/client/replay.js +118 -0
- package/kits/hub-game/code/client/role.js +3 -0
- package/kits/hub-game/code/client/safeLayout.js +441 -56
- package/kits/hub-game/code/client/safeStyle.js +13 -10
- package/kits/hub-game/code/client/say.js +2 -0
- package/kits/hub-game/code/client/soundSurface.js +77 -0
- package/kits/hub-game/code/client/soundTree.js +74 -0
- package/kits/hub-game/code/client/soundscape.js +12 -9
- package/kits/hub-game/code/client/soundscapeCues.js +1 -1
- package/kits/hub-game/code/client/state.js +67 -1
- package/kits/hub-game/code/client/stuckSurface.js +76 -0
- package/kits/hub-game/code/client/stuckTree.js +67 -0
- package/kits/hub-game/code/client/talk.js +42 -12
- package/kits/hub-game/code/client/talkTree.js +4 -2
- package/kits/hub-game/code/client/textAskSurface.js +147 -0
- package/kits/hub-game/code/client/textAskTree.js +67 -0
- package/kits/hub-game/code/client/tiers.js +252 -27
- package/kits/hub-game/code/client/together.js +4 -1
- package/kits/hub-game/code/client/uiDom.js +86 -8
- package/kits/hub-game/code/client/uiTree.js +33 -4
- package/kits/hub-game/code/client/vehicle.js +72 -51
- package/kits/hub-game/code/client/weakestTier.js +75 -31
- package/kits/hub-game/code/client/wear.js +159 -5
- package/kits/hub-game/code/client/worldLabels.js +205 -25
- package/kits/hub-game/code/companionSpec.js +4 -2
- package/kits/hub-game/code/server/act.js +3 -0
- package/kits/hub-game/code/server/actGate.js +83 -0
- package/kits/hub-game/code/server/actions.js +71 -15
- package/kits/hub-game/code/server/actors.js +20 -5
- package/kits/hub-game/code/server/analytics.js +35 -3
- package/kits/hub-game/code/server/ask.js +39 -3
- package/kits/hub-game/code/server/ballot.js +167 -4
- package/kits/hub-game/code/server/celebrate.js +64 -0
- package/kits/hub-game/code/server/companion.js +17 -2
- package/kits/hub-game/code/server/decor.js +11 -2
- package/kits/hub-game/code/server/disguise.js +63 -0
- package/kits/hub-game/code/server/earned.js +6 -2
- package/kits/hub-game/code/server/friendBests.js +13 -4
- package/kits/hub-game/code/server/friendsAmong.js +67 -8
- package/kits/hub-game/code/server/grab.js +12 -2
- package/kits/hub-game/code/server/heldOffers.js +142 -0
- package/kits/hub-game/code/server/holdShow.js +98 -0
- package/kits/hub-game/code/server/hub.js +991 -72
- package/kits/hub-game/code/server/idle.js +110 -9
- package/kits/hub-game/code/server/index.js +9 -0
- package/kits/hub-game/code/server/labels.js +13 -3
- package/kits/hub-game/code/server/manifest.js +94 -6
- package/kits/hub-game/code/server/menu.js +26 -3
- package/kits/hub-game/code/server/npcs.js +55 -9
- package/kits/hub-game/code/server/observe.js +67 -6
- package/kits/hub-game/code/server/players.js +14 -2
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/standing.js +7 -3
- package/kits/hub-game/code/server/storageLimit.js +4 -1
- package/kits/hub-game/code/server/townDay.js +74 -0
- package/kits/hub-game/code/server/vehicle.js +3 -0
- package/kits/hub-game/code/server/vis.js +26 -4
- package/kits/hub-game/code/server/wallet.js +677 -0
- package/kits/hub-game/code/server/wear.js +13 -3
- package/kits/hub-game/code/server/writerLease.js +191 -0
- package/kits/hub-game/code/shared/act.js +1 -1
- package/kits/hub-game/code/shared/expression.js +6 -0
- package/kits/hub-game/code/shared/replay.js +37 -0
- package/kits/hub-game/code/systems/hub.js +429 -55
- package/kits/hub-game/docs/analytics.md +16 -2
- package/kits/hub-game/docs/contract.md +956 -101
- package/kits/hub-game/docs/home-pieces.md +5 -6
- package/kits/hub-game/docs/observed-progress.md +49 -1
- package/kits/hub-game/docs/vehicle-preset.md +23 -0
- package/kits/hub-game/index.html +1 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
- package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
- package/kits/hub-game/models/hats/cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/captain.pxmodel +3 -3
- package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
- package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
- package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
- package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
- package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
- package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
- package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
- package/kits/hub-game/models/hats/straw.pxmodel +3 -3
- package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
- package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
- package/kits/hub-game/models/hats/witch.pxmodel +3 -3
- package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
- package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
- package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
- package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
- package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
- package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
- package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
- package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
- package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
- package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
- package/kits/hub-game/package-lock.json +3 -3
- package/kits/hub-game/package.json +4 -3
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
- package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
- package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
- package/kits/hub-game/scripts/gen-hats.mjs +1 -1
- package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
- package/kits/hub-game/scripts/pack.mjs +89 -23
- package/kits/hub-game/scripts/test-act-client.mjs +5 -0
- package/kits/hub-game/scripts/test-act-core.mjs +32 -0
- package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
- package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
- package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
- package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
- package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
- package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
- package/kits/hub-game/scripts/test-actions.mjs +24 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -0
- package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-analytics.mjs +79 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
- package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
- package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
- package/kits/hub-game/scripts/test-attention.mjs +43 -1
- package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
- package/kits/hub-game/scripts/test-ballot.mjs +421 -4
- package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
- package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
- package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
- package/kits/hub-game/scripts/test-chat.mjs +73 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
- package/kits/hub-game/scripts/test-companion.mjs +110 -3
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
- package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
- package/kits/hub-game/scripts/test-decor.mjs +27 -0
- package/kits/hub-game/scripts/test-device-class.mjs +4 -1
- package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
- package/kits/hub-game/scripts/test-disguise.mjs +176 -0
- package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
- package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
- package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
- package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
- package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
- package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
- package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
- package/kits/hub-game/scripts/test-grab.mjs +10 -1
- package/kits/hub-game/scripts/test-hats.mjs +28 -0
- package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
- package/kits/hub-game/scripts/test-high-only.mjs +3 -3
- package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
- package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
- package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
- package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
- package/kits/hub-game/scripts/test-idle.mjs +160 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
- package/kits/hub-game/scripts/test-labels.mjs +11 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
- package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
- package/kits/hub-game/scripts/test-npcs.mjs +128 -0
- package/kits/hub-game/scripts/test-observed.mjs +171 -3
- package/kits/hub-game/scripts/test-pack.mjs +166 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
- package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
- package/kits/hub-game/scripts/test-quality.mjs +312 -9
- package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
- package/kits/hub-game/scripts/test-rehello.mjs +242 -3
- package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
- package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
- package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
- package/kits/hub-game/scripts/test-replay.mjs +178 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
- package/kits/hub-game/scripts/test-role-client.mjs +2 -1
- package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
- package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
- package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
- package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
- package/kits/hub-game/scripts/test-standing.mjs +135 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +36 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
- package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
- package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
- package/kits/hub-game/scripts/test-tiers.mjs +453 -3
- package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-together.mjs +11 -0
- package/kits/hub-game/scripts/test-town-day.mjs +90 -0
- package/kits/hub-game/scripts/test-try-on.mjs +39 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
- package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
- package/kits/hub-game/scripts/test-vis.mjs +145 -0
- package/kits/hub-game/scripts/test-wallet.mjs +650 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
- package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
- package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
- package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
- package/kits/hub-game/tools/hubScene/export.mjs +6 -5
- package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
- package/kits/multiplayer-3d/code/server/ownership.js +25 -6
- package/kits/multiplayer-3d/code/server/world.js +19 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
- package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-3d/CLAUDE.md +14 -0
- package/kits/physics-3d/behaviors/Player.jsx +39 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-model-cache.md +109 -0
- package/kits/physics-3d/docs/engine-player.md +76 -0
- package/kits/physics-3d/docs/engine-skip-work.md +16 -0
- package/kits/physics-3d/docs/pxmodel-format.md +5 -1
- package/kits/physics-3d/engine3d/gait.js +16 -8
- package/kits/physics-3d/engine3d/groundsize.js +23 -0
- package/kits/physics-3d/engine3d/kithooks.js +50 -0
- package/kits/physics-3d/engine3d/look.js +110 -17
- package/kits/physics-3d/engine3d/lookbake.js +19 -1
- package/kits/physics-3d/engine3d/materialpresets.js +3 -2
- package/kits/physics-3d/engine3d/modelcache.js +280 -0
- package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
- package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
- package/kits/physics-3d/engine3d/modelrefs.js +13 -0
- package/kits/physics-3d/engine3d/optimize.js +20 -9
- package/kits/physics-3d/engine3d/playerRun.js +26 -1
- package/kits/physics-3d/engine3d/pxmodel.js +7 -3
- package/kits/physics-3d/engine3d/templatecache.js +722 -0
- package/kits/physics-3d/engine3d/world3d.js +211 -17
- package/kits/physics-3d/package-lock.json +1 -1
- package/kits/physics-3d/package.json +2 -1
- package/kits/physics-3d/play/behaviors/Player.js +43 -3
- package/kits/physics-3d/scripts/render.mjs +56 -8
- package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
- package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
- package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
- package/kits/physics-3d/scripts/test-gait.mjs +53 -9
- package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
- package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
- package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
- package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
- package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
- package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
- package/kits/physics-3d/systems/physics3d.js +59 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +3 -0
- package/package.json +2 -2
- package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CastleError } from "./errors";
|
|
2
2
|
import { BINARY_MESSAGE_TAG, isBinaryPayload, MAX_CLIENT_FRAME_BYTES, toUint8Array, } from "./multiplayerProtocol";
|
|
3
3
|
import { hostRequest } from "./transport";
|
|
4
|
+
import { retryHostTransport } from "./hostRetry";
|
|
4
5
|
import { MultiplayerVoiceImpl } from "./multiplayerVoice";
|
|
5
6
|
import { ReconnectBudget } from "./reconnectBudget";
|
|
6
7
|
import { noteSessionRejoined } from "./hubRejoin";
|
|
@@ -8,6 +9,20 @@ const KEEPALIVE_INTERVAL_MS = 25_000;
|
|
|
8
9
|
const HELLO_TIMEOUT_MS = 10_000;
|
|
9
10
|
const RECONNECT_BUDGET_MS = 30_000;
|
|
10
11
|
const RECONNECT_DELAYS_MS = [500, 1_000, 2_000, 4_000, 8_000];
|
|
12
|
+
// A connected socket hears something at least once a keepalive (the pong, or
|
|
13
|
+
// the tick that sends the ping). Silence well past that means the page was not
|
|
14
|
+
// running: hidden, frozen or suspended. A connection lost across such a gap is
|
|
15
|
+
// found on the page's return, and its first try goes at once instead of after
|
|
16
|
+
// the first backoff step: the backoff is for a failing network, and an outage
|
|
17
|
+
// found on return has not failed a single try yet. A hidden page whose timers
|
|
18
|
+
// and frames kept running is away too: each sign of life notes whether the
|
|
19
|
+
// page was hidden, and the first one seen visible after that is a return. A
|
|
20
|
+
// resumed page can run an overdue keepalive tick or deliver buffered frames
|
|
21
|
+
// before the socket's close (or a pong deadline's fresh probe can outlast
|
|
22
|
+
// them), so a return stands until a socket frame arrives RETURN_GRACE_MS or
|
|
23
|
+
// more after it, which shows the socket carried on past the return.
|
|
24
|
+
const AWAY_SILENCE_MS = KEEPALIVE_INTERVAL_MS + 5_000;
|
|
25
|
+
const RETURN_GRACE_MS = 5_000;
|
|
11
26
|
const INVALID_DEV_RECONNECT_CLOSE_CODE = 4003;
|
|
12
27
|
// The play proxy closes a handshake it refuses with a reason (cauldron-game-server
|
|
13
28
|
// shared/src/constants.ts). The host that owns the session rejecting the credential is
|
|
@@ -27,6 +42,18 @@ let nextCharacterStatusRequestId = 1;
|
|
|
27
42
|
let activeConnection = null;
|
|
28
43
|
let latestJoinAttempt = 0;
|
|
29
44
|
let pendingDestinationJoin = null;
|
|
45
|
+
// Connections waiting for a newer join to settle (`whenJoinOwner`), woken when
|
|
46
|
+
// a destination join settles or a connection closes, to look again.
|
|
47
|
+
let joinSettledWaiters = [];
|
|
48
|
+
function nextJoinSettled() {
|
|
49
|
+
return new Promise((resolve) => joinSettledWaiters.push(resolve));
|
|
50
|
+
}
|
|
51
|
+
function wakeJoinWaiters() {
|
|
52
|
+
const waiters = joinSettledWaiters;
|
|
53
|
+
joinSettledWaiters = [];
|
|
54
|
+
for (const wake of waiters)
|
|
55
|
+
wake();
|
|
56
|
+
}
|
|
30
57
|
export const Multiplayer = {
|
|
31
58
|
placeCharacters: true,
|
|
32
59
|
join,
|
|
@@ -52,10 +79,14 @@ async function join(options) {
|
|
|
52
79
|
if (!Number.isFinite(pongTimeoutMs) || pongTimeoutMs < 0 || pongTimeoutMs > 2_147_483_647) {
|
|
53
80
|
throw new RangeError("pongTimeoutMs must be between 0 and 2147483647 milliseconds");
|
|
54
81
|
}
|
|
55
|
-
|
|
82
|
+
const attempt = ++latestJoinAttempt;
|
|
83
|
+
// Leaving runs the deck's state listeners, which may begin a newer join:
|
|
84
|
+
// then this one is superseded before it asks for anything.
|
|
56
85
|
cancelPendingDestinationJoin();
|
|
57
86
|
activeConnection?.leave();
|
|
58
|
-
|
|
87
|
+
if (attempt !== latestJoinAttempt)
|
|
88
|
+
throw supersededJoinError();
|
|
89
|
+
const connection = new MultiplayerConnectionImpl(request, attempt, () => {
|
|
59
90
|
if (activeConnection === connection)
|
|
60
91
|
activeConnection = null;
|
|
61
92
|
}, null, pongTimeoutMs);
|
|
@@ -119,8 +150,15 @@ function hubJoin(options) {
|
|
|
119
150
|
async function joinDestination(options) {
|
|
120
151
|
const params = destinationParams(options);
|
|
121
152
|
const attempt = ++latestJoinAttempt;
|
|
153
|
+
// Cancelling a pending destination join leaves its connection, whose state
|
|
154
|
+
// listeners may begin a newer join: then this one is superseded already.
|
|
122
155
|
cancelPendingDestinationJoin();
|
|
156
|
+
if (attempt !== latestJoinAttempt)
|
|
157
|
+
return { status: "cancelled" };
|
|
123
158
|
if (activeConnection?.matchesDestination(params)) {
|
|
159
|
+
// This join is the connection's own join now, for its fence.
|
|
160
|
+
activeConnection.adoptJoinAttempt(attempt);
|
|
161
|
+
wakeJoinWaiters();
|
|
124
162
|
return {
|
|
125
163
|
status: "joined",
|
|
126
164
|
connection: activeConnection,
|
|
@@ -128,14 +166,26 @@ async function joinDestination(options) {
|
|
|
128
166
|
};
|
|
129
167
|
}
|
|
130
168
|
const previousConnection = activeConnection;
|
|
169
|
+
try {
|
|
170
|
+
return await joinNewDestination(params, attempt, previousConnection);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
// The newest join ended without replacing the connection it found: that
|
|
174
|
+
// connection is the player's again, and may ask for its session again.
|
|
175
|
+
if (attempt === latestJoinAttempt && previousConnection && activeConnection === previousConnection) {
|
|
176
|
+
previousConnection.adoptJoinAttempt(attempt);
|
|
177
|
+
}
|
|
178
|
+
wakeJoinWaiters();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function joinNewDestination(params, attempt, previousConnection) {
|
|
131
182
|
const controller = new AbortController();
|
|
132
183
|
const pending = { controller, connection: null };
|
|
133
184
|
pendingDestinationJoin = pending;
|
|
134
185
|
let acquired;
|
|
135
186
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
187
|
+
// A request lost in transit is asked again until a newer join or a cancel.
|
|
188
|
+
acquired = await retryHostTransport("multiplayer.joinDestination", () => hostRequest("multiplayer.joinDestination", params, { signal: controller.signal }), { signal: controller.signal, stopped: () => attempt !== latestJoinAttempt });
|
|
139
189
|
}
|
|
140
190
|
catch (error) {
|
|
141
191
|
if (pendingDestinationJoin === pending)
|
|
@@ -160,7 +210,7 @@ async function joinDestination(options) {
|
|
|
160
210
|
pendingDestinationJoin = null;
|
|
161
211
|
return { status: "unavailable" };
|
|
162
212
|
}
|
|
163
|
-
const connection = new MultiplayerConnectionImpl({ command: "multiplayer.joinDestination", params }, () => {
|
|
213
|
+
const connection = new MultiplayerConnectionImpl({ command: "multiplayer.joinDestination", params }, attempt, () => {
|
|
164
214
|
if (activeConnection === connection)
|
|
165
215
|
activeConnection = null;
|
|
166
216
|
}, acquired.audience);
|
|
@@ -183,6 +233,11 @@ async function joinDestination(options) {
|
|
|
183
233
|
return { status: "cancelled" };
|
|
184
234
|
}
|
|
185
235
|
previousConnection?.leave();
|
|
236
|
+
// The previous connection's state listeners may have begun a newer join.
|
|
237
|
+
if (attempt !== latestJoinAttempt) {
|
|
238
|
+
connection.leave();
|
|
239
|
+
return { status: "cancelled" };
|
|
240
|
+
}
|
|
186
241
|
activeConnection = connection;
|
|
187
242
|
return { status: "joined", connection, audience: acquired.audience };
|
|
188
243
|
}
|
|
@@ -190,6 +245,7 @@ async function joinDestination(options) {
|
|
|
190
245
|
const EARLY_MESSAGES_MAX = 512;
|
|
191
246
|
class MultiplayerConnectionImpl {
|
|
192
247
|
request;
|
|
248
|
+
joinAttempt;
|
|
193
249
|
onClosed;
|
|
194
250
|
destinationAudience;
|
|
195
251
|
pongTimeoutMs;
|
|
@@ -212,6 +268,11 @@ class MultiplayerConnectionImpl {
|
|
|
212
268
|
greeted = false;
|
|
213
269
|
recovering = false;
|
|
214
270
|
reconnectBudget = null;
|
|
271
|
+
// Wall clock, not monotonic: the gap it measures is a suspension, which a
|
|
272
|
+
// paused page's monotonic clock may not count.
|
|
273
|
+
lastHeardAt = 0;
|
|
274
|
+
returnedAt = null;
|
|
275
|
+
heardHidden = false;
|
|
215
276
|
hubSettled = false;
|
|
216
277
|
hubCommit = Promise.resolve(true);
|
|
217
278
|
roster = null;
|
|
@@ -235,8 +296,13 @@ class MultiplayerConnectionImpl {
|
|
|
235
296
|
players: () => this.roster?.players ?? [],
|
|
236
297
|
isSolo: () => this.solo,
|
|
237
298
|
});
|
|
238
|
-
constructor(request,
|
|
299
|
+
constructor(request,
|
|
300
|
+
// The join (Multiplayer.join or joinDestination) this connection belongs
|
|
301
|
+
// to, the attempt it took. While a newer join is pending, this connection
|
|
302
|
+
// asks for no session (`whenJoinOwner`).
|
|
303
|
+
joinAttempt, onClosed, destinationAudience = null, pongTimeoutMs = 0) {
|
|
239
304
|
this.request = request;
|
|
305
|
+
this.joinAttempt = joinAttempt;
|
|
240
306
|
this.onClosed = onClosed;
|
|
241
307
|
this.destinationAudience = destinationAudience;
|
|
242
308
|
this.pongTimeoutMs = pongTimeoutMs;
|
|
@@ -299,6 +365,12 @@ class MultiplayerConnectionImpl {
|
|
|
299
365
|
return;
|
|
300
366
|
this.socket.send(payload);
|
|
301
367
|
}
|
|
368
|
+
reconnect() {
|
|
369
|
+
if (this.currentState !== "connected" || this.recovering || this.solo || !this.socket)
|
|
370
|
+
return false;
|
|
371
|
+
this.recoverSocket(this.socket, "reconnect");
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
302
374
|
requestCharacterTurn(request) {
|
|
303
375
|
const normalized = normalizeCharacterTurnRequest(request, this.currentPlayerId);
|
|
304
376
|
return this.sendCharacterRequest(normalized.requestId, normalized.operationId, "admission", JSON.stringify({ t: "worldCharacterTurn", ...normalized }));
|
|
@@ -427,6 +499,9 @@ class MultiplayerConnectionImpl {
|
|
|
427
499
|
hubCommitted() {
|
|
428
500
|
return this.hubCommit;
|
|
429
501
|
}
|
|
502
|
+
adoptJoinAttempt(attempt) {
|
|
503
|
+
this.joinAttempt = attempt;
|
|
504
|
+
}
|
|
430
505
|
matchesDestination(params) {
|
|
431
506
|
return (this.currentState !== "closed" &&
|
|
432
507
|
this.request.command === "multiplayer.joinDestination" &&
|
|
@@ -434,9 +509,28 @@ class MultiplayerConnectionImpl {
|
|
|
434
509
|
this.request.params.slot === params.slot &&
|
|
435
510
|
this.destinationAudience !== null);
|
|
436
511
|
}
|
|
512
|
+
// Sends an acquisition once this connection owns the newest join attempt,
|
|
513
|
+
// or rejects once it is closed. A destination join keeps this connection
|
|
514
|
+
// open until its own socket connects; an acquisition asked meanwhile would
|
|
515
|
+
// supersede the newer one at the host, so it waits for that join to settle:
|
|
516
|
+
// one that replaced this connection closed it, one that did not handed it
|
|
517
|
+
// the attempt. The check and the send run in the same synchronous callback,
|
|
518
|
+
// so no join can begin between them; after any wake the gate is entered again.
|
|
519
|
+
whenJoinOwner(send) {
|
|
520
|
+
if (this.currentState === "closed")
|
|
521
|
+
return Promise.reject(this.closedError());
|
|
522
|
+
if (this.joinAttempt === latestJoinAttempt)
|
|
523
|
+
return send();
|
|
524
|
+
return nextJoinSettled().then(() => this.whenJoinOwner(send));
|
|
525
|
+
}
|
|
526
|
+
closedError() {
|
|
527
|
+
return multiplayerError("MULTIPLAYER_CONNECTION_CLOSED", "The multiplayer connection is closed.");
|
|
528
|
+
}
|
|
437
529
|
async acquire(initial) {
|
|
438
530
|
this.transition("acquiring");
|
|
439
|
-
|
|
531
|
+
// Every ask, the first and each retry, waits until this connection owns
|
|
532
|
+
// the newest join (`whenJoinOwner`); a retry wait ends once it closes.
|
|
533
|
+
const result = initial ?? await requestAcquisition(this.request, (send) => this.whenJoinOwner(send), () => this.currentState === "closed");
|
|
440
534
|
this.assertOpen();
|
|
441
535
|
if (result.status === "solo") {
|
|
442
536
|
this.connectSolo(result);
|
|
@@ -558,6 +652,8 @@ class MultiplayerConnectionImpl {
|
|
|
558
652
|
closeSocket(socket, 1000, "hello timeout");
|
|
559
653
|
}, HELLO_TIMEOUT_MS);
|
|
560
654
|
socket.onmessage = (event) => {
|
|
655
|
+
if (this.socketAttempt === attempt)
|
|
656
|
+
this.hear(true);
|
|
561
657
|
const data = event.data;
|
|
562
658
|
inbound = inbound
|
|
563
659
|
.then(async () => {
|
|
@@ -704,6 +800,11 @@ class MultiplayerConnectionImpl {
|
|
|
704
800
|
const budget = this.reconnectBudget = new ReconnectBudget();
|
|
705
801
|
let attempt = 0;
|
|
706
802
|
let sessionEndedCloses = 0;
|
|
803
|
+
// Lost while the page was away (AWAY_SILENCE_MS), or found while it still
|
|
804
|
+
// is: the first try goes as soon as the page is back. It is still a try
|
|
805
|
+
// with the token, which is the only way to learn whether the host kept the
|
|
806
|
+
// player; the backoff resumes from its first step after it.
|
|
807
|
+
let immediate = !budget.active || this.heardHidden || this.cameBack();
|
|
707
808
|
try {
|
|
708
809
|
while (true) {
|
|
709
810
|
await budget.waitUntilActive();
|
|
@@ -712,11 +813,16 @@ class MultiplayerConnectionImpl {
|
|
|
712
813
|
// which keeps the player's identity while the host holds its lineage.
|
|
713
814
|
if (budget.exhausted(RECONNECT_BUDGET_MS))
|
|
714
815
|
break;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
816
|
+
if (immediate) {
|
|
817
|
+
immediate = false;
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
const delay = RECONNECT_DELAYS_MS[Math.min(attempt, RECONNECT_DELAYS_MS.length - 1)];
|
|
821
|
+
attempt += 1;
|
|
822
|
+
await pause(delay);
|
|
823
|
+
await budget.waitUntilActive();
|
|
824
|
+
this.assertOpen();
|
|
825
|
+
}
|
|
720
826
|
try {
|
|
721
827
|
budget.noteAttempt();
|
|
722
828
|
await this.openSocket("reconnect", this.reconnectToken);
|
|
@@ -744,6 +850,23 @@ class MultiplayerConnectionImpl {
|
|
|
744
850
|
}
|
|
745
851
|
await this.reacquireOnce();
|
|
746
852
|
}
|
|
853
|
+
// A sign the page is running: a frame from the socket or a keepalive tick.
|
|
854
|
+
hear(fromSocket = false) {
|
|
855
|
+
const now = Date.now();
|
|
856
|
+
const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
857
|
+
if (now - this.lastHeardAt > AWAY_SILENCE_MS || (this.heardHidden && !hidden)) {
|
|
858
|
+
this.returnedAt = now;
|
|
859
|
+
}
|
|
860
|
+
else if (fromSocket && this.returnedAt !== null && now - this.returnedAt >= RETURN_GRACE_MS) {
|
|
861
|
+
this.returnedAt = null;
|
|
862
|
+
}
|
|
863
|
+
this.heardHidden = hidden;
|
|
864
|
+
this.lastHeardAt = now;
|
|
865
|
+
}
|
|
866
|
+
cameBack() {
|
|
867
|
+
const now = Date.now();
|
|
868
|
+
return now - this.lastHeardAt > AWAY_SILENCE_MS || this.returnedAt !== null;
|
|
869
|
+
}
|
|
747
870
|
async reacquireOnce() {
|
|
748
871
|
if (this.reAcquisitionUsed) {
|
|
749
872
|
throw this.closeAfterRecovery();
|
|
@@ -766,7 +889,11 @@ class MultiplayerConnectionImpl {
|
|
|
766
889
|
startKeepalive() {
|
|
767
890
|
this.stopKeepalive();
|
|
768
891
|
this.pongExtensionUsed = false;
|
|
892
|
+
this.lastHeardAt = Date.now();
|
|
893
|
+
this.returnedAt = null;
|
|
894
|
+
this.heardHidden = false;
|
|
769
895
|
this.keepalive = setInterval(() => {
|
|
896
|
+
this.hear();
|
|
770
897
|
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
771
898
|
if (this.pongDeadline !== null)
|
|
772
899
|
return;
|
|
@@ -812,15 +939,18 @@ class MultiplayerConnectionImpl {
|
|
|
812
939
|
}
|
|
813
940
|
catch { /* Fall through to recovery if the fresh probe cannot send. */ }
|
|
814
941
|
}
|
|
815
|
-
|
|
816
|
-
// and enter recovery directly rather than waiting for that close event.
|
|
817
|
-
this.socketAttempt += 1;
|
|
818
|
-
this.socket = null;
|
|
819
|
-
this.stopKeepalive();
|
|
820
|
-
closeSocket(socket, 1000, "pong timeout");
|
|
821
|
-
this.beginRecovery();
|
|
942
|
+
this.recoverSocket(socket, "pong timeout");
|
|
822
943
|
}, this.pongTimeoutMs);
|
|
823
944
|
}
|
|
945
|
+
recoverSocket(socket, reason) {
|
|
946
|
+
// A half-open transport may never emit close. Fence its queued callbacks
|
|
947
|
+
// and enter recovery directly rather than waiting for that close event.
|
|
948
|
+
this.socketAttempt += 1;
|
|
949
|
+
this.socket = null;
|
|
950
|
+
this.stopKeepalive();
|
|
951
|
+
closeSocket(socket, 1000, reason);
|
|
952
|
+
this.beginRecovery();
|
|
953
|
+
}
|
|
824
954
|
transition(state, metadata) {
|
|
825
955
|
if (this.currentState === "closed" || this.currentState === state)
|
|
826
956
|
return;
|
|
@@ -850,11 +980,11 @@ class MultiplayerConnectionImpl {
|
|
|
850
980
|
for (const callback of this.states)
|
|
851
981
|
callStateListener(callback, "closed", metadata);
|
|
852
982
|
this.onClosed();
|
|
983
|
+
wakeJoinWaiters();
|
|
853
984
|
}
|
|
854
985
|
assertOpen() {
|
|
855
|
-
if (this.currentState === "closed")
|
|
856
|
-
throw
|
|
857
|
-
}
|
|
986
|
+
if (this.currentState === "closed")
|
|
987
|
+
throw this.closedError();
|
|
858
988
|
}
|
|
859
989
|
acceptWorldCharacterResult(frame) {
|
|
860
990
|
const pending = this.pendingCharacterRequests.get(frame.requestId);
|
|
@@ -955,22 +1085,34 @@ function destinationParams(options) {
|
|
|
955
1085
|
}
|
|
956
1086
|
return { routeId: options.routeId, slot: options.slot };
|
|
957
1087
|
}
|
|
1088
|
+
// What a join superseded by a newer one before it had a connection rejects
|
|
1089
|
+
// with: the same code as one whose connection the newer join closed.
|
|
1090
|
+
function supersededJoinError() {
|
|
1091
|
+
return multiplayerError("MULTIPLAYER_CONNECTION_CLOSED", "A newer join began; this one was superseded.", "Multiplayer.join");
|
|
1092
|
+
}
|
|
958
1093
|
function cancelPendingDestinationJoin() {
|
|
959
1094
|
const pending = pendingDestinationJoin;
|
|
960
1095
|
pendingDestinationJoin = null;
|
|
961
1096
|
pending?.controller.abort();
|
|
962
1097
|
pending?.connection?.leave();
|
|
963
1098
|
}
|
|
964
|
-
async function requestAcquisition(request
|
|
1099
|
+
async function requestAcquisition(request,
|
|
1100
|
+
// Sends one ask, when the connection may (`whenJoinOwner`).
|
|
1101
|
+
gate, closed) {
|
|
965
1102
|
if (request.command === "hub") {
|
|
966
1103
|
// The nonce was single-use and the trip is the host's; a hub session that
|
|
967
1104
|
// cannot be reconnected to is left by going back through the door.
|
|
968
1105
|
throw multiplayerError("MULTIPLAYER_CONNECTION_LOST", "A hub session cannot be acquired again. Go back through the door.");
|
|
969
1106
|
}
|
|
1107
|
+
// A request lost in transit is asked again until the connection closes; the
|
|
1108
|
+
// wait under way runs out first. Each ask goes through `gate`.
|
|
1109
|
+
const ask = (send) => () => gate(send);
|
|
970
1110
|
if (request.command === "multiplayer.getSession") {
|
|
971
|
-
|
|
1111
|
+
const params = request.params;
|
|
1112
|
+
return retryHostTransport(request.command, ask(() => hostRequest("multiplayer.getSession", params)), { stopped: closed });
|
|
972
1113
|
}
|
|
973
|
-
|
|
1114
|
+
const params = request.params;
|
|
1115
|
+
return retryHostTransport(request.command, ask(() => hostRequest("multiplayer.joinDestination", params)), { stopped: closed });
|
|
974
1116
|
}
|
|
975
1117
|
function destinationStatusFromError(error) {
|
|
976
1118
|
if (!(error instanceof CastleError))
|
|
@@ -5,10 +5,14 @@ export declare class ReconnectBudget {
|
|
|
5
5
|
private wokeSinceAttempt;
|
|
6
6
|
private gapGraceUsed;
|
|
7
7
|
private frozen;
|
|
8
|
+
private offline;
|
|
8
9
|
private disposed;
|
|
9
10
|
private readonly waiters;
|
|
10
11
|
private readonly page;
|
|
12
|
+
private readonly host;
|
|
11
13
|
constructor();
|
|
14
|
+
/** Whether the page is running now: visible, not frozen, not disposed. */
|
|
15
|
+
get active(): boolean;
|
|
12
16
|
get elapsedMs(): number;
|
|
13
17
|
noteAttempt(): void;
|
|
14
18
|
exhausted(limitMs: number): boolean;
|
|
@@ -16,6 +20,8 @@ export declare class ReconnectBudget {
|
|
|
16
20
|
dispose(): void;
|
|
17
21
|
private readonly freeze;
|
|
18
22
|
private readonly resume;
|
|
23
|
+
private readonly goOffline;
|
|
24
|
+
private readonly goOnline;
|
|
19
25
|
private readonly update;
|
|
20
26
|
private readonly observe;
|
|
21
27
|
private stop;
|
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
// Not every suspension is announced (a debugger pause, a native app pausing
|
|
4
4
|
// its web view while the document stays visible), so active time accrues in
|
|
5
5
|
// heartbeat steps and a gap longer than one step counts only that step.
|
|
6
|
+
//
|
|
7
|
+
// Time the browser reports offline does not accrue either: a network drop
|
|
8
|
+
// with the page visible would otherwise spend the whole budget on attempts
|
|
9
|
+
// that fail instantly, and the player rejoins fresh while the host still
|
|
10
|
+
// holds their identity. Offline only pauses the clock; attempts continue at
|
|
11
|
+
// the normal backoff, because navigator.onLine can be wrong (some WebViews
|
|
12
|
+
// and captive networks report false while sockets work) and a wrong flag must
|
|
13
|
+
// never stop a reconnect. If the player stays away past the host's hold, the
|
|
14
|
+
// host refuses the token and recovery ends on that, not on this budget.
|
|
6
15
|
const HEARTBEAT_MS = 1_000;
|
|
7
16
|
const MAX_STEP_MS = 2_000;
|
|
8
17
|
export class ReconnectBudget {
|
|
@@ -15,15 +24,30 @@ export class ReconnectBudget {
|
|
|
15
24
|
// frames for minutes would otherwise renew it forever.
|
|
16
25
|
gapGraceUsed = false;
|
|
17
26
|
frozen = false;
|
|
27
|
+
offline = false;
|
|
18
28
|
disposed = false;
|
|
19
29
|
waiters = new Set();
|
|
20
30
|
page = typeof document === "undefined" ? null : document;
|
|
31
|
+
// Where online/offline arrive: the window, or a worker's own global. With
|
|
32
|
+
// neither, a change of navigator.onLine cannot be seen, so it is not trusted.
|
|
33
|
+
host = typeof window !== "undefined"
|
|
34
|
+
? window
|
|
35
|
+
: typeof globalThis.addEventListener === "function"
|
|
36
|
+
? globalThis
|
|
37
|
+
: null;
|
|
21
38
|
constructor() {
|
|
22
39
|
this.page?.addEventListener("visibilitychange", this.update);
|
|
23
40
|
this.page?.addEventListener("freeze", this.freeze);
|
|
24
41
|
this.page?.addEventListener("resume", this.resume);
|
|
42
|
+
this.host?.addEventListener?.("offline", this.goOffline);
|
|
43
|
+
this.host?.addEventListener?.("online", this.goOnline);
|
|
44
|
+
this.offline = this.host !== null && typeof navigator !== "undefined" && navigator?.onLine === false;
|
|
25
45
|
this.update();
|
|
26
46
|
}
|
|
47
|
+
/** Whether the page is running now: visible, not frozen, not disposed. */
|
|
48
|
+
get active() {
|
|
49
|
+
return this.lastSeen !== null;
|
|
50
|
+
}
|
|
27
51
|
get elapsedMs() {
|
|
28
52
|
this.observe();
|
|
29
53
|
return this.elapsed;
|
|
@@ -47,6 +71,8 @@ export class ReconnectBudget {
|
|
|
47
71
|
this.page?.removeEventListener("visibilitychange", this.update);
|
|
48
72
|
this.page?.removeEventListener("freeze", this.freeze);
|
|
49
73
|
this.page?.removeEventListener("resume", this.resume);
|
|
74
|
+
this.host?.removeEventListener?.("offline", this.goOffline);
|
|
75
|
+
this.host?.removeEventListener?.("online", this.goOnline);
|
|
50
76
|
this.wakeWaiters();
|
|
51
77
|
}
|
|
52
78
|
freeze = () => {
|
|
@@ -57,6 +83,19 @@ export class ReconnectBudget {
|
|
|
57
83
|
this.frozen = false;
|
|
58
84
|
this.update();
|
|
59
85
|
};
|
|
86
|
+
// Each edge settles the time before it at the old state.
|
|
87
|
+
goOffline = () => {
|
|
88
|
+
this.observe();
|
|
89
|
+
this.offline = true;
|
|
90
|
+
};
|
|
91
|
+
// Coming back online is a return like the foreground: one try with the token.
|
|
92
|
+
goOnline = () => {
|
|
93
|
+
if (!this.offline)
|
|
94
|
+
return;
|
|
95
|
+
this.observe();
|
|
96
|
+
this.offline = false;
|
|
97
|
+
this.wokeSinceAttempt = true;
|
|
98
|
+
};
|
|
60
99
|
update = () => {
|
|
61
100
|
const active = !this.disposed && !this.frozen && this.page?.visibilityState !== "hidden";
|
|
62
101
|
if (active && this.lastSeen === null) {
|
|
@@ -78,7 +117,8 @@ export class ReconnectBudget {
|
|
|
78
117
|
this.gapGraceUsed = true;
|
|
79
118
|
this.wokeSinceAttempt = true;
|
|
80
119
|
}
|
|
81
|
-
|
|
120
|
+
if (!this.offline)
|
|
121
|
+
this.elapsed += Math.min(Math.max(gap, 0), MAX_STEP_MS);
|
|
82
122
|
this.lastSeen = now;
|
|
83
123
|
};
|
|
84
124
|
stop() {
|
package/kits/base/sdk/runtime.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CASTLE_SDK_PROTOCOL, } from "./commands";
|
|
2
2
|
import { getCastleEmbed, isEdit } from "./context";
|
|
3
|
+
import { captureErrors, formatConsoleArgs, noteConsoleHooked, recordConsoleLine } from "./debugConsole";
|
|
3
4
|
import { cardUnit, fitStage, getDisplay } from "./display";
|
|
4
5
|
import { appliedNotice, applyTunedParams, } from "./paramsRegistry";
|
|
5
6
|
export const CARD_RATIO = 5 / 7;
|
|
@@ -27,6 +28,8 @@ const origError = console.error;
|
|
|
27
28
|
const dynamicImport = new Function("u", "return import(u)");
|
|
28
29
|
export function setup() {
|
|
29
30
|
interceptConsole();
|
|
31
|
+
captureErrors();
|
|
32
|
+
initHistoryShim();
|
|
30
33
|
connectLocal();
|
|
31
34
|
initLocalWake();
|
|
32
35
|
initHostCapture();
|
|
@@ -429,35 +432,49 @@ function resolveLocalRequest(msg) {
|
|
|
429
432
|
return true;
|
|
430
433
|
}
|
|
431
434
|
function interceptConsole() {
|
|
435
|
+
noteConsoleHooked();
|
|
432
436
|
console.log = (...args) => {
|
|
433
437
|
origLog(...args);
|
|
434
|
-
|
|
438
|
+
forwardConsoleLine("log", args);
|
|
435
439
|
};
|
|
436
440
|
console.warn = (...args) => {
|
|
437
441
|
origWarn(...args);
|
|
438
|
-
|
|
442
|
+
forwardConsoleLine("warn", args);
|
|
439
443
|
};
|
|
440
444
|
console.error = (...args) => {
|
|
441
445
|
origError(...args);
|
|
442
|
-
|
|
446
|
+
forwardConsoleLine("error", args);
|
|
443
447
|
};
|
|
444
448
|
}
|
|
445
|
-
function
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
449
|
+
function forwardConsoleLine(level, args) {
|
|
450
|
+
const msg = formatConsoleArgs(args);
|
|
451
|
+
recordConsoleLine(level, msg);
|
|
452
|
+
sendMsg({ type: "log", level, msg });
|
|
453
|
+
}
|
|
454
|
+
// A published deck's frame has an opaque origin (about:srcdoc on the web), so
|
|
455
|
+
// pushState/replaceState throw a SecurityError the moment they are given a URL.
|
|
456
|
+
// Keep the state and drop the URL: the history entry still lands, and routers
|
|
457
|
+
// that read state rather than the address keep working. Calls without a URL
|
|
458
|
+
// never threw and pass straight through. Only an opaque origin gets this: with
|
|
459
|
+
// an origin of its own a URL that throws is a real error (a cross-origin URL a
|
|
460
|
+
// router may catch to navigate instead), and is left to throw.
|
|
461
|
+
function initHistoryShim() {
|
|
462
|
+
if (typeof history === "undefined" || location.origin !== "null")
|
|
463
|
+
return;
|
|
464
|
+
for (const name of ["pushState", "replaceState"]) {
|
|
465
|
+
const original = history[name];
|
|
466
|
+
history[name] = function (data, unused, url) {
|
|
467
|
+
try {
|
|
468
|
+
original.call(this, data, unused, url);
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
const security = error instanceof DOMException && error.name === "SecurityError";
|
|
472
|
+
if (!security || url === undefined || url === null)
|
|
473
|
+
throw error;
|
|
474
|
+
original.call(this, data, unused);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
461
478
|
}
|
|
462
479
|
// Compositing a card needs html2canvas, and where it comes from decides whether
|
|
463
480
|
// a capture can fail for reasons that have nothing to do with the deck.
|
|
@@ -178,6 +178,21 @@ export interface MultiplayerHubResultsRead {
|
|
|
178
178
|
players: Record<string, MultiplayerHubPlayerResults>;
|
|
179
179
|
boards: Record<string, MultiplayerHubBoard>;
|
|
180
180
|
}
|
|
181
|
+
export type MultiplayerHubPushPreferenceChange = Record<string, never> | {
|
|
182
|
+
enabled: boolean;
|
|
183
|
+
} | {
|
|
184
|
+
declined: true;
|
|
185
|
+
};
|
|
186
|
+
export interface MultiplayerHubPushPreference {
|
|
187
|
+
accepted: true;
|
|
188
|
+
enabled: boolean;
|
|
189
|
+
globalEnabled: boolean;
|
|
190
|
+
/** The player has ever set this place's reminder preference. */
|
|
191
|
+
touched: boolean;
|
|
192
|
+
milestone?: unknown;
|
|
193
|
+
/** Non-null once the player declined or disabled. */
|
|
194
|
+
nextPromptAt: number | null;
|
|
195
|
+
}
|
|
181
196
|
/**
|
|
182
197
|
* The hub place this session runs, as ghost pinned it from the deck's published
|
|
183
198
|
* castle.json `hub` block. `session.hub` is null on a host without hub support
|
|
@@ -186,10 +201,14 @@ export interface MultiplayerHubResultsRead {
|
|
|
186
201
|
export interface MultiplayerServerHub {
|
|
187
202
|
/** Present only for an enabled place on a capable runtime. Reports visits; Ghost owns comeback delivery. */
|
|
188
203
|
readonly push?: {
|
|
204
|
+
/** Absent phase starts a visit; `end` reports its end once, without retry. */
|
|
189
205
|
visit(playerId: string, visit: {
|
|
190
206
|
userId: string;
|
|
191
207
|
timezone: string;
|
|
208
|
+
phase?: "end";
|
|
192
209
|
}): Promise<boolean>;
|
|
210
|
+
/** Present only on a runtime with preferences. `{}` reads; null when refused or unavailable. */
|
|
211
|
+
preference?(playerId: string, change: MultiplayerHubPushPreferenceChange): Promise<MultiplayerHubPushPreference | null>;
|
|
193
212
|
};
|
|
194
213
|
/** Durably appends NPC words to a private platform archive. No read operation. */
|
|
195
214
|
archiveText(playerId: string, entry: {
|
|
@@ -233,10 +233,22 @@ async function pushVisitCall(call, playerId, args) {
|
|
|
233
233
|
return false;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
+
async function pushPreferenceCall(call, playerId, args) {
|
|
237
|
+
try {
|
|
238
|
+
const answer = JSON.parse(await call(JSON.stringify({ ...args, playerId })));
|
|
239
|
+
return answer?.accepted === true ? answer : null;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
236
245
|
function pushCapability(handle) {
|
|
237
246
|
if (handle.hub?.push?.version !== 1 || typeof handle.hubPushVisit !== "function")
|
|
238
247
|
return {};
|
|
239
248
|
return { push: {
|
|
240
249
|
visit: (playerId, visit) => pushVisitCall((raw) => handle.hubPushVisit(raw), playerId, visit),
|
|
250
|
+
...(typeof handle.hubPushPreference === "function"
|
|
251
|
+
? { preference: (playerId, change) => pushPreferenceCall((raw) => handle.hubPushPreference(raw), playerId, change) }
|
|
252
|
+
: {}),
|
|
241
253
|
} };
|
|
242
254
|
}
|
|
@@ -100,6 +100,7 @@ export interface PlatformHandle {
|
|
|
100
100
|
/** Friends among candidates (hub contract v1.36); older images use storage. */
|
|
101
101
|
hubFriendsAmong?(argsJson: string): Promise<string>;
|
|
102
102
|
hubPushVisit?(argsJson: string): Promise<string>;
|
|
103
|
+
hubPushPreference?(argsJson: string): Promise<string>;
|
|
103
104
|
/** Absent on a runtime older than wearables (contract v1.4). */
|
|
104
105
|
hubWear?(argsJson: string): Promise<string>;
|
|
105
106
|
/** Absent on a runtime older than earned items (contract v1.53). */
|
|
@@ -8,7 +8,7 @@ export { createSaveCoordinator } from "../saveCoordinator";
|
|
|
8
8
|
export type { CoordinatedChange, CoordinatedSave, SaveCoordinator, SaveStatus, } from "../saveCoordinator";
|
|
9
9
|
export { SaveError } from "../save";
|
|
10
10
|
export type { SaveApi, SaveBucketApi, SaveBucketRead, SaveChange, SaveCheck, SaveConditionalCheck, SaveConditionalWriteInput, SaveResetFence, SaveClaimed, SaveClaimInput, SaveErrorEnvelope, SaveInitial, SaveInitializeInput, SaveOpened, SaveOperation, SaveReadTarget, SaveReceipt, SaveRecentOperationsInput, SaveRecentOperationsPage, SaveRevision, SaveRows, SaveScope, SaveSelection, SaveSnapshot, SaveTarget, SaveTransactionInput, SaveWriter, } from "../save";
|
|
11
|
-
export type { MultiplayerHubArrival, MultiplayerHubBoard, MultiplayerHubOutcome, MultiplayerHubPadUpdateInput, MultiplayerHubPadUpdateResult, MultiplayerHubPlayerResults, MultiplayerHubRecord, MultiplayerHubReportReceipt, MultiplayerHubResultInput, MultiplayerHubResultRow, MultiplayerHubResultShape, MultiplayerHubResultsRead, MultiplayerHubResultsReadInput, MultiplayerHubWearable, MultiplayerHubWearReceipt, MultiplayerHubEarnedClass, MultiplayerHubEarnedItem, MultiplayerHubHomeClass, MultiplayerHubHomeItem, MultiplayerHubUnlockReceipt, MultiplayerHubUnlocksRead, MultiplayerHubWearEarnedReceipt, MultiplayerServerHub, } from "./hub";
|
|
11
|
+
export type { MultiplayerHubArrival, MultiplayerHubBoard, MultiplayerHubOutcome, MultiplayerHubPadUpdateInput, MultiplayerHubPadUpdateResult, MultiplayerHubPlayerResults, MultiplayerHubPushPreference, MultiplayerHubPushPreferenceChange, MultiplayerHubRecord, MultiplayerHubReportReceipt, MultiplayerHubResultInput, MultiplayerHubResultRow, MultiplayerHubResultShape, MultiplayerHubResultsRead, MultiplayerHubResultsReadInput, MultiplayerHubWearable, MultiplayerHubWearReceipt, MultiplayerHubEarnedClass, MultiplayerHubEarnedItem, MultiplayerHubHomeClass, MultiplayerHubHomeItem, MultiplayerHubUnlockReceipt, MultiplayerHubUnlocksRead, MultiplayerHubWearEarnedReceipt, MultiplayerServerHub, } from "./hub";
|
|
12
12
|
export type { CharacterActionNotice, CharacterGameStateOperation, CharacterGameStateResult, CharacterKnowledgeDeliveryOperation, CharacterKnowledgeDeliveryResult, CharacterKnowledgeSource, CompleteCharacterBeatInput, DeliverCharacterKnowledgeInput, RecordCharacterEventInput, SetCharacterGameStateInput, ShareCharacterClaimInput, ServerStorage, ServerStorageBoard, ServerStorageBoardScore, ServerStorageListEntry, ServerStorageListOptions, ServerStorageListPage, ServerPlaythrough, ServerPlaythroughCharacters, ServerCharacterHistoryOptions, ServerStorageScope, ServerTownStorage, } from "./storage";
|
|
13
13
|
export interface MultiplayerServerPlayer extends PlayerIdentity {
|
|
14
14
|
playerId: string;
|