castle-web-cli 0.4.239 → 0.4.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +2 -0
  19. package/dist/platformDoc.js +3 -2
  20. package/dist/playPagePolicy.js +5 -1
  21. package/dist/resetLeaderboards.d.ts +8 -1
  22. package/dist/resetLeaderboards.js +43 -8
  23. package/dist/roomLogs.d.ts +1 -0
  24. package/dist/roomLogs.js +30 -6
  25. package/dist/save-deck.d.ts +32 -2
  26. package/dist/save-deck.js +240 -39
  27. package/kits/base/CLAUDE.md +1 -1
  28. package/kits/base/castle.json +1 -1
  29. package/kits/base/sdk/README.md +174 -6
  30. package/kits/base/sdk/analytics.d.ts +8 -0
  31. package/kits/base/sdk/analytics.js +92 -0
  32. package/kits/base/sdk/castle.d.ts +5 -1
  33. package/kits/base/sdk/castle.js +2 -0
  34. package/kits/base/sdk/commands.d.ts +48 -0
  35. package/kits/base/sdk/commands.js +1 -0
  36. package/kits/base/sdk/debugConsole.d.ts +17 -0
  37. package/kits/base/sdk/debugConsole.js +154 -0
  38. package/kits/base/sdk/experiments.js +24 -1
  39. package/kits/base/sdk/hostRetry.d.ts +7 -0
  40. package/kits/base/sdk/hostRetry.js +57 -0
  41. package/kits/base/sdk/hub.d.ts +20 -2
  42. package/kits/base/sdk/hub.js +99 -13
  43. package/kits/base/sdk/multiplayer.d.ts +2 -0
  44. package/kits/base/sdk/multiplayer.js +168 -26
  45. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  46. package/kits/base/sdk/reconnectBudget.js +41 -1
  47. package/kits/base/sdk/runtime.js +36 -19
  48. package/kits/base/sdk/server/hub.d.ts +19 -0
  49. package/kits/base/sdk/server/hub.js +12 -0
  50. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  51. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  52. package/kits/base/sdk/server/wrapper.js +26 -1
  53. package/kits/base/sdk/transport.d.ts +2 -1
  54. package/kits/base/sdk/transport.js +35 -0
  55. package/kits/hub-game/CLAUDE.md +66 -19
  56. package/kits/hub-game/code/client/act.js +9 -6
  57. package/kits/hub-game/code/client/actCore.js +26 -6
  58. package/kits/hub-game/code/client/actGateLog.js +36 -0
  59. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  60. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  61. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  62. package/kits/hub-game/code/client/askSurface.js +85 -0
  63. package/kits/hub-game/code/client/askTree.js +51 -0
  64. package/kits/hub-game/code/client/attention.js +31 -6
  65. package/kits/hub-game/code/client/ballot.js +42 -5
  66. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  67. package/kits/hub-game/code/client/ballotTree.js +180 -0
  68. package/kits/hub-game/code/client/catchingUp.js +19 -0
  69. package/kits/hub-game/code/client/celebrate.js +66 -0
  70. package/kits/hub-game/code/client/chrome.js +481 -57
  71. package/kits/hub-game/code/client/companion.js +93 -23
  72. package/kits/hub-game/code/client/companionDress.js +1 -1
  73. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  74. package/kits/hub-game/code/client/cornerTree.js +83 -0
  75. package/kits/hub-game/code/client/decor.js +20 -11
  76. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  77. package/kits/hub-game/code/client/disguise.js +23 -0
  78. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  79. package/kits/hub-game/code/client/dockSurface.js +206 -0
  80. package/kits/hub-game/code/client/dockTree.js +232 -0
  81. package/kits/hub-game/code/client/earned.js +29 -0
  82. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  83. package/kits/hub-game/code/client/emoteTree.js +264 -0
  84. package/kits/hub-game/code/client/farAvatars.js +4 -3
  85. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  86. package/kits/hub-game/code/client/grab.js +121 -50
  87. package/kits/hub-game/code/client/holdShow.js +19 -0
  88. package/kits/hub-game/code/client/hookLayer.js +96 -12
  89. package/kits/hub-game/code/client/hubControls.js +7 -1
  90. package/kits/hub-game/code/client/hudSurface.js +11 -3
  91. package/kits/hub-game/code/client/hudTree.js +7 -4
  92. package/kits/hub-game/code/client/idle.js +21 -3
  93. package/kits/hub-game/code/client/invites.js +24 -3
  94. package/kits/hub-game/code/client/keys.js +15 -0
  95. package/kits/hub-game/code/client/labelsNear.js +8 -1
  96. package/kits/hub-game/code/client/layoutCache.js +57 -8
  97. package/kits/hub-game/code/client/loadingCover.js +53 -4
  98. package/kits/hub-game/code/client/menuIcons.js +15 -0
  99. package/kits/hub-game/code/client/menuSurface.js +102 -0
  100. package/kits/hub-game/code/client/menuTree.js +135 -0
  101. package/kits/hub-game/code/client/modelLook.js +41 -0
  102. package/kits/hub-game/code/client/padCues.js +11 -7
  103. package/kits/hub-game/code/client/padReadability.js +3 -3
  104. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  105. package/kits/hub-game/code/client/pickerTree.js +163 -0
  106. package/kits/hub-game/code/client/pushVisit.js +4 -2
  107. package/kits/hub-game/code/client/quality.js +188 -29
  108. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  109. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  110. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  111. package/kits/hub-game/code/client/rehello.js +75 -0
  112. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  113. package/kits/hub-game/code/client/replay.js +118 -0
  114. package/kits/hub-game/code/client/role.js +3 -0
  115. package/kits/hub-game/code/client/safeLayout.js +441 -56
  116. package/kits/hub-game/code/client/safeStyle.js +13 -10
  117. package/kits/hub-game/code/client/say.js +2 -0
  118. package/kits/hub-game/code/client/soundSurface.js +77 -0
  119. package/kits/hub-game/code/client/soundTree.js +74 -0
  120. package/kits/hub-game/code/client/soundscape.js +12 -9
  121. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  122. package/kits/hub-game/code/client/state.js +67 -1
  123. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  124. package/kits/hub-game/code/client/stuckTree.js +67 -0
  125. package/kits/hub-game/code/client/talk.js +42 -12
  126. package/kits/hub-game/code/client/talkTree.js +4 -2
  127. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  128. package/kits/hub-game/code/client/textAskTree.js +67 -0
  129. package/kits/hub-game/code/client/tiers.js +252 -27
  130. package/kits/hub-game/code/client/together.js +4 -1
  131. package/kits/hub-game/code/client/uiDom.js +86 -8
  132. package/kits/hub-game/code/client/uiTree.js +33 -4
  133. package/kits/hub-game/code/client/vehicle.js +72 -51
  134. package/kits/hub-game/code/client/weakestTier.js +75 -31
  135. package/kits/hub-game/code/client/wear.js +159 -5
  136. package/kits/hub-game/code/client/worldLabels.js +205 -25
  137. package/kits/hub-game/code/companionSpec.js +4 -2
  138. package/kits/hub-game/code/server/act.js +3 -0
  139. package/kits/hub-game/code/server/actGate.js +83 -0
  140. package/kits/hub-game/code/server/actions.js +71 -15
  141. package/kits/hub-game/code/server/actors.js +20 -5
  142. package/kits/hub-game/code/server/analytics.js +35 -3
  143. package/kits/hub-game/code/server/ask.js +39 -3
  144. package/kits/hub-game/code/server/ballot.js +167 -4
  145. package/kits/hub-game/code/server/celebrate.js +64 -0
  146. package/kits/hub-game/code/server/companion.js +17 -2
  147. package/kits/hub-game/code/server/decor.js +11 -2
  148. package/kits/hub-game/code/server/disguise.js +63 -0
  149. package/kits/hub-game/code/server/earned.js +6 -2
  150. package/kits/hub-game/code/server/friendBests.js +13 -4
  151. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  152. package/kits/hub-game/code/server/grab.js +12 -2
  153. package/kits/hub-game/code/server/heldOffers.js +142 -0
  154. package/kits/hub-game/code/server/holdShow.js +98 -0
  155. package/kits/hub-game/code/server/hub.js +991 -72
  156. package/kits/hub-game/code/server/idle.js +110 -9
  157. package/kits/hub-game/code/server/index.js +9 -0
  158. package/kits/hub-game/code/server/labels.js +13 -3
  159. package/kits/hub-game/code/server/manifest.js +94 -6
  160. package/kits/hub-game/code/server/menu.js +26 -3
  161. package/kits/hub-game/code/server/npcs.js +55 -9
  162. package/kits/hub-game/code/server/observe.js +67 -6
  163. package/kits/hub-game/code/server/players.js +14 -2
  164. package/kits/hub-game/code/server/replay.js +135 -0
  165. package/kits/hub-game/code/server/standing.js +7 -3
  166. package/kits/hub-game/code/server/storageLimit.js +4 -1
  167. package/kits/hub-game/code/server/townDay.js +74 -0
  168. package/kits/hub-game/code/server/vehicle.js +3 -0
  169. package/kits/hub-game/code/server/vis.js +26 -4
  170. package/kits/hub-game/code/server/wallet.js +677 -0
  171. package/kits/hub-game/code/server/wear.js +13 -3
  172. package/kits/hub-game/code/server/writerLease.js +191 -0
  173. package/kits/hub-game/code/shared/act.js +1 -1
  174. package/kits/hub-game/code/shared/expression.js +6 -0
  175. package/kits/hub-game/code/shared/replay.js +37 -0
  176. package/kits/hub-game/code/systems/hub.js +429 -55
  177. package/kits/hub-game/docs/analytics.md +16 -2
  178. package/kits/hub-game/docs/contract.md +956 -101
  179. package/kits/hub-game/docs/home-pieces.md +5 -6
  180. package/kits/hub-game/docs/observed-progress.md +49 -1
  181. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  182. package/kits/hub-game/index.html +1 -0
  183. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  207. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  208. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  209. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  210. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  211. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  212. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  213. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  214. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  215. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  216. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  217. package/kits/hub-game/package-lock.json +3 -3
  218. package/kits/hub-game/package.json +4 -3
  219. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  220. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  221. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  222. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  223. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  224. package/kits/hub-game/scripts/pack.mjs +89 -23
  225. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  226. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  227. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  228. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  229. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  230. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  231. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  232. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  233. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  234. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  235. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  236. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  237. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  238. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  239. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  240. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  241. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  242. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  243. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  244. package/kits/hub-game/scripts/test-ballot.mjs +421 -4
  245. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  246. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  247. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  248. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  249. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  250. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  251. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  252. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  253. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  254. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  255. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  256. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  257. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  258. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  259. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  260. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  261. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  262. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  263. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  264. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  265. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  266. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  267. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  268. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  269. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  270. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  271. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  272. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  273. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  274. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  275. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  276. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  277. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  278. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  279. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  280. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  281. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  282. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  283. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  284. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  285. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  286. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  287. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  288. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  289. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  290. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  291. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  292. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  293. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  294. package/kits/hub-game/scripts/test-placeat-server.mjs +648 -0
  295. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  296. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  297. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  298. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  299. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  300. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  301. package/kits/hub-game/scripts/test-rehello.mjs +242 -3
  302. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  303. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  304. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  305. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  306. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  307. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  308. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  309. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  310. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  311. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  312. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  313. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  314. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  315. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  316. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  317. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  318. package/kits/hub-game/scripts/test-stuck.mjs +36 -1
  319. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  320. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  321. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  322. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  323. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  324. package/kits/hub-game/scripts/test-together.mjs +11 -0
  325. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  326. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  327. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  328. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  329. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  330. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  331. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  332. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  333. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  334. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  335. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  336. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  337. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  338. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  339. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  340. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  341. package/kits/multiplayer-3d/castle.json +5 -5
  342. package/kits/multiplayer-3d/code/client/resumeGate.js +66 -2
  343. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  344. package/kits/multiplayer-3d/code/server/world.js +19 -4
  345. package/kits/multiplayer-3d/code/systems/multiplayer.js +108 -18
  346. package/kits/multiplayer-3d/package-lock.json +1 -1
  347. package/kits/multiplayer-3d/package.json +2 -1
  348. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  349. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  350. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  351. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +417 -5
  352. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  353. package/kits/physics-2d/castle.json +2 -2
  354. package/kits/physics-2d/engine/scene.js +10 -2
  355. package/kits/physics-3d/CLAUDE.md +14 -0
  356. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  357. package/kits/physics-3d/castle.json +3 -3
  358. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  359. package/kits/physics-3d/docs/engine-player.md +76 -0
  360. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  361. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  362. package/kits/physics-3d/engine3d/gait.js +16 -8
  363. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  364. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  365. package/kits/physics-3d/engine3d/look.js +110 -17
  366. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  367. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  368. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  369. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  370. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  371. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  372. package/kits/physics-3d/engine3d/optimize.js +20 -9
  373. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  374. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  375. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  376. package/kits/physics-3d/engine3d/world3d.js +211 -17
  377. package/kits/physics-3d/package-lock.json +1 -1
  378. package/kits/physics-3d/package.json +2 -1
  379. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  380. package/kits/physics-3d/scripts/render.mjs +56 -8
  381. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  382. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  383. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  384. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  385. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  386. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  387. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  388. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  389. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  390. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  391. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  392. package/kits/physics-3d/systems/physics3d.js +59 -2
  393. package/kits/real-time/castle.json +2 -2
  394. package/kits/real-time/code/client/connection.js +3 -0
  395. package/package.json +2 -2
  396. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -0,0 +1,648 @@
