castle-web-cli 0.4.251 → 0.4.252
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.
|
@@ -1138,6 +1138,8 @@ function makeContext(h) {
|
|
|
1138
1138
|
// A transport departure precedes real-time's physical removal. The
|
|
1139
1139
|
// opted lifecycle must expose the same live roster as ordinary leave.
|
|
1140
1140
|
if (h.arrivalPoses && !h.session?.players.some(p => p.playerId === playerId)) {continue;}
|
|
1141
|
+
// v1.229: a player told `away` is off the live roster until `back`.
|
|
1142
|
+
if (h.awayTold?.has(playerId) || h.awayGone?.has(playerId)) {continue;}
|
|
1141
1143
|
out.push({
|
|
1142
1144
|
playerId,
|
|
1143
1145
|
username: usernameOf(h, playerId),
|
|
@@ -2060,6 +2062,9 @@ function reconcile(h) {
|
|
|
2060
2062
|
for (const playerId of h.resumeKept?.keys() ?? []) {
|
|
2061
2063
|
prepareResume(h, playerId);
|
|
2062
2064
|
}
|
|
2065
|
+
for (const id of h.awayGone ?? []) {
|
|
2066
|
+
if (!h.sim.players.has(id) || h.session?.players.some((p) => p.playerId === id)) {h.awayGone.delete(id);}
|
|
2067
|
+
}
|
|
2063
2068
|
for (const id of h.playerCells.keys()) {
|
|
2064
2069
|
if (!h.sim.players.has(id)) {
|
|
2065
2070
|
h.playerCells.delete(id);
|
|
@@ -2137,6 +2142,12 @@ function rememberResumePoses(h) {
|
|
|
2137
2142
|
continue;
|
|
2138
2143
|
}
|
|
2139
2144
|
const previous = h.resumeKept.get(id);
|
|
2145
|
+
// v1.229: a player told `away` keeps their absence (and its deadline)
|
|
2146
|
+
// while real-time still holds the body, so a same-body return is `back`.
|
|
2147
|
+
if (previous?.awayAt !== undefined && h.awayTold?.has(id) &&
|
|
2148
|
+
!h.session?.players.some((player) => player.playerId === id)) {
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
2140
2151
|
// v1.145: a resumePose place holds private state on this deadline too.
|
|
2141
2152
|
if ((h.place.resumeVisibility === true || h.place.resumePose === true) && previous) {
|
|
2142
2153
|
const rosterPresent = h.session?.players.some((player) => player.playerId === id) === true;
|
|
@@ -2158,6 +2169,9 @@ function rememberResumePoses(h) {
|
|
|
2158
2169
|
// v1.145: a body real-time still holds after its roster row went keeps
|
|
2159
2170
|
// the account it was retained for (Vis/Companion heldAway).
|
|
2160
2171
|
identityUserId: h.session?.players.some((player) => player.playerId === id) ? userIdOf(h, id) : previous?.identityUserId ?? null,
|
|
2172
|
+
// v1.229: the roster's own id (an anonymous guest's included), so `back`
|
|
2173
|
+
// is told only to the same person, not merely the same transport id.
|
|
2174
|
+
rosterUserId: rosterUserOf(h, id) ?? previous?.rosterUserId ?? null,
|
|
2161
2175
|
...(previous?.pendingClientHello ? { pendingClientHello: previous.pendingClientHello } : {}),
|
|
2162
2176
|
...(previous?.visibilityResumePending ? { visibilityResumePending: true } : {}),
|
|
2163
2177
|
});
|
|
@@ -2235,6 +2249,95 @@ function rememberAnonymousEntries(h) {
|
|
|
2235
2249
|
}
|
|
2236
2250
|
}
|
|
2237
2251
|
|
|
2252
|
+
// v1.229: a place's `away` hook hears once that pinned retention is holding a
|
|
2253
|
+
// dropped, arrived player (the first tick that keeps them past the deadline
|
|
2254
|
+
// check), and `back` once when the same id returns inside the window. Only a
|
|
2255
|
+
// pinned window (`reconnectWindowMs`) tells; the 60 s and pose-only keeps do
|
|
2256
|
+
// not. An expiry, Back, travel or shutdown after `away` runs `leave` as before.
|
|
2257
|
+
function awayHooks(h) {
|
|
2258
|
+
return typeof h.hooks.away === 'function' && typeof h.hooks.back === 'function';
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
function tellAway(h, playerId) {
|
|
2262
|
+
const entry = h.players.get(playerId);
|
|
2263
|
+
if (!pinnedResume(h) || !entry?.arrived || entry.ended || h.awayTold?.has(playerId) || !awayHooks(h)) {
|
|
2264
|
+
if (!h.awayWarned && pinnedResume(h) && (typeof h.hooks.away === 'function') !== (typeof h.hooks.back === 'function')) {
|
|
2265
|
+
h.awayWarned = true;
|
|
2266
|
+
console.warn('[hub] away and back are a pair: a place that defines only one is told neither');
|
|
2267
|
+
}
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
(h.awayTold ??= new Map()).set(playerId, {
|
|
2271
|
+
at: Date.now(),
|
|
2272
|
+
userId: entry.userId ?? null,
|
|
2273
|
+
rosterUserId: h.resumeKept?.get(playerId)?.rosterUserId ?? null,
|
|
2274
|
+
});
|
|
2275
|
+
callAwayHook(h, 'away', playerId, { userId: entry.userId ?? null, username: entry.username ?? 'player' });
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
function rosterUserOf(h, playerId) {
|
|
2279
|
+
const p = h.session?.players.find((q) => q.playerId === playerId);
|
|
2280
|
+
return p && p.userId !== undefined && p.userId !== null ? String(p.userId) : null;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
function visitOver(h, playerId, entry) {
|
|
2284
|
+
return h.players.get(playerId) !== entry || entry.ended === true || h.resumeDeparting?.has(playerId) === true;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// Before anything of the held visit is put back: false when the visit told
|
|
2288
|
+
// `away` does not resume. Another person on its id, or a visit ended while
|
|
2289
|
+
// away, leaves once (its `leave` names the old account; no door end goes down
|
|
2290
|
+
// the id), and whoever is there now arrives fresh.
|
|
2291
|
+
function awayReturns(h, playerId) {
|
|
2292
|
+
const told = h.awayTold?.get(playerId);
|
|
2293
|
+
if (!told) {
|
|
2294
|
+
return true;
|
|
2295
|
+
}
|
|
2296
|
+
const entry = h.players.get(playerId);
|
|
2297
|
+
if (!entry) {
|
|
2298
|
+
h.awayTold.delete(playerId);
|
|
2299
|
+
return false;
|
|
2300
|
+
}
|
|
2301
|
+
const rosterUserId = rosterUserOf(h, playerId);
|
|
2302
|
+
const other = (userIdOf(h, playerId) ?? null) !== told.userId ||
|
|
2303
|
+
(told.rosterUserId !== null && rosterUserId !== told.rosterUserId);
|
|
2304
|
+
if (other || visitOver(h, playerId, entry)) {
|
|
2305
|
+
forget(h, playerId);
|
|
2306
|
+
return false;
|
|
2307
|
+
}
|
|
2308
|
+
return true;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
// After the pose is back: false when the `back` hook ended the visit.
|
|
2312
|
+
function tellBack(h, playerId) {
|
|
2313
|
+
const told = h.awayTold?.get(playerId);
|
|
2314
|
+
if (!told) {
|
|
2315
|
+
return true;
|
|
2316
|
+
}
|
|
2317
|
+
h.awayTold.delete(playerId);
|
|
2318
|
+
const entry = h.players.get(playerId);
|
|
2319
|
+
if (!entry) {
|
|
2320
|
+
return false;
|
|
2321
|
+
}
|
|
2322
|
+
callAwayHook(h, 'back', playerId, {
|
|
2323
|
+
userId: entry.userId ?? null,
|
|
2324
|
+
username: entry.username ?? 'player',
|
|
2325
|
+
awayMs: Math.max(0, Date.now() - told.at),
|
|
2326
|
+
});
|
|
2327
|
+
return !visitOver(h, playerId, entry);
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
function callAwayHook(h, name, playerId, info) {
|
|
2331
|
+
try {
|
|
2332
|
+
const out = h.hooks[name](h.ctx, playerId, Object.freeze(info));
|
|
2333
|
+
if (out && typeof out.then === 'function') {
|
|
2334
|
+
out.then(undefined, () => console.warn(`[hub] ${name} hook failed`));
|
|
2335
|
+
}
|
|
2336
|
+
} catch (err) {
|
|
2337
|
+
console.warn(`[hub] ${name} hook failed: ${err?.message ?? err}`);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2238
2341
|
function prepareResume(h, playerId, greet = true) {
|
|
2239
2342
|
const kept = h.resumeKept?.get(playerId);
|
|
2240
2343
|
if (!kept) {
|
|
@@ -2260,9 +2363,16 @@ function prepareResume(h, playerId, greet = true) {
|
|
|
2260
2363
|
forget(h, playerId);
|
|
2261
2364
|
return;
|
|
2262
2365
|
}
|
|
2366
|
+
if (!present) {
|
|
2367
|
+
tellAway(h, playerId);
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2263
2370
|
if (!returning) {
|
|
2264
2371
|
return;
|
|
2265
2372
|
}
|
|
2373
|
+
if (!awayReturns(h, playerId)) {
|
|
2374
|
+
return h.players.has(playerId) ? 'handled' : 'fresh';
|
|
2375
|
+
}
|
|
2266
2376
|
if (h.place.resumeVisibility === true) {
|
|
2267
2377
|
if (typeof kept.identityUserId === 'string' && kept.identityUserId === userIdOf(h, playerId)) {
|
|
2268
2378
|
kept.visibilityResumePending = true;
|
|
@@ -2300,6 +2410,10 @@ function prepareResume(h, playerId, greet = true) {
|
|
|
2300
2410
|
settle(h, playerId);
|
|
2301
2411
|
kept.body = body;
|
|
2302
2412
|
delete kept.awayAt;
|
|
2413
|
+
// v1.229: after the pose is back, before the hello replay and `resume`.
|
|
2414
|
+
if (!tellBack(h, playerId)) {
|
|
2415
|
+
return h.players.has(playerId) ? 'handled' : 'fresh';
|
|
2416
|
+
}
|
|
2303
2417
|
// The silent same-id case has no fresh arrive hook. Reuse the existing hello
|
|
2304
2418
|
// replay to restore private channels, including a cleared channel it missed.
|
|
2305
2419
|
if (greet) {
|
|
@@ -2577,6 +2691,12 @@ function forget(h, playerId) {
|
|
|
2577
2691
|
console.warn(`[hub] leave hook failed: ${err?.message ?? err}`);
|
|
2578
2692
|
}
|
|
2579
2693
|
}
|
|
2694
|
+
// v1.229: a visit told `away` ends with `leave` alone, never a late `back`;
|
|
2695
|
+
// a body real-time still holds stays off the roster until it goes.
|
|
2696
|
+
if (h.awayTold?.delete(playerId) && h.sim?.players.has(playerId) &&
|
|
2697
|
+
!h.session?.players.some((p) => p.playerId === playerId)) {
|
|
2698
|
+
(h.awayGone ??= new Set()).add(playerId);
|
|
2699
|
+
}
|
|
2580
2700
|
Vehicle.forget(h, playerId, (id, point, face) => placeAt(h, id, point, face));
|
|
2581
2701
|
Disguise.forget(h, playerId);
|
|
2582
2702
|
DoorAnalytics.finish(h, playerId, 3);
|
|
@@ -221,6 +221,8 @@ of any of these. Every hook gets `hub`, the place's context, first:
|
|
|
221
221
|
| `fall(hub, playerId)` | v1.1: a player fell below the place's `fallY` (§5); place them somewhere, or the kit puts them back at the arrival |
|
|
222
222
|
| `carry(hub, playerId, carry)` | where the host has hub ops: what an already-arrived player brings back, when ghost's read came after the arrival window (§7) |
|
|
223
223
|
| `leave(hub, playerId, { userId, username })` | a player left (Back, the host's Back, a closed tab). v1.89 `{ resume: { keep: true } }` delays an unexplained absence up to 60 s (§12); a short resume runs neither leave nor arrive. Runs while the player is still known (v1.2): `hub.result` takes their result for the visit here, and `userId` names their storage (§14) |
|
|
224
|
+
| `away(hub, playerId, { userId, username })` | v1.229, optional; defining it together with `back` is the opt-in (a place defining only one of the pair is told neither, with one warning): pinned retention (a host-pinned `reconnectWindowMs`, the Town's or a door's `resumeWindowSec`) is holding this arrived player, who dropped without Back. Called once, on the first tick that keeps them; from then until `back` they are left out of `hub.players()` (even while the host still holds their body, and through `leave` until that body goes), and their visit, pose and result state stay held. Free what other players wait on (a shared turn, a control, a slot, co-op credit) here; it is neither `leave` nor the end of the visit. Then exactly one of: `back` on a same-id return inside the window, or `leave` (the window expired, the visit was ended or replaced, another person (account or anonymous guest) came back on the id, shutdown). A visit `hub.end`ed while away gets no `back`: on return it leaves once and whoever is there arrives fresh. The 60 s keep (`resume: { keep: true }`) and pose-only places never call it. `info` is frozen; return ignored; throws and rejections contained and logged ("Away and back") |
|
|
225
|
+
| `back(hub, playerId, { userId, username, awayMs })` | v1.229, optional, paired with `away`: the player told `away` is back under the same id and the same account (or the same anonymous guest) inside the window. Called once, after their pose is put back and before the hello replay and `resume`; `awayMs` is wall-clock time since `away`. Re-take what `away` freed; the player is in `hub.players()` again. Never called without an `away` first; a return past the window is a fresh `arrive` after `leave`. Return ignored; throws and rejections contained and logged |
|
|
224
226
|
| `shutdown(hub)` | v1.2: the session is stopping. Anyone still here has had `leave` first; return a promise to finish writing (awaited up to 1.5 s, inside the host's own grace) |
|
|
225
227
|
| `grab(hub, playerId, actorId, op)` | v1.3, a place with `grab`: a player grabbed (`op` `"grab"`) or threw (`"throw"`) a loose object (§6). Return `false` to a grab to refuse it (the player lets go at once); a throw is only told. A hook that throws refuses the grab |
|
|
226
228
|
| `emote(hub, playerId, id)` | v1.6, a place with `idle.emotes`: a player asked to play emote `id` (§6). Return `false` to refuse it (nobody sees it); a hook that throws refuses it |
|
|
@@ -5476,6 +5478,7 @@ a deck written before them remains valid.
|
|
|
5476
5478
|
| 2026-11-18 (v1.222) | Writer leases (server-only, no wire or manifest change): a fresh connection whose account has no connected visit here forgets that account's retained visits whether or not it is lost, and a visit back to a held claim (retained visits, or the 60 s end-save window) revalidates it; a claim another instance took meanwhile is replaced silently instead of losing the fresh visit. `hub.saves.deck`/`user` views are bound to the claim current when made, so a superseded visit's queued writes reject with `CAULDRON_STORAGE_WRITER_LOST`. `resumePose` takes, ends and clears its durable pose through the lease view, so a fenced instance no longer moves the pose revision. No deck opts in yet. |
|
|
5477
5479
|
| 2026-11-18 (v1.223) | Writer leases (server-only, no wire or manifest change): a lone visit back that arrives while an earlier visit's revalidation is still out checks the claim again once that round settles (on whichever claim it settled), so a check from before another instance's takeover never lets the return proceed only to lose its first save. `resumePose` takes its snapshot through the lease view too, so it reads only once the claim settles and keeps a pose the previous writer saved just before; its 5 s read budget starts once the claim has settled. An older pending round that resumes on a replacement claim a newer arrival is already checking waits for that round and keeps the claim it found; it never inherits a claim that round reopens. A take holds its queue place at once, so an end asked while it waits for the claim runs after it. Without `writerLease` nothing changes. No deck opts in yet. |
|
|
5478
5480
|
| 2026-11-18 (v1.224) | Writer leases (server-only): `await hub.saves.holds(view)` tells whether the claim a save view writes through is still active and has not been lost, after pending claim checks settle. Unrecognized views and lease-off stores answer true. No manifest or wire change. |
|
|
5481
|
+
| 2026-11-19 (v1.229) | §4 optional `away(hub, playerId, { userId, username })` and `back(hub, playerId, { userId, username, awayMs })` hooks: pinned retention tells a place once when it holds a dropped arrived player, and once on the same id's return inside the window (after the pose is restored, before the hello replay and `resume`); otherwise the visit ends with `leave` as before ("Away and back"). The 60 s keep and pose-only places never call them. Hook presence is the opt-in; server-only, no manifest or wire change. |
|
|
5479
5482
|
| 2026-11-19 (v1.230) | §1 `resumeWindowSec` may stand beside `resumePose` (still refused beside `result`, `houseResume` and `resumeArrivalPose`): the pinned window holds the same visit and pose, and `resumePose`'s stored pose then places a new id for the same account up to ten minutes after departure, as the Town's places already do ("Door resume window"). Manifest validation only; no runtime or wire change. |
|
|
5480
5483
|
| 2026-11-18 (v1.226) | Writer leases (server-only, no manifest or wire change): every `set`/`remove`/`increment` through a `hub.saves` view carries the platform writer check of the claim it is bound to, so a stale write is refused atomically instead of after a separate fence (the write-after-fence window is closed for ordinary writes where the platform checks). A refusal loses the claim and is never retried. Where a checked write answers `CAULDRON_STORAGE_UNAVAILABLE` (`castle-web serve`, persistent-world sessions; the details may sit under `extensions`) the session fences and writes unchecked as before; view `transaction`/`conditionalWrite` and root atomic calls keep their fence. Every lone arrival now claims anew and the place reloads (no revalidation of a held claim): queued writes of the previous visit go first for up to 5 s; claims are sent or retried only while a connected visit is here, and a resume picks a waiting claim up again. `holds(view)` also waits for the account's current claim. Without `writerLease` nothing changes. No deck opts in yet. |
|
|
5481
5484
|
| 2026-11-18 (v1.228) | Writer leases (server-only, no manifest or wire change): `hub.saves.bind(store, view)` returns another store of the account (a `session.storage.playthrough` handle) bound to the claim `view` is bound to: `set`/`remove` carry that claim's writer check and run in account order, reads wait for that claim. The raw store when `view` is not a lease view or the lease is off. The Town conversation saves through it. No deck opts in yet. |
|
|
@@ -5696,6 +5699,39 @@ has passed `resumePose`'s stored pose still places a new id for the same
|
|
|
5696
5699
|
account (up to ten minutes after departure). Absent, on an older Ghost, or on a host
|
|
5697
5700
|
without grace, nothing is pinned and a drop ends the visit exactly as before.
|
|
5698
5701
|
|
|
5702
|
+
### Away and back (v1.229)
|
|
5703
|
+
|
|
5704
|
+
A pinned window holds a dropped player's visit with no `leave` and no
|
|
5705
|
+
`arrive`, which suits a place that only needs them to stand where they were.
|
|
5706
|
+
A place with shared state (a turn, a relay leg, a host slot, a co-op count, a
|
|
5707
|
+
control one player drives) would otherwise wait on, charge or credit someone
|
|
5708
|
+
who is gone for up to the whole window. Such a place defines `away` and
|
|
5709
|
+
`back` (§4):
|
|
5710
|
+
|
|
5711
|
+
- `away(hub, playerId, { userId, username })` runs once when the kit first
|
|
5712
|
+
keeps the dropped player under the pinned deadline. It does not run for a
|
|
5713
|
+
drop the kit lets go at once (the player's own Back, kit travel, a writer
|
|
5714
|
+
lease replaced) -- those go straight to `leave`.
|
|
5715
|
+
- `back(hub, playerId, { userId, username, awayMs })` runs once on a same-id
|
|
5716
|
+
return inside the window, after the pose is restored and before the hello
|
|
5717
|
+
replay and the `resume` hook.
|
|
5718
|
+
- After `away`, the visit ends in exactly one of `back` or `leave`. A second
|
|
5719
|
+
drop after `back` tells `away` again. The pair is the opt-in: a place that
|
|
5720
|
+
defines only one is told neither (the kit warns once).
|
|
5721
|
+
- Another person (account or anonymous guest) returning on the same id is
|
|
5722
|
+
not `back`: before anything of the held visit is put back, the old visit
|
|
5723
|
+
leaves (its `leave` names the old account) and the newcomer arrives fresh.
|
|
5724
|
+
A visit ended (`hub.end`) while away leaves the same way on return; one
|
|
5725
|
+
ended by `back` ends as any present player's does.
|
|
5726
|
+
- From `away` until `back`, and through `leave` until real-time drops the
|
|
5727
|
+
body, the player is left out of `hub.players()`; the deadline counts from
|
|
5728
|
+
the drop even while the body lingers.
|
|
5729
|
+
|
|
5730
|
+
Only a pinned window tells (`reconnectWindowMs` on the session, the Town's 180
|
|
5731
|
+
s, a door's `resumeWindowSec`, an owner house's grace); the 60 s keep and
|
|
5732
|
+
pose-only resume do not. Absent hooks, an older kit, or no pinned window:
|
|
5733
|
+
unchanged behaviour. Server-only; no manifest key and no wire change.
|
|
5734
|
+
|
|
5699
5735
|
### v1.115: owner-house reconnect retention
|
|
5700
5736
|
|
|
5701
5737
|
Optional place key `hub.houseResume: true` (also in a `hub.places` block), only
|
|
@@ -53,6 +53,8 @@ function boot(keys = {}, more = {}) {
|
|
|
53
53
|
},
|
|
54
54
|
fall: more.fall,
|
|
55
55
|
resume: more.resume,
|
|
56
|
+
away: more.away,
|
|
57
|
+
back: more.back,
|
|
56
58
|
message: more.message,
|
|
57
59
|
leave(ctx, playerId) {
|
|
58
60
|
leaves.push(playerId);
|
|
@@ -1180,6 +1182,198 @@ test('pinned Town:181s expires despite the old five-minute pose marker', () => k
|
|
|
1180
1182
|
r.drop(); r.tick(); advance(181_000); r.tick(181_000); assert.equal(r.leaves.length, 1);
|
|
1181
1183
|
}));
|
|
1182
1184
|
|
|
1185
|
+
// v1.229: pinned retention tells a place `away` once when it holds a dropped
|
|
1186
|
+
// player and `back` once on the same id's return inside the window.
|
|
1187
|
+
function awayBoot(keys = {}, more = {}) {
|
|
1188
|
+
const told = [];
|
|
1189
|
+
const r = boot(keys, { reconnectWindowMs: 180_000,
|
|
1190
|
+
away(c, id, info) { told.push(['away', id, { ...info }, c.players().some(p => p.playerId === id)]); },
|
|
1191
|
+
back(c, id, info) { told.push(['back', id, { ...info }, { ...c.players().find(p => p.playerId === id)?.at }]); },
|
|
1192
|
+
resume(c, { playerId }) { told.push(['resume', playerId]); },
|
|
1193
|
+
leave(c, id) { told.push(['leave', id]); },
|
|
1194
|
+
...more });
|
|
1195
|
+
return { r, told };
|
|
1196
|
+
}
|
|
1197
|
+
for (const away of [30_000, 180_000]) {
|
|
1198
|
+
test(`v1.229 pinned: away once, back once after the pose is put back (${away} ms)`, () => keeping((advance) => {
|
|
1199
|
+
const { r, told } = awayBoot();
|
|
1200
|
+
const at = { x: 44.2, y: 1, z: -2.4 };
|
|
1201
|
+
r.ctx().placeAt('p2', at, 90); r.tick();
|
|
1202
|
+
r.drop(); r.tick();
|
|
1203
|
+
assert.deepEqual(told, [['away', 'p2', { userId: '102', username: 'Bo' }, false]]);
|
|
1204
|
+
r.tick(); advance(away); r.tick(away);
|
|
1205
|
+
assert.equal(told.length, 1, 'told away once while held');
|
|
1206
|
+
r.back(); r.say('p2', rehello); r.tick();
|
|
1207
|
+
assert.deepEqual(told.slice(1).map(t => t[0]), ['back', 'resume']);
|
|
1208
|
+
assert.deepEqual(told[1].slice(0, 3), ['back', 'p2', { userId: '102', username: 'Bo', awayMs: away }]);
|
|
1209
|
+
assert.deepEqual(told[1][3], at, 'back sees the restored pose');
|
|
1210
|
+
assert.equal(r.arrivedTimes('p2'), 1); assert.deepEqual(r.leaves, []);
|
|
1211
|
+
r.tick(); r.tick(5000);
|
|
1212
|
+
assert.equal(told.length, 3, 'nothing more while back');
|
|
1213
|
+
}));
|
|
1214
|
+
}
|
|
1215
|
+
test('v1.229 pinned: a body the host still holds is off hub.players() from away until back', () => keeping((advance) => {
|
|
1216
|
+
const { r, told } = awayBoot();
|
|
1217
|
+
const kept = r.world.players.get('p2');
|
|
1218
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2'); r.tick();
|
|
1219
|
+
assert.equal(told[0][0], 'away'); assert.ok(r.world.players.get('p2') === kept);
|
|
1220
|
+
assert.ok(!r.ctx().players().some(p => p.playerId === 'p2'));
|
|
1221
|
+
r.world.players.delete('p2'); r.tick(); advance(5_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1222
|
+
assert.ok(r.ctx().players().some(p => p.playerId === 'p2'));
|
|
1223
|
+
assert.deepEqual(told.map(t => t[0]), ['away', 'back', 'resume']);
|
|
1224
|
+
}));
|
|
1225
|
+
test('v1.229 pinned: a same-body return (roster row back, body never gone) is back', () => keeping((advance) => {
|
|
1226
|
+
const { r, told } = awayBoot();
|
|
1227
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
|
|
1228
|
+
r.tick(); r.tick(); advance(20_000); r.tick(20_000); r.tick();
|
|
1229
|
+
assert.deepEqual(told.map(t => t[0]), ['away']);
|
|
1230
|
+
r.session.players.push({ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false });
|
|
1231
|
+
r.tick(); r.say('p2', rehello); r.tick();
|
|
1232
|
+
assert.deepEqual(told.filter(t => t[0] !== 'resume').map(t => t[0]), ['away', 'back']);
|
|
1233
|
+
assert.ok(r.ctx().players().some(p => p.playerId === 'p2'));
|
|
1234
|
+
assert.deepEqual(r.leaves, []);
|
|
1235
|
+
}));
|
|
1236
|
+
test('v1.229 pinned: the held deadline does not move while the body lingers', () => keeping((advance) => {
|
|
1237
|
+
const { r, told } = awayBoot();
|
|
1238
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
|
|
1239
|
+
r.tick();
|
|
1240
|
+
for (let i = 0; i < 4; i += 1) { advance(50_000); r.tick(50_000); }
|
|
1241
|
+
assert.deepEqual(told.map(t => t.slice(0, 2)), [['away', 'p2'], ['leave', 'p2']]);
|
|
1242
|
+
}));
|
|
1243
|
+
test('v1.229 pinned: expiry with a lingering body keeps the player off hub.players() during leave and after', () => keeping((advance) => {
|
|
1244
|
+
const seen = [];
|
|
1245
|
+
const { r } = awayBoot({}, { leave(c, id) { seen.push(c.players().some(p => p.playerId === id)); } });
|
|
1246
|
+
r.session.players = r.session.players.filter((p) => p.playerId !== 'p2');
|
|
1247
|
+
r.tick(); advance(181_000); r.tick(181_000);
|
|
1248
|
+
assert.deepEqual(seen, [false]);
|
|
1249
|
+
r.tick(); assert.ok(!r.ctx().players().some(p => p.playerId === 'p2'));
|
|
1250
|
+
r.world.players.delete('p2'); r.tick();
|
|
1251
|
+
r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1252
|
+
assert.ok(r.ctx().players().some(p => p.playerId === 'p2'), 'a fresh arrival on the id is listed');
|
|
1253
|
+
}));
|
|
1254
|
+
test('v1.229 pinned: another account back on the id is a leave of the old visit, never back', () => keeping((advance) => {
|
|
1255
|
+
const { r, told } = awayBoot();
|
|
1256
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000);
|
|
1257
|
+
r.session.players.push({ playerId: 'p2', userId: '103', username: 'Cy', isAnonymous: false });
|
|
1258
|
+
r.world.players.set('p2', body());
|
|
1259
|
+
r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1260
|
+
assert.ok(!told.some(t => t[0] === 'back'));
|
|
1261
|
+
assert.deepEqual(told.filter(t => t[0] === 'leave').map(t => t[1]), ['p2']);
|
|
1262
|
+
assert.ok(!r.sent.some(([id, m]) => id === 'p2' && m.k === 'hub-end'), 'no door end sent to the newcomer');
|
|
1263
|
+
}));
|
|
1264
|
+
for (const where of ['away', 'back']) {
|
|
1265
|
+
test(`v1.229 pinned: a visit ended in ${where} gets no back and no retained replay`, () => keeping((advance) => {
|
|
1266
|
+
const calls = [];
|
|
1267
|
+
const { r } = awayBoot({}, {
|
|
1268
|
+
away(c, id) { calls.push('away'); if (where === 'away') {c.end([id]);} },
|
|
1269
|
+
back(c, id) { calls.push('back'); if (where === 'back') {c.end([id]);} },
|
|
1270
|
+
resume() { calls.push('resume'); },
|
|
1271
|
+
});
|
|
1272
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1273
|
+
r.say('p2', rehello); r.tick(); r.say('p2', rehello); r.tick();
|
|
1274
|
+
if (where === 'away') {
|
|
1275
|
+
assert.deepEqual(calls, ['away'], 'no back, no retained resume on any hello');
|
|
1276
|
+
assert.deepEqual(r.leaves, ['p2'], 'the ended visit leaves once');
|
|
1277
|
+
} else {
|
|
1278
|
+
assert.deepEqual(calls.slice(0, 2), ['away', 'back']);
|
|
1279
|
+
assert.ok(!calls.slice(2).includes('back'));
|
|
1280
|
+
}
|
|
1281
|
+
}));
|
|
1282
|
+
}
|
|
1283
|
+
test('v1.229 pinned: the identity check runs before the old pose is put on the newcomer', () => keeping((advance) => {
|
|
1284
|
+
const { r, told } = awayBoot();
|
|
1285
|
+
const at = { x: 44.2, y: 1, z: -2.4 };
|
|
1286
|
+
r.ctx().placeAt('p2', at, 90); r.tick();
|
|
1287
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000);
|
|
1288
|
+
r.session.players.push({ playerId: 'p2', userId: '103', username: 'Cy', isAnonymous: false });
|
|
1289
|
+
const fresh = body(); r.world.players.set('p2', fresh);
|
|
1290
|
+
r.say('p2', rehello);
|
|
1291
|
+
assert.notDeepEqual(fresh.at, at, 'the newcomer is not moved to the old visit\'s pose');
|
|
1292
|
+
assert.ok(!told.some(t => t[0] === 'back'));
|
|
1293
|
+
}));
|
|
1294
|
+
test('v1.229 pinned: a different anonymous guest on the id is not back', () => keeping((advance) => {
|
|
1295
|
+
const guests = [
|
|
1296
|
+
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
1297
|
+
{ playerId: 'p2', userId: '9001', username: 'guest', isAnonymous: true },
|
|
1298
|
+
];
|
|
1299
|
+
const { r, told } = awayBoot({}, { players: guests });
|
|
1300
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000);
|
|
1301
|
+
r.session.players.push({ playerId: 'p2', userId: '9002', username: 'guest', isAnonymous: true });
|
|
1302
|
+
r.world.players.set('p2', body());
|
|
1303
|
+
r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1304
|
+
assert.equal(told[0][0], 'away');
|
|
1305
|
+
assert.ok(!told.some(t => t[0] === 'back'));
|
|
1306
|
+
assert.deepEqual(told.filter(t => t[0] === 'leave').map(t => t[1]), ['p2']);
|
|
1307
|
+
}));
|
|
1308
|
+
test('v1.229 pinned: the same anonymous guest back on the id is back', () => keeping((advance) => {
|
|
1309
|
+
const guest = { playerId: 'p2', userId: '9001', username: 'guest', isAnonymous: true };
|
|
1310
|
+
const { r, told } = awayBoot({}, { players: [{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false }, guest] });
|
|
1311
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000);
|
|
1312
|
+
r.session.players.push({ ...guest }); r.world.players.set('p2', body());
|
|
1313
|
+
r.say('p2', rehello); r.tick();
|
|
1314
|
+
assert.deepEqual(told.filter(t => t[0] !== 'resume').map(t => t[0]), ['away', 'back']);
|
|
1315
|
+
}));
|
|
1316
|
+
test('v1.229 pinned: a second drop after back tells away again', () => keeping((advance) => {
|
|
1317
|
+
const { r, told } = awayBoot();
|
|
1318
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1319
|
+
r.drop(); r.tick(); advance(5_000); r.tick(5_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1320
|
+
assert.deepEqual(told.map(t => t[0]), ['away', 'back', 'resume', 'away', 'back', 'resume']);
|
|
1321
|
+
assert.equal(told[4][2].awayMs, 5_000);
|
|
1322
|
+
}));
|
|
1323
|
+
test('v1.229 pinned: past the window, away is followed by leave and no back', () => keeping((advance) => {
|
|
1324
|
+
const { r, told } = awayBoot();
|
|
1325
|
+
r.drop(); r.tick(); advance(181_000); r.tick(181_000);
|
|
1326
|
+
assert.deepEqual(told.map(t => t.slice(0, 2)), [['away', 'p2'], ['leave', 'p2']]);
|
|
1327
|
+
r.back(); r.say('p2', rehello); r.tick(2000); r.tick();
|
|
1328
|
+
assert.ok(!told.some(t => t[0] === 'back'), 'a return past the window is not a back');
|
|
1329
|
+
}));
|
|
1330
|
+
test('v1.229 pinned: Back, then a drop, is a leave with no away', () => keeping(() => {
|
|
1331
|
+
const { r, told } = awayBoot();
|
|
1332
|
+
r.say('p2', { k: 'hub-back' }); r.tick(); r.drop(); r.tick();
|
|
1333
|
+
assert.deepEqual(told.map(t => t.slice(0, 2)), [['leave', 'p2']]);
|
|
1334
|
+
}));
|
|
1335
|
+
test('v1.229 pinned: shutdown drains a player told away with leave alone', async () => {
|
|
1336
|
+
const { r, told } = awayBoot();
|
|
1337
|
+
r.drop(); r.tick();
|
|
1338
|
+
await r.server.shutdown();
|
|
1339
|
+
assert.deepEqual(told.filter(t => t[1] === 'p2').map(t => t.slice(0, 2)), [['away', 'p2'], ['leave', 'p2']]);
|
|
1340
|
+
});
|
|
1341
|
+
test('v1.229 pinned: a hook that throws is contained and the hold goes on', () => keeping((advance) => {
|
|
1342
|
+
const calls = [];
|
|
1343
|
+
const { r } = awayBoot({}, { away() { calls.push('away'); throw new Error('x'); }, back() { calls.push('back'); throw new Error('y'); } });
|
|
1344
|
+
const warn = console.warn; console.warn = () => {};
|
|
1345
|
+
try {
|
|
1346
|
+
r.drop(); r.tick(); advance(30_000); r.tick(30_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1347
|
+
} finally { console.warn = warn; }
|
|
1348
|
+
assert.deepEqual(calls, ['away', 'back']);
|
|
1349
|
+
assert.equal(r.arrivedTimes('p2'), 1); assert.deepEqual(r.leaves, []);
|
|
1350
|
+
}));
|
|
1351
|
+
test('v1.229 pinned: back without a hello (late greet) still tells back once', () => keeping((advance) => {
|
|
1352
|
+
const { r, told } = awayBoot();
|
|
1353
|
+
r.drop(); r.tick(); advance(20_000); r.tick(20_000); r.back(); r.tick(); r.tick(3500); r.say('p2', rehello); r.tick();
|
|
1354
|
+
assert.deepEqual(told.filter(t => t[0] !== 'resume').map(t => t[0]), ['away', 'back']);
|
|
1355
|
+
}));
|
|
1356
|
+
test('v1.229: no pinned window, no away or back (60 s keep and plain places)', () => keeping((advance) => {
|
|
1357
|
+
for (const [keys, more] of [[keepGame, {}], [{ resumePose: true }, {}], [{}, {}]]) {
|
|
1358
|
+
const calls = [];
|
|
1359
|
+
const r = boot(keys, { ...more, away() { calls.push('away'); }, back() { calls.push('back'); } });
|
|
1360
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1361
|
+
assert.deepEqual(calls, [], JSON.stringify(keys));
|
|
1362
|
+
}
|
|
1363
|
+
}));
|
|
1364
|
+
for (const only of ['away', 'back']) {
|
|
1365
|
+
test(`v1.229 pinned: a place with only ${only} is told neither and keeps the visit as before`, () => keeping((advance) => {
|
|
1366
|
+
const calls = [];
|
|
1367
|
+
const r = boot({}, { reconnectWindowMs: 180_000, [only]() { calls.push(only); } });
|
|
1368
|
+
const warn = console.warn; const warned = []; console.warn = (m) => warned.push(m);
|
|
1369
|
+
try {
|
|
1370
|
+
r.drop(); r.tick(); advance(10_000); r.tick(10_000); r.back(); r.say('p2', rehello); r.tick();
|
|
1371
|
+
} finally { console.warn = warn; }
|
|
1372
|
+
assert.deepEqual(calls, []); assert.equal(r.arrivedTimes('p2'), 1); assert.deepEqual(r.leaves, []);
|
|
1373
|
+
assert.equal(warned.filter(m => String(m).includes('away and back are a pair')).length, 1);
|
|
1374
|
+
}));
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1183
1377
|
// v1.98: server-only town opt-in; the visit's first door is not a new trip.
|
|
1184
1378
|
for (const away of [30_000, 180_000, 299_999]) {
|
|
1185
1379
|
test(`town resumePose: ${away} ms same-id return restores before resume hook`, () => keeping((advance) => {
|