castle-web-cli 0.4.232 → 0.4.234
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-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +50 -2
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +11 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +2144 -160
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +146 -0
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +107 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +10 -1
- package/kits/hub-game/package.json +6 -2
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +853 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +38 -23
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +541 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1733 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +337 -3
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +661 -87
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +99 -0
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,1733 @@
|
|
|
1
|
+
// A connection the place let go comes back (a phone's app switch): the
|
|
2
|
+
// client's own resume hello (client/rehello.js) and the place's late greet
|
|
3
|
+
// (greetLate, 3 s) arrive the player once between them, in either order, and
|
|
4
|
+
// either one clears what the client still holds privately; a repeated hello
|
|
5
|
+
// from a player still arrived is idempotent; a game (`result`) takes neither,
|
|
6
|
+
// unless its place says `resume: true` (v1.72).
|
|
7
|
+
// Real hub server hooks.
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { register } from 'node:module';
|
|
10
|
+
|
|
11
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
12
|
+
export async function resolve(specifier, context, next) {
|
|
13
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/server/sceneBodies.js') return { url: 'data:text/javascript,export const readScene = () => globalThis.__hubTestActors;', shortCircuit: true };
|
|
14
|
+
if (context.parentURL?.includes('/kits/base/sdk/') && specifier.startsWith('.') && !specifier.endsWith('.js')) return next(specifier + '.js', context);
|
|
15
|
+
return next(specifier, context);
|
|
16
|
+
}
|
|
17
|
+
`)}`);
|
|
18
|
+
const { layer } = await import('../code/server/hub.js');
|
|
19
|
+
const { helloAfter, takesEnd } = await import('../code/client/rehello.js');
|
|
20
|
+
|
|
21
|
+
const actors = [
|
|
22
|
+
{ id: 'player', components: { Player: {}, Transform: { x: 0, y: 1, z: 0 } } },
|
|
23
|
+
{ id: 'floor', components: { Transform: { x: -4, y: 0, z: -3 }, Shape: { kind: 'box', width: 8, height: 0.1, depth: 7 } } },
|
|
24
|
+
];
|
|
25
|
+
const json = (keys = {}) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', ...keys } });
|
|
26
|
+
const players = () => [
|
|
27
|
+
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
28
|
+
{ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
|
|
29
|
+
];
|
|
30
|
+
const body = () => ({ at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
31
|
+
|
|
32
|
+
function boot(keys = {}, more = {}) {
|
|
33
|
+
const sent = [];
|
|
34
|
+
const arrivals = [];
|
|
35
|
+
const leaves = [];
|
|
36
|
+
let ctx = null;
|
|
37
|
+
const hooks = {
|
|
38
|
+
ready(c) {
|
|
39
|
+
ctx = c;
|
|
40
|
+
},
|
|
41
|
+
arrive(c, group) {
|
|
42
|
+
arrivals.push(group.map((p) => ({
|
|
43
|
+
playerId: p.playerId,
|
|
44
|
+
from: p.from,
|
|
45
|
+
fromDeckId: p.fromDeckId,
|
|
46
|
+
party: p.party,
|
|
47
|
+
near: p.near,
|
|
48
|
+
invited: p.invited,
|
|
49
|
+
...(Object.hasOwn(p, 'identityUserId') ? { identityUserId: p.identityUserId } : {}),
|
|
50
|
+
...(p.signedUpFrom ? { signedUpFrom: p.signedUpFrom } : {}),
|
|
51
|
+
})));
|
|
52
|
+
more.arrive?.(c, group);
|
|
53
|
+
},
|
|
54
|
+
fall: more.fall,
|
|
55
|
+
resume: more.resume,
|
|
56
|
+
leave(ctx, playerId) {
|
|
57
|
+
leaves.push(playerId);
|
|
58
|
+
more.leave?.(ctx, playerId);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const engine = {
|
|
62
|
+
createBody(sim, actor, at) {
|
|
63
|
+
return { at: { ...at }, setEnabled() {}, setNextKinematicTranslation() {}, setNextKinematicRotation() {} };
|
|
64
|
+
},
|
|
65
|
+
removeActor(sim, id) {
|
|
66
|
+
sim.bodies.delete(id);
|
|
67
|
+
sim.objects.delete(id);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
globalThis.__hubTestActors = structuredClone(more.actors ?? actors);
|
|
71
|
+
const server = layer(json(keys), hooks, {}, () => true, () => null, null, engine);
|
|
72
|
+
const session = {
|
|
73
|
+
sessionId: 'dev',
|
|
74
|
+
...(more.storage ? { storage: { deck: more.storage } } : {}),
|
|
75
|
+
players: structuredClone(more.players ?? players()),
|
|
76
|
+
hub: more.doors
|
|
77
|
+
? { arrival: (id) => more.doors.get(id) ?? null, readResults: async () => ({ players: {}, boards: {} }), reportResult: async () => ({ recorded: true }) }
|
|
78
|
+
: null,
|
|
79
|
+
send(id, msg) {
|
|
80
|
+
sent.push([id, structuredClone(msg)]);
|
|
81
|
+
},
|
|
82
|
+
broadcast(msg) {
|
|
83
|
+
sent.push(['all', structuredClone(msg)]);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const world = { timeMs: 0, scenePath: 'scenes/main.scene', objects: new Map(), bodies: new Map(), players: new Map(session.players.map((p) => [p.playerId, body()])) };
|
|
87
|
+
for (const actor of more.actors ?? []) {
|
|
88
|
+
if (actor.components.HubNpc) {
|
|
89
|
+
const at = actor.components.Transform;
|
|
90
|
+
world.bodies.set(actor.id, { translation: () => at, rotation: () => ({ x: 0, y: 0, z: 0, w: 1 }), setNextKinematicRotation() {} });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!more.owner && Object.hasOwn(more, 'reconnectWindowMs')) { session.hub = { arrival: () => null, readResults: async () => ({ players: {}, boards: {} }), ...(session.hub ?? {}), reconnectWindowMs: more.reconnectWindowMs }; }
|
|
94
|
+
if (more.owner) {session.hub = { owner: more.owner, ...(Object.hasOwn(more, 'reconnectWindowMs') ? more.reconnectWindowMs === undefined ? {} : { reconnectWindowMs: more.reconnectWindowMs } : { reconnectWindowMs: 180_000 }), arrival: () => null, readResults: async () => ({ players: {}, boards: {} }), ...(session.hub ?? {}) };}
|
|
95
|
+
server.sceneFor(session);
|
|
96
|
+
server.ready(world);
|
|
97
|
+
const say = (id, data) => server.message(session, { playerId: id }, data);
|
|
98
|
+
const tick = (ms = 50) => {
|
|
99
|
+
world.timeMs += ms;
|
|
100
|
+
server.place(world);
|
|
101
|
+
server.step(world, []);
|
|
102
|
+
};
|
|
103
|
+
// Everyone says hello and is arrived: p2 came through a door with a friend.
|
|
104
|
+
const pinnedHub = session.hub;
|
|
105
|
+
if (more.owner || more.reconnectWindowMs !== undefined) { session.hub = null; }
|
|
106
|
+
say('p1', { k: 'hub-hello', avatar: 0, party: 1 });
|
|
107
|
+
say('p2', { k: 'hub-hello', avatar: 3, party: 1, from: 'race', near: '101' });
|
|
108
|
+
tick(2000);
|
|
109
|
+
tick();
|
|
110
|
+
session.hub = pinnedHub;
|
|
111
|
+
|
|
112
|
+
const arrivedTimes = (id) => arrivals.filter((g) => g.some((p) => p.playerId === id)).length;
|
|
113
|
+
// The platform reports p2 gone and the real-time server removes its body.
|
|
114
|
+
const drop = () => {
|
|
115
|
+
session.players = session.players.filter((p) => p.playerId !== 'p2');
|
|
116
|
+
world.players.delete('p2');
|
|
117
|
+
};
|
|
118
|
+
// The SDK resumes the same connection: the same player id, a new body.
|
|
119
|
+
const back = () => {
|
|
120
|
+
session.players.push({ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false });
|
|
121
|
+
world.players.set('p2', body());
|
|
122
|
+
};
|
|
123
|
+
return { server, session, world, sent, arrivals, leaves, say, tick, drop, back, arrivedTimes, ctx: () => ctx };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The client's re-hello (client/rehello.js, sendHello): fresh, a party of one.
|
|
127
|
+
const rehello = { k: 'hub-hello', avatar: 3, party: 1, from: 'race', carry: null, resume: true };
|
|
128
|
+
const result = { result: { score: { unit: 's', better: 'lower' } } };
|
|
129
|
+
|
|
130
|
+
let passed = 0;
|
|
131
|
+
function test(name, fn) {
|
|
132
|
+
fn();
|
|
133
|
+
passed += 1;
|
|
134
|
+
console.log(`ok: ${name}`);
|
|
135
|
+
}
|
|
136
|
+
const toP2 = (r, from) => r.sent.slice(from).filter(([id]) => id === 'p2').map(([, m]) => m);
|
|
137
|
+
|
|
138
|
+
// v1.88: a fresh client under an id the place retained has none of its
|
|
139
|
+
// private channels. Re-send only what was non-empty, to that player alone.
|
|
140
|
+
const privateChannels = [
|
|
141
|
+
{
|
|
142
|
+
k: 'hub-hud',
|
|
143
|
+
set: (r, id) => r.ctx().setHud({ title: 'Mine', text: 'Private HUD' }, id),
|
|
144
|
+
clear: (r) => r.ctx().setHud(null, 'p2'),
|
|
145
|
+
value: { k: 'hub-hud', hud: { title: 'Mine', text: 'Private HUD' } },
|
|
146
|
+
empty: { k: 'hub-hud', hud: null },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
k: 'hub-labels',
|
|
150
|
+
set: (r, id) => r.ctx().label('floor', 'My boat', { to: [id], style: 'sign' }),
|
|
151
|
+
clear: (r) => r.ctx().label('floor', null, { to: ['p2'] }),
|
|
152
|
+
value: { k: 'hub-labels', labels: { floor: { text: 'My boat', style: 'sign' } } },
|
|
153
|
+
empty: { k: 'hub-labels', labels: {} },
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
k: 'hub-tune',
|
|
157
|
+
set: (r, id) => assert.equal(r.ctx().tune(id, { speed: 2, jump: 1.5 }), true),
|
|
158
|
+
clear: (r) => assert.equal(r.ctx().tune('p2', null), true),
|
|
159
|
+
value: { k: 'hub-tune', tune: { speed: 2, jump: 1.5 } },
|
|
160
|
+
empty: { k: 'hub-tune', tune: null },
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
k: 'hub-av',
|
|
164
|
+
// Each player in a hidden pair sees their own avatar privately.
|
|
165
|
+
set(r) {
|
|
166
|
+
r.session.hub = {
|
|
167
|
+
arrival: () => null,
|
|
168
|
+
readResults: async () => ({ players: {}, boards: {} }),
|
|
169
|
+
hiddenPair: () => true,
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
clear: (r) => {
|
|
173
|
+
r.session.hub.hiddenPair = () => false;
|
|
174
|
+
},
|
|
175
|
+
value: { k: 'hub-av', hubAv: { p2: 3 } },
|
|
176
|
+
empty: { k: 'hub-av', hubAv: {} },
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
const privateMessages = (r, from) => r.sent.slice(from).filter(([, m]) => privateChannels.some(({ k }) => m.k === k));
|
|
180
|
+
const freshHello = { k: 'hub-hello', avatar: 3, party: 1 };
|
|
181
|
+
|
|
182
|
+
for (const channel of privateChannels) {
|
|
183
|
+
const withPrivate = () => {
|
|
184
|
+
const r = boot();
|
|
185
|
+
const from = r.sent.length;
|
|
186
|
+
channel.set(r, 'p1');
|
|
187
|
+
channel.set(r, 'p2');
|
|
188
|
+
r.tick();
|
|
189
|
+
assert.deepEqual(toP2(r, from).filter((m) => m.k === channel.k), [channel.value], 'the private value was sent once');
|
|
190
|
+
r.tick();
|
|
191
|
+
assert.deepEqual(toP2(r, from).filter((m) => m.k === channel.k), [channel.value], 'equal values were suppressed');
|
|
192
|
+
return r;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
test(`retained id: fresh hello replays ${channel.k} once to its owner alone`, () => {
|
|
196
|
+
const r = withPrivate();
|
|
197
|
+
const from = r.sent.length;
|
|
198
|
+
// No tick sees the drop, so the place never lets this player go.
|
|
199
|
+
r.drop();
|
|
200
|
+
r.back();
|
|
201
|
+
r.say('p2', freshHello);
|
|
202
|
+
assert.deepEqual(privateMessages(r, from), [], 'the replay waits for the tick');
|
|
203
|
+
r.tick();
|
|
204
|
+
assert.deepEqual(privateMessages(r, from), [['p2', channel.value]], 'only the saying player gets the current value');
|
|
205
|
+
r.tick();
|
|
206
|
+
assert.deepEqual(privateMessages(r, from), [['p2', channel.value]], 'no second send on the following tick');
|
|
207
|
+
assert.deepEqual(r.leaves, [], 'the player was retained');
|
|
208
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'no second arrival');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test(`retained id: fresh hello sends no ${channel.k} where none was ever set`, () => {
|
|
212
|
+
const r = boot();
|
|
213
|
+
// Another player's private state must not be replayed either.
|
|
214
|
+
if (channel.k !== 'hub-av') {
|
|
215
|
+
channel.set(r, 'p1');
|
|
216
|
+
}
|
|
217
|
+
r.tick();
|
|
218
|
+
assert.ok(!r.sent.some(([id, m]) => id === 'p2' && m.k === channel.k), 'no value was ever sent');
|
|
219
|
+
const from = r.sent.length;
|
|
220
|
+
r.say('p2', freshHello);
|
|
221
|
+
r.tick();
|
|
222
|
+
r.tick();
|
|
223
|
+
assert.deepEqual(privateMessages(r, from), [], 'absent channels stay silent for everyone');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test(`retained id: fresh hello sends no ${channel.k} after its empty value was sent`, () => {
|
|
227
|
+
const r = withPrivate();
|
|
228
|
+
const cleared = r.sent.length;
|
|
229
|
+
channel.clear(r);
|
|
230
|
+
r.tick();
|
|
231
|
+
assert.deepEqual(toP2(r, cleared).filter((m) => m.k === channel.k), [channel.empty], 'the default was sent');
|
|
232
|
+
const from = r.sent.length;
|
|
233
|
+
r.say('p2', freshHello);
|
|
234
|
+
r.tick();
|
|
235
|
+
r.tick();
|
|
236
|
+
assert.deepEqual(privateMessages(r, from), [], 'default channels stay silent for everyone');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test(`retained id: a resume hello re-sends a ${channel.k} clear the held client may have missed, once`, () => {
|
|
240
|
+
const r = withPrivate();
|
|
241
|
+
r.drop();
|
|
242
|
+
r.back();
|
|
243
|
+
// The clear goes out while the connection is away; the client keeps the old value.
|
|
244
|
+
channel.clear(r);
|
|
245
|
+
r.tick();
|
|
246
|
+
const from = r.sent.length;
|
|
247
|
+
r.say('p2', { ...freshHello, resume: true });
|
|
248
|
+
r.tick();
|
|
249
|
+
assert.deepEqual(privateMessages(r, from), [['p2', channel.empty]], 'the empty value goes again to its owner alone');
|
|
250
|
+
r.tick();
|
|
251
|
+
assert.deepEqual(privateMessages(r, from), [['p2', channel.empty]], 'no second send on the following tick');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test(`retained id: a resume hello sends no ${channel.k} where none was ever set`, () => {
|
|
255
|
+
const r = boot();
|
|
256
|
+
r.tick();
|
|
257
|
+
const from = r.sent.length;
|
|
258
|
+
r.say('p2', { ...freshHello, resume: true });
|
|
259
|
+
r.tick();
|
|
260
|
+
r.tick();
|
|
261
|
+
assert.deepEqual(privateMessages(r, from), [], 'unused channels stay silent');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test(`retained id: an again hello replays no ${channel.k}`, () => {
|
|
265
|
+
const r = withPrivate();
|
|
266
|
+
const from = r.sent.length;
|
|
267
|
+
r.say('p2', { ...freshHello, again: true });
|
|
268
|
+
r.tick();
|
|
269
|
+
r.tick();
|
|
270
|
+
assert.deepEqual(privateMessages(r, from), [], 'an avatar-only hello replays nothing');
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
test('the client hello comes first: arrived again once, its stale HUD and leaving line cleared, no greet after', () => {
|
|
275
|
+
const r = boot();
|
|
276
|
+
r.ctx().setHud({ title: 'Hi', big: 'B', text: 'Mine' }, 'p2');
|
|
277
|
+
r.tick();
|
|
278
|
+
r.drop();
|
|
279
|
+
r.tick();
|
|
280
|
+
assert.deepEqual(r.leaves, ['p2'], 'the leave ran');
|
|
281
|
+
r.back();
|
|
282
|
+
r.tick(500);
|
|
283
|
+
const from = r.sent.length;
|
|
284
|
+
r.say('p2', rehello);
|
|
285
|
+
r.tick(2000);
|
|
286
|
+
r.tick();
|
|
287
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'arrived again');
|
|
288
|
+
const got = toP2(r, from);
|
|
289
|
+
assert.ok(got.some((m) => m.k === 'hub-arrived'), 'told it arrived');
|
|
290
|
+
assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud === null), 'the stale private HUD is cleared');
|
|
291
|
+
assert.ok(got.some((m) => m.k === 'hub-leaving' && m.text === null), 'a stale leaving line is cleared');
|
|
292
|
+
for (let i = 0; i < 10; i += 1) r.tick(1000);
|
|
293
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the late greet does not fire on top');
|
|
294
|
+
assert.equal(r.arrivedTimes('p1'), 1, 'nobody else arrives again');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test('the place greets first and the client hello lands after: one arrive', () => {
|
|
298
|
+
const r = boot();
|
|
299
|
+
r.drop();
|
|
300
|
+
r.tick();
|
|
301
|
+
r.back();
|
|
302
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
303
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the late greet arrived it');
|
|
304
|
+
const from = r.sent.length;
|
|
305
|
+
r.say('p2', rehello);
|
|
306
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
307
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the client hello did not arrive it again');
|
|
308
|
+
assert.ok(!toP2(r, from).some((m) => m.k === 'hub-leaving' && m.text === null), 'and is not treated as a return twice');
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test('the client hello lands in the tick the greet fires, and again after: one arrive', () => {
|
|
312
|
+
const r = boot();
|
|
313
|
+
r.drop();
|
|
314
|
+
r.tick();
|
|
315
|
+
r.back();
|
|
316
|
+
r.tick(1000);
|
|
317
|
+
r.tick(3100);
|
|
318
|
+
r.say('p2', rehello);
|
|
319
|
+
r.tick();
|
|
320
|
+
r.say('p2', rehello);
|
|
321
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
322
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
323
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test('a repeated hello from a player the place still has is idempotent', () => {
|
|
327
|
+
const r = boot();
|
|
328
|
+
const arrivedAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
|
|
329
|
+
assert.equal(typeof arrivedAt, 'number');
|
|
330
|
+
const from = r.sent.length;
|
|
331
|
+
// The connection came back before the place's tick saw it go: it never
|
|
332
|
+
// forgot the player, and the client's hello is a repeat.
|
|
333
|
+
r.drop();
|
|
334
|
+
r.back();
|
|
335
|
+
r.tick();
|
|
336
|
+
r.say('p2', rehello);
|
|
337
|
+
r.say('p2', rehello);
|
|
338
|
+
for (let i = 0; i < 6; i += 1) r.tick(1000);
|
|
339
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'the arrive hook ran once');
|
|
340
|
+
assert.deepEqual(r.leaves, [], 'no leave');
|
|
341
|
+
assert.ok(!toP2(r, from).some((m) => m.k === 'hub-arrived'), 'not told it arrived again');
|
|
342
|
+
// A repeat with another avatar and another door: only the avatar changes.
|
|
343
|
+
r.say('p2', { ...rehello, avatar: 5, from: 'other', near: '101', invited: true, party: 4 });
|
|
344
|
+
r.tick(2000);
|
|
345
|
+
r.tick();
|
|
346
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
347
|
+
assert.equal(r.server.join().hubAv2?.p2, 5, 'the new avatar is worn');
|
|
348
|
+
assert.equal(r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt, arrivedAt, 'its arrival kept');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('a game (result) takes neither the greet nor a client resume hello from a player it let go', () => {
|
|
352
|
+
const r = boot(result);
|
|
353
|
+
r.drop();
|
|
354
|
+
r.tick();
|
|
355
|
+
r.back();
|
|
356
|
+
r.tick(500);
|
|
357
|
+
r.say('p2', rehello);
|
|
358
|
+
for (let i = 0; i < 8; i += 1) r.tick(1000);
|
|
359
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'not arrived again');
|
|
360
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('two resume hellos in one tick: the stale ballot card and HUD are each cleared once', () => {
|
|
364
|
+
const r = boot({ ballot: true });
|
|
365
|
+
r.ctx().setHud({ title: 'Hi', big: 'B', text: 'Mine' }, 'p2');
|
|
366
|
+
assert.equal(r.ctx().ballot(['p2'], { mode: 'vote', faces: [{ playerId: 'p1' }, { playerId: 'p2' }] }), true);
|
|
367
|
+
r.tick();
|
|
368
|
+
r.drop();
|
|
369
|
+
r.tick();
|
|
370
|
+
r.back();
|
|
371
|
+
r.tick(500);
|
|
372
|
+
const from = r.sent.length;
|
|
373
|
+
r.say('p2', rehello);
|
|
374
|
+
r.say('p2', rehello);
|
|
375
|
+
r.tick();
|
|
376
|
+
r.tick();
|
|
377
|
+
const got = toP2(r, from);
|
|
378
|
+
assert.equal(got.filter((m) => m.k === 'hub-ballot-card' && m.card === null).length, 1, 'one card clear');
|
|
379
|
+
assert.equal(got.filter((m) => m.k === 'hub-hud' && m.hud === null).length, 1, 'one HUD clear');
|
|
380
|
+
assert.equal(got.filter((m) => m.k === 'hub-leaving' && m.text === null).length, 1, 'one leaving clear');
|
|
381
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'arrived again once');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// v1.72: a game whose place says `resume: true` is greeted and re-helloed as any place.
|
|
385
|
+
const resumeGame = { ...result, resume: true };
|
|
386
|
+
const pose = { look: { x: 1, y: 2, z: 3 }, distance: 8, pitch: 30, yaw: 45 };
|
|
387
|
+
|
|
388
|
+
test('a resume game: the client hello after a leave arrives once, with its HUD and shot back', () => {
|
|
389
|
+
const r = boot(resumeGame);
|
|
390
|
+
r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
|
|
391
|
+
assert.equal(r.ctx().shot('p2', pose), true);
|
|
392
|
+
r.tick();
|
|
393
|
+
r.drop();
|
|
394
|
+
r.tick();
|
|
395
|
+
assert.deepEqual(r.leaves, ['p2'], 'the leave ran');
|
|
396
|
+
assert.equal(r.ctx().shot('p2', pose), false, 'no shot for a player let go');
|
|
397
|
+
r.back();
|
|
398
|
+
r.tick(500);
|
|
399
|
+
const from = r.sent.length;
|
|
400
|
+
r.say('p2', rehello);
|
|
401
|
+
r.tick(2000);
|
|
402
|
+
r.tick();
|
|
403
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'arrived again, once');
|
|
404
|
+
r.ctx().setHud({ title: 'Vote', big: '0:20', text: 'Mine' }, 'p2');
|
|
405
|
+
assert.equal(r.ctx().shot('p2', { ...pose, yaw: 50 }), true, 'hub.shot is accepted again');
|
|
406
|
+
r.tick();
|
|
407
|
+
const got = toP2(r, from);
|
|
408
|
+
assert.ok(got.some((m) => m.k === 'hub-arrived'), 'told it arrived');
|
|
409
|
+
assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud?.title === 'Vote'), 'a live HUD');
|
|
410
|
+
assert.ok(got.some((m) => m.k === 'hub-shot' && m.shot?.yaw === 50), 'the shot');
|
|
411
|
+
for (let i = 0; i < 10; i += 1) r.tick(1000);
|
|
412
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the late greet does not fire on top');
|
|
413
|
+
assert.equal(r.arrivedTimes('p1'), 1);
|
|
414
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('a resume game: a player it still has is not arrived again, and is re-sent its HUD', () => {
|
|
418
|
+
const r = boot(resumeGame);
|
|
419
|
+
r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
|
|
420
|
+
r.tick();
|
|
421
|
+
const arrivedAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
|
|
422
|
+
r.drop();
|
|
423
|
+
r.back();
|
|
424
|
+
r.tick();
|
|
425
|
+
const from = r.sent.length;
|
|
426
|
+
r.say('p2', rehello);
|
|
427
|
+
r.say('p2', rehello);
|
|
428
|
+
for (let i = 0; i < 6; i += 1) r.tick(1000);
|
|
429
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'the arrive hook ran once');
|
|
430
|
+
assert.deepEqual(r.leaves, []);
|
|
431
|
+
const got = toP2(r, from);
|
|
432
|
+
assert.ok(!got.some((m) => m.k === 'hub-arrived'), 'not told it arrived again');
|
|
433
|
+
assert.ok(got.some((m) => m.k === 'hub-hud' && m.hud?.title === 'Talk'), 'its HUD goes again');
|
|
434
|
+
assert.ok(!got.some((m) => m.k === 'hub-leaving'), 'no leaving line it never had');
|
|
435
|
+
assert.equal(r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt, arrivedAt, 'its arrival kept');
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test('a resume game: the greet first, then the client hello: one arrive, and it keeps its door', () => {
|
|
439
|
+
const r = boot(resumeGame);
|
|
440
|
+
r.drop();
|
|
441
|
+
r.tick();
|
|
442
|
+
r.back();
|
|
443
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
444
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the late greet arrived it');
|
|
445
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p2').from, 'race', 'the door it first came by, though the greet names none');
|
|
446
|
+
r.say('p2', rehello);
|
|
447
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
448
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the client hello did not arrive it again');
|
|
449
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test('a resume game: the client hello in the tick the greet fires, and again: one arrive', () => {
|
|
453
|
+
const r = boot(resumeGame);
|
|
454
|
+
r.drop();
|
|
455
|
+
r.tick();
|
|
456
|
+
r.back();
|
|
457
|
+
r.tick(1000);
|
|
458
|
+
r.tick(3100);
|
|
459
|
+
r.say('p2', rehello);
|
|
460
|
+
r.tick();
|
|
461
|
+
r.say('p2', rehello);
|
|
462
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
463
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
464
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test('a resume game: a result reported before the leave is kept, so a second is refused', () => {
|
|
468
|
+
const r = boot(resumeGame);
|
|
469
|
+
assert.equal(r.ctx().result('p2', { outcome: 'win', score: 12 }), true);
|
|
470
|
+
r.drop();
|
|
471
|
+
r.tick();
|
|
472
|
+
r.back();
|
|
473
|
+
r.say('p2', rehello);
|
|
474
|
+
r.tick(2000);
|
|
475
|
+
r.tick();
|
|
476
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
477
|
+
assert.equal(r.ctx().result('p2', { outcome: 'lose', score: 11 }), false, 'already reported');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test('a resume game: one who left with no result may still report one, once', () => {
|
|
481
|
+
const r = boot(resumeGame);
|
|
482
|
+
r.drop();
|
|
483
|
+
r.tick();
|
|
484
|
+
r.back();
|
|
485
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
486
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
487
|
+
assert.equal(r.ctx().result('p2', { outcome: 'win', score: 12 }), true);
|
|
488
|
+
assert.equal(r.ctx().result('p2', { outcome: 'win', score: 10 }), false);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test('review I1: a result the leave hook reports is kept, so after resume a second is refused (one hub-result sent)', () => {
|
|
492
|
+
const r = boot(resumeGame, { leave: (ctx, id) => assert.equal(ctx.result(id, { outcome: 'win', score: 3 }), true) });
|
|
493
|
+
r.drop();
|
|
494
|
+
r.tick();
|
|
495
|
+
r.back();
|
|
496
|
+
r.say('p2', rehello);
|
|
497
|
+
r.tick(2000);
|
|
498
|
+
r.tick();
|
|
499
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
500
|
+
assert.equal(r.ctx().result('p2', { outcome: 'lose', score: 1 }), false, 'already reported in the leave');
|
|
501
|
+
assert.equal(r.sent.filter(([id, m]) => id === 'p2' && m.k === 'hub-result').length, 1, 'one result sent');
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test('review I2: the visit deadline is set once: 30 s max, a drop at 25 s, resumed, ended at 30 s', () => {
|
|
505
|
+
const r = boot({ ...resumeGame, maxDurationSec: 30 });
|
|
506
|
+
const firstAt = r.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
|
|
507
|
+
while (r.world.timeMs < firstAt + 25000) r.tick(500);
|
|
508
|
+
r.drop();
|
|
509
|
+
r.tick();
|
|
510
|
+
r.back();
|
|
511
|
+
r.say('p2', rehello);
|
|
512
|
+
r.tick(2000);
|
|
513
|
+
r.tick();
|
|
514
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
515
|
+
const ends = () => r.sent.filter(([id, m]) => id === 'p2' && m.k === 'hub-end');
|
|
516
|
+
while (r.world.timeMs < firstAt + 29500) r.tick(500);
|
|
517
|
+
assert.equal(ends().length, 0, 'not before 30 s');
|
|
518
|
+
while (r.world.timeMs < firstAt + 30500) r.tick(250);
|
|
519
|
+
assert.deepEqual(ends().map(([, m]) => m), [{ k: 'hub-end', why: 'time' }], 'ended at the first deadline');
|
|
520
|
+
// Without the key the same drop starts the clock again (unchanged).
|
|
521
|
+
const plain = boot({ maxDurationSec: 30 });
|
|
522
|
+
const at = plain.ctx().players().find((p) => p.playerId === 'p2').arrivedAt;
|
|
523
|
+
plain.drop();
|
|
524
|
+
plain.tick();
|
|
525
|
+
plain.back();
|
|
526
|
+
while (plain.world.timeMs < at + 5000) plain.tick(500);
|
|
527
|
+
plain.say('p2', rehello);
|
|
528
|
+
plain.tick(2000);
|
|
529
|
+
plain.tick();
|
|
530
|
+
assert.ok(plain.ctx().players().find((p) => p.playerId === 'p2').arrivedAt > at);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
test('review I3: an ended visit hears the end again on resume, marked again; the client takes it only if not already ending', () => {
|
|
534
|
+
const r = boot({ ...resumeGame, maxDurationSec: 30 });
|
|
535
|
+
while (!r.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-end')) r.tick(500);
|
|
536
|
+
r.drop();
|
|
537
|
+
r.tick();
|
|
538
|
+
r.back();
|
|
539
|
+
const from = r.sent.length;
|
|
540
|
+
r.say('p2', rehello);
|
|
541
|
+
r.tick(2000);
|
|
542
|
+
r.tick();
|
|
543
|
+
const got = toP2(r, from);
|
|
544
|
+
const arrived = got.findIndex((m) => m.k === 'hub-arrived');
|
|
545
|
+
const end = got.findIndex((m) => m.k === 'hub-end');
|
|
546
|
+
assert.ok(arrived >= 0 && end > arrived, 'arrived, then the end again');
|
|
547
|
+
assert.deepEqual(got[end], { k: 'hub-end', why: 'time', again: true });
|
|
548
|
+
assert.equal(got.filter((m) => m.k === 'hub-end').length, 1, 'once');
|
|
549
|
+
assert.equal(r.ctx().shot('p2', pose), false, 'still ended: no shot');
|
|
550
|
+
// A resume hello while still here and ended: the end once more.
|
|
551
|
+
const at2 = r.sent.length;
|
|
552
|
+
r.say('p2', rehello);
|
|
553
|
+
assert.equal(toP2(r, at2).filter((m) => m.k === 'hub-end' && m.again).length, 1);
|
|
554
|
+
// The client: an end said again does not restart one already pending.
|
|
555
|
+
assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, 1000, 's1', 's1'), false);
|
|
556
|
+
assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, null, null, 's1'), true, 'one that missed it ends');
|
|
557
|
+
assert.equal(takesEnd({ k: 'hub-end', why: 'time', again: true }, 1000, 's0', 's1'), true, 'another session');
|
|
558
|
+
assert.equal(takesEnd({ k: 'hub-end', why: 'time' }, 1000, 's1', 's1'), true, 'a plain end as before');
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test('review I4: provenance is written once: greet first, client hello, drop, hello again: the door kept', () => {
|
|
562
|
+
const r = boot(resumeGame);
|
|
563
|
+
const bare = { ...rehello };
|
|
564
|
+
delete bare.from;
|
|
565
|
+
r.drop();
|
|
566
|
+
r.tick();
|
|
567
|
+
r.back();
|
|
568
|
+
for (let i = 0; i < 5; i += 1) r.tick(1000);
|
|
569
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the greet arrived it');
|
|
570
|
+
r.say('p2', bare); // the client's own hello, naming no door
|
|
571
|
+
r.tick();
|
|
572
|
+
r.drop();
|
|
573
|
+
r.tick();
|
|
574
|
+
r.back();
|
|
575
|
+
r.say('p2', bare);
|
|
576
|
+
r.tick(2000);
|
|
577
|
+
r.tick();
|
|
578
|
+
assert.equal(r.arrivedTimes('p2'), 3);
|
|
579
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p2').from, 'race', 'the first door, kept');
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
test('review I4: a first visit by no door keeps none: a resume whose hello or platform arrival names one is not taken', () => {
|
|
583
|
+
// Dev (the client's word): p1 came by no door.
|
|
584
|
+
const r = boot(resumeGame);
|
|
585
|
+
assert.equal(r.arrivals[0].find((p) => p.playerId === 'p1').from, null);
|
|
586
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p1');
|
|
587
|
+
r.world.players.delete('p1');
|
|
588
|
+
r.tick();
|
|
589
|
+
r.session.players.push({ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false });
|
|
590
|
+
r.world.players.set('p1', body());
|
|
591
|
+
r.say('p1', { ...rehello, avatar: 0, from: 'other' });
|
|
592
|
+
r.tick(2000);
|
|
593
|
+
r.tick();
|
|
594
|
+
assert.equal(r.arrivedTimes('p1'), 2);
|
|
595
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'p1').from, null, 'from stays none');
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// Where the host has hub ops (ghost's arrival, an async read to wait for).
|
|
599
|
+
{
|
|
600
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
601
|
+
const doors = new Map();
|
|
602
|
+
const plat = boot(resumeGame, { doors });
|
|
603
|
+
const settle = async () => {
|
|
604
|
+
for (let i = 0; i < 4; i += 1) {
|
|
605
|
+
await flush();
|
|
606
|
+
plat.tick(1000);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
await settle();
|
|
610
|
+
const first = plat.arrivals.flat().find((p) => p.playerId === 'p2');
|
|
611
|
+
assert.equal(first.from, null, 'p2 came by no door');
|
|
612
|
+
assert.equal(first.fromDeckId, null);
|
|
613
|
+
doors.set('p2', { doorId: 'other', fromDeckId: 'deckOther' });
|
|
614
|
+
plat.drop();
|
|
615
|
+
plat.tick();
|
|
616
|
+
plat.back();
|
|
617
|
+
plat.say('p2', rehello);
|
|
618
|
+
await settle();
|
|
619
|
+
assert.equal(plat.arrivedTimes('p2'), 2);
|
|
620
|
+
const again = plat.arrivals.at(-1).find((p) => p.playerId === 'p2');
|
|
621
|
+
assert.equal(again.from, null, 'from stays none');
|
|
622
|
+
assert.equal(again.fromDeckId, null, 'fromDeckId stays none');
|
|
623
|
+
// A repeated hello while still here cannot write it either.
|
|
624
|
+
plat.say('p2', rehello);
|
|
625
|
+
plat.drop();
|
|
626
|
+
plat.tick();
|
|
627
|
+
plat.back();
|
|
628
|
+
plat.say('p2', rehello);
|
|
629
|
+
await settle();
|
|
630
|
+
assert.equal(plat.arrivedTimes('p2'), 3);
|
|
631
|
+
assert.deepEqual([plat.arrivals.at(-1).find((p) => p.playerId === 'p2').from, plat.arrivals.at(-1).find((p) => p.playerId === 'p2').fromDeckId], [null, null]);
|
|
632
|
+
passed += 1;
|
|
633
|
+
console.log('ok: review I4: with hub ops, a platform arrival naming a door on resume does not replace none');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
test('keys absent: a game without resume sends the same bytes whether or not the client re-hellos', () => {
|
|
637
|
+
const trace = (rehelloToo) => {
|
|
638
|
+
const r = boot(result);
|
|
639
|
+
r.ctx().setHud({ title: 'Talk', big: '0:30', text: 'Mine' }, 'p2');
|
|
640
|
+
r.tick();
|
|
641
|
+
r.drop();
|
|
642
|
+
r.tick();
|
|
643
|
+
r.back();
|
|
644
|
+
r.tick(500);
|
|
645
|
+
if (rehelloToo) {
|
|
646
|
+
r.say('p2', rehello);
|
|
647
|
+
}
|
|
648
|
+
for (let i = 0; i < 8; i += 1) r.tick(1000);
|
|
649
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
650
|
+
assert.ok(!('resume' in r.server.join({ playerId: 'p1' }).hubPlace), 'no resume key in its place');
|
|
651
|
+
return JSON.stringify(r.sent);
|
|
652
|
+
};
|
|
653
|
+
assert.equal(trace(true), trace(false));
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
// v1.89: a retained hello can reinstall deck-owned HUD/pointers after replay.
|
|
657
|
+
test('resume hook: retained fresh/resume hellos notify after private replay, coalesced per step', () => {
|
|
658
|
+
const calls = [];
|
|
659
|
+
let r;
|
|
660
|
+
r = boot({}, { resume(c, { playerId: id }) {
|
|
661
|
+
assert.equal(c, r.ctx());
|
|
662
|
+
calls.push(id);
|
|
663
|
+
const messages = toP2(r, from);
|
|
664
|
+
for (const key of ['hub-hud', 'hub-labels', 'hub-tune', 'hub-av']) {
|
|
665
|
+
assert.ok(messages.some((m) => m.k === key), `${key} sent before resume`);
|
|
666
|
+
}
|
|
667
|
+
c.setHud({ title: 'Current step' }, id);
|
|
668
|
+
} });
|
|
669
|
+
assert.deepEqual(calls, [], 'first arrivals do not notify');
|
|
670
|
+
r.ctx().setHud({ title: 'Previous step' }, 'p2');
|
|
671
|
+
r.ctx().label('floor', 'Pointer', { to: ['p2'], style: 'sign' });
|
|
672
|
+
r.ctx().tune('p2', { speed: 2 });
|
|
673
|
+
privateChannels.find((c) => c.k === 'hub-av').set(r, 'p2');
|
|
674
|
+
r.tick();
|
|
675
|
+
let from = r.sent.length;
|
|
676
|
+
r.say('p2', { k: 'hub-hello', avatar: 3 });
|
|
677
|
+
r.say('p2', { k: 'hub-hello', avatar: 3 });
|
|
678
|
+
assert.deepEqual(calls, [], 'deferred until replay sends');
|
|
679
|
+
r.tick();
|
|
680
|
+
assert.deepEqual(calls, ['p2']);
|
|
681
|
+
r.tick();
|
|
682
|
+
assert.ok(toP2(r, from).some((m) => m.k === 'hub-hud' && m.hud?.title === 'Current step'));
|
|
683
|
+
from = r.sent.length;
|
|
684
|
+
r.say('p2', rehello);
|
|
685
|
+
r.tick();
|
|
686
|
+
assert.deepEqual(calls, ['p2', 'p2']);
|
|
687
|
+
r.say('p2', { ...rehello, again: true });
|
|
688
|
+
r.tick();
|
|
689
|
+
assert.deepEqual(calls, ['p2', 'p2'], 'avatar-change hello excluded');
|
|
690
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
691
|
+
assert.deepEqual(r.leaves, []);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
test('resume hook: genuine re-arrivals do not notify and a leave cancels queued retained hello', () => {
|
|
695
|
+
const calls = [];
|
|
696
|
+
const r = boot({}, { resume(c, { playerId: id }) { calls.push(id); } });
|
|
697
|
+
r.say('p2', rehello);
|
|
698
|
+
r.drop();
|
|
699
|
+
r.tick();
|
|
700
|
+
r.back();
|
|
701
|
+
r.say('p2', rehello);
|
|
702
|
+
r.tick();
|
|
703
|
+
assert.deepEqual(calls, []);
|
|
704
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
705
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test('resume hook: missing hook preserves wire bytes for a retained hello', () => {
|
|
709
|
+
const trace = (hook) => {
|
|
710
|
+
const r = boot({}, hook ? { resume() {} } : {});
|
|
711
|
+
r.ctx().setHud({ title: 'Same' }, 'p2');
|
|
712
|
+
r.tick();
|
|
713
|
+
const from = r.sent.length;
|
|
714
|
+
r.say('p2', rehello);
|
|
715
|
+
r.tick();
|
|
716
|
+
return JSON.stringify(r.sent.slice(from));
|
|
717
|
+
};
|
|
718
|
+
assert.equal(trace(false), trace(true));
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
test('resume hook: avatar update preserves an already queued signal and hook errors are contained', () => {
|
|
722
|
+
const calls = [];
|
|
723
|
+
const r = boot({}, { resume(c, { playerId: id }) {
|
|
724
|
+
calls.push(id);
|
|
725
|
+
throw Error('deck hook failure');
|
|
726
|
+
} });
|
|
727
|
+
r.say('p2', rehello);
|
|
728
|
+
r.say('p2', { ...rehello, again: true, avatar: 2 });
|
|
729
|
+
r.say('p1', { k: 'hub-hello', avatar: 0, resume: true });
|
|
730
|
+
assert.doesNotThrow(() => r.tick());
|
|
731
|
+
assert.deepEqual(calls, ['p2', 'p1']);
|
|
732
|
+
r.tick();
|
|
733
|
+
assert.deepEqual(calls, ['p2', 'p1'], 'failed hooks are not retried');
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
// v1.89: advance a wall clock independently of simulation time. A suspended
|
|
737
|
+
// tab must not extend the grace by stopping its own frames.
|
|
738
|
+
function keeping(fn) {
|
|
739
|
+
const realNow = Date.now;
|
|
740
|
+
let now = realNow();
|
|
741
|
+
Date.now = () => now;
|
|
742
|
+
try {
|
|
743
|
+
fn((ms) => {
|
|
744
|
+
now += ms;
|
|
745
|
+
});
|
|
746
|
+
} finally {
|
|
747
|
+
Date.now = realNow;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const keepGame = { ...result, resume: { keep: true } };
|
|
751
|
+
|
|
752
|
+
test('keep resume: 30 s same-id return restores position, arrival, hold and tuning with no hooks', () =>
|
|
753
|
+
keeping((advance) => {
|
|
754
|
+
const r = boot(keepGame);
|
|
755
|
+
const at = { x: 2, y: 1, z: 3 };
|
|
756
|
+
r.ctx().placeAt('p2', at, 90);
|
|
757
|
+
r.ctx().hold('p2');
|
|
758
|
+
assert.equal(r.ctx().tune('p2', { speed: 2, jump: 1.5 }), true);
|
|
759
|
+
r.ctx().setHud({ title: 'Still playing' }, 'p2');
|
|
760
|
+
r.tick();
|
|
761
|
+
const arrivedAt = r
|
|
762
|
+
.ctx()
|
|
763
|
+
.players()
|
|
764
|
+
.find((p) => p.playerId === 'p2').arrivedAt;
|
|
765
|
+
r.drop();
|
|
766
|
+
r.tick();
|
|
767
|
+
advance(30000);
|
|
768
|
+
r.tick(30000);
|
|
769
|
+
assert.deepEqual(r.leaves, []);
|
|
770
|
+
r.back();
|
|
771
|
+
const from = r.sent.length;
|
|
772
|
+
r.say('p2', rehello); // hello before the first returning tick
|
|
773
|
+
r.tick();
|
|
774
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
775
|
+
assert.equal(r.world.players.get('p2').facing, Math.PI / 2);
|
|
776
|
+
assert.equal(r.world.players.get('p2').maxSpeed, 24);
|
|
777
|
+
assert.ok(r.server.join({ playerId: 'p2' }).held.includes('p2'));
|
|
778
|
+
assert.equal(
|
|
779
|
+
r
|
|
780
|
+
.ctx()
|
|
781
|
+
.players()
|
|
782
|
+
.find((p) => p.playerId === 'p2').arrivedAt,
|
|
783
|
+
arrivedAt,
|
|
784
|
+
);
|
|
785
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
786
|
+
assert.deepEqual(r.leaves, []);
|
|
787
|
+
assert.ok(toP2(r, from).some((m) => m.k === 'hub-hud' && m.hud?.title === 'Still playing'));
|
|
788
|
+
assert.ok(toP2(r, from).some((m) => m.k === 'hub-tune' && m.tune?.speed === 2));
|
|
789
|
+
assert.equal(r.ctx().tune('p2', { speed: 1.5 }), true);
|
|
790
|
+
assert.equal(r.ctx().result('p2', { score: 8 }), true);
|
|
791
|
+
assert.equal(r.ctx().result('p2', { score: 9 }), false);
|
|
792
|
+
r.drop();
|
|
793
|
+
r.tick();
|
|
794
|
+
advance(60000);
|
|
795
|
+
r.tick();
|
|
796
|
+
r.tick();
|
|
797
|
+
assert.deepEqual(r.leaves, ['p2'], 'leave once at grace expiry');
|
|
798
|
+
}));
|
|
799
|
+
|
|
800
|
+
test('keep resume: silent return and repeated hellos never re-arrive or reset a result', () =>
|
|
801
|
+
keeping((advance) => {
|
|
802
|
+
const r = boot(keepGame);
|
|
803
|
+
r.ctx().placeAt('p2', { x: 2, y: 1, z: 2 });
|
|
804
|
+
assert.equal(r.ctx().result('p2', { score: 1 }), true);
|
|
805
|
+
r.tick();
|
|
806
|
+
r.drop();
|
|
807
|
+
r.tick();
|
|
808
|
+
advance(30000);
|
|
809
|
+
r.back();
|
|
810
|
+
r.tick(30000); // no client hello: same position and replay from the server
|
|
811
|
+
assert.deepEqual(r.world.players.get('p2').at, { x: 2, y: 1, z: 2 });
|
|
812
|
+
r.say('p2', rehello);
|
|
813
|
+
r.say('p2', rehello);
|
|
814
|
+
r.tick();
|
|
815
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
816
|
+
assert.deepEqual(r.leaves, []);
|
|
817
|
+
assert.equal(r.ctx().result('p2', { score: 2 }), false);
|
|
818
|
+
}));
|
|
819
|
+
|
|
820
|
+
test('resume hook: keep-mode silent return notifies once and expired return arrives instead', () =>
|
|
821
|
+
keeping((advance) => {
|
|
822
|
+
const calls = [];
|
|
823
|
+
const r = boot(keepGame, { resume(c, { playerId: id }) { calls.push(id); } });
|
|
824
|
+
r.drop();
|
|
825
|
+
r.tick();
|
|
826
|
+
advance(30000);
|
|
827
|
+
r.back();
|
|
828
|
+
r.tick();
|
|
829
|
+
assert.deepEqual(calls, ['p2']);
|
|
830
|
+
r.say('p2', rehello);
|
|
831
|
+
r.tick();
|
|
832
|
+
assert.deepEqual(calls, ['p2'], 'late client hello shares the silent-return signal');
|
|
833
|
+
r.drop();
|
|
834
|
+
r.tick();
|
|
835
|
+
advance(60000);
|
|
836
|
+
r.back();
|
|
837
|
+
r.say('p2', rehello);
|
|
838
|
+
r.tick();
|
|
839
|
+
assert.deepEqual(calls, ['p2']);
|
|
840
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
841
|
+
}));
|
|
842
|
+
|
|
843
|
+
test('keep resume: return at 60 s is fresh, including hello before reconcile', () =>
|
|
844
|
+
keeping((advance) => {
|
|
845
|
+
const r = boot(keepGame);
|
|
846
|
+
assert.equal(r.ctx().result('p2', { score: 1 }), true);
|
|
847
|
+
r.ctx().hold('p2', { x: 2, y: 1, z: 3 });
|
|
848
|
+
r.ctx().tune('p2', { speed: 2 });
|
|
849
|
+
r.tick();
|
|
850
|
+
const arrivedAt = r
|
|
851
|
+
.ctx()
|
|
852
|
+
.players()
|
|
853
|
+
.find((p) => p.playerId === 'p2').arrivedAt;
|
|
854
|
+
r.drop();
|
|
855
|
+
r.tick();
|
|
856
|
+
advance(60000);
|
|
857
|
+
r.back();
|
|
858
|
+
r.say('p2', rehello);
|
|
859
|
+
r.tick(60000);
|
|
860
|
+
r.tick();
|
|
861
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
862
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
863
|
+
assert.ok(
|
|
864
|
+
r
|
|
865
|
+
.ctx()
|
|
866
|
+
.players()
|
|
867
|
+
.find((p) => p.playerId === 'p2').arrivedAt > arrivedAt,
|
|
868
|
+
);
|
|
869
|
+
assert.ok(!r.server.join({ playerId: 'p2' }).held.includes('p2'));
|
|
870
|
+
assert.equal(r.world.players.get('p2').maxSpeed, undefined);
|
|
871
|
+
assert.equal(r.ctx().result('p2', { score: 2 }), true, 'new visit is eligible');
|
|
872
|
+
}));
|
|
873
|
+
|
|
874
|
+
test('keep resume: the original duration cap and fall hook work after return', () =>
|
|
875
|
+
keeping((advance) => {
|
|
876
|
+
let falls = 0;
|
|
877
|
+
const r = boot(
|
|
878
|
+
{ ...keepGame, maxDurationSec: 40, fallY: -5 },
|
|
879
|
+
{
|
|
880
|
+
fall: () => {
|
|
881
|
+
falls += 1;
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
);
|
|
885
|
+
r.drop();
|
|
886
|
+
r.tick();
|
|
887
|
+
advance(30000);
|
|
888
|
+
r.back();
|
|
889
|
+
r.tick(30000);
|
|
890
|
+
r.world.players.get('p2').at.y = -10;
|
|
891
|
+
r.tick();
|
|
892
|
+
assert.ok(r.world.players.get('p2').at.y >= -5, 'fall is caught');
|
|
893
|
+
assert.equal(falls, 1, 'deck fall hook remains eligible');
|
|
894
|
+
while (r.world.timeMs < 42500) r.tick(500);
|
|
895
|
+
assert.ok(toP2(r, 0).some((m) => m.k === 'hub-end' && m.why === 'time'));
|
|
896
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
897
|
+
}));
|
|
898
|
+
|
|
899
|
+
test('keep resume: shutdown drains a retained absent player once', async () => {
|
|
900
|
+
// Shutdown runs its synchronous leave drain before its first await.
|
|
901
|
+
const r = boot(keepGame);
|
|
902
|
+
r.drop();
|
|
903
|
+
r.tick();
|
|
904
|
+
const shut = r.server.shutdown();
|
|
905
|
+
assert.deepEqual(r.leaves, ['p1', 'p2']);
|
|
906
|
+
await shut;
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
{
|
|
910
|
+
const r = boot({
|
|
911
|
+
...keepGame,
|
|
912
|
+
unlocks: [
|
|
913
|
+
{
|
|
914
|
+
id: 'ribbon',
|
|
915
|
+
class: 'sash',
|
|
916
|
+
shape: 'sash-plain',
|
|
917
|
+
name: 'Ribbon',
|
|
918
|
+
deed: 'Finish',
|
|
919
|
+
color: '#ff0000',
|
|
920
|
+
},
|
|
921
|
+
],
|
|
922
|
+
});
|
|
923
|
+
r.drop();
|
|
924
|
+
r.tick();
|
|
925
|
+
r.back();
|
|
926
|
+
r.tick();
|
|
927
|
+
const receipt = await r.ctx().unlock('p2', 'ribbon');
|
|
928
|
+
assert.equal(receipt?.isNew, true, 'unlock accepted after retained resume');
|
|
929
|
+
assert.equal(receipt?.saved, false, 'dev unlock is session-only');
|
|
930
|
+
passed += 1;
|
|
931
|
+
console.log('ok: keep resume: unlock remains eligible after same-id return');
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
test('keep resume: body replacement between ticks restores the old pose', () => {
|
|
935
|
+
const r = boot(keepGame);
|
|
936
|
+
r.ctx().placeAt('p2', { x: 2, y: 1, z: 3 });
|
|
937
|
+
r.tick();
|
|
938
|
+
r.drop();
|
|
939
|
+
r.back();
|
|
940
|
+
r.tick();
|
|
941
|
+
assert.deepEqual(r.world.players.get('p2').at, { x: 2, y: 1, z: 3 });
|
|
942
|
+
assert.deepEqual(r.leaves, []);
|
|
943
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
test('keep resume: travel from the first arrive bypasses retention before any pose snapshot', () => {
|
|
947
|
+
const r = boot({ ...keepGame, places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
|
|
948
|
+
actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
949
|
+
arrive: (hub, group) => {
|
|
950
|
+
if (group.some((p) => p.playerId === 'p2')) assert.ok(hub.go('out', ['p2']));
|
|
951
|
+
},
|
|
952
|
+
});
|
|
953
|
+
assert.ok(toP2(r, 0).some((m) => m.k === 'hub-go'));
|
|
954
|
+
r.drop();
|
|
955
|
+
r.tick();
|
|
956
|
+
r.tick();
|
|
957
|
+
assert.deepEqual(r.leaves, ['p2'], 'explicit trip leaves exactly once without waiting');
|
|
958
|
+
r.back();
|
|
959
|
+
r.say('p2', rehello);
|
|
960
|
+
r.tick(2000);
|
|
961
|
+
r.tick();
|
|
962
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'a return after travel is a fresh arrival');
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
test('resume hook: retained hello without a body is ignored safely', () => {
|
|
966
|
+
const calls = [];
|
|
967
|
+
const r = boot({}, { resume(c, { playerId }) { calls.push(playerId); } });
|
|
968
|
+
r.drop();
|
|
969
|
+
assert.doesNotThrow(() => r.say('p2', rehello));
|
|
970
|
+
r.tick();
|
|
971
|
+
assert.deepEqual(calls, []);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
test('resume hook: travel cancels pending signals and failed travel allows a later resume', () => {
|
|
975
|
+
const calls = [];
|
|
976
|
+
const r = boot({ places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
|
|
977
|
+
actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
978
|
+
resume(c, { playerId }) { calls.push(playerId); },
|
|
979
|
+
});
|
|
980
|
+
r.say('p2', rehello);
|
|
981
|
+
assert.ok(r.ctx().go('out', ['p2']));
|
|
982
|
+
r.say('p2', rehello);
|
|
983
|
+
r.tick();
|
|
984
|
+
assert.deepEqual(calls, [], 'travel cancels earlier and later retained hellos');
|
|
985
|
+
r.say('p2', { k: 'hub-shut', door: 'out' });
|
|
986
|
+
r.say('p2', rehello);
|
|
987
|
+
r.tick();
|
|
988
|
+
assert.deepEqual(calls, ['p2'], 'a failed trip does not permanently block resumes');
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
test('which hello a connection that came back says (helloAfter)', () => {
|
|
992
|
+
assert.equal(helloAfter(null, false), 'none', 'nothing came back: none');
|
|
993
|
+
assert.equal(helloAfter(null, true), 'none');
|
|
994
|
+
assert.equal(helloAfter('world', true), 'none', 'a game under the same id: none (the old way)');
|
|
995
|
+
assert.equal(helloAfter('self', true), 'fresh', 'a game under a new id: a fresh hello');
|
|
996
|
+
assert.equal(helloAfter('world', false), 'resume', 'a place under the same id: resume');
|
|
997
|
+
assert.equal(helloAfter('self', false), 'resume', 'a place under a new id: resume, as before');
|
|
998
|
+
// v1.72: the third input, the place's `resume`.
|
|
999
|
+
assert.equal(helloAfter('world', true, true), 'resume', 'a resume game under the same id: resume');
|
|
1000
|
+
assert.equal(helloAfter('world', true, false), 'none', 'a game without the key: none');
|
|
1001
|
+
assert.equal(helloAfter('self', true, true), 'fresh', 'a resume game under a new id: fresh');
|
|
1002
|
+
assert.equal(helloAfter(null, true, true), 'none');
|
|
1003
|
+
assert.equal(helloAfter('world', false, true), 'resume');
|
|
1004
|
+
assert.equal(helloAfter('self', false, false), 'resume');
|
|
1005
|
+
// Fails if the third input is ignored: the same first two, different answers.
|
|
1006
|
+
assert.notEqual(helloAfter('world', true, true), helloAfter('world', true, false));
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
test('a game: a fresh hello from the same account under a new player id arrives once; the old id left once', () => {
|
|
1010
|
+
const r = boot(result);
|
|
1011
|
+
r.drop();
|
|
1012
|
+
r.tick();
|
|
1013
|
+
assert.deepEqual(r.leaves, ['p2'], 'the old id left');
|
|
1014
|
+
// The connection is re-acquired under a new id (past the window, or a refused token).
|
|
1015
|
+
r.session.players.push({ playerId: 'p9', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1016
|
+
r.world.players.set('p9', { at: { x: 0, y: 1, z: 0 }, facing: 0, body: { setTranslation() {} } });
|
|
1017
|
+
for (let i = 0; i < 6; i += 1) r.tick(1000);
|
|
1018
|
+
assert.equal(r.arrivedTimes('p9'), 0, 'a game never greets for a new id');
|
|
1019
|
+
r.say('p9', { k: 'hub-hello', avatar: 3, from: null, party: 1, carry: null });
|
|
1020
|
+
r.tick(2000);
|
|
1021
|
+
r.tick();
|
|
1022
|
+
assert.equal(r.arrivedTimes('p9'), 1, 'arrived at once');
|
|
1023
|
+
r.say('p9', { k: 'hub-hello', avatar: 3, from: null, party: 1, carry: null });
|
|
1024
|
+
for (let i = 0; i < 4; i += 1) r.tick(1000);
|
|
1025
|
+
assert.equal(r.arrivedTimes('p9'), 1, 'and once');
|
|
1026
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'the old id is not arrived again');
|
|
1027
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
1028
|
+
// A result is one per player id: the old id's (reported at its leave, while
|
|
1029
|
+
// known) and the new id's are separate entries.
|
|
1030
|
+
assert.equal(r.ctx().result('p9', { outcome: 'win', score: 12 }), true);
|
|
1031
|
+
assert.equal(r.ctx().result('p9', { outcome: 'win', score: 11 }), false, 'a second for the new id is refused');
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
test('houseResume without a trusted owner leaves and cleans up just like the legacy place', () => keeping((advance) => {
|
|
1035
|
+
const legacy = boot({}, { resume() {} });
|
|
1036
|
+
const flagged = boot({ houseResume: true }, { resume() {} });
|
|
1037
|
+
for (const r of [legacy, flagged]) { r.drop(); r.tick(); }
|
|
1038
|
+
assert.deepEqual(flagged.leaves, legacy.leaves);
|
|
1039
|
+
assert.deepEqual(flagged.ctx().players(), legacy.ctx().players());
|
|
1040
|
+
advance(180_000);
|
|
1041
|
+
for (const r of [legacy, flagged]) { r.tick(180_000); r.back(); r.say('p2', rehello); r.tick(); }
|
|
1042
|
+
assert.deepEqual(flagged.leaves, legacy.leaves);
|
|
1043
|
+
assert.equal(flagged.arrivedTimes('p2'), legacy.arrivedTimes('p2'));
|
|
1044
|
+
assert.deepEqual(flagged.ctx().players(), legacy.ctx().players());
|
|
1045
|
+
}));
|
|
1046
|
+
|
|
1047
|
+
// v1.115: house guests return at arrival, owners keep their pose and role.
|
|
1048
|
+
for (const owner of ['101', '102']) {
|
|
1049
|
+
for (const away of [30_000, 179_000, 180_000]) {
|
|
1050
|
+
test(`house resume: owner=${owner} drop=p2 ${away}ms`, () => keeping((advance) => {
|
|
1051
|
+
const at = { x: 44.2, y: 1, z: -2.4 };
|
|
1052
|
+
const calls = [];
|
|
1053
|
+
const r = boot({ houseResume: true, arrival: { actor: 'arrival', face: 90 } }, {
|
|
1054
|
+
owner,
|
|
1055
|
+
actors: [...actors, { id: 'arrival', components: { Transform: { x: 2, y: 1, z: 3 } } }],
|
|
1056
|
+
resume(c, { playerId }) { calls.push(c.players().find(p => p.playerId === playerId)); },
|
|
1057
|
+
});
|
|
1058
|
+
r.ctx().placeAt('p2', at, 90); r.tick();
|
|
1059
|
+
r.drop(); r.tick(); advance(away); r.tick(away); r.back();
|
|
1060
|
+
r.say('p2', rehello); r.tick();
|
|
1061
|
+
assert.equal(calls.length, 1);
|
|
1062
|
+
assert.equal(calls[0].userId, '102');
|
|
1063
|
+
assert.equal(r.session.players.filter(p => p.playerId === 'p2').length, 1);
|
|
1064
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
1065
|
+
assert.deepEqual(r.leaves, []);
|
|
1066
|
+
if (owner === '101') {
|
|
1067
|
+
assert.equal(r.world.players.get('p2').at.x, 2);
|
|
1068
|
+
assert.equal(r.world.players.get('p2').at.z, 3);
|
|
1069
|
+
} else { assert.deepEqual(r.world.players.get('p2').at, at); }
|
|
1070
|
+
}));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
test('unstamped owner house keeps legacy exact 60-second expiry', () => keeping((advance) => {
|
|
1075
|
+
const r = boot({ houseResume: true }, { owner: '101', reconnectWindowMs: undefined, resume() {} });
|
|
1076
|
+
r.drop(); r.tick(); advance(60_000); r.tick(60_000);
|
|
1077
|
+
assert.equal(r.leaves.length, 1);
|
|
1078
|
+
}));
|
|
1079
|
+
|
|
1080
|
+
for (const grace of [1000, 180_000]) {
|
|
1081
|
+
test(`house resume expires after spec deadline ${grace}ms`, () => keeping((advance) => {
|
|
1082
|
+
const r = boot({ houseResume: true, resumePose: true }, { owner: '101', reconnectWindowMs: grace, resume() {} });
|
|
1083
|
+
r.drop(); r.tick(); advance(grace + 1); r.tick(grace + 1);
|
|
1084
|
+
assert.equal(r.leaves.length, 1);
|
|
1085
|
+
}));
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// Trusted Town grace keeps the same visit, even without an author pose marker.
|
|
1089
|
+
for (const away of [30_000, 179_000, 180_000]) {
|
|
1090
|
+
test(`pinned Town: ${away}ms keeps pose, activity state and first arrival`, () => keeping((advance) => {
|
|
1091
|
+
const activities = new Map(); const calls = [];
|
|
1092
|
+
const r = boot({}, { reconnectWindowMs: 180_000,
|
|
1093
|
+
arrive(c, group) { for (const p of group) activities.set(p.playerId, { kind: 'fishing', startedAt: 7 }); },
|
|
1094
|
+
leave(c, id) { activities.delete(id); },
|
|
1095
|
+
resume(c, { playerId }) { calls.push(c.players().find(p => p.playerId === playerId)); } });
|
|
1096
|
+
const at = { x: 44.2, y: 1, z: -2.4 }; const activity = activities.get('p2');
|
|
1097
|
+
r.ctx().placeAt('p2', at, 90); r.tick();
|
|
1098
|
+
r.drop(); r.tick(); advance(away); r.tick(away); r.back(); r.say('p2', rehello); r.tick();
|
|
1099
|
+
assert.deepEqual(calls[0].at, at); assert.equal(calls.length, 1);
|
|
1100
|
+
assert.equal(activities.get('p2'), activity);
|
|
1101
|
+
assert.equal(r.arrivedTimes('p2'), 1); assert.deepEqual(r.leaves, []);
|
|
1102
|
+
}));
|
|
1103
|
+
}
|
|
1104
|
+
test('pinned Town:181s expires despite the old five-minute pose marker', () => keeping((advance) => {
|
|
1105
|
+
const r = boot({ resumePose: true }, { reconnectWindowMs: 180_000 });
|
|
1106
|
+
r.drop(); r.tick(); advance(181_000); r.tick(181_000); assert.equal(r.leaves.length, 1);
|
|
1107
|
+
}));
|
|
1108
|
+
|
|
1109
|
+
// v1.98: server-only town opt-in; the visit's first door is not a new trip.
|
|
1110
|
+
for (const away of [30_000, 180_000, 299_999]) {
|
|
1111
|
+
test(`town resumePose: ${away} ms same-id return restores before resume hook`, () => keeping((advance) => {
|
|
1112
|
+
const calls = [];
|
|
1113
|
+
const at = { x: 44.2, y: 1, z: -2.4 };
|
|
1114
|
+
const r = boot({ resumePose: true }, { resume(c, { playerId }) {
|
|
1115
|
+
calls.push({ playerId, at: { ...c.players().find(p => p.playerId === playerId).at } });
|
|
1116
|
+
} });
|
|
1117
|
+
r.ctx().placeAt('p2', at, 90);
|
|
1118
|
+
r.tick();
|
|
1119
|
+
const arrivedAt = r.ctx().players().find(p => p.playerId === 'p2').arrivedAt;
|
|
1120
|
+
r.drop(); r.tick();
|
|
1121
|
+
advance(away);
|
|
1122
|
+
r.tick(away);
|
|
1123
|
+
r.back();
|
|
1124
|
+
r.say('p2', rehello);
|
|
1125
|
+
assert.deepEqual(r.world.players.get('p2').at, at, 'restored before hello replay or step');
|
|
1126
|
+
r.tick();
|
|
1127
|
+
assert.deepEqual(calls, [{ playerId: 'p2', at }]);
|
|
1128
|
+
assert.equal(r.world.players.get('p2').facing, Math.PI / 2);
|
|
1129
|
+
assert.equal(r.ctx().players().find(p => p.playerId === 'p2').arrivedAt, arrivedAt);
|
|
1130
|
+
assert.deepEqual(r.leaves, []);
|
|
1131
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'old door provenance never re-arrives');
|
|
1132
|
+
r.say('p2', rehello); r.tick();
|
|
1133
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1134
|
+
}));
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
for (const away of [30_000, 179_000, 180_000]) {
|
|
1138
|
+
test(`town invite: ${away} ms retained same-id player is placed beside the inviter`, () => keeping((advance) => {
|
|
1139
|
+
const retained = { x: 44.2, y: 1, z: -2.4 };
|
|
1140
|
+
const inviter = { x: 10, y: 1, z: 5 };
|
|
1141
|
+
const resumed = [];
|
|
1142
|
+
const r = boot({ invite: true, resumePose: true }, { resume(c, { playerId }) { resumed.push(playerId); } });
|
|
1143
|
+
r.ctx().placeAt('p1', inviter, 0);
|
|
1144
|
+
r.ctx().placeAt('p2', retained, 90);
|
|
1145
|
+
r.tick();
|
|
1146
|
+
r.drop(); r.tick(); advance(away); r.back();
|
|
1147
|
+
r.say('p2', { k: 'hub-hello', avatar: 3, party: 1, from: 'race', near: '101', invited: true });
|
|
1148
|
+
r.tick();
|
|
1149
|
+
const at = r.world.players.get('p2').at;
|
|
1150
|
+
assert.ok(Math.abs(Math.hypot(at.x - inviter.x, at.z - inviter.z) - 1.6) < 1e-9, JSON.stringify(at));
|
|
1151
|
+
assert.ok(Math.abs(r.world.players.get('p2').facing - Math.atan2(inviter.x - at.x, inviter.z - at.z)) < 1e-9);
|
|
1152
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the accepted invite has a fresh arrival');
|
|
1153
|
+
assert.deepEqual(r.arrivals.at(-1).find((p) => p.playerId === 'p2'), {
|
|
1154
|
+
playerId: 'p2', from: 'race', fromDeckId: null, party: 1, near: '101', invited: true,
|
|
1155
|
+
});
|
|
1156
|
+
r.say('p2', { k: 'hub-hello', avatar: 4, party: 1, from: 'race', near: '101', invited: true, again: true });
|
|
1157
|
+
r.tick();
|
|
1158
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'the avatar hello does not replay placement');
|
|
1159
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1160
|
+
assert.deepEqual(resumed, [], 'fresh invite placement does not also invoke resume');
|
|
1161
|
+
assert.deepEqual(r.leaves, [], 'pose retention did not turn the invite into a leave');
|
|
1162
|
+
}));
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
test('town resumePose: replacement between ticks restores pose before deck step', () => keeping((advance) => {
|
|
1166
|
+
const r = boot({ resumePose: true });
|
|
1167
|
+
const at = { x: 44.2, y: 1, z: -2.4 };
|
|
1168
|
+
r.ctx().placeAt('p2', at, 75); r.tick();
|
|
1169
|
+
r.drop(); advance(180000); r.back();
|
|
1170
|
+
r.tick(180000); // no absent tick or client hello
|
|
1171
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1172
|
+
assert.equal(r.world.players.get('p2').facing, 75 * Math.PI / 180);
|
|
1173
|
+
assert.deepEqual(r.leaves, []);
|
|
1174
|
+
assert.equal(r.arrivedTimes('p2'), 1);
|
|
1175
|
+
}));
|
|
1176
|
+
|
|
1177
|
+
test('town resumePose: five-minute boundary expires once, including hello before reconcile', () => keeping((advance) => {
|
|
1178
|
+
const r = boot({ resumePose: true });
|
|
1179
|
+
r.ctx().placeAt('p2', { x: 44.2, y: 1, z: -2.4 }); r.tick();
|
|
1180
|
+
r.drop(); r.tick(); advance(300000); r.back();
|
|
1181
|
+
r.say('p2', rehello); r.tick(300000); r.tick();
|
|
1182
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
1183
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1184
|
+
assert.notEqual(r.world.players.get('p2').at.x, 44.2);
|
|
1185
|
+
}));
|
|
1186
|
+
|
|
1187
|
+
test('town resumePose: a new id never takes the old id pose', () => keeping((advance) => {
|
|
1188
|
+
const r = boot({ resumePose: true });
|
|
1189
|
+
r.ctx().placeAt('p2', { x: 44.2, y: 1, z: -2.4 }); r.tick();
|
|
1190
|
+
r.drop(); r.tick(); advance(180000);
|
|
1191
|
+
r.session.players.push({ playerId: 'p9', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1192
|
+
r.world.players.set('p9', body());
|
|
1193
|
+
r.say('p9', { k: 'hub-hello', avatar: 3, party: 1 });
|
|
1194
|
+
r.tick(2000); r.tick();
|
|
1195
|
+
assert.equal(r.arrivedTimes('p9'), 1);
|
|
1196
|
+
assert.notEqual(r.world.players.get('p9').at.x, 44.2);
|
|
1197
|
+
advance(120000); r.tick(); r.tick();
|
|
1198
|
+
assert.deepEqual(r.leaves, ['p2'], 'old retained visit expires once');
|
|
1199
|
+
}));
|
|
1200
|
+
|
|
1201
|
+
test('town resumePose: explicit travel leaves immediately and its return arrives afresh', () => {
|
|
1202
|
+
const r = boot({ resumePose: true, places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
|
|
1203
|
+
actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
1204
|
+
});
|
|
1205
|
+
r.ctx().placeAt('p2', { x: 44.2, y: 1, z: -2.4 }); r.tick();
|
|
1206
|
+
assert.ok(r.ctx().go('out', ['p2']));
|
|
1207
|
+
r.drop(); r.tick(); r.tick();
|
|
1208
|
+
assert.deepEqual(r.leaves, ['p2']);
|
|
1209
|
+
r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1210
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1211
|
+
assert.notEqual(r.world.players.get('p2').at.x, 44.2);
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
// Join on a friend at home: a trip the client started on its own would leave
|
|
1216
|
+
// the town retaining this visit, so Back restored the old spot. The place's
|
|
1217
|
+
// `hub-house-visit` sends it through the House door like any door's trip.
|
|
1218
|
+
for (const viaPlace of [false, true]) {
|
|
1219
|
+
test(`town resumePose: a House visit ${viaPlace ? 'through the place ends the visit' : 'the place never heard of is retained'}`, () => {
|
|
1220
|
+
const r = boot({ resumePose: true, places: { house: { title: 'House', scene: 'scenes/house.scene' } } }, {
|
|
1221
|
+
reconnectWindowMs: 180_000,
|
|
1222
|
+
actors: [...actors, { id: 'home', components: { HubDoor: { id: 'home-1', to: 'house' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
1223
|
+
});
|
|
1224
|
+
r.ctx().placeAt('p2', { x: 44.2, y: 1, z: -2.4 }); r.tick();
|
|
1225
|
+
const from = r.sent.length;
|
|
1226
|
+
if (viaPlace) {
|
|
1227
|
+
r.say('p2', { k: 'hub-house-visit', door: 'home-1', owner: '101' });
|
|
1228
|
+
assert.deepEqual(toP2(r, from).filter((m) => m.k === 'hub-go'), [
|
|
1229
|
+
{ k: 'hub-go', door: 'home-1', key: null, place: null, scene: null, title: 'House', party: 1, owner: '101' },
|
|
1230
|
+
]);
|
|
1231
|
+
}
|
|
1232
|
+
r.drop(); r.tick(); r.tick();
|
|
1233
|
+
assert.deepEqual(r.leaves, viaPlace ? ['p2'] : []);
|
|
1234
|
+
r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1235
|
+
if (viaPlace) {
|
|
1236
|
+
assert.notEqual(r.world.players.get('p2').at.x, 44.2, 'back from the House arrives afresh');
|
|
1237
|
+
} else {
|
|
1238
|
+
assert.equal(r.world.players.get('p2').at.x, 44.2, 'the retained visit restores the old spot');
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
test('town: a sitter who joins a friend at home gets up and goes through the House door', () => {
|
|
1244
|
+
const r = boot({ idle: { seats: true }, places: { house: { title: 'House', scene: 'scenes/house.scene' } } }, {
|
|
1245
|
+
reconnectWindowMs: 180_000,
|
|
1246
|
+
actors: [
|
|
1247
|
+
...actors,
|
|
1248
|
+
{ id: 'home', components: { HubDoor: { id: 'home-1', to: 'house' }, Transform: { x: 5, y: 0, z: 5 } } },
|
|
1249
|
+
{ id: 'stool', components: { Transform: { x: 0, y: 0, z: 1 }, HubSeat: { height: 1.2 } } },
|
|
1250
|
+
],
|
|
1251
|
+
});
|
|
1252
|
+
r.ctx().placeAt('p2', { x: 0, y: 1, z: 0.5 }); r.tick();
|
|
1253
|
+
r.say('p2', { k: 'hub-sit', seat: 'stool' });
|
|
1254
|
+
assert.equal(r.ctx().seat?.('p2') ?? 'stool', 'stool', 'seated first');
|
|
1255
|
+
const from = r.sent.length;
|
|
1256
|
+
r.say('p2', { k: 'hub-house-visit', door: 'home-1', owner: '101' });
|
|
1257
|
+
assert.deepEqual(toP2(r, from).filter((m) => m.k === 'hub-go').map((m) => m.owner), ['101']);
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
test('town: a House visit without an owner, or a malformed one, is the jump to the door', () => {
|
|
1261
|
+
const r = boot({ places: { house: { title: 'House', scene: 'scenes/house.scene' } } }, {
|
|
1262
|
+
reconnectWindowMs: 180_000,
|
|
1263
|
+
actors: [...actors, { id: 'home', components: { HubDoor: { id: 'home-1', to: 'house' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
1264
|
+
});
|
|
1265
|
+
const from = r.sent.length;
|
|
1266
|
+
r.say('p2', { k: 'hub-house-visit', door: 'home-1', owner: 'nope' });
|
|
1267
|
+
assert.equal(toP2(r, from).some((m) => m.k === 'hub-go'), false);
|
|
1268
|
+
assert.ok(toP2(r, from).some((m) => m.k === 'hub-jumped'), 'jumped to the door instead');
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
// Exercise durable new-socket restoration through the real hub lifecycle.
|
|
1272
|
+
const flushPose = async () => { for (let i = 0; i < 40; i++) { await Promise.resolve(); } };
|
|
1273
|
+
const { poseStorage: makePoseStorage } = await import('./pose-storage-fixture.mjs');
|
|
1274
|
+
const poseStorage = makePoseStorage();
|
|
1275
|
+
{
|
|
1276
|
+
const r = boot({ resumePose: true }, { storage: poseStorage });
|
|
1277
|
+
await flushPose(); r.tick(2000); r.tick();
|
|
1278
|
+
r.ctx().placeAt('p2', { x: 44.2, y: 2.3, z: -8.4 }, 100);
|
|
1279
|
+
r.tick(); r.drop(); r.tick();
|
|
1280
|
+
await flushPose();
|
|
1281
|
+
r.session.players.push({ playerId: 'new-p2', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1282
|
+
r.world.players.set('new-p2', body());
|
|
1283
|
+
r.say('new-p2', rehello);
|
|
1284
|
+
// Repeated hello while the asynchronous read is pending keeps its guard.
|
|
1285
|
+
r.say('new-p2', rehello);
|
|
1286
|
+
await flushPose(); r.tick(2000); r.tick();
|
|
1287
|
+
assert.deepEqual(r.world.players.get('new-p2').at, { x: 44.2, y: 2.3, z: -8.4 });
|
|
1288
|
+
assert.equal(r.world.players.get('new-p2').facing, 100 * Math.PI / 180);
|
|
1289
|
+
assert.equal(r.arrivedTimes('new-p2'), 1);
|
|
1290
|
+
console.log('ok: durable new-id hello restores full pose before next step');
|
|
1291
|
+
r.ctx().placeAt('new-p2', { x: 5, y: 4, z: -9 });
|
|
1292
|
+
r.tick();
|
|
1293
|
+
await r.server.shutdown();
|
|
1294
|
+
const next = boot({ resumePose: true }, { storage: poseStorage });
|
|
1295
|
+
await flushPose(); next.tick(2000); next.tick();
|
|
1296
|
+
assert.deepEqual(next.world.players.get('p2').at, { x: 5, y: 4, z: -9 });
|
|
1297
|
+
console.log('ok: private-session shutdown restores pose in a new hub layer');
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
for (const away of [30_000, 179_000, 180_000]) {
|
|
1301
|
+
const realNow = Date.now;
|
|
1302
|
+
let now = realNow();
|
|
1303
|
+
Date.now = () => now;
|
|
1304
|
+
try {
|
|
1305
|
+
const storage = makePoseStorage();
|
|
1306
|
+
const r = boot({ invite: true, resumePose: true }, { storage });
|
|
1307
|
+
await flushPose(); r.tick(2000); r.tick();
|
|
1308
|
+
const inviter = { x: 10, y: 1, z: 5 };
|
|
1309
|
+
const cold = { x: 44.2, y: 2.3, z: -8.4 };
|
|
1310
|
+
r.ctx().placeAt('p1', inviter, 0);
|
|
1311
|
+
r.ctx().placeAt('p2', cold, 100);
|
|
1312
|
+
r.tick(); r.drop(); r.tick();
|
|
1313
|
+
await flushPose();
|
|
1314
|
+
now += away;
|
|
1315
|
+
r.session.players.push({ playerId: 'new-p2', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1316
|
+
r.world.players.set('new-p2', body());
|
|
1317
|
+
r.say('new-p2', { k: 'hub-hello', avatar: 3, party: 1, from: 'race', near: '101', invited: true });
|
|
1318
|
+
await flushPose(); r.tick(2000); r.tick();
|
|
1319
|
+
const placed = r.world.players.get('new-p2');
|
|
1320
|
+
assert.ok(Math.abs(Math.hypot(placed.at.x - inviter.x, placed.at.z - inviter.z) - 1.6) < 1e-9, JSON.stringify(placed.at));
|
|
1321
|
+
assert.ok(Math.abs(placed.facing - Math.atan2(inviter.x - placed.at.x, inviter.z - placed.at.z)) < 1e-9);
|
|
1322
|
+
assert.notDeepEqual(placed.at, cold, 'the accepted invite wins over the stored pose');
|
|
1323
|
+
assert.equal(r.arrivedTimes('new-p2'), 1);
|
|
1324
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'new-p2').invited, true);
|
|
1325
|
+
console.log(`ok: ${away} ms cold pose yields to fresh invite placement`);
|
|
1326
|
+
} finally {
|
|
1327
|
+
Date.now = realNow;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// v1.90: real hello transport replays the private opt-in preference only to
|
|
1332
|
+
// its player, including a missed clear on a retained client.
|
|
1333
|
+
{
|
|
1334
|
+
const r = boot({}, { actors: [...actors, { id: 'rowan', components: {
|
|
1335
|
+
Transform: { x: 1, y: 1, z: 0 }, Body: { type: 'kinematic' }, HubNpc: { name: 'Rowan' },
|
|
1336
|
+
} }] });
|
|
1337
|
+
assert.ok(!r.sent.some(([, m]) => m.k === 'hub-npc-preferred'));
|
|
1338
|
+
assert.equal(r.ctx().preferNpc('p2', 'rowan'), true);
|
|
1339
|
+
let from = r.sent.length;
|
|
1340
|
+
r.say('p2', rehello); r.tick();
|
|
1341
|
+
assert.deepEqual(r.sent.slice(from).filter(([, m]) => m.k === 'hub-npc-preferred'), [
|
|
1342
|
+
['p2', { k: 'hub-npc-preferred', npc: 'rowan' }],
|
|
1343
|
+
]);
|
|
1344
|
+
r.ctx().preferNpc('p2', null);
|
|
1345
|
+
from = r.sent.length;
|
|
1346
|
+
r.say('p2', rehello); r.tick();
|
|
1347
|
+
assert.deepEqual(r.sent.slice(from).filter(([, m]) => m.k === 'hub-npc-preferred'), [
|
|
1348
|
+
['p2', { k: 'hub-npc-preferred', npc: null }],
|
|
1349
|
+
]);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
const guestRoster = () => [
|
|
1353
|
+
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
1354
|
+
{ playerId: 'p2', userId: '102', username: 'Guest', isAnonymous: true },
|
|
1355
|
+
];
|
|
1356
|
+
|
|
1357
|
+
test('anonymous entry is opt-in and keeps account-only userId null', () => {
|
|
1358
|
+
const plain = boot({}, { players: guestRoster() });
|
|
1359
|
+
assert.equal(Object.hasOwn(plain.server.join(), 'hubGuests'), false);
|
|
1360
|
+
assert.equal(Object.hasOwn(plain.server.delta() ?? {}, 'hubGuests'), false);
|
|
1361
|
+
assert.equal(Object.hasOwn(plain.ctx().players().find((p) => p.playerId === 'p2'), 'identityUserId'), false);
|
|
1362
|
+
assert.equal(Object.hasOwn(plain.arrivals.flat().find((p) => p.playerId === 'p2'), 'identityUserId'), false);
|
|
1363
|
+
|
|
1364
|
+
const opted = boot({ anonymousEntry: true }, { players: guestRoster() });
|
|
1365
|
+
assert.deepEqual(opted.server.join().hubGuests, ['p2']);
|
|
1366
|
+
const guest = opted.ctx().players().find((p) => p.playerId === 'p2');
|
|
1367
|
+
assert.equal(guest.userId, null, 'account-only APIs still see no user id');
|
|
1368
|
+
assert.equal(guest.identityUserId, '102');
|
|
1369
|
+
assert.equal(opted.arrivals.flat().find((p) => p.playerId === 'p2').identityUserId, '102');
|
|
1370
|
+
opted.session.hub = { hiddenPair: (a, b) => [a, b].sort().join() === 'p1,p2' };
|
|
1371
|
+
opted.world.timeMs += 1;
|
|
1372
|
+
assert.deepEqual(opted.server.join().hubGuests, [], 'the shared guest list hides blocked players like hubAv');
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
test('per-viewer avatar overrides restore and clear guest status', () => {
|
|
1376
|
+
const roster = [...guestRoster(), { playerId: 'p3', userId: '103', username: 'Cy', isAnonymous: false }];
|
|
1377
|
+
const r = boot({ anonymousEntry: true }, { players: roster });
|
|
1378
|
+
r.say('p3', { k: 'hub-hello', avatar: 1, party: 1 });
|
|
1379
|
+
r.session.hub = {
|
|
1380
|
+
arrival: () => null,
|
|
1381
|
+
readResults: async () => ({ players: {}, boards: {} }),
|
|
1382
|
+
hiddenPair: (a, b) => [a, b].sort().join() === 'p1,p2',
|
|
1383
|
+
};
|
|
1384
|
+
let from = r.sent.length;
|
|
1385
|
+
r.tick();
|
|
1386
|
+
assert.deepEqual(
|
|
1387
|
+
r.sent.slice(from).filter(([id, m]) => id === 'p3' && m.k === 'hub-av'),
|
|
1388
|
+
[['p3', { k: 'hub-av', hubAv: { p1: 0, p2: 3 }, hubGuests: ['p2'] }]],
|
|
1389
|
+
);
|
|
1390
|
+
r.session.players.find((p) => p.playerId === 'p2').isAnonymous = false;
|
|
1391
|
+
from = r.sent.length;
|
|
1392
|
+
r.world.timeMs += 1;
|
|
1393
|
+
r.tick();
|
|
1394
|
+
assert.deepEqual(
|
|
1395
|
+
r.sent.slice(from).filter(([id, m]) => id === 'p3' && m.k === 'hub-av'),
|
|
1396
|
+
[['p3', { k: 'hub-av', hubAv: { p1: 0, p2: 3 }, hubGuests: [] }]],
|
|
1397
|
+
);
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
test('same-socket sign-up restores only pose/avatar choice and arrives with authoritative provenance', () => {
|
|
1401
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
|
|
1402
|
+
const at = { x: 18, y: 2, z: -7 };
|
|
1403
|
+
r.ctx().placeAt('p2', at, 75);
|
|
1404
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
|
|
1405
|
+
r.tick();
|
|
1406
|
+
const roster = r.session.players.find((p) => p.playerId === 'p2');
|
|
1407
|
+
Object.assign(roster, { username: 'Bo', isAnonymous: false });
|
|
1408
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, party: 1 });
|
|
1409
|
+
// A second account hello before the arrival batch must not consume the
|
|
1410
|
+
// one-time link a second time or replace its still-pending continuity.
|
|
1411
|
+
r.say('p2', { k: 'hub-hello', avatar: 1, color: 2, party: 1 });
|
|
1412
|
+
r.tick(2000); r.tick();
|
|
1413
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1414
|
+
assert.equal(r.world.players.get('p2').facing, 75 * Math.PI / 180);
|
|
1415
|
+
assert.equal(r.server.join().hubAv2.p2, 7, 'guest avatar choice is copied');
|
|
1416
|
+
assert.equal(r.server.join().hubAvC.p2, 11, 'guest avatar color is copied with the avatar choice');
|
|
1417
|
+
assert.deepEqual(r.server.join().hubGuests, []);
|
|
1418
|
+
const arrival = r.arrivals.at(-1).find((p) => p.playerId === 'p2');
|
|
1419
|
+
assert.equal(arrival.signedUpFrom, 'p2');
|
|
1420
|
+
assert.equal(arrival.identityUserId, '102');
|
|
1421
|
+
assert.equal(r.arrivedTimes('p2'), 2, 'sign-up produces one fresh arrival');
|
|
1422
|
+
r.say('p2', { k: 'hub-hello', avatar: 2, color: 3, again: true });
|
|
1423
|
+
r.tick();
|
|
1424
|
+
assert.equal(r.server.join().hubAv.p2, 2, 'consumed continuity is not recreated by a later hello');
|
|
1425
|
+
assert.equal(r.server.join().hubAvC.p2, 3);
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
for (const away of [30_000, 179_000, 180_000]) {
|
|
1429
|
+
const realNow = Date.now;
|
|
1430
|
+
let now = realNow();
|
|
1431
|
+
Date.now = () => now;
|
|
1432
|
+
try {
|
|
1433
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
|
|
1434
|
+
const at = { x: 31, y: 1.5, z: 12 };
|
|
1435
|
+
r.ctx().placeAt('p2', at, 120);
|
|
1436
|
+
r.say('p2', { k: 'hub-hello', avatar: 6, color: 9, again: true });
|
|
1437
|
+
r.tick();
|
|
1438
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
|
|
1439
|
+
r.world.players.delete('p2');
|
|
1440
|
+
r.tick();
|
|
1441
|
+
now += away;
|
|
1442
|
+
r.session.players.push({ playerId: 'new-p2', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1443
|
+
r.world.players.set('new-p2', body());
|
|
1444
|
+
r.say('new-p2', { k: 'hub-hello', avatar: 0, party: 1 });
|
|
1445
|
+
r.tick(2000); r.tick();
|
|
1446
|
+
assert.deepEqual(r.world.players.get('new-p2').at, at);
|
|
1447
|
+
assert.equal(r.world.players.get('new-p2').facing, 120 * Math.PI / 180);
|
|
1448
|
+
assert.equal(r.server.join().hubAv2['new-p2'], 6);
|
|
1449
|
+
assert.equal(r.server.join().hubAvC['new-p2'], 9);
|
|
1450
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'new-p2').signedUpFrom, 'p2');
|
|
1451
|
+
console.log(`ok: new-socket sign-up restores at ${away} ms`);
|
|
1452
|
+
} finally {
|
|
1453
|
+
Date.now = realNow;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
test('a changed trusted account cannot inherit pending sign-up continuity', () => {
|
|
1458
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
|
|
1459
|
+
const at = { x: 24, y: 2, z: -13 };
|
|
1460
|
+
r.ctx().placeAt('p2', at, 35);
|
|
1461
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
|
|
1462
|
+
r.tick();
|
|
1463
|
+
const roster = r.session.players.find((p) => p.playerId === 'p2');
|
|
1464
|
+
Object.assign(roster, { userId: '102', username: 'Bo', isAnonymous: false });
|
|
1465
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 1, party: 1 });
|
|
1466
|
+
Object.assign(roster, { userId: '999', username: 'Other' });
|
|
1467
|
+
r.say('p2', { k: 'hub-hello', avatar: 1, color: 2, party: 1 });
|
|
1468
|
+
r.tick(2000); r.tick();
|
|
1469
|
+
assert.notDeepEqual(r.world.players.get('p2').at, at);
|
|
1470
|
+
assert.equal(r.server.join().hubAv.p2, 1);
|
|
1471
|
+
assert.equal(r.server.join().hubAvC.p2, 2);
|
|
1472
|
+
const arrival = r.arrivals.at(-1).find((p) => p.playerId === 'p2');
|
|
1473
|
+
assert.equal(arrival.signedUpFrom, undefined);
|
|
1474
|
+
assert.equal(arrival.identityUserId, '999');
|
|
1475
|
+
});
|
|
1476
|
+
|
|
1477
|
+
test('a different signed-in user cannot consume a guest entry', () => {
|
|
1478
|
+
const r = boot({ anonymousEntry: true }, { players: guestRoster() });
|
|
1479
|
+
r.ctx().placeAt('p2', { x: 40, y: 2, z: 40 }, 10);
|
|
1480
|
+
r.tick();
|
|
1481
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
|
|
1482
|
+
r.world.players.delete('p2');
|
|
1483
|
+
r.tick();
|
|
1484
|
+
r.session.players.push({ playerId: 'other', userId: '999', username: 'Other', isAnonymous: false });
|
|
1485
|
+
r.world.players.set('other', body());
|
|
1486
|
+
r.say('other', { k: 'hub-hello', avatar: 1, party: 1 });
|
|
1487
|
+
r.tick(2000); r.tick();
|
|
1488
|
+
assert.notDeepEqual(r.world.players.get('other').at, { x: 40, y: 2, z: 40 });
|
|
1489
|
+
assert.equal(r.arrivals.at(-1).find((p) => p.playerId === 'other').signedUpFrom, undefined);
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
for (const readFirst of [true, false]) {
|
|
1493
|
+
const realNow = Date.now;
|
|
1494
|
+
let now = realNow();
|
|
1495
|
+
Date.now = () => now;
|
|
1496
|
+
try {
|
|
1497
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
|
|
1498
|
+
const at = { x: 27, y: 2, z: -9 };
|
|
1499
|
+
r.ctx().placeAt('p2', at, 55);
|
|
1500
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
|
|
1501
|
+
r.tick();
|
|
1502
|
+
let resolveRead;
|
|
1503
|
+
const read = new Promise((resolve) => { resolveRead = resolve; });
|
|
1504
|
+
r.session.hub = { arrival: () => null, readResults: () => read };
|
|
1505
|
+
Object.assign(r.session.players.find((p) => p.playerId === 'p2'), { username: 'Bo', isAnonymous: false });
|
|
1506
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
|
|
1507
|
+
r.tick();
|
|
1508
|
+
if (readFirst) {
|
|
1509
|
+
resolveRead({ players: { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
|
|
1510
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1511
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
|
|
1512
|
+
now += 2000;
|
|
1513
|
+
r.tick();
|
|
1514
|
+
} else {
|
|
1515
|
+
now += 2000;
|
|
1516
|
+
r.tick();
|
|
1517
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
|
|
1518
|
+
resolveRead({ players: { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
|
|
1519
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1520
|
+
}
|
|
1521
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1522
|
+
assert.equal(r.server.join().hubAv2.p2, 7);
|
|
1523
|
+
assert.equal(r.server.join().hubAvC.p2, 11);
|
|
1524
|
+
r.say('p2', { k: 'hub-hello', avatar: 2, color: 3, again: true });
|
|
1525
|
+
r.tick();
|
|
1526
|
+
assert.equal(r.server.join().hubAv.p2, 2, 'both consumers finished, so a later choice wins');
|
|
1527
|
+
assert.equal(r.server.join().hubAvC.p2, 3);
|
|
1528
|
+
console.log(`ok: sign-up appearance survives ${readFirst ? 'read-before-arrival' : 'arrival-before-read'}`);
|
|
1529
|
+
} finally {
|
|
1530
|
+
Date.now = realNow;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
// Terminal carry regression matrix against the real hub server: both orders,
|
|
1535
|
+
// success/empty/rejection, delayed reads, repeated hellos, explicit choices,
|
|
1536
|
+
// account switches and throwing authored arrivals. Carry is consumed once.
|
|
1537
|
+
for (const readFirst of [true, false]) {
|
|
1538
|
+
for (const outcome of ['success', 'empty', 'failure']) {
|
|
1539
|
+
for (const choice of [false, 'different', 'default']) {
|
|
1540
|
+
const realNow = Date.now;
|
|
1541
|
+
let now = realNow();
|
|
1542
|
+
Date.now = () => now;
|
|
1543
|
+
try {
|
|
1544
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, { players: guestRoster() });
|
|
1545
|
+
const at = { x: 27, y: 2, z: -9 };
|
|
1546
|
+
r.ctx().placeAt('p2', at, 55);
|
|
1547
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true });
|
|
1548
|
+
r.tick();
|
|
1549
|
+
let resolveRead, rejectRead;
|
|
1550
|
+
const read = new Promise((resolve, reject) => { resolveRead = resolve; rejectRead = reject; });
|
|
1551
|
+
r.session.hub = { arrival: () => null, readResults: () => read };
|
|
1552
|
+
Object.assign(r.session.players.find((p) => p.playerId === 'p2'), { username: 'Bo', isAnonymous: false });
|
|
1553
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
|
|
1554
|
+
r.tick();
|
|
1555
|
+
const arrivals = r.arrivedTimes('p2');
|
|
1556
|
+
const settleRead = async () => {
|
|
1557
|
+
if (outcome === 'failure') rejectRead(new Error('account read failed'));
|
|
1558
|
+
else resolveRead({ players: outcome === 'empty' ? {} : { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
|
|
1559
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1560
|
+
};
|
|
1561
|
+
if (readFirst) await settleRead();
|
|
1562
|
+
else { now += 2000; r.tick(); }
|
|
1563
|
+
assert.equal(r.arrivedTimes('p2'), arrivals, 'no authored carry arrival before BOTH settle');
|
|
1564
|
+
for (let i = 0; i < 3; i++) r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, party: 1 });
|
|
1565
|
+
const chosenAvatar = choice === 'different' ? 2 : 0;
|
|
1566
|
+
const chosenColor = choice === 'different' ? 3 : 0;
|
|
1567
|
+
if (choice) r.say('p2', { k: 'hub-hello', avatar: chosenAvatar, color: chosenColor, again: true });
|
|
1568
|
+
if (readFirst) { now += 2000; r.tick(); }
|
|
1569
|
+
else await settleRead();
|
|
1570
|
+
assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'one terminal carry arrival');
|
|
1571
|
+
assert.deepEqual(r.world.players.get('p2').at, at);
|
|
1572
|
+
assert.equal(r.server.join().hubAv2?.p2 ?? r.server.join().hubAv.p2, choice ? chosenAvatar : 7);
|
|
1573
|
+
assert.equal(r.server.join().hubAvC?.p2 ?? 0, choice ? chosenColor : 11);
|
|
1574
|
+
for (let i = 0; i < 3; i++) { r.say('p2', { k: 'hub-hello', avatar: chosenAvatar, color: chosenColor, party: 1 }); r.tick(); }
|
|
1575
|
+
assert.equal(r.arrivedTimes('p2'), arrivals + 1, 'repeat hellos cannot replay carry');
|
|
1576
|
+
assert.equal(r.server.join().hubAv2?.p2 ?? r.server.join().hubAv.p2, choice ? chosenAvatar : 7);
|
|
1577
|
+
r.say('p2', { k: 'hub-hello', avatar: 4, color: 5, again: true }); r.tick();
|
|
1578
|
+
assert.equal(r.server.join().hubAv2?.p2 ?? r.server.join().hubAv.p2, 4, 'terminal read never locks later choice');
|
|
1579
|
+
assert.equal(r.server.join().hubAvC.p2, 5);
|
|
1580
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, again: true }); r.tick();
|
|
1581
|
+
assert.equal(r.server.join().hubAv.p2, 0, 'explicit default choice wins after carry completion too');
|
|
1582
|
+
assert.equal(r.server.join().hubAvC?.p2 ?? 0, 0);
|
|
1583
|
+
passed++;
|
|
1584
|
+
console.log(`ok: terminal signup ${readFirst ? 'read-first' : 'arrival-first'} ${outcome} choice=${choice}`);
|
|
1585
|
+
} finally { Date.now = realNow; }
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
for (const switched of [false, true]) {
|
|
1591
|
+
const realNow = Date.now;
|
|
1592
|
+
let now = realNow();
|
|
1593
|
+
Date.now = () => now;
|
|
1594
|
+
try {
|
|
1595
|
+
let throwArrival = false;
|
|
1596
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, {
|
|
1597
|
+
players: guestRoster(),
|
|
1598
|
+
arrive: () => { if (throwArrival) throw new Error('authored arrival failed'); },
|
|
1599
|
+
});
|
|
1600
|
+
r.ctx().placeAt('p2', { x: 27, y: 2, z: -9 }, 55);
|
|
1601
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true }); r.tick();
|
|
1602
|
+
let resolveRead;
|
|
1603
|
+
const read = new Promise((resolve) => { resolveRead = resolve; });
|
|
1604
|
+
r.session.hub = { arrival: () => null, readResults: () => read };
|
|
1605
|
+
const roster = r.session.players.find((p) => p.playerId === 'p2');
|
|
1606
|
+
Object.assign(roster, { username: 'Bo', isAnonymous: false });
|
|
1607
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0 }); r.tick();
|
|
1608
|
+
now += 2000; r.tick();
|
|
1609
|
+
const arrivals = r.arrivedTimes('p2');
|
|
1610
|
+
if (switched) {
|
|
1611
|
+
Object.assign(roster, { userId: '999', username: 'Other' });
|
|
1612
|
+
r.say('p2', { k: 'hub-hello', avatar: 2, color: 3 });
|
|
1613
|
+
} else {
|
|
1614
|
+
// A later authored placement wins too; town must not restore old pose.
|
|
1615
|
+
r.ctx().placeAt('p2', { x: 60, y: 2, z: 60 }, 90);
|
|
1616
|
+
throwArrival = true;
|
|
1617
|
+
}
|
|
1618
|
+
resolveRead({ players: { 102: { avatar: 0, avatarColor: 0 } }, boards: {} });
|
|
1619
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1620
|
+
if (switched) {
|
|
1621
|
+
assert.equal(r.arrivedTimes('p2'), arrivals, 'old read cannot arrive a different identity');
|
|
1622
|
+
assert.equal(r.server.join().hubAv.p2, 2);
|
|
1623
|
+
assert.equal(r.server.join().hubAvC.p2, 3);
|
|
1624
|
+
} else {
|
|
1625
|
+
assert.deepEqual(r.world.players.get('p2').at, { x: 60, y: 2, z: 60 });
|
|
1626
|
+
assert.equal(r.arrivedTimes('p2'), arrivals + 1);
|
|
1627
|
+
}
|
|
1628
|
+
r.say('p2', { k: 'hub-hello', avatar: 4, color: 5, again: true }); r.tick();
|
|
1629
|
+
assert.equal(r.server.join().hubAv2?.p2 ?? r.server.join().hubAv.p2, 4, 'finally releases carry even after cancellation/hook throw');
|
|
1630
|
+
assert.equal(r.server.join().hubAvC.p2, 5);
|
|
1631
|
+
passed++;
|
|
1632
|
+
console.log(`ok: terminal signup ${switched ? 'account switch' : 'hook throw and later placement'}`);
|
|
1633
|
+
} finally { Date.now = realNow; }
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
test('an unrelated ordinary arrival exception cannot strand signup', () => {
|
|
1637
|
+
const r = boot({ anonymousEntry: true, avatarColors: true }, {
|
|
1638
|
+
players: guestRoster(),
|
|
1639
|
+
arrive: (ctx, group) => { if (group.some((p) => p.playerId === 'p3')) throw new Error('other arrival failed'); },
|
|
1640
|
+
});
|
|
1641
|
+
r.say('p2', { k: 'hub-hello', avatar: 7, color: 11, again: true }); r.tick();
|
|
1642
|
+
Object.assign(r.session.players.find((p) => p.playerId === 'p2'), { username: 'Bo', isAnonymous: false });
|
|
1643
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0 });
|
|
1644
|
+
r.session.players.push({ playerId: 'p3', userId: '103', username: 'Cy', isAnonymous: false });
|
|
1645
|
+
r.world.players.set('p3', body());
|
|
1646
|
+
r.say('p3', { k: 'hub-hello', avatar: 1, party: 1 });
|
|
1647
|
+
assert.throws(() => r.tick(), /other arrival failed/);
|
|
1648
|
+
assert.equal(r.server.join().hubAv2.p2, 7);
|
|
1649
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1650
|
+
r.say('p2', { k: 'hub-hello', avatar: 0, color: 0, again: true }); r.tick();
|
|
1651
|
+
assert.equal(r.server.join().hubAv.p2, 0);
|
|
1652
|
+
assert.equal(r.server.join().hubAvC?.p2 ?? 0, 0);
|
|
1653
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1654
|
+
});
|
|
1655
|
+
|
|
1656
|
+
test('pose-only mode bypasses pinned retention and restores after leave/arrive', () => {
|
|
1657
|
+
const r = boot({ resumeArrivalPose: true }, { reconnectWindowMs: 180000 });
|
|
1658
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 0.7); r.tick();
|
|
1659
|
+
r.drop(); r.tick();
|
|
1660
|
+
assert.equal(r.leaves.filter(id => id === 'p2').length, 1);
|
|
1661
|
+
r.session.hub = null; // The synchronous fixture does not drain platform reads.
|
|
1662
|
+
r.back(); r.say('p2', rehello); r.tick();
|
|
1663
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1664
|
+
assert.equal(r.world.players.get('p2').at.x, -3);
|
|
1665
|
+
assert.equal(r.world.players.get('p2').facing, 0.7 * Math.PI / 180);
|
|
1666
|
+
});
|
|
1667
|
+
|
|
1668
|
+
test('pose-only explicit travel cannot return to its old pose', () => {
|
|
1669
|
+
const r = boot({ resumeArrivalPose: true, places: { lobby: { title: 'Lobby', scene: 'scenes/lobby.scene' } } }, {
|
|
1670
|
+
actors: [...actors, { id: 'door', components: { HubDoor: { id: 'out', to: 'lobby' }, Transform: { x: 5, y: 0, z: 5 } } }],
|
|
1671
|
+
});
|
|
1672
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick();
|
|
1673
|
+
assert.ok(r.ctx().go('out', ['p2']));
|
|
1674
|
+
r.drop(); r.tick(); r.back(); r.say('p2', rehello); r.tick();
|
|
1675
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1676
|
+
assert.notEqual(r.world.players.get('p2').at.x, -3);
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
test('pose-only mode fails closed across changed or anonymous identity', () => {
|
|
1680
|
+
for (const identity of [{ userId: '103', isAnonymous: false }, { userId: '102', isAnonymous: true }]) {
|
|
1681
|
+
const r = boot({ resumeArrivalPose: true });
|
|
1682
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 0.7); r.tick(); r.drop(); r.tick(); r.back();
|
|
1683
|
+
Object.assign(r.session.players.find(p => p.playerId === 'p2'), identity);
|
|
1684
|
+
r.say('p2', rehello); r.tick();
|
|
1685
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1686
|
+
assert.notEqual(r.world.players.get('p2').at.x, -3);
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
test('pose-only anonymous dev subjects never restore a pose', () => {
|
|
1691
|
+
for (const isAnonymous of [true, false]) {
|
|
1692
|
+
const roster = players().map(p => p.playerId === 'p2' ? { ...p, userId: 'dev-guest-2', isAnonymous } : p);
|
|
1693
|
+
const r = boot({ resumeArrivalPose: true }, { players: roster });
|
|
1694
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick(); r.drop(); r.tick(); r.back();
|
|
1695
|
+
Object.assign(r.session.players.find(p => p.playerId === 'p2'), { userId: 'dev-guest-2', isAnonymous });
|
|
1696
|
+
r.say('p2', rehello); r.tick();
|
|
1697
|
+
assert.notEqual(r.world.players.get('p2').at.x, -3);
|
|
1698
|
+
}
|
|
1699
|
+
});
|
|
1700
|
+
|
|
1701
|
+
test('pose-only qualifying hello reserves pose across the normal group wait', () => keeping(advance => {
|
|
1702
|
+
const r = boot({ resumeArrivalPose: true });
|
|
1703
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick(); r.drop(); r.tick();
|
|
1704
|
+
advance(59900); r.back(); r.say('p2', { ...rehello, party: 2 }); r.tick();
|
|
1705
|
+
assert.equal(r.arrivedTimes('p2'), 1, 'normal group wait still applies');
|
|
1706
|
+
advance(1600); r.tick();
|
|
1707
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1708
|
+
assert.equal(r.world.players.get('p2').at.x, -3, 'accepted pose survives delayed arrival');
|
|
1709
|
+
}));
|
|
1710
|
+
|
|
1711
|
+
test('pose-only pending claims are discarded on identity replacement', () => keeping(advance => {
|
|
1712
|
+
const r = boot({ resumeArrivalPose: true });
|
|
1713
|
+
r.ctx().placeAt('p2', { x: -3, y: 1, z: -2 }, 40); r.tick(); r.drop(); r.tick();
|
|
1714
|
+
r.back(); r.say('p2', { ...rehello, party: 2 }); r.tick();
|
|
1715
|
+
r.session.players.find(p => p.playerId === 'p2').userId = '103';
|
|
1716
|
+
r.say('p2', { ...rehello, party: 2 });
|
|
1717
|
+
advance(1600); r.tick();
|
|
1718
|
+
assert.equal(r.arrivedTimes('p2'), 2);
|
|
1719
|
+
assert.notEqual(r.world.players.get('p2').at.x, -3);
|
|
1720
|
+
}));
|
|
1721
|
+
|
|
1722
|
+
test('pose-only transport leave exposes the ordinary live roster before physical removal', () => {
|
|
1723
|
+
let observed = null;
|
|
1724
|
+
const r = boot({ resumeArrivalPose: true }, { leave: (ctx, id) => { if (id === 'p2') observed = ctx.players(); } });
|
|
1725
|
+
r.session.players = r.session.players.filter(p => p.playerId !== 'p2');
|
|
1726
|
+
assert.equal(r.world.players.has('p2'), true);
|
|
1727
|
+
r.server.departed(r.session, { playerId: 'p2' });
|
|
1728
|
+
assert.ok(!observed.some(p => p.playerId === 'p2'));
|
|
1729
|
+
assert.equal(r.world.players.has('p2'), true, 'physical removal still belongs to real-time');
|
|
1730
|
+
assert.equal(boot().server.departed, undefined, 'absent mode adds no transport hook');
|
|
1731
|
+
});
|
|
1732
|
+
|
|
1733
|
+
console.log(`rehello: ${passed} tests passed`);
|