1
+ // Real transport -> SDK wrapper -> real-time -> Rapier -> hub: a place's
2
+ // `hub.placeAt` wins over the move reports its client sent before it heard of
3
+ // the placement, and a leave right after one stores the placed pose.
4
+ //
5
+ // node scripts/test-placeat-server.mjs reports
6
+ // A client that goes on reporting its spawn for a while after the place
7
+ // moved it (its frames still on their way) still ends at the placed spot,
8
+ // server and client alike, and walks on from there as usual.
9
+ // node scripts/test-placeat-server.mjs walk | pinned | held | against
10
+ // A client that eases corrections as the shipped one does and walks on
11
+ // at full pace after placeAt is taken at once; a place putting a player
12
+ // where they stand every step arms nothing; a hold ends the wait.
13
+ // node scripts/test-placeat-server.mjs close
14
+ // A close in the same breath as the placement resumes the account's fresh
15
+ // socket at the placed spot, not where the last server step saw it.
16
+ // node scripts/test-placeat-server.mjs stepoff | restoreFree | restoreOccupied
17
+ // v1.218, on this ground-backed place (as the Town is): a lone joiner who
18
+ // finds someone on the spawn is placed off it; a returner whose stored pose
19
+ // nobody stands on is put back exactly there, and one whose pose is taken
20
+ // steps off it. Each in one server move, never dragged.
21
+ // node scripts/test-placeat-server.mjs arrivalFree | arrivalTaken
22
+ // The same with an arrival actor apart from the scene spawn: a joiner
23
+ // finding the spawn taken but the arrival free starts on the arrival; one
24
+ // finding the arrival taken starts beside it. Either way its first WORLD is
25
+ // the only move its client makes.
26
+ //
27
+ // With no argument both run.
28
+ import assert from 'node:assert/strict';
29
+ import { cp, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
30
+ import path from 'node:path';
31
+ import { fileURLToPath } from 'node:url';
32
+ import { WebSocket } from 'ws';
33
+ import { startDevSessionServer } from '../../../cli/dist/devSessionServer.js';
34
+
35
+ const root = fileURLToPath(new URL('../../../', import.meta.url));
36
+ const scratch = path.join(root, '.castle');
37
+ await mkdir(scratch, { recursive: true });
38
+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
39
+ const spawn = { x: 0, y: 1, z: 0 };
40
+ const cold = { x: 6, y: 1, z: 8 };
41
+ const user = { userId: '102', username: 'Bo', isAnonymous: false };
42
+ const other = { userId: '103', username: 'Cy', isAnonymous: false };
43
+ // Two capsule radii (the test scene's player has the default 0.35 m shape).
44
+ const TWO_RADII = 0.7;
45
+ // The arrival actor of the arrivalFree/arrivalTaken place: 2.5 m from the
46
+ // scene spawn, under the client's 4 m snap, so an eased correction would show.
47
+ const ARRIVAL = { x: 2, y: 1, z: 1.5 };
48
+ const ARRIVAL_CASES = new Set(['arrivalFree', 'arrivalTaken']);
49
+ const flat = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
50
+ const cases = { reports, close, walk, pinned, held, against, restoreReports, restorePreplaced, stepoff, restoreFree, restoreOccupied, arrivalFree, arrivalTaken };
51
+ const chosen = process.argv[2] ? [process.argv[2]] : Object.keys(cases);
52
+ for (const name of chosen) {
53
+ assert.ok(cases[name], `unknown case ${name}`);
54
+ await run(name, cases[name]);
55
+ }
56
+
57
+ async function run(name, body) {
58
+ const dir = await mkdtemp(path.join(scratch, 'placeat-'));
59
+ const logs = [];
60
+ const sockets = [];
61
+ let server;
62
+ try {
63
+ await mkdir(path.join(dir, 'imports'), { recursive: true });
64
+ for (const kit of ['base', 'hub-game', 'real-time', 'multiplayer-3d', 'physics-3d', 'physics-2d']) {
65
+ await cp(path.join(root, 'kits', kit), path.join(dir, 'imports', `castle.${kit}`), {
66
+ recursive: true,
67
+ filter: source => !['node_modules', 'imports', '.castle'].includes(path.basename(source)),
68
+ });
69
+ }
70
+ await symlink(path.join(root, 'kits/hub-game/node_modules'), path.join(dir, 'node_modules'));
71
+ await mkdir(path.join(dir, 'code/server'), { recursive: true });
72
+ await mkdir(path.join(dir, 'scenes'), { recursive: true });
73
+ await writeFile(path.join(dir, 'package.json'), JSON.stringify({ type: 'module', private: true }));
74
+ await writeFile(path.join(dir, 'castle.json'), JSON.stringify({
75
+ hub: { contract: 1, title: 'Resume pose boundary', resumePose: true,
76
+ ...(ARRIVAL_CASES.has(name) ? { arrival: { actor: 'arrival', spread: 1.5, face: 0 } } : {}) },
77
+ server: { main: 'code/server/main.js', tickRate: 20, maxPlayers: 8 },
78
+ }));
79
+ await writeFile(path.join(dir, 'scenes/main.scene'), JSON.stringify({ actors: [
80
+ { id: 'player', components: { Player: {}, Transform: { ...spawn } } },
81
+ ...(ARRIVAL_CASES.has(name) ? [{ id: 'arrival', components: { Transform: { ...ARRIVAL } } }] : []),
82
+ ] }));
83
+ // Local serve refuses storage to an unsaved deck: the session sees a
84
+ // revision-checked store kept in a file, so it outlives one session process.
85
+ await writeFile(path.join(dir, 'code/server/poseStorage.js'), `
86
+ import fs from 'node:fs';
87
+ const file = ${JSON.stringify(path.join(dir, 'pose-rows.json'))};
88
+ const load = () => { try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { rows: {}, revisions: {} }; } };
89
+ export function poseStorage() {
90
+ return {
91
+ async snapshot({ prefix }) {
92
+ const { rows, revisions } = load();
93
+ return { access: 'test-access', targets: [{ revision: revisions[prefix] ?? null,
94
+ rows: Object.fromEntries(Object.entries(rows).filter(([key]) => key.startsWith(prefix))) }] };
95
+ },
96
+ async transaction({ changes }) {
97
+ const state = load();
98
+ const { prefix, expectedRevision, replace } = changes[0];
99
+ if ((state.revisions[prefix] ?? null) !== expectedRevision) throw new Error('SAVE_CONFLICT');
100
+ for (const key of Object.keys(state.rows)) if (key.startsWith(prefix)) delete state.rows[key];
101
+ Object.assign(state.rows, structuredClone(replace));
102
+ const revision = process.pid + ':' + Date.now() + ':' + Math.random();
103
+ state.revisions[prefix] = revision;
104
+ fs.writeFileSync(file, JSON.stringify(state));
105
+ return { revisions: [{ revision }] };
106
+ },
107
+ async list({ prefix, limit }) {
108
+ const entries = Object.entries(load().rows).filter(([key]) => key.startsWith(prefix)).slice(0, limit);
109
+ return { entries: entries.map(([key, value]) => ({ key, value })), cursor: null };
110
+ },
111
+ };
112
+ }
113
+ `);
114
+ await writeFile(path.join(dir, 'code/server/main.js'), `
115
+ import callbacks from '@imports/castle.hub-game/code/server/index.js';
116
+ import { poseStorage } from './poseStorage.js';
117
+ const deck = poseStorage();
118
+ const seen = new WeakMap();
119
+ const wrap = (session) => {
120
+ if (!session || typeof session !== 'object') return session;
121
+ if (!seen.has(session)) {
122
+ seen.set(session, new Proxy(session, { get(target, key) {
123
+ if (key === 'storage') return { ...target.storage, deck };
124
+ const value = Reflect.get(target, key);
125
+ return typeof value === 'function' ? value.bind(target) : value;
126
+ } }));
127
+ }
128
+ return seen.get(session);
129
+ };
130
+ export default Object.fromEntries(Object.entries(callbacks).map(([key, value]) =>
131
+ [key, typeof value === 'function' ? (session, ...rest) => value(wrap(session), ...rest) : value]));
132
+ `);
133
+ await writeFile(path.join(dir, 'code/server/game.js'), `
134
+ // Server steps run: the kit records the pose a leave stores on a step.
135
+ let steps = 0;
136
+ // playerId -> { last, gap }: the longest the server went without taking a
137
+ // move report (its movedAt) since 'mark', in simulation ms.
138
+ const marks = new Map();
139
+ // A Dojo-like place: put the player where they stand, six steps running.
140
+ let pin = null;
141
+ let arrivalAt = null;
142
+ const paths = new Map();
143
+ let arrivalPlaced = 0;
144
+ export default {
145
+ arrive(h, group) {
146
+ if (arrivalAt) for (const p of group) { h.placeAt(p.playerId, arrivalAt, 40); arrivalPlaced++; }
147
+ },
148
+ step(h) {
149
+ steps += 1;
150
+ // Every place each body has stood, a new entry only when it moved.
151
+ for (const [id, body] of h.sim.players) {
152
+ const path = paths.get(id) ?? [];
153
+ const last = path.at(-1);
154
+ if (!last || Math.hypot(body.at.x - last.x, body.at.z - last.z) > 0.01) path.push({ ...body.at });
155
+ paths.set(id, path);
156
+ }
157
+ for (const [id, mark] of marks) {
158
+ const body = h.sim.players.get(id);
159
+ if (body && body.movedAt !== mark.last) { mark.gap = Math.max(mark.gap, body.movedAt - mark.last); mark.last = body.movedAt; }
160
+ }
161
+ if (pin && pin.n-- > 0) { const body = h.sim.players.get(pin.id); if (body) h.placeAt(pin.id, { ...body.at }); }
162
+ },
163
+ message(h, p, d) {
164
+ const id = p.playerId;
165
+ let body = h.sim.players.get(id);
166
+ if (d?.test === 'move') h.placeAt(id, ${JSON.stringify(cold)}, 40);
167
+ if (d?.test === 'prepare-restore') h.placeAt(id, d.at, 40);
168
+ if (d?.test === 'preplace-return') arrivalAt = d.at;
169
+ if (d?.test === 'shove') h.placeAt(id, { ...body.at, z: body.at.z + 1 });
170
+ if (d?.test === 'pin') pin = { id, n: 6 };
171
+ if (d?.test === 'back') h.placeAt(id, { ...body.at, x: body.at.x - 1.4 });
172
+ if (d?.test === 'hold-here') { h.placeAt(id, ${JSON.stringify(cold)}); h.hold(id, ${JSON.stringify(cold)}); }
173
+ if (d?.test === 'release') h.release(id);
174
+ if (d?.test === 'mark') marks.set(id, { last: body.movedAt, gap: 0 });
175
+ body = h.sim.players.get(id);
176
+ const mark = marks.get(id);
177
+ // clamped: false once the server took a report from where the body stands.
178
+ if (d?.test) h.send(id, { test: d.test, pose: body && { ...body.at }, facing: body?.facing, clamped: body?.clamped, steps,
179
+ arrivalPlaced, path: paths.get(id) ?? [],
180
+ others: [...h.sim.players].filter(([o]) => o !== id).map(([, b]) => ({ ...b.at })),
181
+ now: h.sim.timeMs, movedAt: body?.movedAt, arrivedAt: h.players().find(p => p.playerId === id)?.arrivedAt,
182
+ gap: mark && body ? Math.max(mark.gap, h.sim.timeMs - mark.last) : null });
183
+ },
184
+ };
185
+ `);
186
+ server = await startDevSessionServer({ projectDir: dir, log: (level, message) => logs.push(`${level}: ${message}`) });
187
+ await body({ dir, sockets, logs, server: () => server, restart: async () => {
188
+ await server.shutdown();
189
+ server = await startDevSessionServer({ projectDir: dir, log: (level, message) => logs.push(`${level}: ${message}`) });
190
+ return server;
191
+ } });
192
+ } catch (error) {
193
+ console.error(logs.join('\n'));
194
+ throw error;
195
+ } finally {
196
+ for (const socket of sockets) socket.terminate();
197
+ await server?.shutdown();
198
+ await rm(dir, { recursive: true, force: true });
199
+ }
200
+ }
201
+
202
+
203
+ // Arrive at the spawn and wait until the server takes the client's reports
204
+ // there (clamped false), so nothing about the arrival is still settling.
205
+ async function arrive(t, who = user, where = spawn) {
206
+ const server = t.server();
207
+ const a = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(who)}`);
208
+ await a.wait(f => f.t === 'hello');
209
+ a.send({ k: 'hub-hello', avatar: 0, party: 1 });
210
+ a.local = { ...spawn };
211
+ a.reporting = true;
212
+ await a.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
213
+ await world(a);
214
+ const agreed = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose, where) < 0.3);
215
+ assert.equal(agreed.clamped, false, `server takes the client's reports at the spawn ${JSON.stringify(agreed)}`);
216
+ // One step after that, so the leave has a pose from a step to fall back on.
217
+ await until(a, 'state', {}, s => s.steps > agreed.steps);
218
+ return a;
219
+ }
220
+
221
+ // The client keeps naming the spawn for 600 ms after asking to be moved,
222
+ // as a slow phone's reports still on their way do. Before the fix each such
223
+ // report pulled the body back toward the spawn (the movement clamp), and the
224
+ // clamped row sent back put the client there too, for good.
225
+ async function reports(t) {
226
+ const a = await arrive(t);
227
+ a.deafUntil = Date.now() + 600;
228
+ const moved = await query(a, 'move');
229
+ assert.ok(flat(moved.pose, cold) < 0.05, `placeAt moved the body ${JSON.stringify(moved)}`);
230
+ await sleep(700);
231
+ const at = s => s.clamped === false && flat(s.pose, cold) < 0.3;
232
+ const settled = await until(a, 'state', {}, at);
233
+ assert.ok(at(settled), `server body ends at the placed spot ${JSON.stringify(settled)}, client ${JSON.stringify(a.local)}`);
234
+ assert.ok(flat(a.local, cold) < 0.3, `client was put there too ${JSON.stringify(a.local)}`);
235
+ await sleep(1000);
236
+ const later = await query(a, 'state');
237
+ assert.ok(flat(later.pose, cold) < 0.3 && flat(a.local, cold) < 0.3, `both stay there ${JSON.stringify(later)}, client ${JSON.stringify(a.local)}`);
238
+ // Once caught up the client moves as usual: a step from the spot is taken.
239
+ a.local = { ...a.local, x: a.local.x + 1 };
240
+ const walked = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose, a.local) < 0.05);
241
+ assert.ok(walked.clamped === false && flat(walked.pose, a.local) < 0.05, `a walk from the spot is taken ${JSON.stringify(walked)}`);
242
+ // And the movement limit still holds: reports 30 m off are cut to its pace.
243
+ a.deafUntil = Date.now() + 10000;
244
+ const from = walked.pose;
245
+ a.local = { ...from, x: from.x + 30 };
246
+ await sleep(300);
247
+ const leapt = await query(a, 'state');
248
+ assert.ok(leapt.clamped === true && flat(leapt.pose, from) < 15, `a 30 m leap is still clamped ${JSON.stringify(leapt)}`);
249
+ console.log('test-placeat-server reports: placeAt wins over the reports already on their way');
250
+ }
251
+
252
+ // A player walking at full pace when the place shoves them a metre aside:
253
+ // the reports a client that eased part of the way there and walked on sends
254
+ // are taken. Before, each one more than 0.25 m off the spot was dropped, for
255
+ // the whole 4 s give-up, since an easing, walking client is never that near.
256
+ async function walk(t) {
257
+ const a = await arrive(t);
258
+ a.vel = { x: 6, z: 0 };
259
+ await sleep(300);
260
+ await query(a, 'mark');
261
+ await query(a, 'shove');
262
+ await sleep(1500);
263
+ const s = await query(a, 'state');
264
+ // One report every 50 ms; one dropped (sent before it heard) is a 100 ms gap.
265
+ assert.ok(s.gap < 200, `a walk after placeAt is taken at once: ${s.gap} ms without a report taken`);
266
+ assert.ok(s.clamped === false && flat(s.pose, a.local) < 1, `the body follows the walk ${JSON.stringify(s)}, client ${JSON.stringify(a.local)}`);
267
+ console.log('test-placeat-server walk: a walk right after placeAt is taken');
268
+ }
269
+
270
+ // Put 1.4 m back while walking on at 6 m/s the other way: an easing client's
271
+ // reports stay nearer the old pose than the spot. That rule only holds for the
272
+ // kit's in-flight window (500 ms), so a report is taken within it and one
273
+ // report interval. Before, every one was dropped for the 4 s give-up.
274
+ async function against(t) {
275
+ const a = await arrive(t);
276
+ a.vel = { x: 6, z: 0 };
277
+ await sleep(300);
278
+ await query(a, 'mark');
279
+ await query(a, 'back');
280
+ await sleep(1500);
281
+ const s = await query(a, 'state');
282
+ assert.ok(s.gap < 650, `a walk against placeAt is taken within the window: ${s.gap} ms without a report taken`);
283
+ assert.ok(s.clamped === false && flat(s.pose, a.local) < 1, `the body follows the walk ${JSON.stringify(s)}, client ${JSON.stringify(a.local)}`);
284
+ console.log('test-placeat-server against: a walk against placeAt is taken after the in-flight window');
285
+ }
286
+
287
+ // Dojo-like: the place puts a walking player where they stand, every step for
288
+ // six steps. That arms nothing. Before, each renewed a 4 s wait.
289
+ async function pinned(t) {
290
+ const a = await arrive(t);
291
+ a.vel = { x: 6, z: 0 };
292
+ await sleep(300);
293
+ await query(a, 'mark');
294
+ await query(a, 'pin');
295
+ await sleep(1500);
296
+ const s = await query(a, 'state');
297
+ assert.ok(s.gap < 200, `placeAt(where they stand) does not stop a walk: ${s.gap} ms without a report taken`);
298
+ assert.ok(s.clamped === false && flat(s.pose, a.local) < 1, `the body follows the walk ${JSON.stringify(s)}, client ${JSON.stringify(a.local)}`);
299
+ console.log('test-placeat-server pinned: repeated placeAt to the current pose arms nothing');
300
+ }
301
+
302
+ // placeAt, then a hold at the same spot, then release: the hold is a placement
303
+ // of its own and ends the placeAt's wait, so after the release the client's
304
+ // reports are taken as any held player's are (here still from the spawn, as
305
+ // it never heard). Before, the wait survived a hold at the same spot.
306
+ async function held(t) {
307
+ const a = await arrive(t);
308
+ a.deafUntil = Date.now() + 60000;
309
+ await query(a, 'hold-here');
310
+ await sleep(300);
311
+ await query(a, 'release');
312
+ await query(a, 'mark');
313
+ await sleep(500);
314
+ const s = await query(a, 'state');
315
+ assert.ok(s.gap < 200 && flat(s.pose, cold) > 1, `after hold and release reports are taken again: ${JSON.stringify(s)}`);
316
+ console.log('test-placeat-server held: a hold ends the placeAt wait');
317
+ }
318
+
319
+ // The close goes out in the same breath as the ask, so the leave comes before
320
+ // any server step has seen the body at the placed spot. Before the fix the
321
+ // leave stored the pose that step had recorded: the spawn.
322
+ async function close(t) {
323
+ const a = await arrive(t);
324
+ a.reporting = false;
325
+ a.local = { ...cold };
326
+ a.send({ test: 'move' });
327
+ a.socket.close();
328
+ await new Promise(resolve => a.socket.once('close', resolve));
329
+ const rowsFile = path.join(t.dir, 'pose-rows.json');
330
+ const rows = async () => { try { return JSON.parse(await readFile(rowsFile, 'utf8')).rows; } catch { return {}; } };
331
+ for (const end = Date.now() + 10000; !Object.keys(await rows()).length && Date.now() < end;) await sleep(50);
332
+ const stored = await rows();
333
+ assert.equal(Object.keys(stored).length, 1, `one durable row ${JSON.stringify(stored)}`);
334
+ const server = await t.restart();
335
+ const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(user)}`);
336
+ await b.wait(f => f.t === 'hello');
337
+ b.local = { ...spawn };
338
+ b.reporting = true;
339
+ b.send({ k: 'hub-hello', avatar: 0, party: 1 });
340
+ await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
341
+ await sleep(2000);
342
+ const after = (await query(b, 'state')).pose;
343
+ assert.ok(flat(after, cold) < 0.5, `fresh socket resumes at the placed spot: ${JSON.stringify(after)} (stored ${JSON.stringify(stored)})`);
344
+ assert.ok(flat(b.local, cold) < 0.5, `client was put there too ${JSON.stringify(b.local)}`);
345
+ console.log('test-placeat-server close: a leave right after placeAt stores the placed pose');
346
+ }
347
+
348
+ // A correction under 4 m is eased by the browser. A restored cold pose
349
+ // needs the same stale-report guard as placeAt while spawn reports arrive.
350
+ async function restoreReports(t, preplaced = false) {
351
+ const restoredAt = { ...spawn, z: spawn.z + 3.2 };
352
+ const a = await arrive(t);
353
+ a.reporting = false;
354
+ a.local = { ...restoredAt };
355
+ const placed = await query(a, 'prepare-restore', { at: restoredAt });
356
+ await until(a, 'state', {}, s => s.steps > placed.steps);
357
+ if (preplaced) await query(a, 'preplace-return', { at: restoredAt });
358
+ a.socket.close();
359
+ await new Promise(resolve => a.socket.once('close', resolve));
360
+ const rowsFile = path.join(t.dir, 'pose-rows.json');
361
+ const rows = async () => { try { return JSON.parse(await readFile(rowsFile, 'utf8')).rows; } catch { return {}; } };
362
+ for (const end = Date.now() + 10000; !Object.keys(await rows()).length && Date.now() < end;) await sleep(50);
363
+ assert.equal(Object.keys(await rows()).length, 1, 'the near-spawn pose was stored');
364
+ const server = preplaced ? t.server() : await t.restart();
365
+ if (preplaced) server.defaultSession.nextGuest = () => user;
366
+ const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(user)}`);
367
+ await b.wait(f => f.t === 'hello');
368
+ b.local = { ...spawn };
369
+ b.deafUntil = Date.now() + 10000;
370
+ b.send({ k: 'hub-hello', avatar: 0, party: 1 });
371
+ await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
372
+ const restored = await query(b, 'state');
373
+ assert.ok(flat(restored.pose, restoredAt) < 0.05, `cold pose restored 3.2 m from spawn: ${JSON.stringify(restored)}`);
374
+ if (preplaced) assert.equal(restored.arrivalPlaced, 1, 'the arrival hook placed the returner before the cold restore');
375
+ assert.ok(Number.isFinite(restored.arrivedAt), 'arrival and restore share the same simulation tick');
376
+ const report = at => b.send({ k: 'i', p: [at.x, at.y, at.z, 0], c: [], r: [], o: [] });
377
+ for (const z of [spawn.z, spawn.z + 0.1]) {
378
+ report({ ...spawn, z });
379
+ await sleep(50);
380
+ const s = await query(b, 'state');
381
+ assert.ok(s.now - restored.arrivedAt < 500, 'spawn-side reports exercise STALE_FROM_MS');
382
+ assert.ok(flat(s.pose, restoredAt) < 0.05, `stale reports leave the restored body in place: ${JSON.stringify(s)}`);
383
+ assert.equal(s.movedAt, restored.movedAt, 'a stale report is refused outright');
384
+ }
385
+ // A client that applied the correction can walk on immediately.
386
+ const onward = { ...restoredAt, z: restoredAt.z + 0.2 };
387
+ report(onward);
388
+ const walked = await until(b, 'state', {}, s => s.clamped === false && flat(s.pose, onward) < 0.05);
389
+ assert.ok(walked.clamped === false && flat(walked.pose, onward) < 0.05, `a walk from the restored spot is taken: ${JSON.stringify(walked)}`);
390
+ // Once one valid report is taken, even a reachable spawn-side report is
391
+ // ordinary movement. It would still be stale if the guard had survived.
392
+ await sleep(50);
393
+ const before = await query(b, 'state');
394
+ assert.ok(before.now - restored.arrivedAt < 500, 'guard release is tested inside STALE_FROM_MS');
395
+ report({ ...spawn, z: spawn.z + 1.2 });
396
+ const released = await until(b, 'state', {}, s => s.movedAt !== walked.movedAt);
397
+ assert.notEqual(released.movedAt, walked.movedAt, 'the valid walk ended the restore guard');
398
+ assert.ok(released.pose.z < onward.z - 0.1, 'the subsequent report moves the body');
399
+ console.log(`test-placeat-server ${preplaced ? 'restorePreplaced' : 'restoreReports'}: a 3.2 m cold restore${preplaced ? ' preceded by placeAt to the same pose' : ''} rejects stale spawn reports, takes a walk and ends its guard`);
400
+ }
401
+
402
+ async function restorePreplaced(t) {
403
+ await restoreReports(t, true);
404
+ }
405
+
406
+ // Every point of a path is where it started or where it ended: one move.
407
+ function oneMove(path, label) {
408
+ const [first, last] = [path[0], path.at(-1)];
409
+ const between = path.filter(p => flat(p, first) > 0.05 && flat(p, last) > 0.05);
410
+ assert.equal(between.length, 0, `${label} was moved in one step, not dragged: ${JSON.stringify(path)}`);
411
+ }
412
+
413
+ // A second lone joiner, as two accounts entering the Town one after the other.
414
+ // Before v1.218 a ground-backed place put both on the very spawn, where each
415
+ // client's capsule wedged under the other's avatar (Nov 17 Market check).
416
+ async function stepoff(t) {
417
+ const a = await arrive(t);
418
+ const server = t.server();
419
+ // The real order: the session sends the joiner's WORLD the tick after it
420
+ // admits them, before their hub-hello is heard. The client reports and takes
421
+ // corrections as the shipped one does (eased under 4 m, a WORLD at once).
422
+ const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(other)}`);
423
+ b.local = { ...spawn };
424
+ b.reporting = true;
425
+ await b.wait(f => f.t === 'hello');
426
+ await world(b);
427
+ b.send({ k: 'hub-hello', avatar: 0, party: 1 });
428
+ await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
429
+ await sleep(600);
430
+ const sb = await query(b, 'state');
431
+ const sa = await query(a, 'state');
432
+ assert.ok(flat(sa.pose, spawn) < 0.3, `the first player stays on the spawn ${JSON.stringify(sa.pose)}`);
433
+ const gap = flat(sb.pose, sa.pose);
434
+ assert.ok(gap >= TWO_RADII, `the joiner is placed off the occupied spawn: ${gap.toFixed(3)} m ${JSON.stringify(sb.pose)}`);
435
+ assert.ok(b.worldAt && flat(b.worldAt, sb.pose) < 0.05, `the joiner's WORLD already put it there: ${JSON.stringify(b.worldAt)} vs ${JSON.stringify(sb.pose)}`);
436
+ // On the client: the scene spawn it started from, then the WORLD spot, and
437
+ // nothing between or after (no eased correction, no glide).
438
+ assert.ok(b.path.length >= 1 && flat(b.path.at(-1), sb.pose) < 0.05 &&
439
+ b.path.every(p => flat(p, spawn) < 0.05 || flat(p, sb.pose) < 0.05), `the client moved once, straight to the spot: ${JSON.stringify(b.path)}`);
440
+ oneMove(sb.path, 'the joiner');
441
+ console.log(`test-placeat-server stepoff: a lone joiner on an occupied spawn starts ${gap.toFixed(2)} m off it with its WORLD, and stays`);
442
+ }
443
+
444
+ // A second joiner on a place whose arrival actor (ARRIVAL) stands apart from
445
+ // the scene spawn. Reports and corrections on, WORLD before hello.
446
+ async function joinSecond(t) {
447
+ const server = t.server();
448
+ const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(other)}`);
449
+ b.local = { ...spawn };
450
+ b.reporting = true;
451
+ await b.wait(f => f.t === 'hello');
452
+ await world(b);
453
+ b.send({ k: 'hub-hello', avatar: 0, party: 1 });
454
+ await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
455
+ await sleep(600);
456
+ const s = await query(b, 'state');
457
+ assert.ok(b.worldAt && flat(b.worldAt, s.pose) < 0.05, `the joiner's WORLD already put it where it arrived: ${JSON.stringify(b.worldAt)} vs ${JSON.stringify(s.pose)}`);
458
+ assert.ok(flat(b.path.at(-1), s.pose) < 0.05 && b.path.every(p => flat(p, spawn) < 0.05 || flat(p, s.pose) < 0.05),
459
+ `the client moved once, straight to the spot: ${JSON.stringify(b.path)}`);
460
+ oneMove(s.path, 'the joiner');
461
+ return s;
462
+ }
463
+
464
+ // The scene spawn is taken, the arrival is free: the joiner starts on the
465
+ // arrival, not beside the spawn.
466
+ async function arrivalFree(t) {
467
+ const a = await arrive(t, user, ARRIVAL);
468
+ a.local = { ...spawn };
469
+ await query(a, 'prepare-restore', { at: spawn });
470
+ const there = await until(a, 'state', {}, s => s.clamped === false && flat(s.pose, spawn) < 0.05);
471
+ assert.ok(flat(there.pose, spawn) < 0.05, `the first player stands on the scene spawn ${JSON.stringify(there.pose)}`);
472
+ const s = await joinSecond(t);
473
+ assert.ok(flat(s.pose, ARRIVAL) < 0.01, `the joiner is on the arrival ${JSON.stringify(s.pose)}`);
474
+ console.log('test-placeat-server arrivalFree: spawn taken, arrival free: the joiner starts on the arrival');
475
+ }
476
+
477
+ // The arrival is taken, the scene spawn is free: the joiner starts beside the
478
+ // arrival with its WORLD, not on the spawn to be moved later.
479
+ async function arrivalTaken(t) {
480
+ const a = await arrive(t, user, ARRIVAL);
481
+ const sa = await query(a, 'state');
482
+ assert.ok(flat(sa.pose, ARRIVAL) < 0.05, `the first player stands on the arrival ${JSON.stringify(sa.pose)}`);
483
+ const s = await joinSecond(t);
484
+ const gap = flat(s.pose, sa.pose);
485
+ assert.ok(gap >= TWO_RADII && gap <= 1.6, `the joiner is beside the arrival: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
486
+ console.log(`test-placeat-server arrivalTaken: arrival taken, spawn free: the joiner starts ${gap.toFixed(2)} m beside the arrival`);
487
+ }
488
+
489
+ // Stores `user`'s pose at `at` (a leave stores it) and starts a fresh session.
490
+ async function storePose(t, at) {
491
+ const a = await arrive(t);
492
+ a.reporting = false;
493
+ a.local = { ...at };
494
+ const placed = await query(a, 'prepare-restore', { at });
495
+ await until(a, 'state', {}, s => s.steps > placed.steps);
496
+ a.socket.close();
497
+ await new Promise(resolve => a.socket.once('close', resolve));
498
+ const rowsFile = path.join(t.dir, 'pose-rows.json');
499
+ const rows = async () => { try { return JSON.parse(await readFile(rowsFile, 'utf8')).rows; } catch { return {}; } };
500
+ for (const end = Date.now() + 10000; !Object.keys(await rows()).length && Date.now() < end;) await sleep(50);
501
+ assert.equal(Object.keys(await rows()).length, 1, 'the pose was stored');
502
+ return t.restart();
503
+ }
504
+
505
+ // The returner, deaf so only the server moves its body. The dev server gives
506
+ // the author's identity to the first socket only; a later one is a guest, so
507
+ // the returner is named as that guest (as restorePreplaced does).
508
+ async function rejoin(t, server) {
509
+ server.defaultSession.nextGuest = () => user;
510
+ const b = await connect(t.sockets, `ws://127.0.0.1:${server.port}/__castle/mp?nonce=${server.mintNonce(user)}`);
511
+ await b.wait(f => f.t === 'hello');
512
+ b.local = { ...spawn };
513
+ b.deafUntil = Date.now() + 60000;
514
+ b.send({ k: 'hub-hello', avatar: 0, party: 1 });
515
+ await b.wait(f => f.t === 'm' && f.d?.k === 'hub-arrived');
516
+ await sleep(300);
517
+ return query(b, 'state');
518
+ }
519
+
520
+ // Someone else in the place, but not on the stored pose: it is restored exactly.
521
+ async function restoreFree(t) {
522
+ const at = { ...spawn, x: spawn.x + 2.5, z: spawn.z + 3.2 };
523
+ const server = await storePose(t, at);
524
+ const c = await arrive(t, other);
525
+ const s = await rejoin(t, server);
526
+ assert.ok(flat(s.pose, at) < 0.01 && Math.abs(s.pose.y - at.y) < 0.01, `a free stored pose is restored exactly: ${JSON.stringify(s.pose)} vs ${JSON.stringify(at)}`);
527
+ // prepare-restore's placeAt faced the player 40 degrees.
528
+ assert.ok(Math.abs(s.facing - 40 * Math.PI / 180) < 1e-6, `and its facing: ${s.facing}`);
529
+ assert.ok(flat((await query(c, 'state')).pose, spawn) < 0.3, 'the other player stays on the spawn');
530
+ oneMove(s.path, 'the returner');
531
+ console.log('test-placeat-server restoreFree: a free stored pose on a ground-backed place is restored exactly');
532
+ }
533
+
534
+ // Someone standing on the stored pose: the returner steps off it.
535
+ async function restoreOccupied(t) {
536
+ const at = { ...spawn, x: spawn.x + 2.5, z: spawn.z + 3.2 };
537
+ const server = await storePose(t, at);
538
+ const c = await arrive(t, other);
539
+ c.local = { ...at };
540
+ await query(c, 'prepare-restore', { at });
541
+ const there = await until(c, 'state', {}, s => s.clamped === false && flat(s.pose, at) < 0.05);
542
+ assert.ok(flat(there.pose, at) < 0.05, `the other player stands on the stored pose ${JSON.stringify(there.pose)}`);
543
+ const s = await rejoin(t, server);
544
+ const gap = flat(s.pose, there.pose);
545
+ assert.ok(gap >= TWO_RADII, `the returner steps off the occupied pose: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
546
+ assert.ok(gap <= 1, `beside its own pose, not sent back to the spawn: ${gap.toFixed(3)} m ${JSON.stringify(s.pose)}`);
547
+ assert.ok(flat(s.pose, spawn) > 2, `not at the spawn ${JSON.stringify(s.pose)}`);
548
+ oneMove(s.path, 'the returner');
549
+ console.log(`test-placeat-server restoreOccupied: a returner whose pose is taken is put ${gap.toFixed(2)} m off it, in one move`);
550
+ }
551
+
552
+ // The client's starting WORLD (the frame that places its body; see connect).
553
+ function world(client) {
554
+ return client.wait(f => f.t === 'm' && [].concat(f.d?.batch ?? f.d).some(d => d?.k === 'w' && !d.again));
555
+ }
556
+ // Asks again until `done` holds or the deadline passes, then returns the last
557
+ // answer, so the caller's assertion still decides (and fails) on it.
558
+ async function until(client, test, extra, done, ms = 10000) {
559
+ const deadline = Date.now() + ms;
560
+ let answer = await query(client, test, extra);
561
+ while (!done(answer) && Date.now() < deadline) {
562
+ await sleep(50);
563
+ answer = await query(client, test, extra);
564
+ }
565
+ return answer;
566
+ }
567
+ async function query(client, test, extra = {}) {
568
+ client.send({ test, ...extra });
569
+ return (await client.wait(f => f.t === 'm' && f.d?.test === test)).d;
570
+ }
571
+ function trackPath(client) {
572
+ const last = client.path.at(-1);
573
+ if (client.local && (!last || flat(last, client.local) > 0.01)) client.path.push({ ...client.local });
574
+ }
575
+
576
+ async function connect(sockets, url) {
577
+ const socket = new WebSocket(url);
578
+ sockets.push(socket);
579
+ const frames = [];
580
+ const client = {
581
+ socket,
582
+ selfId: null,
583
+ local: null,
584
+ reporting: false,
585
+ deafUntil: 0,
586
+ vel: { x: 0, z: 0 },
587
+ clampedTo: null,
588
+ // Every place the client's body stood (a new entry when it moved over
589
+ // 1 cm), and where its first WORLD put it.
590
+ path: [],
591
+ worldAt: null,
592
+ send: d => socket.send(JSON.stringify({ t: 'm', d })),
593
+ async wait(predicate) {
594
+ const deadline = Date.now() + 10000;
595
+ while (Date.now() < deadline) {
596
+ const index = frames.findIndex(predicate);
597
+ if (index >= 0) return frames.splice(index, 1)[0];
598
+ await sleep(20);
599
+ }
600
+ throw Error('multiplayer frame timed out');
601
+ },
602
+ };
603
+ // The browser's multiplayer system: the starting WORLD places the body, a
604
+ // clamped self row corrects it, nothing else moves it; it reports at 20 Hz.
605
+ socket.on('message', (data, binary) => {
606
+ if (binary) return;
607
+ const frame = JSON.parse(data);
608
+ if (frame.t === 'hello') client.selfId = frame.playerId;
609
+ for (const d of frame.t === 'm' ? [].concat(frame.d?.batch ?? frame.d) : []) {
610
+ for (const [id, x, y, z, , clamped] of d?.ps ?? []) {
611
+ // A deaf client stands for one whose frames are still on their way.
612
+ if (id === client.selfId && d.k === 'w' && !d.again && !client.worldAt) client.worldAt = { x, y, z };
613
+ if (Date.now() < client.deafUntil || id !== client.selfId || !client.local) continue;
614
+ if (d.k === 'w' && !d.again) client.local = { x, y, z };
615
+ else if (clamped) client.clampedTo = { x, y, z };
616
+ }
617
+ }
618
+ frames.push(frame);
619
+ trackPath(client);
620
+ });
621
+ // Its frames, as multiplayer-3d's client runs them: walk at `vel`, then take
622
+ // the newest clamped row, at once from over CLAMP_SNAP (4 m) and otherwise
623
+ // CLAMP_EASE (a quarter) of the way, once per row.
624
+ let frameAt = Date.now();
625
+ const frameTimer = setInterval(() => {
626
+ const now = Date.now();
627
+ const dt = (now - frameAt) / 1000;
628
+ frameAt = now;
629
+ if (!client.local) return;
630
+ client.local = { ...client.local, x: client.local.x + client.vel.x * dt, z: client.local.z + client.vel.z * dt };
631
+ const to = client.clampedTo;
632
+ client.clampedTo = null;
633
+ if (!to) return;
634
+ const off = { x: to.x - client.local.x, y: to.y - client.local.y, z: to.z - client.local.z };
635
+ client.local = Math.hypot(off.x, off.y, off.z) > 4 ? { ...to }
636
+ : { x: client.local.x + off.x * 0.25, y: client.local.y + off.y * 0.25, z: client.local.z + off.z * 0.25 };
637
+ trackPath(client);
638
+ }, 16);
639
+ socket.on('close', () => clearInterval(frameTimer));
640
+ const timer = setInterval(() => {
641
+ if (client.reporting && client.local && socket.readyState === 1) {
642
+ client.send({ k: 'i', p: [client.local.x, client.local.y, client.local.z, 0], c: [], r: [], o: [] });
643
+ }
644
+ }, 50);
645
+ socket.on('close', () => clearInterval(timer));
646
+ await new Promise((resolve, reject) => { socket.once('open', resolve); socket.once('error', reject); });
647
+ return client;
648
+ }
@@ -420,7 +420,7 @@ const hubSource = readFileSync(new URL('../code/systems/hub.js', import.meta.url
420
420
  const node = { style: {}, getBoundingClientRect: () => ({ left: 0, right: 100, top, bottom: top + 24, width: 100, height: 24 }) };
421
421
  geometry.register(node); geometry.beginFrame(); top = 80;
422
422
  const context = {
423
- applyVisibility() {}, applyWear() {}, applyCars() {},
423
+ applyVisibility() {}, applyWear() {}, applyCars() {}, applyDisguise() {},
424
424
  fadeNames() {assert.equal(geometry.rect(node).top, 20, 'late crowd geometry uses the read-phase sample');},
425
425
  endLayoutFrame() {geometry.endFrame();},
426
426
  };