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
@@ -22,15 +22,21 @@ import * as Blocks from './blocks.js';
22
22
  import * as Cabinets from './cabinets.js';
23
23
  import * as Grab from './grab.js';
24
24
  import * as Act from './act.js';
25
+ import * as ActGate from './actGate.js';
25
26
  import * as Idle from './idle.js';
26
27
  import * as Vehicle from './vehicle.js';
28
+ import * as Disguise from './disguise.js';
29
+ import * as TownDay from './townDay.js';
30
+ import * as Replay from './replay.js';
27
31
  import * as Decor from './decor.js';
28
32
  import * as Actions from './actions.js';
29
33
  import * as Invites from './invites.js';
30
34
  import * as Companion from './companion.js';
31
35
  import * as Ask from './ask.js';
32
36
  import * as Menu from './menu.js';
37
+ import * as HeldOffers from './heldOffers.js';
33
38
  import * as Cues from './cues.js';
39
+ import * as Celebrate from './celebrate.js';
34
40
  import * as Shot from './shot.js';
35
41
  import * as Vis from './vis.js';
36
42
  import * as Yours from './yours.js';
@@ -44,13 +50,16 @@ import * as Say from './say.js';
44
50
  import * as Ballot from './ballot.js';
45
51
  import * as Wear from './wear.js';
46
52
  import * as Role from './role.js';
53
+ import * as HoldShow from './holdShow.js';
47
54
  import * as Earned from './earned.js';
48
55
  import * as Analytics from './analytics.js';
49
56
  import * as DoorAnalytics from './doorAnalytics.js';
50
57
  import * as LoadAbandon from './loadAbandon.js';
51
58
  import * as ResumePose from './resumePose.js';
59
+ import * as WriterLease from './writerLease.js';
52
60
  import * as ArrivalPose from './arrivalPose.js';
53
61
  import * as Observe from './observe.js';
62
+ import * as Wallet from './wallet.js';
54
63
  import { makeAnonymousEntry } from './anonymousEntry.js';
55
64
  import { doorPoint } from '../client/doorFrame.js';
56
65
 
@@ -141,6 +150,14 @@ const USER_ID = /^\d{1,20}$/;
141
150
  // A scene with implicit ground needs it too: that finite floor has an edge.
142
151
  const DEFAULT_FALL_Y = -20;
143
152
 
153
+ // Half the side of the server's ground slab: `ground.half` clamped to 1..200,
154
+ // else 100 (multiplayer-3d world.js `colliderHalf`, whose rule this repeats:
155
+ // that function is not exported).
156
+ function groundHalf(setting) {
157
+ const half = setting?.half;
158
+ return typeof half === 'number' && Number.isFinite(half) ? Math.min(200, Math.max(1, half)) : 100;
159
+ }
160
+
144
161
  function hasHook(deckHooks, placeHooks, name) {
145
162
  return typeof deckHooks?.[name] === 'function' || Object.values(placeHooks ?? {}).some((hooks) => typeof hooks?.[name] === 'function');
146
163
  }
@@ -198,17 +215,30 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
198
215
  ...(manifest.act === true || Object.values(manifest.places).some(place => place.resumeArrivalPose === true) ? {
199
216
  departed(session, player) {
200
217
  if (h.manifest.act === true) {Act.forget(h, player.playerId);}
218
+ if (h.place?.actGateLog === true) {ActGate.forget(h, player.playerId, userIdOf(h, player.playerId));}
201
219
  if (h.place?.resumeArrivalPose !== true || !h.sim || !h.players.has(player.playerId)) {return;}
202
220
  h.session = session;
203
221
  forget(h, player.playerId);
204
222
  },
205
223
  } : {}),
224
+ // v1.163: a transport leave ends a player's recording and ghosts at once,
225
+ // even when real-time keeps the body for a rejoin before the next tick.
226
+ // Nothing is held or sent for a player who never had either.
227
+ replayDeparted(session, player) {
228
+ if (h.recordings?.has(player.playerId) || h.replays?.has(player.playerId)) {Replay.forget(h, player.playerId);}
229
+ },
206
230
  // v1.138: load-abandoned connections follow the transport's own join,
207
231
  // leave and tick (`index.js`), which run before the simulation exists.
