castle-web-cli 0.4.243 → 0.4.245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -0
- package/dist/api.js +13 -0
- package/dist/contentOriginTiming.d.ts +13 -0
- package/dist/contentOriginTiming.js +15 -0
- package/dist/imports.js +28 -6
- package/dist/index.js +54 -5
- package/dist/init.js +1 -1
- package/dist/projectState.d.ts +33 -0
- package/dist/projectState.js +97 -0
- package/dist/serve.d.ts +18 -0
- package/dist/serve.js +103 -2
- package/dist/serveSecurity.d.ts +105 -3
- package/dist/serveSecurity.js +500 -39
- package/dist/shell/assets/{index-DulbYIJm.js → index-Bec6LpAv.js} +87 -87
- package/dist/shell/index.html +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/runtime.js +57 -0
- package/kits/hub-game/code/client/chrome.js +9 -2
- package/kits/hub-game/code/client/hookLayer.js +8 -0
- package/kits/hub-game/code/client/padCues.js +2 -0
- package/kits/hub-game/code/client/padReadability.js +6 -1
- package/kits/hub-game/code/client/signals.js +126 -0
- package/kits/hub-game/code/client/state.js +4 -0
- package/kits/hub-game/code/server/friendBests.js +8 -2
- package/kits/hub-game/code/server/hub.js +31 -4
- package/kits/hub-game/code/server/npcs.js +4 -0
- package/kits/hub-game/code/server/party.js +3 -0
- package/kits/hub-game/code/server/resumePose.js +30 -9
- package/kits/hub-game/code/server/signals.js +124 -0
- package/kits/hub-game/code/server/writerLease.js +161 -17
- package/kits/hub-game/code/systems/hub.js +21 -2
- package/kits/hub-game/docs/contract.md +92 -11
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-menu-client.mjs +7 -6
- package/kits/hub-game/scripts/test-menu-footer-dom.mjs +94 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +6 -3
- package/kits/hub-game/scripts/test-resume-pose.mjs +85 -0
- package/kits/hub-game/scripts/test-signals.mjs +412 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +108 -4
- package/kits/hub-game/scripts/test-writer-lease.mjs +385 -1
- package/package.json +2 -2
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// v1.221: first-input signals (contract §4 `signal`, §12 "First-input
|
|
2
|
+
// signals"). A place whose module defines a `signal` hook hears a fixed
|
|
3
|
+
// vocabulary of a player's first moments, never free text:
|
|
4
|
+
//
|
|
5
|
+
// { kind: 'move' } their first walk input } from the client,
|
|
6
|
+
// { kind: 'jump' } their first jump } each at most once
|
|
7
|
+
// { kind: 'prompt', door } the first door prompt shown } an arrival, within
|
|
8
|
+
// } WINDOW_MS of it
|
|
9
|
+
// { kind: 'talk', npc } a conversation opened (an NPC actor id, or
|
|
10
|
+
// 'companion' for the player's own companion)
|
|
11
|
+
// { kind: 'press', door } they were put at a door they asked for (a door
|
|
12
|
+
// jump, a party Go or Go-yes, a friend's House)
|
|
13
|
+
// { kind: 'pad', door } the place's `hub.pad` first counted them on a
|
|
14
|
+
// door's pad
|
|
15
|
+
//
|
|
16
|
+
// Without the hook nothing is kept, sent or called: an older kit, which knows
|
|
17
|
+
// no such hook, simply never calls it.
|
|
18
|
+
|
|
19
|
+
const CLIENT_KINDS = new Set(['move', 'jump', 'prompt']);
|
|
20
|
+
// The client signals belong to this long after an arrival.
|
|
21
|
+
export const WINDOW_MS = 120_000;
|
|
22
|
+
const own = (data, keys) => Object.keys(data).every((key) => keys.includes(key));
|
|
23
|
+
|
|
24
|
+
export function on(h) {
|
|
25
|
+
return typeof h.hooks?.signal === 'function';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A hook that throws or rejects never reaches the kit; it is said once. Call
|
|
29
|
+
// it after the kit's own work for the event is done.
|
|
30
|
+
export function emit(h, playerId, signal) {
|
|
31
|
+
if (!on(h)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const failed = () => {
|
|
35
|
+
if (!h.signalFailed) {
|
|
36
|
+
h.signalFailed = true;
|
|
37
|
+
console.warn('[hub] signal hook failed');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
const result = h.hooks.signal(h.ctx, playerId, Object.freeze({ ...signal }));
|
|
42
|
+
result?.catch?.(failed);
|
|
43
|
+
} catch {
|
|
44
|
+
failed();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// A genuine arrival (the place's `arrive` hook has heard it): the client
|
|
49
|
+
// signals start again for this player. A rehello or a retained resume is not
|
|
50
|
+
// one. Returns the arrival's number for `hub-arrived`, or null without a hook.
|
|
51
|
+
export function arrived(h, playerId) {
|
|
52
|
+
if (!on(h)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
h.signalN = (h.signalN ?? 0) + 1;
|
|
56
|
+
(h.signalArrivals ??= new Map()).set(playerId, { n: h.signalN, at: Date.now(), sent: new Set() });
|
|
57
|
+
return h.signalN;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The client's `{ k: 'hub-signal', kind, a, door? }`, from a present sender
|
|
61
|
+
// whose arrival is still in its window; the sender comes from the session,
|
|
62
|
+
// never the payload. `a` is the arrival number the client was armed with: one
|
|
63
|
+
// from an earlier arrival (a rejoin race) is dropped before the kind is spent.
|
|
64
|
+
// Once and window checks come before any door lookup.
|
|
65
|
+
// `doorIds()`: the ids of this place's doors.
|
|
66
|
+
export function message(h, player, data, doorIds) {
|
|
67
|
+
const playerId = player?.playerId;
|
|
68
|
+
const arrival = typeof playerId === 'string' ? h.signalArrivals?.get(playerId) : null;
|
|
69
|
+
if (!arrival || !on(h) || Date.now() - arrival.at >= WINDOW_MS) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
if (data.a !== arrival.n) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const kind = data.kind;
|
|
77
|
+
if (!CLIENT_KINDS.has(kind) || arrival.sent.has(kind)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Spent before it is checked further: a bad one costs its sender the kind.
|
|
81
|
+
arrival.sent.add(kind);
|
|
82
|
+
if (!h.players.get(playerId)?.arrived || !h.session?.players.some((p) => p.playerId === playerId) || !h.sim?.players.has(playerId)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (kind !== 'prompt') {
|
|
86
|
+
if (own(data, ['k', 'kind', 'a'])) {
|
|
87
|
+
emit(h, playerId, { kind });
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const door = data.door;
|
|
92
|
+
if (own(data, ['k', 'kind', 'a', 'door']) && typeof door === 'string' && doorIds().includes(door)) {
|
|
93
|
+
emit(h, playerId, { kind: 'prompt', door });
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
// Refused wire data, including throwing accessors, is silent.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// A retained rehello or resume (a reloaded page, a rejoined socket) is not an
|
|
101
|
+
// arrival: it is told the current arrival's number, what of its window is
|
|
102
|
+
// left and the kinds already spent, so it can say what is left and nothing
|
|
103
|
+
// more. Neither the window nor the allowance starts again.
|
|
104
|
+
export function replay(h, playerId) {
|
|
105
|
+
const arrival = on(h) ? h.signalArrivals?.get(playerId) : null;
|
|
106
|
+
const left = arrival ? WINDOW_MS - (Date.now() - arrival.at) : 0;
|
|
107
|
+
if (left <= 0 || arrival.sent.size >= CLIENT_KINDS.size) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
h.session?.send(playerId, { k: 'hub-signals', n: arrival.n, left, sent: [...arrival.sent] });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function forget(h, playerId) {
|
|
114
|
+
h.signalArrivals?.delete(playerId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// `hub.pad(door, playerIds)`: who is on `door`'s pad now that was not before.
|
|
118
|
+
export function pad(h, door, before, on) {
|
|
119
|
+
for (const playerId of on) {
|
|
120
|
+
if (typeof playerId === 'string' && h.players.get(playerId)?.arrived && !before?.has(playerId)) {
|
|
121
|
+
emit(h, playerId, { kind: 'pad', door });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -20,12 +20,19 @@ export function create(session, optedIn) {
|
|
|
20
20
|
const visits = new Map();
|
|
21
21
|
const listeners = new Set();
|
|
22
22
|
const views = new Map();
|
|
23
|
+
const bindings = new WeakMap();
|
|
23
24
|
let closed = false;
|
|
24
25
|
let syncing = false;
|
|
25
26
|
const active = (entry) => !closed && accounts.get(entry.userId) === entry;
|
|
27
|
+
// Visits whose connection has gone but whose state the place still holds.
|
|
28
|
+
const away = new Set();
|
|
29
|
+
const visiting = (userId) => [...visits.values()].includes(userId);
|
|
30
|
+
const connected = (userId) => [...visits].some(([id, user]) => user === userId && !away.has(id));
|
|
26
31
|
const markLost = (entry) => {
|
|
27
32
|
if (!active(entry) || entry.lost) { return; }
|
|
28
33
|
entry.lost = true;
|
|
34
|
+
// A revalidating claim that turns out taken is replaced, not reported.
|
|
35
|
+
if (entry.revalidating) { return; }
|
|
29
36
|
for (const fn of listeners) {
|
|
30
37
|
try { fn(entry.userId); } catch (error) { console.warn(`[hub] saves onLost failed: ${error?.message ?? error}`); }
|
|
31
38
|
}
|
|
@@ -71,16 +78,121 @@ export function create(session, optedIn) {
|
|
|
71
78
|
entry.timer = setTimeout(resolve, delay);
|
|
72
79
|
});
|
|
73
80
|
entry.wake = null;
|
|
81
|
+
// Every visit of the account here has gone: a retry now could take
|
|
82
|
+
// the account from the instance the player has moved to.
|
|
83
|
+
if (active(entry) && !visiting(userId)) { entry.lost = true; return; }
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
})();
|
|
77
87
|
return entry;
|
|
78
88
|
};
|
|
89
|
+
// A fresh visit back to an account nobody here is connected to may find
|
|
90
|
+
// another instance took it meanwhile. This arrival is the newest, so it
|
|
91
|
+
// claims afresh; the old claim (and every view bound to it) ends silently,
|
|
92
|
+
// so the previous visit's late writes fail rather than land under the new one.
|
|
93
|
+
// Views made while it runs (the arrival's) follow the outcome; views made
|
|
94
|
+
// before it (the previous visit's) keep the old claim.
|
|
95
|
+
// A return while a round is still pending starts its own round after it:
|
|
96
|
+
// the pending round's check may predate a takeover, so this arrival checks
|
|
97
|
+
// again, on whichever claim that round settled on.
|
|
98
|
+
const revalidate = (entry) => {
|
|
99
|
+
if (entry.unleased) { return; }
|
|
100
|
+
const pending = entry.revalidating || null;
|
|
101
|
+
const prior = entry.ready;
|
|
102
|
+
// The round a view made now follows: its outcome only, never a later one.
|
|
103
|
+
const round = {};
|
|
104
|
+
entry.revalidating = round;
|
|
105
|
+
entry.ready = round.ready = (async () => {
|
|
106
|
+
let target = entry;
|
|
107
|
+
try {
|
|
108
|
+
await prior;
|
|
109
|
+
target = pending?.successor ?? entry;
|
|
110
|
+
if (target !== entry) {
|
|
111
|
+
if (!active(target) || target.unleased) { round.successor = target; return; }
|
|
112
|
+
// A later arrival is already checking the replacement claim: its
|
|
113
|
+
// check started after this one's arrival, so this round waits for
|
|
114
|
+
// it and stays with this claim. It never inherits a claim that
|
|
115
|
+
// round opens: that write authority is the later arrival's alone.
|
|
116
|
+
const newer = target.revalidating;
|
|
117
|
+
if (newer) {
|
|
118
|
+
await newer.ready;
|
|
119
|
+
round.successor = target;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
target.revalidating = round;
|
|
123
|
+
target.ready = round.ready;
|
|
124
|
+
}
|
|
125
|
+
const started = Date.now();
|
|
126
|
+
let unanswered = false;
|
|
127
|
+
for (let tries = 0; active(target) && !target.unleased && !target.lost;) {
|
|
128
|
+
try {
|
|
129
|
+
await storage.transaction({ operationId: operationId(), expectedAccess: target.access,
|
|
130
|
+
checks: [{ target: target.target, writer: target.writer }], changes: [] });
|
|
131
|
+
if (target !== entry) { round.successor = target; }
|
|
132
|
+
return;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (invalid(error)) { break; }
|
|
135
|
+
// Only a check that answers keeps the claim for an arrival. One
|
|
136
|
+
// refused, or still failing after the claim's own wait, cannot
|
|
137
|
+
// show that no other instance took the account.
|
|
138
|
+
if (!transient(error) || Date.now() - started >= CLAIM_WAIT_MS) { unanswered = true; break; }
|
|
139
|
+
const delay = Math.max(error?.retryAfterMs ?? 0, Math.min(8000, 250 * 2 ** Math.min(tries++, 5)));
|
|
140
|
+
await new Promise((resolve) => {
|
|
141
|
+
target.wake = resolve;
|
|
142
|
+
target.timer = setTimeout(resolve, delay);
|
|
143
|
+
});
|
|
144
|
+
target.wake = null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!active(target) || target.unleased) { return; }
|
|
148
|
+
// A visit held after its connection went counts as gone: the
|
|
149
|
+
// player may already be on another instance.
|
|
150
|
+
const present = () => connected(target.userId);
|
|
151
|
+
if (unanswered && !target.lost) {
|
|
152
|
+
// The arrival has gone again: nobody here needs a fresh claim, and
|
|
153
|
+
// one would take the account from wherever the player is now.
|
|
154
|
+
if (!present()) { if (target !== entry) { round.successor = target; } return; }
|
|
155
|
+
// Writes the previous visit queued under this claim go first, each
|
|
156
|
+
// under its own fence: they land if the claim is still this
|
|
157
|
+
// instance's. Then the arrival (the newest) claims afresh rather
|
|
158
|
+
// than load under a claim it may have lost.
|
|
159
|
+
target.draining = true;
|
|
160
|
+
for (const wake of target.waiters ?? []) { wake(); }
|
|
161
|
+
try {
|
|
162
|
+
// Including end saves queued while earlier ones were in flight.
|
|
163
|
+
for (let tail; tail !== target.tail;) { tail = target.tail; await tail; }
|
|
164
|
+
} finally { target.draining = false; }
|
|
165
|
+
if (!active(target) || target.unleased) { return; }
|
|
166
|
+
}
|
|
167
|
+
// Taken (or left unconfirmed) with no visit here: end it silently.
|
|
168
|
+
if (!present()) {
|
|
169
|
+
target.lost = true;
|
|
170
|
+
if (target !== entry) { round.successor = target; }
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
target.lost = true;
|
|
174
|
+
cancel(target);
|
|
175
|
+
round.successor = open(target.userId);
|
|
176
|
+
} finally {
|
|
177
|
+
for (const each of new Set([entry, target])) {
|
|
178
|
+
if (each.revalidating === round) { each.revalidating = false; }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await round.successor?.ready;
|
|
182
|
+
})();
|
|
183
|
+
};
|
|
79
184
|
const fenceEntry = (entry) => {
|
|
80
185
|
if (!entry || !active(entry) || entry.lost) { return Promise.reject(lostError()); }
|
|
81
186
|
if (entry.fencing) { return entry.fencing; }
|
|
82
187
|
entry.fencing = (async () => {
|
|
83
|
-
|
|
188
|
+
// A return whose check went unanswered lets writes already queued
|
|
189
|
+
// under this claim through (`draining`) before it claims afresh.
|
|
190
|
+
await new Promise((resolve) => {
|
|
191
|
+
if (entry.draining) { resolve(); return; }
|
|
192
|
+
const waiters = (entry.waiters ??= new Set());
|
|
193
|
+
waiters.add(resolve);
|
|
194
|
+
entry.ready.then(() => { waiters.delete(resolve); resolve(); });
|
|
195
|
+
});
|
|
84
196
|
if (!active(entry) || entry.lost) { throw lostError(); }
|
|
85
197
|
if (entry.unleased) { return; }
|
|
86
198
|
try {
|
|
@@ -94,54 +206,83 @@ export function create(session, optedIn) {
|
|
|
94
206
|
})().finally(() => { entry.fencing = null; });
|
|
95
207
|
return entry.fencing;
|
|
96
208
|
};
|
|
97
|
-
|
|
209
|
+
// A view is bound to the claim that existed when it was made: a write a
|
|
210
|
+
// visit queued keeps that claim, never a later visit's.
|
|
211
|
+
const view = (raw, userId, bound = accounts.get(userId), follow = bound?.revalidating || null) => {
|
|
98
212
|
if (!enabled || !raw) { return raw; }
|
|
99
|
-
|
|
213
|
+
const send = (entry, run) => {
|
|
214
|
+
const work = entry.tail.then(async () => { await fenceEntry(entry); return run(); });
|
|
215
|
+
entry.tail = work.catch(() => {});
|
|
216
|
+
return work;
|
|
217
|
+
};
|
|
218
|
+
const proxy = new Proxy(raw, {
|
|
100
219
|
get(target, name) {
|
|
101
|
-
if (['get', 'list'].includes(name) && typeof target[name] === 'function') {
|
|
220
|
+
if (['get', 'list', 'snapshot'].includes(name) && typeof target[name] === 'function') {
|
|
102
221
|
return async (...args) => { await api.ready(userId); return target[name](...args); };
|
|
103
222
|
}
|
|
104
223
|
if (['set', 'remove', 'increment', 'transaction', 'conditionalWrite'].includes(name) && typeof target[name] === 'function') {
|
|
105
224
|
return (...args) => {
|
|
106
|
-
const entry = accounts.get(userId);
|
|
225
|
+
const entry = bound ?? accounts.get(userId);
|
|
107
226
|
if (!entry) { return Promise.reject(lostError()); }
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
227
|
+
const run = () => target[name](...args);
|
|
228
|
+
// A round's successor may itself be revalidated later: this view
|
|
229
|
+
// stays with the claim its round settled on.
|
|
230
|
+
if (follow) { return follow.ready.then(() => send(follow.successor ?? entry, run)); }
|
|
231
|
+
return send(entry, run);
|
|
111
232
|
};
|
|
112
233
|
}
|
|
113
234
|
return typeof target[name] === 'function' ? target[name].bind(target) : target[name];
|
|
114
235
|
},
|
|
115
236
|
});
|
|
237
|
+
bindings.set(proxy, { userId, bound, follow });
|
|
238
|
+
return proxy;
|
|
116
239
|
};
|
|
117
240
|
const api = {
|
|
118
241
|
enabled,
|
|
119
242
|
deck(userId) {
|
|
120
243
|
if (!enabled) { return storage?.deck; }
|
|
121
|
-
|
|
122
|
-
return
|
|
244
|
+
const entry = accounts.get(userId);
|
|
245
|
+
if (!entry) { return view(storage?.deck, userId); }
|
|
246
|
+
const follow = entry.revalidating || null, cached = views.get(userId);
|
|
247
|
+
if (cached?.entry !== entry || cached.follow !== follow) { views.set(userId, { entry, follow, view: view(storage?.deck, userId, entry, follow) }); }
|
|
248
|
+
return views.get(userId).view;
|
|
123
249
|
},
|
|
124
250
|
user(userId) {
|
|
125
251
|
return view(storage?.user?.(userId), userId);
|
|
126
252
|
},
|
|
253
|
+
async holds(view) {
|
|
254
|
+
const binding = bindings.get(view);
|
|
255
|
+
if (!binding) { return true; }
|
|
256
|
+
const { userId, bound, follow } = binding;
|
|
257
|
+
const entry = bound ?? accounts.get(userId);
|
|
258
|
+
await follow?.ready;
|
|
259
|
+
const target = follow?.successor ?? entry;
|
|
260
|
+
// Even an older view must wait for an in-progress return to decide
|
|
261
|
+
// whether its claim is still active.
|
|
262
|
+
await target?.ready;
|
|
263
|
+
return Boolean(target && active(target) && !target.lost);
|
|
264
|
+
},
|
|
127
265
|
ready(userId) { return enabled ? accounts.get(userId)?.ready ?? Promise.resolve() : Promise.resolve(); },
|
|
128
266
|
fence(userId) { return enabled ? fenceEntry(accounts.get(userId)) : Promise.resolve(); },
|
|
129
|
-
lost(userId) {
|
|
267
|
+
lost(userId) { const entry = accounts.get(userId); return enabled && entry?.lost === true && !entry.revalidating; },
|
|
130
268
|
onLost(fn) { listeners.add(fn); return () => listeners.delete(fn); },
|
|
131
269
|
};
|
|
132
270
|
return {
|
|
133
271
|
api,
|
|
134
272
|
join(playerId, userId) {
|
|
273
|
+
away.delete(playerId);
|
|
135
274
|
if (!enabled || closed || typeof userId !== 'string' || visits.get(playerId) === userId) { return; }
|
|
136
275
|
this.leave(playerId);
|
|
137
276
|
// Retained stale visits must be finalized by sync before a fresh join.
|
|
138
|
-
|
|
277
|
+
const entry = accounts.get(userId);
|
|
278
|
+
if (!entry) { open(userId); } else if (![...visits.values()].includes(userId)) { revalidate(entry); }
|
|
139
279
|
clearTimeout(accounts.get(userId).expiry);
|
|
140
280
|
visits.set(playerId, userId);
|
|
141
281
|
},
|
|
142
282
|
leave(playerId) {
|
|
143
283
|
const userId = visits.get(playerId);
|
|
144
284
|
visits.delete(playerId);
|
|
285
|
+
away.delete(playerId);
|
|
145
286
|
const entry = accounts.get(userId);
|
|
146
287
|
if (!entry || [...visits.values()].includes(userId)) { return; }
|
|
147
288
|
const drop = () => {
|
|
@@ -154,19 +295,20 @@ export function create(session, optedIn) {
|
|
|
154
295
|
clearTimeout(entry.expiry);
|
|
155
296
|
if (entry.lost) { drop(); } else { entry.expiry = setTimeout(drop, KEEP_MS); }
|
|
156
297
|
},
|
|
157
|
-
// `held`: player ids whose authored state remains. A fresh
|
|
158
|
-
// finalizes
|
|
298
|
+
// `held`: player ids whose authored state remains. A fresh connection with
|
|
299
|
+
// no connected peer finalizes held visits through forgetHeld, then claims
|
|
300
|
+
// (a lost account) or revalidates its claim; otherwise keep them.
|
|
159
301
|
sync(players, held = [], forgetHeld) {
|
|
160
302
|
if (!enabled || closed || syncing) { return; }
|
|
161
303
|
const next = new Map(players), kept = new Set(held);
|
|
162
304
|
syncing = true;
|
|
163
305
|
try {
|
|
164
306
|
for (const [id, userId] of next) {
|
|
165
|
-
if (!forgetHeld || visits.has(id) ||
|
|
307
|
+
if (!forgetHeld || visits.has(id) ||
|
|
166
308
|
[...next].some(([otherId, otherUser]) => otherId !== id && otherUser === userId)) { continue; }
|
|
167
309
|
// Only a new connection with no connected account peer can replace
|
|
168
310
|
// stale held state. The kit's ordinary forget runs its leave hook
|
|
169
|
-
//
|
|
311
|
+
// (under the old claim) before the new visit claims or revalidates.
|
|
170
312
|
for (const [oldId, oldUser] of [...visits]) {
|
|
171
313
|
if (oldUser !== userId) { continue; }
|
|
172
314
|
if (kept.has(oldId)) { forgetHeld(oldId); }
|
|
@@ -178,6 +320,8 @@ export function create(session, optedIn) {
|
|
|
178
320
|
for (const [id, userId] of [...visits]) {
|
|
179
321
|
if (next.has(id) ? next.get(id) !== userId : !kept.has(id)) { this.leave(id); }
|
|
180
322
|
}
|
|
323
|
+
away.clear();
|
|
324
|
+
for (const id of visits.keys()) { if (!next.has(id)) { away.add(id); } }
|
|
181
325
|
} finally {
|
|
182
326
|
syncing = false;
|
|
183
327
|
}
|
|
@@ -185,7 +329,7 @@ export function create(session, optedIn) {
|
|
|
185
329
|
shutdown() {
|
|
186
330
|
closed = true;
|
|
187
331
|
for (const entry of accounts.values()) { cancel(entry); }
|
|
188
|
-
accounts.clear(); visits.clear(); views.clear(); listeners.clear();
|
|
332
|
+
accounts.clear(); visits.clear(); views.clear(); listeners.clear(); away.clear();
|
|
189
333
|
},
|
|
190
334
|
};
|
|
191
335
|
}
|
|
@@ -5,6 +5,7 @@ import { kitBackNeeded } from '../client/backVisibility.js';
|
|
|
5
5
|
import { cancelArrivalShot, faceArrivalCamera } from '../client/arrivalCamera.js';
|
|
6
6
|
import { makeDoorErrors } from '../client/doorErrors.js';
|
|
7
7
|
import { makeVisibility } from '../client/visibility.js';
|
|
8
|
+
import { makeSignals } from '../client/signals.js';
|
|
8
9
|
import { makeInvites } from '../client/invites.js';
|
|
9
10
|
import { makeHubEntry, planHubEntry } from '../client/hubEntry.js';
|
|
10
11
|
import { makeHostGo } from '../client/hostGo.js';
|
|
@@ -856,6 +857,13 @@ class HubSystem {
|
|
|
856
857
|
delete this.companionTappedUntil;
|
|
857
858
|
}
|
|
858
859
|
this.drawChrome(scene, local, now);
|
|
860
|
+
// v1.221: first-input signals, only for an arrival the place's `signal`
|
|
861
|
+
// hook hears (its `hub-arrived` carried a number).
|
|
862
|
+
if (Hub.hub.signalArrival || this.signals) {
|
|
863
|
+
this.signals ??= makeSignals();
|
|
864
|
+
this.signals.frame(mp.net ?? null, this.trip ? null : Hub.hub.signalArrival, now,
|
|
865
|
+
{ keys: scene.keys, stick: scene.moveInput, prompt: this.signalDoor });
|
|
866
|
+
}
|
|
859
867
|
if (Hub.hub.place?.actions === true || Hub.hub.place?.anonymousEntry === true) {
|
|
860
868
|
this.actionsDrawn = true;
|
|
861
869
|
const hud = Hub.hub.hudMe ?? Hub.hub.hud;
|
|
@@ -3865,6 +3873,10 @@ class HubSystem {
|
|
|
3865
3873
|
drawChrome(scene, local, now) {
|
|
3866
3874
|
const chrome = this.chrome;
|
|
3867
3875
|
const place = Hub.hub.place;
|
|
3876
|
+
// v1.221: a door whose prompt is drawn this frame, while the arrival's
|
|
3877
|
+
// first prompt is still to be said (first-input signals).
|
|
3878
|
+
this.signalDoor = null;
|
|
3879
|
+
const wantsPrompt = this.signals?.wantsPrompt(Hub.hub.signalArrival) === true;
|
|
3868
3880
|
const idle = !this.trip;
|
|
3869
3881
|
const tickets = scene.persistent.hubTickets;
|
|
3870
3882
|
const ticket = tickets[tickets.length - 1];
|
|
@@ -3895,7 +3907,11 @@ class HubSystem {
|
|
|
3895
3907
|
const askVisible = town && !this.askInput && !this.menuInput && !this.actionInput && this.decor?.opened() !== true &&
|
|
3896
3908
|
chrome.askShowable?.() !== false;
|
|
3897
3909
|
const ask = askVisible ? this.ask(now) : null;
|
|
3898
|
-
|
|
3910
|
+
const shownAsk = askVisible ? this.askSlot.display(ask, askAt, askPads, now) : null;
|
|
3911
|
+
chrome.setAsk?.(shownAsk);
|
|
3912
|
+
if (wantsPrompt && typeof shownAsk?.door === 'string') {
|
|
3913
|
+
this.signalDoor = shownAsk.door;
|
|
3914
|
+
}
|
|
3899
3915
|
this.retireExpiredAsk(ask);
|
|
3900
3916
|
this.startBeside(scene, local, town, now);
|
|
3901
3917
|
// A friend or party member went through a door: say so, and offer to follow.
|
|
@@ -4347,8 +4363,11 @@ class HubSystem {
|
|
|
4347
4363
|
context: engine.hubPadContext, ring: engine.hubPadRing, spawn: engine.hubSpawnRing };
|
|
4348
4364
|
}
|
|
4349
4365
|
const selfId = scene.multiplayer?.net?.selfId?.();
|
|
4350
|
-
this.padReadability.frame(scene.actors, Hub.hub.hidden, local?.components.Transform, Boolean(this.trip),
|
|
4366
|
+
const captioned = this.padReadability.frame(scene.actors, Hub.hub.hidden, local?.components.Transform, Boolean(this.trip),
|
|
4351
4367
|
this.carded || this.decor?.opened() === true, selfId != null && Hub.hub.guests?.has?.(selfId) === true);
|
|
4368
|
+
if (captioned && !this.signalDoor && this.signals?.wantsPrompt(Hub.hub.signalArrival)) {
|
|
4369
|
+
this.signalDoor = captioned;
|
|
4370
|
+
}
|
|
4352
4371
|
}
|
|
4353
4372
|
|
|
4354
4373
|
// A town's world labels under `hub.labels: "near"` (v1.43): the plate and
|