208
- ...(manifest.places[Manifest.MAIN_PLACE]?.loadTelemetry === true ? {
209
- transportJoin(session, player) {LoadAbandon.join(h, session, player?.playerId);},
210
- transportLeave(session, player) {LoadAbandon.leave(h, player?.playerId);},
211
- transportTick() {LoadAbandon.tick(h);},
232
+ ...(manifest.places[Manifest.MAIN_PLACE]?.loadTelemetry === true || Object.values(manifest.places).some(place => place.writerLease === true) ? {
233
+ transportJoin(session, player) {
234
+ if (manifest.places[Manifest.MAIN_PLACE]?.loadTelemetry === true) {LoadAbandon.join(h, session, player?.playerId);}
235
+ syncWriterVisits(h);
236
+ },
237
+ transportLeave(session, player) {
238
+ if (manifest.places[Manifest.MAIN_PLACE]?.loadTelemetry === true) {LoadAbandon.leave(h, player?.playerId);}
239
+ syncWriterVisits(h);
240
+ },
241
+ transportTick() {if (manifest.places[Manifest.MAIN_PLACE]?.loadTelemetry === true) {LoadAbandon.tick(h);}},
212
242
  } : {}),
213
243
  persist: false,
214
244
  poseEvery,
@@ -216,12 +246,16 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
216
246
 
217
247
  sceneFor(session) {
218
248
  const previousSession = h.session;
249
+ if (previousSession && previousSession !== session) {Replay.end(h);}
219
250
  h.session = session;
220
251
  const { id, source } = Place.resolvePlace(session, manifest);
221
252
  if (h.manifest.act === true && (h.placeId !== id || previousSession !== session)) {delete h.actPlayers;}
253
+ if (h.placeId !== id || previousSession !== session) {Celebrate.clear(h);}
222
254
  h.placeId = id;
223
255
  h.place = manifest.places[id];
224
256
  h.hooks = placeHooks[id] ?? deckHooks;
257
+ h.writerLease ??= WriterLease.create(session, h.place.writerLease === true);
258
+ syncWriterVisits(h);
225
259
  if (h.place.anonymousEntry === true) {
226
260
  h.anonymousEntry ??= makeAnonymousEntry();
227
261
  } else {
@@ -264,10 +298,12 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
264
298
  h.ctx.companion = (playerId, spec) => Companion.set(h, playerId, spec);
265
299
  h.ctx.companionDress = true;
266
300
  h.ctx.companionPose = true;
301
+ h.ctx.companionShown = true;
267
302
  } else {
268
303
  delete h.ctx.companion;
269
304
  delete h.ctx.companionDress;
270
305
  delete h.ctx.companionPose;
306
+ delete h.ctx.companionShown;
271
307
  }
272
308
  if (h.place.ask === true) {
273
309
  h.ctx.ask = (playerId, spec) => Ask.set(h, playerId, spec);
@@ -280,6 +316,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
280
316
  delete h.ctx.menu;
281
317
  }
282
318
  h.noGround = sceneGround(h.place.scene)?.none === true;
319
+ h.groundHalf = h.noGround ? 0 : groundHalf(sceneGround(h.place.scene));
283
320
  h.fallY = h.place.fallY ?? DEFAULT_FALL_Y;
284
321
  console.log(`[hub] place ${id} (${source}): ${h.place.scene}`);
285
322
  return h.place.scene;
@@ -291,12 +328,39 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
291
328
  return h.sim === sim && h.place ? standingY(h, at) : at.y;
292
329
  },
293
330
 
331
+ // v1.218: a body admitted with no pose (players.js puts it on the scene
332
+ // spawn, `at`) where another body stands, at the spawn or at the slot its
333
+ // lone arrival would take, starts where that arrival will put it instead,
334
+ // before its WORLD goes out: that snapshot is then the one placement its
335
+ // client makes, at once. That is the arrival slot when it is free, else
336
+ // the free spot beside it the arrival would step off to (`loneSlot`, the
337
+ // search `placeGroup` makes). Null when neither is taken (the arrival
338
+ // places it as before), or when nowhere is free (it shares the spawn, as
339
+ // before v1.218, and the arrival row is its only way off).
340
+ joinSpot(sim, playerId, at) {
341
+ if (h.sim !== sim || !h.place) {return null;}
342
+ const others = othersAt(h, [playerId]);
343
+ const slot = loneSlot(h);
344
+ if (!others.some((p) => takes(h, p, at) || takes(h, p, slot.standing))) {return null;}
345
+ const spot = others.some((p) => takes(h, p, slot.standing)) ? slot.stepOff(others) : slot.standing;
346
+ if (spot) {h.joinedOff.set(playerId, { ...spot });}
347
+ return spot;
348
+ },
349
+
294
350
  ready(sim) {
295
351
  h.sim = sim;
296
352
  h.actors = Scene.readScene(sim.scenePath);
353
+ const marked = new Set((Scene.sceneOptions?.(sim.scenePath)?.actors ?? []).filter((actor) => actor.decor === true).map((actor) => actor.id));
354
+ const decor = new Set(h.actors.filter((actor) => marked.has(actor.id) && classify(actor.components) === 'decor').map((actor) => actor.id));
297
355
  if (h.manifest.quality) {
298
- const decor = new Set((Scene.sceneOptions?.(sim.scenePath)?.actors ?? []).filter((actor) => actor.decor === true).map((actor) => actor.id));
299
- h.qualityDecor = new Set(h.actors.filter((actor) => decor.has(actor.id) && classify(actor.components) === 'decor').map((actor) => actor.id));
356
+ h.qualityDecor = decor;
357
+ delete h.doorDecor;
358
+ } else {
359
+ // v1.197: a deck with no quality block of its own (a game behind a
360
+ // Town's door) names its decor templates apart, in `hubDecorTpl`, so
361
+ // the Town's Low cap can count their copies; an older client ignores it.
362
+ delete h.qualityDecor;
363
+ h.doorDecor = decor.size ? decor : null;
300
364
  }
301
365
  if (Scene.sceneOptions?.(sim.scenePath)?.engine?.hubPadOccupancy === true) {
302
366
  h.padOccupancy = makePadOccupancy(h.actors);
@@ -330,6 +394,9 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
330
394
  // read when the player gets a body.
331
395
  message(session, player, data) {
332
396
  h.session ??= session;
397
+ // v1.179: a keepAway place notes an account change on a player id the
398
+ // moment any of their messages shows it (a hello among them).
399
+ if (h.place?.ballot?.keepAway === true && h.ballotSeen) {Ballot.observe(h, ballotDeps(h), player?.playerId);}
333
400
  if (h.place?.fpsTelemetry && data?.k === 'hub-fps') {Analytics.fps(h, session, player, data); return;}
334
401
  if (h.place?.loadTelemetry === true && data?.k === 'hub-load') {LoadAbandon.message(h, session, player, data); return;}
335
402
 
@@ -374,9 +441,25 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
374
441
  noTrips(h, session, player);
375
442
  return;
376
443
  }
444
+ // v1.169: said once, and touches no progress; a stay that comes during a
445
+ // progress read waits for it (`stay`), as one before arrival does.
446
+ if (data?.k === 'hub-stay') {
447
+ stay(h, player, data);
448
+ return;
449
+ }
450
+ // v1.173: consumed by the kit in every place, never the place's hook;
451
+ // touches no progress, so it is heard during a progress read too.
452
+ if (data?.k === 'hub-back') {
453
+ backOut(h, player);
454
+ return;
455
+ }
377
456
  // A reset check is in flight. Old client actions must not recreate the
378
457
  // player's deleted progress before the deck has reloaded it.
379
- if (h.players.get(player?.playerId)?.progressReading) { return; }
458
+ // v1.204: what touches no progress is heard during the read too.
459
+ if (h.players.get(player?.playerId)?.progressReading && !progressFree(h, data)) {
460
+ droppedDuringProgress(h, player.playerId);
461
+ return;
462
+ }
380
463
  if (data?.k === 'hub-shut') {
381
464
  doorShut(h, player, data);
382
465
  return;
@@ -414,7 +497,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
414
497
  // v1.68: only a place that declares `ballot` knows the message; in any
415
498
  // other it goes on to the place's own hooks, as it always did.
416
499
  if (h.place?.ballot && data?.k === 'hub-ballot') {
417
- Ballot.message(h, player, data, h.place.ballot.lines);
500
+ Ballot.message(h, player, data, h.place.ballot.lines, h.place.ballot.keepAway === true ? ballotDeps(h) : undefined);
418
501
  return;
419
502
  }
420
503
  if (data?.k === 'hub-dev-classic') {
@@ -440,6 +523,11 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
440
523
  Menu.message(h, player?.playerId, data);
441
524
  return;
442
525
  }
526
+ // v1.203: advisory only, a stdout line and nothing else.
527
+ if (h.place?.actGateLog === true && data?.k === 'hub-gate') {
528
+ ActGate.message(h, player, data, userIdOf(h, player?.playerId));
529
+ return;
530
+ }
443
531
  if (h.manifest.act === true && (data?.k === 'hub-act' || data?.k === 'hub-act-hold')) {
444
532
  Act.message(h, player, data, placeAt);
445
533
  return;
@@ -478,8 +566,11 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
478
566
  logStats(h);
479
567
  const dt = h.lastPlaceAt === null ? 0 : Math.min(0.25, (sim.timeMs - h.lastPlaceAt) / 1000);
480
568
  h.lastPlaceAt = sim.timeMs;
569
+ Replay.tick(h);
481
570
  reconcile(h);
482
571
  if (Role.used(h)) { Role.prune(h); }
572
+ if (h.holdShowUsed) { HoldShow.prune(h); }
573
+ if (h.disguiseUsed) {Disguise.prune(h);}
483
574
  Friends.tick(h, friendUserIdOf);
484
575
  // v1.28: a try-on on a player who went before saying hello goes too.
485
576
  if (Wear.tryOnUsed(h)) {
@@ -491,6 +582,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
491
582
  }
492
583
  retryProgress(h);
493
584
  readResults(h);
585
+ releaseSignUpHolds(h);
494
586
  arrivals(h);
495
587
  if (h.place.visibility === true) {notifyVisibility(h);}
496
588
  Vehicle.tick(h, (id, at, face) => placeAt(h, id, at, face));
@@ -518,7 +610,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
518
610
  // replacement cancels the queued preparation before either hook runs.
519
611
  cancelChangedResumeIdentity(h);
520
612
  const resumeDeferred = notifyResumes(h, true);
613
+ Replay.tick(h);
521
614
  h.hooks.step?.(h.ctx, dt);
615
+ Celebrate.tick(h);
616
+ liftStayHolds(h);
522
617
  rememberResumePoses(h);
523
618
  if (h.arrivalPoses) {
524
619
  for (const [id, entry] of h.players) {
@@ -536,8 +631,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
536
631
  h.renewShots?.();
537
632
  Actors.flushTints(h);
538
633
  sendHudOverrides(h);
539
- // v1.68: nothing in a place that has never shown a choice card.
540
- if (h.ballotState) {
634
+ // v1.68: nothing in a place that has never shown a choice card. v1.179:
635
+ // a `ballot.keepAway` place also notes who is here with whom from the
636
+ // start, so a later card can keep an away player's face.
637
+ if (h.ballotState || h.place.ballot?.keepAway === true) {
541
638
  Ballot.send(h, ballotDeps(h));
542
639
  }
543
640
  Actors.applyTunes(h, h.engine?.maxSpeed?.() ?? 12);
@@ -550,6 +647,8 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
550
647
  }
551
648
  Party.tick(partyDeps(h));
552
649
  Wear.sendOverrides(h, blockedPairs(h));
650
+ // v1.183: seats, emotes and holds of a hidden pair, to each who may see them.
651
+ Idle.sendAlone(h, blockedPairs(h));
553
652
  // v1.53 earned items: nothing in a place where nobody shows one.
554
653
  if (Earned.used(h)) {
555
654
  Earned.sendOverrides(h, blockedPairs(h));
@@ -559,6 +658,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
559
658
  Wear.sendTryOverrides(h, blockedPairs(h));
560
659
  }
561
660
  if (Role.used(h)) { Role.sendOverrides(h, blockedPairs(h)); }
661
+ if (h.holdShowUsed) { HoldShow.sendOverrides(h, blockedPairs(h)); }
562
662
  // Cabinet cards (v1.7): nothing in a place with no classic door.
563
663
  Cabinets.send(h, (playerId) => namesOf(h, blockedPairs(h)?.get(playerId) ?? []));
564
664
  notifyResumes(h, false, resumeDeferred);
@@ -623,6 +723,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
623
723
  },
624
724
 
625
725
  allowPlayerPose: (id) => !Vehicle.riding(h, id),
726
+ stalePose: (sim, id, point) => stalePose(h, sim, id, point),
626
727
  shutdown: () => shutdown(h),
627
728
 
628
729
  join() {
@@ -637,25 +738,30 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
637
738
  ...avatarColorsForJoin(h),
638
739
  ...wearingForJoin(h),
639
740
  ...(h.place.companion === true && h.companionUsed ? { hubGlow: Companion.glowOf(h) } : {}),
741
+ ...(h.place.companion === true && h.companionShownUsed ? { hubChirp: Companion.chirpOf(h) } : {}),
640
742
  // v1.53, only once someone here shows an earned item.
641
743
  ...(h.earned.size > 0 ? earnedForJoin(h) : {}),
642
744
  hud: hudForAll(h),
643
745
  hidden: [...h.hidden],
644
- held: [...h.held.keys()],
746
+ held: Idle.heldShared(h, blockedPairs(h)),
645
747
  labels: labelsForAll(h),
646
748
  tints: Actors.tintsOf(h),
647
749
  marks: Actors.marksOf(h),
648
750
  hubDoors: doorList(h),
649
751
  spawned: Actors.spawnedOf(h),
650
752
  spawnTemplates: Actors.templatesOf(h),
753
+ // v1.197, only while a copy of a decor template is alive.
754
+ ...(Actors.doorDecorOf(h).length ? { hubDecorTpl: Actors.doorDecorOf(h) } : {}),
651
755
  // v1.6, only in a place that turns idle play on.
652
- ...Idle.fields(h),
756
+ ...Idle.fields(h, blockedPairs(h)),
653
757
  ...Vehicle.fields(h),
758
+ ...Disguise.fields(h),
654
759
  // v1.27, only once the place keeps an object for a player.
655
760
  ...(h.keptFor.size > 0 ? { hubKept: Grab.keptOf(h) } : {}),
656
761
  // v1.28, only while the place shows a try-on on someone.
657
762
  ...(h.trying.size > 0 ? tryingForJoin(h) : {}),
658
763
  ...(h.roles.size > 0 ? rolesForJoin(h) : {}),
764
+ ...(h.holdShowUsed ? { hubHoldShow: HoldShow.fields(h, blockedPairs(h)) } : {}),
659
765
  // v1.33, only a town of a deck with `hub.stuck`.
660
766
  ...(stuckHere(h) ? { hubStuck: { to: arrivalName(h), ...(hasUnstick(h) ? { hook: true } : {}) } } : {}),
661
767
  };
@@ -673,23 +779,31 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
673
779
  if (h.place.companion === true && h.companionUsed) {
674
780
  latch(h, 'hubGlow', Companion.glowOf(h), out);
675
781
  }
782
+ if (h.place.companion === true && h.companionShownUsed) {
783
+ latch(h, 'hubChirp', Companion.chirpOf(h), out);
784
+ }
676
785
  // v1.53: nothing until someone shows an earned item, then each change.
677
786
  if (h.earned.size > 0 || h.sent.has('hubEarned')) {
678
787
  latchEarned(h, out);
679
788
  }
680
789
  latch(h, 'hud', hudForAll(h), out);
681
790
  latch(h, 'hidden', [...h.hidden], out);
682
- latch(h, 'held', [...h.held.keys()], out);
791
+ latch(h, 'held', Idle.heldShared(h, blockedPairs(h)), out);
683
792
  latch(h, 'labels', labelsForAll(h), out);
684
793
  latch(h, 'tints', Actors.tintsOf(h), out);
685
794
  latch(h, 'marks', Actors.marksOf(h), out);
686
795
  latch(h, 'hubDoors', doorList(h), out);
687
796
  latch(h, 'spawnTemplates', Actors.templatesOf(h), out);
797
+ // v1.197: nothing until a decor template has a copy, then each change.
798
+ if (Actors.doorDecorOf(h).length || h.sent.has('hubDecorTpl')) {
799
+ latch(h, 'hubDecorTpl', Actors.doorDecorOf(h), out);
800
+ }
688
801
  latch(h, 'spawned', Actors.spawnedOf(h), out);
689
- for (const [field, value] of Object.entries(Idle.fields(h))) {
802
+ for (const [field, value] of Object.entries(Idle.fields(h, blockedPairs(h)))) {
690
803
  latch(h, field, value, out);
691
804
  }
692
805
  if (h.cars?.size || h.sent.has('hubCars')) {latch(h, 'hubCars', Vehicle.fields(h).hubCars ?? {}, out);}
806
+ if (h.disguiseUsed || h.sent.has('hubDisguise')) {latch(h, 'hubDisguise', Disguise.fields(h).hubDisguise, out);}
693
807
  // v1.27 `hub.keepFor`: nothing until something is kept, then each change.
694
808
  if (h.keptFor.size > 0 || h.sent.has('hubKept')) {
695
809
  latch(h, 'hubKept', Grab.keptOf(h), out);
@@ -699,6 +813,7 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
699
813
  latchTrying(h, out);
700
814
  }
701
815
  if (h.roles.size > 0 || h.sent.has('hubRole')) { latchRoles(h, out); }
816
+ if (h.holdShowUsed) { latch(h, 'hubHoldShow', HoldShow.fields(h, blockedPairs(h)), out); }
702
817
  return Object.keys(out).length ? out : null;
703
818
  },
704
819
 
@@ -844,6 +959,12 @@ function newState(manifest, savedDeckId) {
844
959
  whereAt: new Map(),
845
960
  // playerId -> { at, facing, until }: bodies kept where a jump put them (`settle`)
846
961
  settling: new Map(),
962
+ // playerId -> where `joinSpot` put a body that found the spawn taken
963
+ // (v1.218): its WORLD starts it there, and its arrival keeps it there.
964
+ joinedOff: new Map(),
965
+ // playerId -> { at, body, until }: a place's `hub.placeAt` waiting for its
966
+ // client to report from the spot (`stalePose`)
967
+ placed: new Map(),
847
968
  // `logStats`: when the window began, the CPU reading then, ticks since
848
969
  stats: { at: null, cpu: null, ticks: 0 },
849
970
  // playerId -> { avatar, clientAvatar, from, fromDeckId, party, carry, read,
@@ -908,6 +1029,8 @@ function newState(manifest, savedDeckId) {
908
1029
  // what players wear on their avatars (`wear.js`, v1.4)
909
1030
  ...Wear.newWearState(),
910
1031
  ...Role.newRoleState(),
1032
+ ...HoldShow.newHoldShowState(),
1033
+ ...Disguise.newDisguiseState(),
911
1034
  // earned items players show (`earned.js`, v1.53)
912
1035
  ...Earned.newEarnedState(),
913
1036
  // emotes, seats and sounds (`idle.js`, v1.6)
@@ -920,10 +1043,25 @@ function newState(manifest, savedDeckId) {
920
1043
  ...Say.newSayState(),
921
1044
  };
922
1045
  h.ctx = makeContext(h);
1046
+ if (manifest.holdShow === true) {
1047
+ h.ctx.holdShow = (id, spec) => HoldShow.holdShow(h, id, spec);
1048
+ h.ctx.holdShowing = (id) => HoldShow.holdShowing(h, id);
1049
+ }
923
1050
  // v1.68: `hub.ballot` only in a deck that declares the card in some place.
924
1051
  if (manifest.ballot) {
925
1052
  h.ctx.ballot = (playerIds, spec) => Ballot.ballot(h, playerIds, spec);
926
1053
  }
1054
+ // v1.185: `hub.wallet` only in a deck that declares one.
1055
+ if (manifest.wallet) {
1056
+ h.wallet = Wallet.createWallet({
1057
+ ...manifest.wallet,
1058
+ storage: () => h.session?.storage ?? null,
1059
+ identify: (playerId) => walletIdentity(h, playerId),
1060
+ // A lost writer lease stops this instance's wallet writes too.
1061
+ fence: (userId) => h.writerLease?.api.fence(userId) ?? Promise.resolve(),
1062
+ });
1063
+ h.ctx.wallet = h.wallet.api;
1064
+ }
927
1065
  h.npcLabel = (actorId, text, options) => setLabel(h, isSceneActor(h, actorId) ? actorId : null, text, options, true);
928
1066
  h.blockedPairs = () => blockedPairs(h);
929
1067
  h.npcs = makeNpcs(h);
@@ -933,6 +1071,9 @@ function newState(manifest, savedDeckId) {
933
1071
  // The `hub` every deck hook is handed.
934
1072
  function makeContext(h) {
935
1073
  return {
1074
+ get saves() {
1075
+ return h.writerLease?.api;
1076
+ },
936
1077
  get push() {
937
1078
  return h.place?.push?.version === 1 ? h.session?.hub?.push : undefined;
938
1079
  },
@@ -947,6 +1088,20 @@ function makeContext(h) {
947
1088
  const userId = userIdOf(h, playerId);
948
1089
  return userId ? h.progressGenerations.get(userId) ?? null : null;
949
1090
  },
1091
+ // v1.195: the `resetFences` a place passes to `session.storage.
1092
+ // conditionalWrite` for one or two players here, one per account, from
1093
+ // the markers observed above; null when any is unknown.
1094
+ resetFences(playerIds) {
1095
+ if (!Array.isArray(playerIds) || playerIds.length < 1 || playerIds.length > 2) { return null; }
1096
+ const fences = [];
1097
+ for (const playerId of playerIds) {
1098
+ const userId = userIdOf(h, playerId);
1099
+ const resetGeneration = userId ? h.progressGenerations.get(userId) : undefined;
1100
+ if (!userId || !/^[1-9]\d{0,19}$/.test(userId) || !Number.isSafeInteger(resetGeneration) || resetGeneration < 0 || resetGeneration > 2147483647) { return null; }
1101
+ if (!fences.some((fence) => fence.playerId === userId)) { fences.push({ playerId: userId, resetGeneration }); }
1102
+ }
1103
+ return fences;
1104
+ },
950
1105
  progressPending(userId) {
951
1106
  return [...h.players.values()].some((entry) => entry.progressReading && (userId === undefined || String(entry.userId) === String(userId)));
952
1107
  },
@@ -967,6 +1122,7 @@ function makeContext(h) {
967
1122
  return h.sim?.timeMs ?? 0;
968
1123
  },
969
1124
  goalPositions: true,
1125
+ goalSelf: true,
970
1126
  players() {
971
1127
  const out = [];
972
1128
  for (const [playerId, body] of h.sim?.players ?? []) {
@@ -995,13 +1151,19 @@ function makeContext(h) {
995
1151
  signUp.chosenPose = { ...at, facing };
996
1152
  if (h.held.get(playerId)?.waiting) {h.held.delete(playerId);}
997
1153
  }
998
- return placeAt(h, playerId, at, facing);
1154
+ const body = h.sim?.players.get(playerId);
1155
+ const from = body ? { ...body.at } : null;
1156
+ const guard = h.placed.get(playerId);
1157
+ placeAt(h, playerId, at, facing);
1158
+ guardPlacement(h, playerId, from, guard);
999
1159
  },
1000
1160
  // v1.141 observed progress (`docs/observed-progress.md`).
1001
1161
  observed: (playerId) => Observe.observed(h, playerId),
1002
1162
  station: (id, spec) => Observe.station(h, id, spec),
1003
1163
  dwell: (playerId, id) => Observe.dwell(h, playerId, id),
1004
- hold(playerId, at, facingDeg) {
1164
+ // v1.190: `{ turnCamera: true }` turns the held player's own avatar to
1165
+ // the held facing now and again at `release`, the way `hub-jumped` does.
1166
+ hold(playerId, at, facingDeg, options) {
1005
1167
  if (Vehicle.riding(h, playerId)) {Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));}
1006
1168
  const body = h.sim?.players.get(playerId);
1007
1169
  if (!body) {
@@ -1009,14 +1171,18 @@ function makeContext(h) {
1009
1171
  }
1010
1172
  const point = at ? { ...at } : { ...body.at };
1011
1173
  const facing = facingDeg === undefined ? body.facing : facingDeg * DEG;
1012
- h.held.set(playerId, { at: point, facing });
1174
+ const turnCamera = options?.turnCamera === true && Number.isFinite(facing);
1175
+ h.held.set(playerId, turnCamera ? { at: point, facing, turnCamera } : { at: point, facing });
1013
1176
  Grab.stilled(h, playerId);
1014
1177
  placeAt(h, playerId, point, facing);
1178
+ if (turnCamera) {h.session?.send(playerId, { k: 'hub-hold-face', facing });}
1015
1179
  },
1016
1180
  release(playerId) {
1017
1181
  if (Vehicle.riding(h, playerId)) {Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));}
1018
- if (h.held.get(playerId)?.ground) {Idle.stand(h, playerId);}
1182
+ const held = h.held.get(playerId);
1183
+ if (held?.ground) {Idle.stand(h, playerId);}
1019
1184
  h.held.delete(playerId);
1185
+ if (held?.turnCamera) {h.session?.send(playerId, { k: 'hub-hold-face', facing: held.facing });}
1020
1186
  },
1021
1187
  setHud(spec, playerId) {
1022
1188
  const clean = cleanHud(spec);
@@ -1083,7 +1249,15 @@ function makeContext(h) {
1083
1249
  drive: (id, car, at) => Vehicle.drive(h, id, car, at, (pid, point, face) => placeAt(h, pid, point, face)),
1084
1250
  ride: (id, driver, seat) => Vehicle.ride(h, id, driver, seat, (pid, point, face) => placeAt(h, pid, point, face)),
1085
1251
  vehicle: (id) => Vehicle.vehicle(h, id),
1086
- spawn: (fromActorId, at) => Actors.spawn(h, fromActorId, at, h.engine),
1252
+ disguise: (id, spec) => Disguise.disguise(h, id, spec),
1253
+ disguised: (id) => Disguise.disguised(h, id),
1254
+ // v1.200: the Town's day (LA midnight), for a game's dailies and streaks.
1255
+ townDay: (nowMs) => TownDay.townDay(nowMs),
1256
+ townDayStart: (day) => TownDay.townDayStart(day),
1257
+ townDayFrom: (stored, nowMs) => TownDay.townDayFrom(stored, nowMs),
1258
+ record: (id, op) => Replay.record(h, id, op),
1259
+ replay: (id, slot, spec) => Replay.replay(h, id, slot, spec),
1260
+ spawn: (fromActorId, at, options) => Actors.spawn(h, fromActorId, at, h.engine, options),
1087
1261
  pose: (actorId) => Actors.pose(h, actorId),
1088
1262
  reset: (actorId, at) => Actors.reset(h, actorId, at, h.engine),
1089
1263
  despawn: (actorId) => Actors.despawn(h, actorId, h.engine),
@@ -1101,16 +1275,31 @@ function makeContext(h) {
1101
1275
  emote: (playerId, id) => Idle.emote(h, playerId, id),
1102
1276
  ...(h.place.idle?.expression ? { emotesFor: (playerId, ids) => Idle.emotesFor(h, playerId, ids) } : {}),
1103
1277
  seat: (playerId) => Idle.seat(h, playerId),
1278
+ sitOn: (playerId, seatId) => Idle.sitOn(h, placeAt, playerId, seatId),
1104
1279
  sound: (actorId, file, options) => Idle.sound(h, actorId, file, options),
1105
1280
  danceIdle: (actorId, options) => Idle.danceIdle(h, actorId, options),
1106
1281
  cue: (target, name) => Cues.cue(h, target, name),
1282
+ // The method itself advertises the optional capability; no public field.
1283
+ get celebrate() {
1284
+ return !h.place.result && h.placeId === Manifest.MAIN_PLACE ? (id, spec) => Celebrate.celebrate(h, id, spec, userIdOf) : undefined;
1285
+ },
1107
1286
  shot: (playerId, value) => Shot.shot(h, playerId, value),
1108
1287
  holding: (playerId) => Grab.holding(h, playerId),
1109
1288
  keepFor: (actorId, playerId) => Grab.keepFor(h, actorId, playerId),
1110
- end(playerIds) {
1289
+ // v1.169: `{ door }` names one player's own door (an action the place
1290
+ // runs when they walk into it); an end their own Act or action press
1291
+ // makes is tagged by the kit itself (`h.acting`).
1292
+ end(playerIds, options) {
1111
1293
  const ids = playerIds ?? [...(h.sim?.players.keys() ?? [])];
1294
+ // Only a list of exactly one player is ever a door: the named one, or
1295
+ // the player whose press is running. Everyone, or several, never is.
1296
+ const one = playerIds && ids.length === 1 ? ids[0] : null;
1297
+ const door = one !== null && doorTag(options?.door) ? options.door :
1298
+ one !== null && h.acting?.playerId === one ? h.acting.id : null;
1299
+ // An end for everyone is no one's door, players already let go included.
1300
+ if (!playerIds) {h.stayable?.clear();}
1112
1301
  for (const playerId of ids) {
1113
- end(h, playerId, 'end');
1302
+ end(h, playerId, 'end', door);
1114
1303
  }
1115
1304
  },
1116
1305
  go: (door, playerIds, options) => go(h, door, playerIds, options),
@@ -1161,6 +1350,11 @@ function queuedResumeHello(h, playerId, known, data, synthetic, signUp, invitedA
1161
1350
  }
1162
1351
 
1163
1352
  function hello(h, player, data, synthetic = false) {
1353
+ if (data.again !== true) {Replay.forget(h, player.playerId); h.replayDeparting?.delete(player.playerId);}
1354
+ // v1.173: a Back mark belongs to the account that pressed Back.
1355
+ if (h.backing?.has(player.playerId) && h.backing.get(player.playerId).userId !== (userIdOf(h, player.playerId) ?? null)) {
1356
+ h.backing.delete(player.playerId);
1357
+ }
1164
1358
  const prepared = prepareResume(h, player.playerId, false);
1165
1359
  if (prepared === 'handled') {
1166
1360
  return;
@@ -1301,6 +1495,10 @@ function hello(h, player, data, synthetic = false) {
1301
1495
  Shot.joinedAfresh(h, player.playerId);
1302
1496
  Vis.joinedAfresh(h, player.playerId, userIdOf(h, player.playerId));
1303
1497
  Decor.joinedAfresh(h, player.playerId);
1498
+ // v1.180: the owner back on the visit's body lets held offers go again.
1499
+ if (HeldOffers.on(h)) {
1500
+ HeldOffers.replay(h, player.playerId);
1501
+ }
1304
1502
  if (h.place.actions === true) {
1305
1503
  Actions.joinedAfresh(h, player.playerId);
1306
1504
  }
@@ -1318,9 +1516,10 @@ function hello(h, player, data, synthetic = false) {
1318
1516
  }
1319
1517
  Cabinets.forget(h, player.playerId);
1320
1518
  Friends.resend(h, player.playerId);
1321
- // v1.28: nothing in a place that never sent a try-on to one player alone.
1519
+ // v1.28: nothing in a place that never sent a try-on or wearable to one player alone.
1322
1520
  Wear.joinedAfresh(h, player.playerId);
1323
1521
  if (Role.used(h) || h.roleAloneUsed) { Role.joinedAfresh(h, player.playerId); }
1522
+ HoldShow.joinedAfresh(h, player.playerId);
1324
1523
  // v1.53: likewise its earned items alone, only where someone has one.
1325
1524
  if (Earned.used(h)) {
1326
1525
  Earned.joinedAfresh(h, player.playerId);
@@ -1330,6 +1529,9 @@ function hello(h, player, data, synthetic = false) {
1330
1529
  h.session?.send(player.playerId, { k: 'hub-leaving', text: h.leaving.get(player.playerId) });
1331
1530
  }
1332
1531
  }
1532
+ // Replacement forgets may resync this account's progress flags. Finish
1533
+ // them before registering the new entry and its required initial read.
1534
+ syncWriterVisits(h);
1333
1535
  const progressUser = userIdOf(h, player.playerId) ?? known?.userId ?? null;
1334
1536
  let progressState = h.progressStates.get(player.playerId);
1335
1537
  if (!progressState || progressState.userId !== progressUser) {
@@ -1369,6 +1571,7 @@ function hello(h, player, data, synthetic = false) {
1369
1571
  read: progressState.readLifetime?.phase ?? (continuedProgress ? (known?.read === 'reading' ? 'want' : known?.read) : null) ?? (hub ? 'want' : 'done'),
1370
1572
  progressVersion: progressState.version,
1371
1573
  progressState,
1574
+ ...(known?.protection ? { protection: { ...known.protection, sent: false } } : {}),
1372
1575
  ...(known?.device !== undefined ? { device: known.device } : {}),
1373
1576
  ...(h.progressEnabled ? { progressReading: Boolean(progressState.locks.size || accountProgressBlocked(h, progressUser) || (!resumeBeforeProgressRead && progressUser && canReadProgress(h) && typeof h.session?.storage?.playthrough === 'function')) } : {}),
1374
1577
  ...(resumeBeforeProgressRead ? { progressRefreshPending: true } : {}),
@@ -1391,6 +1594,8 @@ function hello(h, player, data, synthetic = false) {
1391
1594
  historyFrom: known?.historyFrom ?? null,
1392
1595
  ...(h.manifest.yourGames ? { hearts: known?.hearts ?? [], yoursKey: data.again === true ? known?.yoursKey : null } : {}),
1393
1596
  ended: known?.ended ?? (last ? last.ended === true : false),
1597
+ // v1.169: a door end is still the player's own door across a hello (the
1598
+ // resume hello comes before their hub-stay).
1394
1599
  // v1.72 (I2, I3): only in a resume place, and only once known.
1395
1600
  ...(resumes && (known?.visitAt ?? last?.visitAt) !== undefined ? { visitAt: known?.visitAt ?? last.visitAt } : {}),
1396
1601
  ...(resumes && (known?.endWhy ?? last?.endWhy) !== undefined ? { endWhy: known?.endWhy ?? last.endWhy } : {}),
@@ -1403,6 +1608,12 @@ function hello(h, player, data, synthetic = false) {
1403
1608
  signUp.colorRev = entry.colorRev;
1404
1609
  }
1405
1610
  h.players.set(player.playerId, entry);
1611
+ // v1.180: a fresh hello, its entry rebuilt for whoever is on the row,
1612
+ // lifts an ownership block and stamps the hold calls while away land under.
1613
+ if (HeldOffers.on(h) && data.again !== true) {
1614
+ HeldOffers.hello(h, player.playerId);
1615
+ }
1616
+ takeStayable(h, player.playerId, entry, known, data);
1406
1617
  if (h.poseStore && !signedUp && !known?.hello && entry.userId) {
1407
1618
  // The new socket may say hello before reconciliation observed the old one
1408
1619
  // disappear. End only an absent socket belonging to this same account.
@@ -1413,7 +1624,12 @@ function hello(h, player, data, synthetic = false) {
1413
1624
  entry.poseReading = true;
1414
1625
  void h.poseStore.take(entry.userId, player.playerId).then((pose) => {
1415
1626
  const current = h.players.get(player.playerId);
1416
- if (!current || current.progressState !== entry.progressState || h.resumeDeparting?.has(player.playerId)) { return; }
1627
+ if (!current || current.progressState !== entry.progressState || h.resumeDeparting?.has(player.playerId)) {
1628
+ // A discarded read still ends the wait: arrivals hold the whole
1629
+ // group while any entry reads its pose.
1630
+ if (current === entry) {current.poseReading = false;}
1631
+ return;
1632
+ }
1417
1633
  current.coldPose = pose;
1418
1634
  current.poseReading = false;
1419
1635
  });
@@ -1494,7 +1710,10 @@ async function refreshProgress(h, playerId) {
1494
1710
  const newer = Number.isSafeInteger(generation) && generation > (h.progressGenerations.get(userId) ?? 0);
1495
1711
  const sameUser = [...h.players].filter(([id]) => userIdOf(h, id) === userId);
1496
1712
  const retryFailed = sameUser.some(([, current]) => current.progressState.failure && current.progressState.appliedGeneration < generation);
1497
- const targets = newer || retryFailed ? sameUser.filter(([, current]) => current.progressState.resetting?.generation !== generation)
1713
+ // A retry of a failed hook reruns only the ids not yet at this generation:
1714
+ // a sibling whose hook succeeded keeps its side effects once.
1715
+ const targets = newer ? sameUser.filter(([, current]) => current.progressState.resetting?.generation !== generation)
1716
+ : retryFailed ? sameUser.filter(([, current]) => current.progressState.appliedGeneration < generation && current.progressState.resetting?.generation !== generation)
1498
1717
  : Number.isSafeInteger(generation) && generation > 0
1499
1718
  ? sameUser.filter(([, current]) => current.progressState.appliedGeneration < generation && current.progressState.resetting?.generation !== generation)
1500
1719
  : [];
@@ -1516,6 +1735,7 @@ async function refreshProgress(h, playerId) {
1516
1735
  const targetState = current.progressState;
1517
1736
  targetState.markerKnown = true;
1518
1737
  targetState.markerBypass = false;
1738
+ delete current.progressReleased;
1519
1739
  if (targetState.resetting && targetState.resetting.generation < generation) {
1520
1740
  unlock(id, targetState, targetState.resetting);
1521
1741
  }
@@ -1542,7 +1762,9 @@ async function refreshProgress(h, playerId) {
1542
1762
  delete current.endReplayPending;
1543
1763
  Wear.forget(h, id);
1544
1764
  Role.forget(h, id);
1765
+ HoldShow.forget(h, id);
1545
1766
  Earned.forget(h, id);
1767
+ h.wallet?.reset(userId);
1546
1768
  h.npcs.leave(id);
1547
1769
  h.hudMe.delete(id);
1548
1770
  h.labelsMe.delete(id);
@@ -1563,11 +1785,16 @@ async function refreshProgress(h, playerId) {
1563
1785
  await h.hooks.progressReset?.(h.ctx, id, generation, { arrived: current.arrived });
1564
1786
  if (h.progressStates.get(id) === targetState && targetState.resetting === reset && h.progressGenerations.get(userId) === generation) {
1565
1787
  targetState.appliedGeneration = generation;
1788
+ targetState.hookFailures = 0;
1566
1789
  }
1567
1790
  } catch {
1568
1791
  if (h.progressStates.get(id) === targetState && targetState.resetting === reset && h.progressGenerations.get(userId) === generation) {
1569
1792
  targetState.failure = reset;
1570
1793
  failed = true;
1794
+ // v1.204: a failed hook is retried on the read's own cadence,
1795
+ // not only at a new hello.
1796
+ targetState.hookFailures = (targetState.hookFailures ?? 0) + 1;
1797
+ targetState.markerRetryAt = Date.now() + Math.min(PROGRESS_RETRY_MS * 2 ** (targetState.hookFailures - 1), PROGRESS_RETRY_MAX_MS);
1571
1798
  }
1572
1799
  if (!h.progressHookWarned) {
1573
1800
  h.progressHookWarned = true;
@@ -1591,6 +1818,11 @@ async function refreshProgress(h, playerId) {
1591
1818
  if (h.progressRequests.get(playerId) === request && h.players.get(playerId) === entry) {
1592
1819
  if (!state.readFailure) {
1593
1820
  state.readFailure = {};
1821
+ // A release let the arrival through, not a failure found after it:
1822
+ // an arrived id takes the ordinary failure protection again.
1823
+ for (const current of h.players.values()) {
1824
+ if (current.arrived && current.userId === state.userId) { delete current.progressReleased; }
1825
+ }
1594
1826
  lock(playerId, state, state.readFailure);
1595
1827
  }
1596
1828
  state.readFailures = (state.readFailures ?? 0) + 1;
@@ -1621,11 +1853,17 @@ function syncProgressUser(h, userId) {
1621
1853
  const blocked = accountProgressBlocked(h, userId);
1622
1854
  for (const [id, entry] of h.players) {
1623
1855
  if (entry.userId === userId) {
1624
- entry.progressReading = Boolean((entry.progressState.locks.size && !entry.progressState.markerBypass) || blocked);
1856
+ const reading = Boolean((entry.progressState.locks.size && !entry.progressState.markerBypass) || blocked);
1857
+ // A released arrival stays released until this episode settles; a
1858
+ // newer reset clears the release where it starts (`refreshProgress`).
1859
+ if (!reading) { delete entry.progressReleased; }
1860
+ entry.progressReading = reading && !entry.progressReleased;
1861
+ noteProtection(h, id, entry);
1625
1862
  if (!entry.progressReading && !entry.progressRefreshPending && entry.endReplayPending) {
1626
1863
  delete entry.endReplayPending;
1627
1864
  endAgain(h, id);
1628
1865
  }
1866
+ stayAfterProgress(h, id);
1629
1867
  }
1630
1868
  }
1631
1869
  }
@@ -1637,7 +1875,7 @@ function retryProgress(h) {
1637
1875
  const now = Date.now();
1638
1876
  for (const [id, entry] of h.players) {
1639
1877
  const state = entry.progressState;
1640
- if (!state || (state.markerKnown && !state.readFailure)) { continue; }
1878
+ if (!state || (state.markerKnown && !state.readFailure && !state.failure)) { continue; }
1641
1879
  if (!state.markerKnown && !state.markerBypass && now - state.markerStartedAt >= PROGRESS_ARRIVAL_WAIT_MS) {
1642
1880
  state.markerBypass = true;
1643
1881
  console.warn('[hub] progress reset marker unavailable; allowing arrival while retrying');
@@ -1645,6 +1883,108 @@ function retryProgress(h) {
1645
1883
  }
1646
1884
  if (now >= (state.markerRetryAt ?? Infinity)) { void refreshProgress(h, id); }
1647
1885
  }
1886
+ releaseProgressHolds(h, now);
1887
+ for (const [id, entry] of h.players) {
1888
+ if (entry.protection) { noteProtection(h, id, entry, now); }
1889
+ }
1890
+ }
1891
+
1892
+ // v1.204: the messages the kit handles itself that write no progress (chat,
1893
+ // party, emotes, seats, travel, where, unstick, the gate log), heard while
1894
+ // an arrived player's progress is read. hub-go carries no progress, and the
1895
+ // destination reads its own marker. Everything else, the place's own hooks
1896
+ // included, waits and is refused visibly (`hub-progress`).
1897
+ function progressFree(h, data) {
1898
+ switch (data?.k) {
1899
+ case 'hub-shut': case 'hub-door-jump': case 'hub-house-visit': case 'hub-where': case 'hub-goto':
1900
+ case 'hub-say': case 'hub-party': case 'hub-dev-classic': case 'hub-emote': case 'hub-stand':
1901
+ return true;
1902
+ case 'hub-unstick': return Boolean(h.manifest.stuck);
1903
+ case 'hub-gate': return h.place?.actGateLog === true;
1904
+ case 'hub-horn': return Boolean(h.cars);
1905
+ case 'hub-sit-here': return Boolean(h.place.idle?.expression);
1906
+ case 'hub-sit': return h.manifest.act !== true;
1907
+ default: return false;
1908
+ }
1909
+ }
1910
+
1911
+ // An arrived player's action is never dropped silently. A spell of progress
1912
+ // protection on an arrived player is logged on, and then off, once it drops
1913
+ // a message, comes from a failure or reset, or lasts a second; a quick
1914
+ // successful reread stays quiet.
1915
+ const PROTECTION_LOG_MS = 1000;
1916
+ // Past this the client's line says to re-enter, and it is logged once; the
1917
+ // protection itself holds until a read or the reset hook succeeds.
1918
+ const PROTECTION_PAST_MS = 30_000;
1919
+
1920
+ function noteProtection(h, id, entry, now = Date.now()) {
1921
+ if (!entry.arrived || !entry.progressReading) {
1922
+ if (entry.protection) { protectionOff(h, id, entry, ''); }
1923
+ return;
1924
+ }
1925
+ const reason = progressHoldReason(h, entry.userId);
1926
+ entry.protection ??= { since: now, reason, dropped: 0, logged: false };
1927
+ const spell = entry.protection;
1928
+ if (reason !== 'progress-read') { spell.reason = reason; }
1929
+ // v1.204: the client hears at once, so its controls never offer what the
1930
+ // server would refuse.
1931
+ if (!spell.sent) {
1932
+ spell.sent = true;
1933
+ h.session?.send(id, { k: 'hub-progress', catching: true });
1934
+ }
1935
+ if (!spell.logged && (spell.dropped || spell.reason !== 'progress-read' || now - spell.since >= PROTECTION_LOG_MS)) {
1936
+ spell.logged = true;
1937
+ console.warn(`[hub] progress protection on: ${id} (user ${entry.userId ?? 'guest'}) ${spell.reason}`);
1938
+ }
1939
+ if (!spell.past && now - spell.since >= PROTECTION_PAST_MS) {
1940
+ spell.past = true;
1941
+ console.warn(`[hub] progress protection past 30 s: ${id} (user ${entry.userId ?? 'guest'}) ${spell.reason}`);
1942
+ }
1943
+ }
1944
+
1945
+ function protectionOff(h, id, entry, why) {
1946
+ const spell = entry.protection;
1947
+ delete entry.protection;
1948
+ if (spell.sent && !why) { h.session?.send(id, { k: 'hub-progress', catching: false }); }
1949
+ // One that settled between ticks after the second still says it was on.
1950
+ if (!spell.logged && Date.now() - spell.since >= PROTECTION_LOG_MS) {
1951
+ spell.logged = true;
1952
+ console.warn(`[hub] progress protection on: ${id} (user ${entry.userId ?? 'guest'}) ${spell.reason}`);
1953
+ }
1954
+ if (spell.logged) {
1955
+ console.warn(`[hub] progress protection off: ${id} (user ${entry.userId ?? 'guest'}) ${spell.reason} after ${Date.now() - spell.since} ms, ${spell.dropped} dropped${why}`);
1956
+ }
1957
+ }
1958
+
1959
+ function droppedDuringProgress(h, id) {
1960
+ const entry = h.players.get(id);
1961
+ if (!entry?.arrived) { return; }
1962
+ noteProtection(h, id, entry);
1963
+ if (!entry.protection) { return; }
1964
+ entry.protection.dropped += 1;
1965
+ noteProtection(h, id, entry);
1966
+ }
1967
+
1968
+ // No progress state holds an arrival past the same five seconds: a known
1969
+ // marker whose read hangs or keeps failing, and a reset hook that threw or
1970
+ // has not settled, let a player not yet arrived go once, logged with why.
1971
+ // The read and its retries carry on behind; only a newer reset locks again.
1972
+ function releaseProgressHolds(h, now) {
1973
+ for (const entry of h.players.values()) {
1974
+ if (!entry.hello || entry.arrived || !entry.progressReading || entry.progressReleased) { continue; }
1975
+ if (now - Math.max(entry.helloAt, entry.progressState?.markerStartedAt ?? 0) < PROGRESS_ARRIVAL_WAIT_MS) { continue; }
1976
+ entry.progressReleased = true;
1977
+ console.warn(`[hub] arrival hold released after 5 s: ${progressHoldReason(h, entry.userId)}`);
1978
+ syncProgressUser(h, entry.userId);
1979
+ }
1980
+ }
1981
+
1982
+ function progressHoldReason(h, userId) {
1983
+ const states = [...h.progressStates.values()].filter((state) => state.userId === userId);
1984
+ if (states.some((state) => state.failure)) { return 'progress-reset-failed'; }
1985
+ if (states.some((state) => state.resetting)) { return 'progress-reset'; }
1986
+ if (states.some((state) => state.readFailure)) { return 'progress-read-failed'; }
1987
+ return 'progress-read';
1648
1988
  }
1649
1989
 
1650
1990
  // An unsaved local serve has no deck Store or platform reset marker. Its SDK
@@ -1677,11 +2017,20 @@ function outcomeOrNone(outcome) {
1677
2017
  return outcome === undefined || outcome === null || Manifest.OUTCOMES.includes(outcome);
1678
2018
  }
1679
2019
 
2020
+ // Storage-capable transport identities, including dev guests, own the lease.
2021
+ // A fresh connection may replace a lost account's held visits only when no
2022
+ // other connection here shares it. Finalize their authored state before join.
2023
+ function syncWriterVisits(h) {
2024
+ if (!h.writerLease?.api.enabled) { return; }
2025
+ h.writerLease.sync((h.session?.players ?? []).map(p => [p.playerId, userIdOf(h, p.playerId)]).filter(([, userId]) => userId !== null), h.players.keys(), playerId => forget(h, playerId));
2026
+ }
2027
+
1680
2028
  // Forget players the session no longer has, telling the deck first: its
1681
2029
  // `leave` hook runs while the player is still known, so it may report their
1682
2030
  // result for the visit (the host takes one for a player who has just left)
1683
2031
  // and save their progress under the user id it is handed (v1.2).
1684
2032
  function reconcile(h) {
2033
+ syncWriterVisits(h);
1685
2034
  // v1.145: before any private channel below can send to a changed account.
1686
2035
  if (h.place.resumePose === true && h.place.resumeVisibility !== true) {
1687
2036
  clearChangedHeldIdentity(h);
@@ -1705,6 +2054,10 @@ function reconcile(h) {
1705
2054
  }
1706
2055
  Vis.prune(h);
1707
2056
  Decor.prune(h);
2057
+ // v1.180: every hold is checked each tick, before the offers it keeps.
2058
+ if (HeldOffers.on(h)) {
2059
+ HeldOffers.prune(h);
2060
+ }
1708
2061
  if (h.place.actions === true) {
1709
2062
  Actions.prune(h);
1710
2063
  }
@@ -1868,6 +2221,10 @@ function prepareResume(h, playerId, greet = true) {
1868
2221
  const body = h.sim?.players.get(playerId);
1869
2222
  const present = body && h.session?.players.some((p) => p.playerId === playerId);
1870
2223
  const returning = present && (kept.awayAt !== undefined || body !== kept.body);
2224
+ // v1.173: the drop a player's own Back led to is the visit's end.
2225
+ if (!present || returning) {
2226
+ backDropped(h, playerId);
2227
+ }
1871
2228
  if (!present) {
1872
2229
  if (kept.awayAt === undefined && h.poseStore && !h.resumeDeparting.has(playerId) && !h.players.get(playerId)?.ended) {
1873
2230
  void h.poseStore.end(h.players.get(playerId)?.userId, kept, Date.now(), playerId);
@@ -2169,6 +2526,9 @@ function restartRetainedAsFresh(h, player, entry, data, synthetic) {
2169
2526
  }
2170
2527
 
2171
2528
  function forget(h, playerId) {
2529
+ parkStayable(h, playerId);
2530
+ Replay.forget(h, playerId);
2531
+ h.replayDeparting?.delete(playerId);
2172
2532
  h.vehicleDeparting?.delete(playerId);
2173
2533
  h.padOccupancy?.selected.delete(playerId);
2174
2534
  const entry = h.players.get(playerId);
@@ -2178,6 +2538,8 @@ function forget(h, playerId) {
2178
2538
  h.inviteAt?.delete(playerId);
2179
2539
  h.resumePending?.delete(playerId);
2180
2540
  h.resumeKept?.delete(playerId);
2541
+ if (!h.session?.players.some((p) => p.playerId === playerId)) {backDropped(h, playerId);}
2542
+ h.backing?.delete(playerId);
2181
2543
  const poseDeparting = h.arrivalPoses && h.resumeDeparting?.has(playerId);
2182
2544
  h.resumeDeparting?.delete(playerId);
2183
2545
  if (entry?.arrived && h.place.analytics === true) {Analytics.leave(h, playerId);}
@@ -2194,6 +2556,7 @@ function forget(h, playerId) {
2194
2556
  }
2195
2557
  }
2196
2558
  Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));
2559
+ Disguise.forget(h, playerId);
2197
2560
  DoorAnalytics.finish(h, playerId, 3);
2198
2561
  if (h.arrivalPoses) {
2199
2562
  h.arrivalPoses.leave(playerId, entry?.userId, entry?.arrived === true && !entry.ended && !poseDeparting);
@@ -2221,14 +2584,20 @@ function forget(h, playerId) {
2221
2584
  if (h.ballotState) {
2222
2585
  Ballot.forget(h, playerId);
2223
2586
  }
2587
+ h.ballotSeen?.records.delete(playerId);
2224
2588
  Friends.forget(h, playerId);
2225
2589
  h.caps.delete(playerId);
2226
2590
  h.capAt.delete(playerId);
2227
2591
  h.playerCells.delete(playerId);
2592
+ if (entry?.protection) { protectionOff(h, playerId, entry, ' (left)'); }
2228
2593
  h.players.delete(playerId);
2594
+ syncWriterVisits(h);
2229
2595
  if (entry?.progressState) { entry.progressState.readLifetime = null; }
2230
2596
  h.progressStates.delete(playerId);
2231
2597
  syncProgressUser(h, entry?.userId);
2598
+ if (h.wallet && entry?.userId) {
2599
+ h.wallet.forget(entry.userId, (userId) => [...h.players.values()].some((other) => other.userId === userId));
2600
+ }
2232
2601
  h.held.delete(playerId);
2233
2602
  h.hudMe.delete(playerId);
2234
2603
  h.sentHudMe.delete(playerId);
@@ -2241,6 +2610,7 @@ function forget(h, playerId) {
2241
2610
  h.marks.delete(playerId);
2242
2611
  Wear.forget(h, playerId);
2243
2612
  Role.forget(h, playerId);
2613
+ HoldShow.forget(h, playerId);
2244
2614
  Earned.forget(h, playerId);
2245
2615
  h.shut.delete(playerId);
2246
2616
  h.noTrips.delete(playerId);
@@ -2250,8 +2620,11 @@ function forget(h, playerId) {
2250
2620
  h.unstuckAt?.delete(playerId);
2251
2621
  h.unstuckAskAt?.delete(playerId);
2252
2622
  h.settling.delete(playerId);
2623
+ h.joinedOff.delete(playerId);
2624
+ h.placed.delete(playerId);
2253
2625
  Grab.forget(h, playerId);
2254
2626
  if (h.manifest.act === true) {Act.forget(h, playerId);}
2627
+ if (h.place?.actGateLog === true) {ActGate.forget(h, playerId, userIdOf(h, playerId));}
2255
2628
  Idle.forget(h, playerId);
2256
2629
  Decor.forget(h, playerId);
2257
2630
  if (h.place.actions === true) {
@@ -2266,6 +2639,7 @@ function forget(h, playerId) {
2266
2639
  if (h.place.menu === true) {
2267
2640
  Menu.forget(h, playerId);
2268
2641
  }
2642
+ HeldOffers.forget(h, playerId);
2269
2643
  if (h.cueBudgets) {
2270
2644
  h.cueBudgets.delete(`player:${playerId}`);
2271
2645
  }
@@ -2283,8 +2657,17 @@ function forget(h, playerId) {
2283
2657
  const SHUTDOWN_DRAIN_MS = 1500;
2284
2658
 
2285
2659
  async function shutdown(h) {
2660
+ Replay.end(h);
2661
+ Celebrate.clear(h);
2662
+ if (h.recordings || h.replays) {h.replayClosed = true;}
2663
+ // A fresh Back is leaving even when no tick saw its drop: let it go before
2664
+ // anything below keeps a pose.
2665
+ for (const playerId of [...(h.backing?.keys() ?? [])]) {
2666
+ backDropped(h, playerId);
2667
+ }
2286
2668
  h.arrivalPoses?.shutdown();
2287
2669
  if (!h.sim) {
2670
+ h.writerLease?.shutdown();
2288
2671
  return;
2289
2672
  }
2290
2673
  for (const playerId of [...h.players.keys()]) {
@@ -2298,12 +2681,15 @@ async function shutdown(h) {
2298
2681
  Wear.endTries(h);
2299
2682
  }
2300
2683
  Role.end(h);
2684
+ HoldShow.end(h);
2685
+ Disguise.end(h);
2301
2686
  let timer = null;
2302
2687
  await Promise.race([
2303
2688
  Promise.resolve()
2304
2689
  .then(async () => {
2305
2690
  await h.hooks.shutdown?.(h.ctx);
2306
2691
  await h.poseStore?.drain();
2692
+ await h.wallet?.settled();
2307
2693
  await Promise.all([...(h.friendBestHelpers?.values() ?? [])].map((helper) => helper.drain()));
2308
2694
  })
2309
2695
  .catch((err) => console.warn(`[hub] shutdown hook failed: ${err?.message ?? err}`)),
@@ -2312,6 +2698,7 @@ async function shutdown(h) {
2312
2698
  }),
2313
2699
  ]);
2314
2700
  clearTimeout(timer);
2701
+ h.writerLease?.shutdown();
2315
2702
  }
2316
2703
 
2317
2704
  // Signup carry invariant: ONE terminal function applies allowed guest state
@@ -2345,6 +2732,21 @@ function finishSignUp(h, playerId, signUp, cancel = false) {
2345
2732
  }
2346
2733
  }
2347
2734
 
2735
+ // A placed sign-up waits for its account read at most five seconds, then
2736
+ // arrives without it. The read still lands later, but cannot replace the
2737
+ // carried look: that stays the terminal function's alone.
2738
+ function releaseSignUpHolds(h) {
2739
+ const now = Date.now();
2740
+ for (const [playerId, entry] of h.players) {
2741
+ const signUp = entry.signUp;
2742
+ if (!signUp || signUp.finished || !signUp.arrivalSettled || signUp.readSettled || now - signUp.placedAt < PROGRESS_ARRIVAL_WAIT_MS) { continue; }
2743
+ signUp.readSettled = true;
2744
+ if (entry.progressState?.readLifetime) { entry.progressState.readLifetime.keepLook = true; }
2745
+ console.warn('[hub] arrival hold released after 5 s: signup-results');
2746
+ finishSignUp(h, playerId, signUp);
2747
+ }
2748
+ }
2749
+
2348
2750
  // Players with a body who said hello and have not arrived, placed as groups
2349
2751
  // at the arrival (contract §5). A group is everyone who said hello inside one
2350
2752
  // window; it is placed when it has as many as its members said were coming,
@@ -2418,6 +2820,7 @@ function arrivals(h) {
2418
2820
  if (!signUp) {continue;}
2419
2821
  signUp.member = member;
2420
2822
  signUp.arrivalSettled = true;
2823
+ signUp.placedAt = Date.now();
2421
2824
  const body = h.sim.players.get(member.playerId);
2422
2825
  h.held.set(member.playerId, { at: { ...body.at }, facing: body.facing, waiting: true });
2423
2826
  finishSignUp(h, member.playerId, signUp);
@@ -2444,6 +2847,13 @@ function arrivals(h) {
2444
2847
  // A player ghost placed through a door (a House's Back, a host's trip)
2445
2848
  // arrives at that door, not where an earlier visit was left standing.
2446
2849
  if (entry?.coldPose && platformHub(h)?.arrival(playerId)?.doorId) {delete entry.coldPose;}
2850
+ // Nor back onto a door's pad (v1.19's rule for every placement): a pose
2851
+ // stored as they left standing on one put them back on it, and the pad
2852
+ // took them into its game -- Oct 7, a late join into the Lantern Lot with
2853
+ // whoever was inside. They arrive where the arrival put them instead.
2854
+ // Nor beside one: a pose left within COLD_POSE_PAD_CLEAR_M of a pad's edge
2855
+ // is close enough that the first stick or a report's drift steps onto it.
2856
+ if (entry?.coldPose && padAt(h, entry.coldPose.at, COLD_POSE_PAD_CLEAR_M) !== null) {delete entry.coldPose;}
2447
2857
  if (entry?.coldPose) {
2448
2858
  restorePose(h, playerId, entry.coldPose.at, entry.coldPose.facing);
2449
2859
  settle(h, playerId);
@@ -2472,6 +2882,10 @@ function arrivals(h) {
2472
2882
  endAgain(h, playerId);
2473
2883
  }
2474
2884
  }
2885
+ // v1.169: a hub-stay that came before arrival, now that arrival has placed them.
2886
+ for (const { playerId } of group) {
2887
+ if (h.stayable?.get(playerId)?.requested && h.players.get(playerId)?.ended) {applyStay(h, playerId);}
2888
+ }
2475
2889
  }
2476
2890
 
2477
2891
  // v1.72 (I3): the end of a resume place's visit, again, to a client a drop
@@ -2496,8 +2910,8 @@ function arrivalPoint(h) {
2496
2910
  return actor?.components.Transform ?? h.sim?.spawn ?? { x: 0, y: 1, z: 0 };
2497
2911
  }
2498
2912
 
2499
- // A row at the arrival actor, facing the way the manifest says.
2500
- function placeGroup(h, playerIds) {
2913
+ // The arrival point, the way the row faces and the direction it runs.
2914
+ function arrivalRow(h) {
2501
2915
  const arrival = h.place.arrival;
2502
2916
  const t = arrivalPoint(h);
2503
2917
  let facing;
@@ -2509,29 +2923,93 @@ function placeGroup(h, playerIds) {
2509
2923
  facing = (t.rotationY ?? 0) * DEG;
2510
2924
  }
2511
2925
  // Facing f looks along (sin f, cos f); the row runs across it.
2512
- const across = { x: Math.cos(facing), z: -Math.sin(facing) };
2513
- const radius = bodySize(h)?.radius ?? BODY_RADIUS_M;
2514
- const occupied = othersAt(h, playerIds);
2515
- const n = playerIds.length;
2516
- const slots = playerIds.map((_, i) => {
2517
- const offset = (i - (n - 1) / 2) * arrival.spread;
2518
- return { x: t.x + across.x * offset, y: Math.max(t.y ?? 1, 1.2), z: t.z + across.z * offset };
2926
+ return { t, facing, across: { x: Math.cos(facing), z: -Math.sin(facing) } };
2927
+ }
2928
+
2929
+ // Whether a body standing at `p` takes the spot `at`: nearer than two radii
2930
+ // across the ground and overlapping it in height. A player on a floor above
2931
+ // or below takes nothing here (v1.218).
2932
+ function takes(h, p, at) {
2933
+ const size = bodySize(h) ?? { radius: BODY_RADIUS_M, halfHeight: BODY_HALF_M };
2934
+ return Math.hypot(p.x - at.x, p.z - at.z) < 2 * size.radius && Math.abs(p.y - at.y) < 2 * size.halfHeight;
2935
+ }
2936
+
2937
+ // The row's slots for `n` players: each authored (`at`, at least 1.2 m up)
2938
+ // and where a body stands there (`standing`), which is what occupancy is
2939
+ // judged at (v1.218: an elevated marker's raw height let an earlier member
2940
+ // stepping off take a later member's slot).
2941
+ function rowSlots(h, n) {
2942
+ const { t, across } = arrivalRow(h);
2943
+ const spread = h.place.arrival.spread;
2944
+ return Array.from({ length: n }, (_, i) => {
2945
+ const offset = (i - (n - 1) / 2) * spread;
2946
+ const at = { x: t.x + across.x * offset, y: Math.max(t.y ?? 1, 1.2), z: t.z + across.z * offset };
2947
+ return { at, standing: { ...at, y: standingY(h, at) } };
2519
2948
  });
2949
+ }
2950
+
2951
+ // Where a lone arrival goes (`placeGroup` with one player): the slot, or,
2952
+ // when `occupied` takes it, the free spot beside it (null when none is).
2953
+ // `joinSpot` asks the same, so the two cannot disagree.
2954
+ function loneSlot(h) {
2955
+ const [slot] = rowSlots(h, 1);
2956
+ return { ...slot, stepOff: (occupied) => stepOffSlot(h, slot.at, occupied) };
2957
+ }
2958
+
2959
+ function stepOffSlot(h, at, occupied) {
2960
+ const { across } = arrivalRow(h);
2961
+ const radius = bodySize(h)?.radius ?? BODY_RADIUS_M;
2962
+ return freeArrivalSlot(h, at, across, Math.max(h.place.arrival.spread, 2 * radius + 0.1), radius, occupied, true);
2963
+ }
2964
+
2965
+ // A row at the arrival actor, facing the way the manifest says.
2966
+ function placeGroup(h, ids) {
2967
+ const { t, facing, across } = arrivalRow(h);
2968
+ const occupied = othersAt(h, ids);
2969
+ const off = new Map(ids.filter((id) => h.joinedOff.has(id)).map((id) => [id, h.joinedOff.get(id)]));
2970
+ for (const id of ids) {h.joinedOff.delete(id);}
2971
+ // v1.218: one admitted beside a taken spawn (`joinSpot`) was put there by
2972
+ // its WORLD. Alone, it arrives where it stands while that is still free:
2973
+ // moving it now would reach its client as a clamp, eased a quarter of the
2974
+ // way per update, the glide v1.147 removed. (One whose spot was taken
2975
+ // since, or that moved, is placed as anyone is.)
2976
+ if (ids.length === 1 && off.has(ids[0])) {
2977
+ const body = h.sim.players.get(ids[0]);
2978
+ const kept = off.get(ids[0]);
2979
+ if (body && Math.hypot(body.at.x - kept.x, body.at.z - kept.z) <= HOLD_SLACK && !occupied.some((p) => takes(h, p, body.at))) {
2980
+ placeAt(h, ids[0], { ...body.at }, facing);
2981
+ return;
2982
+ }
2983
+ }
2984
+ // A group with a member admitted beside the spawn takes the row's slots in
2985
+ // the order its members stand along it, so nobody crosses the row.
2986
+ const along = (id) => {
2987
+ const at = h.sim.players.get(id)?.at;
2988
+ return at ? (at.x - t.x) * across.x + (at.z - t.z) * across.z : 0;
2989
+ };
2990
+ const playerIds = off.size ? [...ids].sort((a, b) => along(a) - along(b)) : ids;
2991
+ const slots = rowSlots(h, playerIds.length);
2520
2992
  // Where earlier members of this batch were put, and which of them moved: a
2521
2993
  // moved member may sit on a later authored slot, which must then move too.
2522
2994
  const assigned = [];
2523
2995
  const moved = [];
2524
2996
  playerIds.forEach((playerId, i) => {
2525
- const at = slots[i];
2997
+ const { at, standing } = slots[i];
2526
2998
  // A lone door visitor may find the owner still at the arrival (a House
2527
2999
  // visit from People carries no `near`), and two solid bodies on one spot
2528
- // wedge. Only authored-floor places step off an occupied slot: a town or
2529
- // ground-backed game keeps the spawn WORLD already showed (Oct 17, the
2530
- // ring's later correction glided a joiner 1.1 m), and empty rows keep
2531
- // their authored placement.
2532
- const alternate = h.noGround === true && [...occupied, ...moved].some((p) => Math.hypot(p.x - at.x, p.z - at.z) < 2 * radius)
2533
- ? freeArrivalSlot(h, at, across, Math.max(arrival.spread, 2 * radius + 0.1), radius, [...occupied, ...assigned, ...slots.slice(i + 1)], true) : null;
2534
- const spot = alternate ?? { ...at, y: standingY(h, at) };
3000
+ // wedge. Every place steps off an occupied slot (v1.218). Ground-backed
3001
+ // places (the Town) used to keep the spawn for everyone, so two lone
3002
+ // joiners stood on exactly the same point; each client's physics then
3003
+ // pressed its own capsule into the ground under the other's avatar and
3004
+ // ate every step until one left (Nov 17 Market check). The step-off is
3005
+ // one placement, not the ring's later 1.1 m glide that v1.147 removed
3006
+ // (Oct 17). Empty slots keep their authored placement.
3007
+ // When no spot beside it is free (`freeArrivalSlot` null) the slot
3008
+ // itself is used, shared, as before v1.218. Later members' slots are
3009
+ // held for them where they will stand, as every occupant is judged.
3010
+ const alternate = [...occupied, ...moved].some((p) => takes(h, p, standing))
3011
+ ? stepOffSlot(h, at, [...occupied, ...assigned, ...slots.slice(i + 1).map((slot) => slot.standing)]) : null;
3012
+ const spot = alternate ?? standing;
2535
3013
  assigned.push(spot);
2536
3014
  if (alternate) {moved.push(alternate);}
2537
3015
  placeAt(h, playerId, spot, facing);
@@ -2539,21 +3017,33 @@ function placeGroup(h, playerIds) {
2539
3017
  }
2540
3018
 
2541
3019
  // Every other body in the place where it stands now, arrived or not: a body
2542
- // waiting for its group or held is as solid as one that arrived.
3020
+ // waiting for its group or held is as solid as one that arrived. Not one whose
3021
+ // player has left the roster: real-time admits a joiner before it removes the
3022
+ // bodies of players who left that tick (v1.218), and those are going.
2543
3023
  function othersAt(h, except) {
2544
- return [...h.sim.players.entries()].filter(([id]) => !except.includes(id)).map(([, body]) => body.at);
3024
+ const roster = Array.isArray(h.session?.players) ? new Set(h.session.players.map((p) => p.playerId)) : null;
3025
+ return [...h.sim.players.entries()]
3026
+ .filter(([id]) => !except.includes(id) && (roster === null || roster.has(id)))
3027
+ .map(([, body]) => body.at);
2545
3028
  }
2546
3029
 
2547
3030
  // A stored pose (an arrival pose, a durable resumePose, a retained visit)
2548
3031
  // puts a returning player back where they stood, but someone may stand there
2549
- // now. On an authored-floor place one closer than two radii steps off along
2550
- // the row across their facing, else takes the arrival (Oct 19 QA: a guest's
2551
- // stored House pose was restored 0.42 m from the owner, and they wedged).
3032
+ // now. One closer than two radii steps off along the row across their
3033
+ // facing, else takes the arrival (Oct 19 QA: a guest's stored House pose was
3034
+ // restored 0.42 m from the owner, and they wedged). On every place since
3035
+ // v1.218, ground-backed ones too: two capsules on one spot wedge there as well
3036
+ // (Nov 17 Market check). A pose nobody stands on is restored exactly.
2552
3037
  function restorePose(h, playerId, at, facing) {
3038
+ const body = h.sim.players.get(playerId);
3039
+ const from = body ? { ...body.at } : null;
3040
+ // An arrival hook may already have placed them here; keep its stale-report guard.
3041
+ const guard = h.placed.get(playerId);
2553
3042
  const radius = bodySize(h)?.radius ?? BODY_RADIUS_M;
2554
3043
  const others = othersAt(h, [playerId]);
2555
- if (h.noGround !== true || !others.some((p) => Math.hypot(p.x - at.x, p.z - at.z) < 2 * radius)) {
3044
+ if (!others.some((p) => takes(h, p, at))) {
2556
3045
  moveBody(h, playerId, at, facing);
3046
+ guardPlacement(h, playerId, from, guard);
2557
3047
  return;
2558
3048
  }
2559
3049
  const across = { x: Math.cos(facing ?? 0), z: -Math.sin(facing ?? 0) };
@@ -2563,6 +3053,7 @@ function restorePose(h, playerId, at, facing) {
2563
3053
  } else {
2564
3054
  placeGroup(h, [playerId]);
2565
3055
  }
3056
+ guardPlacement(h, playerId, from, guard);
2566
3057
  // A hold the player kept across the drop would put them back on the
2567
3058
  // occupied spot next tick: it follows them to where they now stand.
2568
3059
  const hold = h.held.get(playerId);
@@ -2575,8 +3066,10 @@ function restorePose(h, playerId, at, facing) {
2575
3066
  // `around`: when the row has no free slot, also try the eight compass
2576
3067
  // directions at the same steps (a narrow floor may run across the row).
2577
3068
  function freeArrivalSlot(h, at, across, step, radius, occupied, around = false) {
2578
- // The legacy envelope intersects authored floors under shorter players.
2579
- const size = (h.noGround === true ? bodySize(h) : null) ?? { radius: BODY_RADIUS_M, halfHeight: BODY_HALF_M };
3069
+ // The place's own body, as its players are (v1.218: ground-backed places
3070
+ // used the larger legacy envelope, which intersects authored floors under
3071
+ // shorter players).
3072
+ const size = bodySize(h) ?? { radius: BODY_RADIUS_M, halfHeight: BODY_HALF_M };
2580
3073
  const dirs = [[across.x, across.z], [-across.x, -across.z]];
2581
3074
  if (around) {
2582
3075
  for (let i = 0; i < 8; i += 1) {dirs.push([Math.cos(i * Math.PI / 4), Math.sin(i * Math.PI / 4)]);}
@@ -2587,7 +3080,7 @@ function freeArrivalSlot(h, at, across, step, radius, occupied, around = false)
2587
3080
  const [dx, dz] = dirs[d];
2588
3081
  const candidate = { x: at.x + dx * k * step, y: at.y, z: at.z + dz * k * step };
2589
3082
  candidate.y = standingY(h, candidate);
2590
- if (!occupied.some((p) => Math.hypot(p.x - candidate.x, p.z - candidate.z) < 2 * radius) &&
3083
+ if (!occupied.some((p) => takes(h, p, candidate)) &&
2591
3084
  spotClear(h, candidate, size) && padAt(h, candidate, radius) === null) {
2592
3085
  return candidate;
2593
3086
  }
@@ -2667,6 +3160,9 @@ function placeBeside(h, playerId, otherId, used = new Map()) {
2667
3160
 
2668
3161
  // The id of the pad actor a body at `at` stands on, or within `margin` of, or
2669
3162
  // null. A pad takes a player whose middle is inside its radius.
3163
+ // How far from a pad's edge a restored cold pose must stand (resumePose).
3164
+ const COLD_POSE_PAD_CLEAR_M = 2.5;
3165
+
2670
3166
  function padAt(h, at, margin) {
2671
3167
  for (const actor of h.actors) {
2672
3168
  const pad = actor.components.HubPad;
@@ -2682,7 +3178,9 @@ function padAt(h, at, margin) {
2682
3178
  // or a spawned copy (a House's placed furniture), at its live pose -- and on
2683
3179
  // a scene with no ground (`fallY`) a solid's top is under its feet.
2684
3180
  function spotClear(h, at, { radius, halfHeight }) {
2685
- let supported = h.noGround !== true;
3181
+ // The ground slab is finite (`ground.half`, 100 m by default): a spot past
3182
+ // its edge stands only on an authored solid (v1.218).
3183
+ let supported = h.noGround !== true && Math.abs(at.x) <= (h.groundHalf ?? Infinity) && Math.abs(at.z) <= (h.groundHalf ?? Infinity);
2686
3184
  for (const { shape, pose } of solids(h)) {
2687
3185
  // A tilted solid is judged by its enclosing sphere, as standingY does.
2688
3186
  const bound = pose.upright ? null : boundingRadius(shape);
@@ -2723,6 +3221,89 @@ function moveBody(h, playerId, at, facing) {
2723
3221
  }
2724
3222
  body.clamped = true;
2725
3223
  body.body.setTranslation(body.at, true);
3224
+ // Any placement is where the player is now, not a `hub.placeAt` still
3225
+ // waiting for its client (a hold, an arrival, a car, a pose restore, at any
3226
+ // distance; `hub.placeAt` and pose restores arm theirs again, `guardPlacement`).
3227
+ h.placed.delete(playerId);
3228
+ // A leave before the next server step stores where the body was put, not
3229
+ // where that step's predecessor recorded it (`rememberResumePoses`).
3230
+ const kept = h.resumeKept?.get(playerId);
3231
+ if (kept && kept.body === body && kept.awayAt === undefined) {
3232
+ kept.at = { ...body.at };
3233
+ kept.facing = body.facing;
3234
+ }
3235
+ }
3236
+
3237
+ // A place's `hub.placeAt` wins over the move reports its client sent before
3238
+ // it heard of the placement. Those still name where the player stood, and
3239
+ // the movement clamp let each one pull the body a step back toward it; the
3240
+ // clamped row sent back then put the client there too, for good (up to
3241
+ // 1.2 m short, and a whole walk back on a client slow to hear). Such a report
3242
+ // is not taken at all (`stalePose`): the body stays put and every snapshot
3243
+ // keeps the correction. Anything a client that has applied the placement
3244
+ // could have sent is taken as usual, eased part of the way (the shipped
3245
+ // client eases a correction under 4 m a quarter of the way per row) and
3246
+ // walking on included, and the first one taken ends the wait: a socket keeps
3247
+ // order, so every report from before the placement reached the client has
3248
+ // come in by then. SETTLE_MAX_MS bounds a client that never hears.
3249
+ //
3250
+ // A placement within the movement slack of where the body stands (a place
3251
+ // that puts a player where they are, every tick) neither arms nor renews it,
3252
+ // and leaves an earlier one as it was.
3253
+ function guardPlacement(h, playerId, from, guard) {
3254
+ const body = h.sim?.players.get(playerId);
3255
+ if (!body || !from) {
3256
+ return;
3257
+ }
3258
+ if (Math.hypot(body.at.x - from.x, body.at.y - from.y, body.at.z - from.z) <= moveSlack(h)) {
3259
+ if (guard && guard.body === body) {h.placed.set(playerId, guard);}
3260
+ return;
3261
+ }
3262
+ h.placed.set(playerId, { at: { ...body.at }, from, body, placedAt: h.sim.timeMs, until: Date.now() + SETTLE_MAX_MS });
3263
+ }
3264
+
3265
+ // How long after a placement a report nearer the old pose is still taken for
3266
+ // one sent before the client heard of it. A slow phone's in-flight window:
3267
+ // probes of the old code put the body 2.4 to 9.6 m off with the client hearing
3268
+ // 50 to 300 ms late, and twice that covers a stall. After it only
3269
+ // reachability applies, since a player walking against the placement (put
3270
+ // 1.4 m back while walking on at 6 m/s) reports nearer the old pose for good.
3271
+ const STALE_FROM_MS = 500;
3272
+
3273
+ // The movement clamp's fixed slack (multiplayer-3d `MOVE_SLACK`).
3274
+ function moveSlack(h) {
3275
+ const slack = h.engine?.moveSlack?.();
3276
+ return Number.isFinite(slack) ? slack : 0.6;
3277
+ }
3278
+
3279
+ // Whether a move report could not have come from a client that has applied
3280
+ // the placement: farther from the spot than the movement limit allows since
3281
+ // it, or, within STALE_FROM_MS of it, nearer where the player stood before it
3282
+ // than the spot by more than the slack.
3283
+ function stalePose(h, sim, playerId, point) {
3284
+ const placed = h.placed.get(playerId);
3285
+ if (!placed) {
3286
+ return false;
3287
+ }
3288
+ const body = sim.players.get(playerId);
3289
+ if (body !== placed.body || Date.now() >= placed.until) {
3290
+ h.placed.delete(playerId);
3291
+ return false;
3292
+ }
3293
+ if (!point) {
3294
+ return false;
3295
+ }
3296
+ const slack = moveSlack(h);
3297
+ const speed = Number.isFinite(body.maxSpeed) ? body.maxSpeed : h.engine?.maxSpeed?.() ?? 12;
3298
+ const toSpot = Math.hypot(point.x - placed.at.x, point.y - placed.at.y, point.z - placed.at.z);
3299
+ const toFrom = Math.hypot(point.x - placed.from.x, point.y - placed.from.y, point.z - placed.from.z);
3300
+ const since = Math.max(0, sim.timeMs - placed.placedAt);
3301
+ const reach = speed * since / 1000 + slack;
3302
+ if (toSpot > reach || (since < STALE_FROM_MS && toFrom + slack < toSpot)) {
3303
+ return true;
3304
+ }
3305
+ h.placed.delete(playerId);
3306
+ return false;
2726
3307
  }
2727
3308
 
2728
3309
  // After a jump (to a door's pad, beside a player) or an arrival (v1.40) the
@@ -2871,16 +3452,53 @@ function report(h, playerId, value) {
2871
3452
  return true;
2872
3453
  }
2873
3454
 
2874
- function end(h, playerId, why) {
3455
+ // v1.169: the id a player's own door end is tagged with, as Act's.
3456
+ function doorTag(value) {
3457
+ return typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(value);
3458
+ }
3459
+
3460
+ function end(h, playerId, why, door = null) {
3461
+ const known = h.players.get(playerId);
3462
+ // v1.169: a player's own door end (`door`) in a place without a result. One
3463
+ // their client cancelled (`hub-stay`) is held shut until they step off it,
3464
+ // and one already ended says nothing again.
3465
+ const tag = door && !h.place.result && known ? door : null;
3466
+ if (tag) {
3467
+ const hold = h.stayHolds?.get(playerId);
3468
+ if (hold?.door === tag) {
3469
+ hold.seen = true;
3470
+ return;
3471
+ }
3472
+ if (known.ended) {
3473
+ return;
3474
+ }
3475
+ }
3476
+ Replay.forget(h, playerId);
2875
3477
  Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));
3478
+ Disguise.forget(h, playerId);
2876
3479
  if (h.place.analyticsRounds !== 'authored') {DoorAnalytics.finish(h, playerId);}
2877
3480
  const entry = h.players.get(playerId);
3481
+ // v1.169: the player's stay record follows their latest end: their own door
3482
+ // makes one, any other end (a kick, a timer, everyone's) takes it away,
3483
+ // with or without an entry here.
3484
+ // Each tagged door end is numbered per player, monotonic for the session
3485
+ // (never reset by a forget or a hello), so a stay for an older end can
3486
+ // never match a newer record.
3487
+ let endNumber = null;
3488
+ if (tag) {
3489
+ endNumber = ((h.endNumbers ??= new Map()).get(playerId) ?? 0) + 1;
3490
+ h.endNumbers.set(playerId, endNumber);
3491
+ (h.stayable ??= new Map()).set(playerId, { door: tag, end: endNumber, userId: known.userId ?? null, at: null, facing: 0, until: null, requested: false });
3492
+ } else {
3493
+ h.stayable?.delete(playerId);
3494
+ }
2878
3495
  if (entry) {
2879
3496
  entry.ended = true;
2880
3497
  // v1.72 (I3): kept to say it again on resume.
2881
3498
  if (h.place.resume === true && h.place.result) {
2882
3499
  entry.endWhy = why;
2883
3500
  }
3501
+ if (entry.arrived && !h.place.result && h.place.analytics === true) {Analytics.ended(h, playerId);}
2884
3502
  }
2885
3503
  // A visit the place ended is over, like a kit trip (sendGo): a drop on the
2886
3504
  // way out keeps no durable pose to come back to. A House front-door leave
@@ -2890,9 +3508,178 @@ function end(h, playerId, why) {
2890
3508
  h.resumeDeparting?.add(playerId);
2891
3509
  void h.poseStore.clear(entry?.userId, playerId);
2892
3510
  }
3511
+ h.backing?.delete(playerId);
2893
3512
  h.held.delete(playerId);
2894
3513
  Shot.stopHolding(h, playerId);
2895
- h.session?.send(playerId, { k: 'hub-end', why });
3514
+ h.session?.send(playerId, tag ? { k: 'hub-end', why, door: tag, end: endNumber } : { k: 'hub-end', why });
3515
+ }
3516
+
3517
+ // v1.169: one stay record per player (`h.stayable`), the authority on whether
3518
+ // their end can be stayed: { door, userId, at, facing, until, requested }. It
3519
+ // exists exactly while their latest end was their own door end (`end`), until
3520
+ // they stay, a fresh visit's hello, or the resume window after they were let
3521
+ // go runs out. `at`/`facing`/`until` are set when the visit is let go
3522
+ // (`parkStayable`); `requested` is a hub-stay that came before arrival.
3523
+ function stayWindowMs(h) {
3524
+ return pinnedResume(h) ? h.session.hub.reconnectWindowMs :
3525
+ houseResume(h) ? RESUME_KEEP_MS : h.place.resumePose === true ? RESUME_POSE_MS : RESUME_KEEP_MS;
3526
+ }
3527
+
3528
+ // The client's word that it cancelled its own door end, taken while it was
3529
+ // offline, and stayed. Honoured only for the record's own account and a
3530
+ // player still ended; before arrival it waits for arrival (`arrivals`), so
3531
+ // nothing there moves the player after their pose is put back.
3532
+ function stay(h, player, data) {
3533
+ const playerId = player?.playerId;
3534
+ const end = data?.end;
3535
+ if (!Number.isSafeInteger(end) || end < 1 || !Object.keys(data).every((key) => key === 'k' || key === 'end') ||
3536
+ !h.session?.players.some((p) => p.playerId === playerId)) {
3537
+ return;
3538
+ }
3539
+ // A repeat of the stay already applied: acknowledged again (its first
3540
+ // answer may have been lost), changing nothing.
3541
+ if (h.stayedEnds?.get(playerId) === end) {
3542
+ h.session.send(playerId, { k: 'hub-stayed', end });
3543
+ return;
3544
+ }
3545
+ const record = h.stayable?.get(playerId);
3546
+ if (record?.end !== end) {
3547
+ return;
3548
+ }
3549
+ const entry = h.players.get(playerId);
3550
+ // Said before the session took the player back (their visit already let
3551
+ // go, their resume hello not yet heard): kept for their next arrival.
3552
+ if (record && !entry && record.at && h.session?.players.some((p) => p.playerId === playerId) &&
3553
+ (userIdOf(h, playerId) ?? null) === record.userId) {
3554
+ record.requested = true;
3555
+ return;
3556
+ }
3557
+ if (!record || !entry?.ended || h.place.result || (entry.userId ?? null) !== record.userId ||
3558
+ !h.session?.players.some((p) => p.playerId === playerId)) {
3559
+ return;
3560
+ }
3561
+ if (!entry.arrived || entry.progressReading) {
3562
+ record.requested = true;
3563
+ return;
3564
+ }
3565
+ applyStay(h, playerId);
3566
+ }
3567
+
3568
+ // A stay that waited on a progress read, applied once the read lets an
3569
+ // arrived player act again (`syncProgressUser`).
3570
+ function stayAfterProgress(h, playerId) {
3571
+ const entry = h.players.get(playerId);
3572
+ if (entry?.arrived && !entry.progressReading && entry.ended && h.stayable?.get(playerId)?.requested) {
3573
+ applyStay(h, playerId);
3574
+ }
3575
+ }
3576
+
3577
+ // The visit goes on: prompts, chips, ask, decor and companion back, the pose
3578
+ // lease taken again, and on a replacement body the player put back where the
3579
+ // end left them (a House guest at its arrival, as a resume does). The door is
3580
+ // held shut for them until they step off it (`liftStayHolds`).
3581
+ function applyStay(h, playerId) {
3582
+ const record = h.stayable.get(playerId);
3583
+ const entry = h.players.get(playerId);
3584
+ // Every path here may run later than the word that asked (a progress read,
3585
+ // an arrival): the trusted roster's account now must still be the one the
3586
+ // end and the entry were for, or the record goes and nothing is undone. A
3587
+ // player briefly out of the roster keeps it, still asked for, until they
3588
+ // are back (the next stay, hello or arrival) or it ends the usual ways.
3589
+ if (!h.session?.players.some((p) => p.playerId === playerId)) {
3590
+ if (record) {record.requested = true;}
3591
+ return;
3592
+ }
3593
+ h.stayable.delete(playerId);
3594
+ if (!record || !entry || h.place.result || (entry.userId ?? null) !== record.userId || (userIdOf(h, playerId) ?? null) !== record.userId) {
3595
+ return;
3596
+ }
3597
+ entry.ended = false;
3598
+ delete entry.endAgain;
3599
+ delete entry.endWhy;
3600
+ if (h.place.analytics === true) {Analytics.stayed(h, playerId);}
3601
+ h.resumeDeparting?.delete(playerId);
3602
+ h.actDeparting?.delete(playerId);
3603
+ h.backing?.delete(playerId);
3604
+ (h.stayHolds ??= new Map()).set(playerId, { door: record.door, seen: true });
3605
+ (h.stayedEnds ??= new Map()).set(playerId, record.end);
3606
+ h.session?.send(playerId, { k: 'hub-stayed', end: record.end });
3607
+ if (h.poseStore && entry.userId) {void h.poseStore.take(entry.userId, playerId);}
3608
+ if (record.at && h.sim?.players.has(playerId)) {
3609
+ if (houseResume(h) && h.session?.hub?.owner && entry.userId !== h.session.hub.owner) {
3610
+ placeGroup(h, [playerId]);
3611
+ } else {
3612
+ restorePose(h, playerId, record.at, record.facing);
3613
+ }
3614
+ settle(h, playerId);
3615
+ }
3616
+ if (h.manifest.act === true) {Act.replay(h, playerId);}
3617
+ Decor.joinedAfresh(h, playerId);
3618
+ if (h.place.actions === true) {Actions.joinedAfresh(h, playerId);}
3619
+ if (h.place.companion === true) {Companion.joinedAfresh(h, playerId, userIdOf(h, playerId));}
3620
+ if (h.place.ask === true) {Ask.joinedAfresh(h, playerId);}
3621
+ }
3622
+
3623
+ // A door end lets the visit go at a drop (resumeDeparting): the record keeps
3624
+ // the pose the end left them at, for the resume window. Kept only for a
3625
+ // player still ended; a second let-go keeps the first pose and deadline.
3626
+ function parkStayable(h, playerId) {
3627
+ const record = h.stayable?.get(playerId);
3628
+ if (!record) {
3629
+ return;
3630
+ }
3631
+ const entry = h.players.get(playerId);
3632
+ const kept = h.resumeKept?.get(playerId);
3633
+ const body = h.sim?.players.get(playerId);
3634
+ const pose = kept?.at ? { at: kept.at, facing: kept.facing } : body?.at ? { at: body.at, facing: body.facing } : null;
3635
+ if (!entry?.ended || (!record.at && !pose)) {
3636
+ h.stayable.delete(playerId);
3637
+ return;
3638
+ }
3639
+ if (!record.at) {
3640
+ record.at = { ...pose.at };
3641
+ record.facing = pose.facing;
3642
+ record.until = Date.now() + stayWindowMs(h);
3643
+ }
3644
+ record.requested = false;
3645
+ }
3646
+
3647
+ // A fresh entry for a player who was let go: a resume hello under the same
3648
+ // account in time arrives still ended by that door; any other hello (a fresh
3649
+ // visit) drops the record.
3650
+ function takeStayable(h, playerId, entry, known, data) {
3651
+ const record = h.stayable?.get(playerId);
3652
+ if (!record) {
3653
+ return;
3654
+ }
3655
+ // Every hello checks the account: a queued stay never crosses to another.
3656
+ if ((entry.userId ?? null) !== record.userId) {
3657
+ h.stayable.delete(playerId);
3658
+ return;
3659
+ }
3660
+ if (known) {
3661
+ return;
3662
+ }
3663
+ if (data.resume === true && record.at && Date.now() <= record.until && (entry.userId ?? null) === record.userId) {
3664
+ entry.ended = true;
3665
+ } else {
3666
+ h.stayable.delete(playerId);
3667
+ }
3668
+ }
3669
+
3670
+ // A held door stays shut while the place keeps asking for it: a step in which
3671
+ // it did not (the player stepped off) lets it go.
3672
+ function liftStayHolds(h) {
3673
+ for (const [playerId, record] of h.stayable ?? []) {
3674
+ if (record.until !== null && Date.now() > record.until) {h.stayable.delete(playerId);}
3675
+ }
3676
+ for (const [playerId, hold] of h.stayHolds ?? []) {
3677
+ if (!hold.seen || !h.players.has(playerId)) {
3678
+ h.stayHolds.delete(playerId);
3679
+ } else {
3680
+ hold.seen = false;
3681
+ }
3682
+ }
2896
3683
  }
2897
3684
 
2898
3685
  // This place's doors (contract §4): in dev, the `HubDoor` scene actors whose
@@ -3198,14 +3985,61 @@ function frontOf(door) {
3198
3985
  // What `ballot.js` uses of this layer (v1.68): names and avatars are the
3199
3986
  // kit's own, never the deck's; a player not in the session is no face.
3200
3987
  function ballotDeps(h) {
3988
+ const usernameOf = (playerId) => (h.sim?.players.has(playerId) ? h.session?.players.find((p) => p.playerId === playerId)?.username ?? null : null);
3201
3989
  return {
3202
3990
  blockedPairs: () => blockedPairs(h),
3203
3991
  namesOf: (ids) => namesOf(h, ids),
3204
- usernameOf: (playerId) => (h.sim?.players.has(playerId) ? h.session?.players.find((p) => p.playerId === playerId)?.username ?? null : null),
3992
+ usernameOf,
3205
3993
  avatarOf: (playerId) => (h.players.get(playerId)?.hello ? h.players.get(playerId).avatar : null),
3994
+ // v1.179 `ballot.keepAway` only (the invariant in ballot.js).
3995
+ ...(h.place.ballot?.keepAway === true ? {
3996
+ inRoster: (playerId) => h.session?.players.some((p) => p.playerId === playerId) === true,
3997
+ // The signed-in Castle account on a player id now; null for every guest
3998
+ // (anonymous, dev guests included) and anyone not in the roster.
3999
+ identityOf: (playerId) => {
4000
+ const p = h.session?.players.find((q) => q.playerId === playerId);
4001
+ return p && p.isAnonymous !== true && USER_ID.test(String(p.userId)) ? String(p.userId) : null;
4002
+ },
4003
+ // The account a retained visit is held for, on the same terms.
4004
+ awayIdentityOf: (playerId) => {
4005
+ const kept = h.resumeKept?.get(playerId)?.identityUserId;
4006
+ return typeof kept === 'string' && USER_ID.test(kept) ? kept : null;
4007
+ },
4008
+ // Retained away now: arrived, dropped, inside its resume deadline (as
4009
+ // prepareResume reckons it), not let go, and not dropped right after
4010
+ // their own Back (a fresh v1.173 mark lets the visit go).
4011
+ retained: (playerId) => retainedAway(h, playerId, usernameOf),
4012
+ // A present player's profile under `account`: their session name and
4013
+ // the avatar of a hello made under that same account, else none.
4014
+ profileOf: (playerId, account) => {
4015
+ const entry = h.players.get(playerId);
4016
+ const name = usernameOf(playerId);
4017
+ if (!entry?.hello || entry.userId !== account || !name) {
4018
+ return null;
4019
+ }
4020
+ return Number.isInteger(entry.avatar) ? { name, avatar: entry.avatar } : { name };
4021
+ },
4022
+ } : {}),
3206
4023
  };
3207
4024
  }
3208
4025
 
4026
+ // v1.179 keepAway: whether the place still holds a dropped player's visit
4027
+ // now, by the same deadline and Back rule `prepareResume` applies, so a tap
4028
+ // or send between ticks never outlives what reconcile would let go.
4029
+ function retainedAway(h, playerId, usernameOf) {
4030
+ const entry = h.players.get(playerId);
4031
+ const kept = h.resumeKept?.get(playerId);
4032
+ if (!entry?.arrived || !kept || h.resumeDeparting?.has(playerId) || usernameOf(playerId)) {
4033
+ return false;
4034
+ }
4035
+ const since = kept.awayAt ?? kept.seenAt;
4036
+ const expired = pinnedResume(h) ? Date.now() - since > h.session.hub.reconnectWindowMs
4037
+ : Date.now() - since >= (houseResume(h) ? RESUME_KEEP_MS : h.place.resumePose === true ? RESUME_POSE_MS : RESUME_KEEP_MS);
4038
+ const mark = h.backing?.get(playerId);
4039
+ const backed = mark && Date.now() - mark.at <= BACK_WINDOW_MS && mark.userId === (entry.userId ?? null);
4040
+ return !expired && !backed;
4041
+ }
4042
+
3209
4043
  // What `say.js` uses of this layer. A deck whose manifest sets `cues` (v1.23)
3210
4044
  // hands it more; any other hands it exactly what it did.
3211
4045
  function sayDeps(h) {
@@ -3313,15 +4147,18 @@ function goTo(h, player, data) {
3313
4147
  // The players staying in a town are told who went through which door
3314
4148
  // (`hub-went`, v1.15), so a friend left behind can follow: each client shows
3315
4149
  // it only for its own friends and party. Never across a block, and not for a
3316
- // cabinet (a classic deck is played alone).
4150
+ // cabinet (a classic deck is played alone). Only connected players are told:
4151
+ // a lineage kept for its reconnect window, or one already gone, has no one
4152
+ // to read it.
3317
4153
  function tellWent(h, goingIds, door) {
3318
4154
  if (!h.sim || h.place.result || !goingIds.length) {
3319
4155
  return;
3320
4156
  }
3321
4157
  const going = new Set(goingIds);
3322
4158
  const pairs = blockedPairs(h);
4159
+ const connected = new Set(h.session?.players.map((p) => p.playerId));
3323
4160
  for (const [playerId, entry] of h.players) {
3324
- if (!entry.arrived || going.has(playerId)) {
4161
+ if (!entry.arrived || going.has(playerId) || !connected.has(playerId)) {
3325
4162
  continue;
3326
4163
  }
3327
4164
  const hidden = pairs?.get(playerId);
@@ -3404,17 +4241,69 @@ function deckDoorPlace(h, props, deck) {
3404
4241
 
3405
4242
  // All outgoing travel paths retire the lease after sending the command.
3406
4243
  function sendGo(h, playerId, msg) {
4244
+ HoldShow.forget(h, playerId);
4245
+ Replay.forget(h, playerId);
4246
+ if (h.recordings || h.replays) {(h.replayDeparting ??= new Set()).add(playerId);}
3407
4247
  if (h.session?.send) {
3408
4248
  Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));
3409
- if (h.cars) {(h.vehicleDeparting ??= new Set()).add(playerId);}
4249
+ Disguise.forget(h, playerId);
4250
+ if (h.cars || h.disguiseUsed) {(h.vehicleDeparting ??= new Set()).add(playerId);}
3410
4251
  h.session.send(playerId, msg);
3411
4252
  Shot.stopHolding(h, playerId);
3412
- // An explicit kit trip ends the visit rather than retaining it for a drop.
3413
- h.resumeDeparting?.add(playerId);
3414
4253
  if (h.manifest.act === true) {Act.forget(h, playerId); (h.actDeparting ??= new Set()).add(playerId);}
3415
- h.arrivalPoses?.clear(playerId);
3416
- if (h.poseStore) { void h.poseStore.clear(h.players.get(playerId)?.userId, playerId); }
3417
- h.resumePending?.delete(playerId);
4254
+ // An explicit kit trip ends the visit rather than retaining it for a drop.
4255
+ letVisitGo(h, playerId);
4256
+ }
4257
+ }
4258
+
4259
+ // The visit is over, not paused: a drop on the way out is not retained, and
4260
+ // no arrival or durable pose is kept to come back to. A kit trip (`sendGo`)
4261
+ // and a drop right after the player's own Back (`hub-back`) both end a visit
4262
+ // this way.
4263
+ function letVisitGo(h, playerId) {
4264
+ h.backing?.delete(playerId);
4265
+ h.resumeDeparting?.add(playerId);
4266
+ h.arrivalPoses?.clear(playerId);
4267
+ if (h.poseStore) { void h.poseStore.clear(h.players.get(playerId)?.userId, playerId); }
4268
+ h.resumePending?.delete(playerId);
4269
+ }
4270
+
4271
+ // v1.173: how long a player's own Back (`hub-back`) stays armed: the SDK's
4272
+ // Hub.back timeout (30 s) and some slack. A drop inside it is the Back
4273
+ // leaving; one after it is an ordinary drop.
4274
+ const BACK_WINDOW_MS = 35_000;
4275
+
4276
+ // v1.173: the client's word that its player is leaving this place by their
4277
+ // own Back (system back, Escape or the Back control), said just before it
4278
+ // asks the host for the way back. It only arms (`h.backing`): nothing changes
4279
+ // until that connection drops while the mark is fresh (`backDropped`), when
4280
+ // the visit ends as a kit trip's does, so the next entry is a fresh arrival.
4281
+ // A Back that fails leaves the visit as it was once the mark goes stale.
4282
+ // Ignored in a game (`result`), in a place that retains no visit, before
4283
+ // arrival, from a player not in the roster or unknown here, and once the
4284
+ // player is already departing (a trip or an end); a repeat refreshes the
4285
+ // mark's time.
4286
+ function backOut(h, player) {
4287
+ const playerId = player?.playerId;
4288
+ const entry = h.players.get(playerId);
4289
+ if (h.place?.result || !h.resumeDeparting || !entry?.arrived ||
4290
+ !h.session?.players.some((p) => p.playerId === playerId) || h.resumeDeparting.has(playerId)) {
4291
+ return;
4292
+ }
4293
+ (h.backing ??= new Map()).set(playerId, { at: Date.now(), userId: entry.userId ?? null });
4294
+ }
4295
+
4296
+ // The kit has just seen this player's connection gone. A fresh Back mark
4297
+ // for the same account lets the visit go before anything of it is kept;
4298
+ // a stale one is dropped and changes nothing.
4299
+ function backDropped(h, playerId) {
4300
+ const mark = h.backing?.get(playerId);
4301
+ if (!mark) {
4302
+ return;
4303
+ }
4304
+ h.backing.delete(playerId);
4305
+ if (Date.now() - mark.at <= BACK_WINDOW_MS && mark.userId === (h.players.get(playerId)?.userId ?? null)) {
4306
+ letVisitGo(h, playerId);
3418
4307
  }
3419
4308
  }
3420
4309
 
@@ -3758,9 +4647,17 @@ function firePad(h, hub, door, playerIds) {
3758
4647
  // The pad keeps its id until ghost answers the fire, so a retried go (or a
3759
4648
  // gathering update) after a lost answer names the same pad, which ghost
3760
4649
  // answers with the group it already fixed rather than firing a second one.
3761
- const pad = h.pads.get(door) ?? { padId: newPadId(door), json: null, at: 0 };
4650
+ // A go while that fire is still out sends no second fire: for players it
4651
+ // already names, its answer sends them; anyone else is not sent (null), so
4652
+ // the place may try them again once it settles.
4653
+ const pending = h.pads.get(door);
4654
+ if (pending?.firing) {
4655
+ return [...members.keys()].every((userId) => pending.fireMembers?.has(userId)) ? pending.padId : null;
4656
+ }
4657
+ const pad = pending ?? { padId: newPadId(door), json: null, at: 0 };
3762
4658
  pad.firing = true;
3763
4659
  pad.fireSent = true;
4660
+ pad.fireMembers = new Set(members.keys());
3764
4661
  h.pads.set(door, pad);
3765
4662
  hub
3766
4663
  .updatePad({ doorId: door, padId: pad.padId, memberUserIds: [...members.keys()], fire: true })
@@ -3790,9 +4687,14 @@ function padFired(h, door, pad, users, fired) {
3790
4687
  const group = Array.isArray(fired) ? fired : [];
3791
4688
  // The group is ghost's; anyone of it still here goes, on the pad now or not,
3792
4689
  // but a player whose app has turned out to have no door trips since (v1.156).
3793
- const here = travelersOf(h, h.session?.players.map((p) => p.playerId));
4690
+ // "Here" is the roster as the answer lands: the player the pad was asked for
4691
+ // if still connected, else the account's current connection, never one that
4692
+ // has since dropped (its reconnect window or a departed lineage).
4693
+ const connected = h.session?.players.map((p) => p.playerId) ?? [];
4694
+ const here = travelersOf(h, connected);
3794
4695
  const going = (userId) => {
3795
- const playerId = users.get(userId) ?? here.get(userId);
4696
+ const asked = users.get(userId);
4697
+ const playerId = asked && connected.includes(asked) ? asked : here.get(userId);
3796
4698
  return playerId && !h.noTrips.has(playerId) ? playerId : null;
3797
4699
  };
3798
4700
  tellWent(h, group.map(going).filter(Boolean), door);
@@ -4114,7 +5016,7 @@ function applyRead(h, { playerId, state, lifetime }, read) {
4114
5016
  if (!entry || entry.progressState !== state || h.progressStates.get(playerId) !== state || state.readLifetime !== lifetime || !read) {
4115
5017
  return;
4116
5018
  }
4117
- const { avatarRev, colorRev, wearRev, earnedRev, startedAt } = lifetime;
5019
+ const { avatarRev, colorRev, wearRev, earnedRev, startedAt, keepLook } = lifetime;
4118
5020
  // Their results and records, for `hub.results` (v1.5).
4119
5021
  History.take(h, playerId, read, startedAt);
4120
5022
  // The wearable likewise, unless the game put one on since (v1.4).
@@ -4122,14 +5024,14 @@ function applyRead(h, { playerId, state, lifetime }, read) {
4122
5024
  // The earned item likewise, unless an unlock or choice was made since (v1.53).
4123
5025
  Earned.applyRead(h, playerId, earnedRev, read);
4124
5026
  // The platform avatar, unless the client chose another since the read began.
4125
- if (!entry.signUp && Number.isInteger(read.avatar) && read.avatar >= 0 && read.avatar < AVATARS && entry.avatarRev === avatarRev) {
5027
+ if (!entry.signUp && !keepLook && Number.isInteger(read.avatar) && read.avatar >= 0 && read.avatar < AVATARS && entry.avatarRev === avatarRev) {
4126
5028
  if (entry.avatar !== read.avatar) {
4127
5029
  // A colour queued for the previous character cannot follow a new body.
4128
5030
  entry.color = cleanAvatarColor(read.avatarColor);
4129
5031
  }
4130
5032
  entry.avatar = read.avatar;
4131
5033
  }
4132
- if (!entry.signUp && entry.colorRev === colorRev) {
5034
+ if (!entry.signUp && !keepLook && entry.colorRev === colorRev) {
4133
5035
  entry.color = cleanAvatarColor(read.avatarColor);
4134
5036
  }
4135
5037
  const row = entry.fromDeckId
@@ -4205,6 +5107,9 @@ function sendHudOverrides(h) {
4205
5107
  spec = JSON.stringify(mine) === JSON.stringify(Blocks.redactHud(h.hud, all)) ? null : mine;
4206
5108
  }
4207
5109
  }
5110
+ if (h.writerLease?.api.lost(h.players.get(playerId)?.userId)) {
5111
+ spec = { ...(spec ?? hudForAll(h)), text: WriterLease.NOTICE };
5112
+ }
4208
5113
  const json = JSON.stringify(spec);
4209
5114
  if ((h.sentHudMe.get(playerId) ?? 'null') !== json) {
4210
5115
  h.sentHudMe.set(playerId, json);
@@ -4430,7 +5335,8 @@ function latchAvatarColors(h, out) {
4430
5335
  // and again when the roster changes.
4431
5336
  function blockedPairs(h) {
4432
5337
  const players = h.session?.players ?? [];
4433
- const key = `${h.sim?.timeMs ?? ''}:${players.map((p) => p.playerId).join(',')}`;
5338
+ // By player id and account: a switch on an id never reads an old answer.
5339
+ const key = `${h.sim?.timeMs ?? ''}:${players.map((p) => `${p.playerId}=${p.userId}`).join(',')}`;
4434
5340
  if (h.blocked.key !== key) {
4435
5341
  h.blocked = { key, pairs: Blocks.hiddenPairs(h.session, players.map((p) => p.playerId)) };
4436
5342
  }
@@ -4530,7 +5436,7 @@ function earnedDeps(h, playerId, op) {
4530
5436
  // shows an earned item, in deltas from the first one on.
4531
5437
  function earnedForJoin(h) {
4532
5438
  const earned = Earned.earnedForAll(h, blockedPairs(h));
4533
- return Object.keys(earned).length ? { hubEarned: earned } : {};
5439
+ return Object.keys(earned).length || h.holdShowUsed ? { hubEarned: earned } : {};
4534
5440
  }
4535
5441
 
4536
5442
  function latchEarned(h, out) {
@@ -4672,6 +5578,19 @@ function identityUserIdOf(h, playerId) {
4672
5578
  return p && USER_ID.test(String(p.userId ?? '')) ? String(p.userId) : null;
4673
5579
  }
4674
5580
 
5581
+ // v1.185 `hub.wallet`: a signed-in account's wallet is stored under its
5582
+ // numeric user id; an anonymous player or a dev guest has one for the session.
5583
+ function walletIdentity(h, playerId) {
5584
+ const p = h.session?.players.find((q) => q.playerId === playerId);
5585
+ if (!p) {
5586
+ return null;
5587
+ }
5588
+ if (!p.isAnonymous && USER_ID.test(String(p.userId ?? ''))) {
5589
+ return { stored: true, userId: String(p.userId) };
5590
+ }
5591
+ return { stored: false, key: typeof p.userId === 'string' && p.userId ? `u:${p.userId}` : `p:${playerId}` };
5592
+ }
5593
+
4675
5594
  function usernameOf(h, playerId) {
4676
5595
  return h.session?.players.find((p) => p.playerId === playerId)?.username ?? 'player';
4677
5596
  }