@wildshard/engine 0.1.20 → 0.1.22
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/CHANGELOG.md +16 -0
- package/lint/engine-sides.json +4 -0
- package/lint/shardfile-boundaries.mjs +4 -2
- package/lint/wildshard-plugin.js +1 -1
- package/package.json +3 -1
- package/scripts/audio-download-proof.mjs +1 -1
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/check-spelled-paths.mjs +6 -3
- package/scripts/committed-fast-checks.mjs +2 -2
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +556 -0
- package/scripts/grid-crossing-nightly.mjs +5 -4
- package/scripts/grid-crossing-report.mjs +5 -2
- package/scripts/grid-crossing-tour.mjs +25 -8
- package/scripts/grid-crossing-walk-proof.mjs +3 -3
- package/scripts/hover-speed-probe.mjs +136 -0
- package/scripts/mmo-bots.mjs +7 -3
- package/scripts/net-lag-proof.mjs +4 -3
- package/scripts/online-rig.mjs +11 -9
- package/scripts/parity/boot-smoke.mjs +1 -1
- package/scripts/release-cook.mjs +113 -0
- package/scripts/test-products.json +0 -21
- package/scripts/vps/cook-follow.d.mts +6 -0
- package/scripts/vps/cook-follow.mjs +45 -0
- package/scripts/vps/harden-apply.sh +10 -1
- package/scripts/vps/rebuild.sh +120 -26
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -3
- package/src/client/app/entry.ts +2 -3
- package/src/client/engine/boot/contentRead.ts +78 -9
- package/src/client/engine/boot/downloadGiveUp.ts +34 -0
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- package/src/client/engine/combat/EquipmentService.ts +2 -0
- package/src/client/engine/core/Game.ts +6 -2
- package/src/client/engine/core/shadowLayer.ts +18 -0
- package/src/client/engine/explore/pick.ts +13 -1
- package/src/client/engine/net/predictor.ts +12 -4
- package/src/client/engine/player/TouchControls.ts +3 -2
- package/src/client/engine/render/families/sceneSurface.ts +3 -1
- package/src/client/engine/telemetry/browserErrors.ts +3 -1
- package/src/client/engine/ui/ErrorModal.ts +1 -1
- package/src/client/engine/ui/Loading.ts +14 -2
- package/src/client/engine/ui/downloadFailed.ts +54 -0
- package/src/client/engine/ui/errorScreen.ts +51 -9
- package/src/client/engine/ui/hoverBoost.ts +31 -4
- package/src/client/engine/ui/styles/touch.css +6 -0
- package/src/client/game/boot/spawnDownload.ts +56 -7
- package/src/client/game/grid/copyPrompts.ts +3 -4
- package/src/client/game/grid/dataCellKit.ts +91 -0
- package/src/client/game/grid/enteredEquipment.ts +11 -2
- package/src/client/game/grid/live.ts +11 -301
- package/src/client/game/grid/liveSession.ts +33 -10
- package/src/client/game/grid/neighbourLife.ts +50 -32
- package/src/client/game/grid/reveal.ts +7 -2
- package/src/client/game/grid/session.ts +6 -70
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/plugin/weaponFamily.ts +6 -0
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientWorker.ts +17 -7
- package/src/client/game/shardfile/groundMerge.ts +5 -3
- package/src/client/host/online/linkScreens.ts +12 -6
- package/src/client/host/online/reconnectStrip.ts +3 -2
- package/src/client/host/online/release.ts +87 -16
- package/src/client/host/online/releaseScreens.ts +108 -0
- package/src/client/host/online/shell.ts +46 -12
- package/src/client/host/online/voice.ts +45 -1
- package/src/client/host/online/voiceUi.ts +24 -6
- package/src/server/engine/sim/playerSim.ts +1 -1
- package/src/server/game/grid/room.ts +2 -38
- package/src/server/game/grid/simulation.ts +12 -6
- package/src/server/game/shardfile/declaredKitItems.ts +8 -2
- package/src/server/host/dedicated/cellHost.ts +9 -2
- package/src/server/host/dedicated/cellProtocol.ts +1 -1
- package/src/server/host/dedicated/cellWorker.ts +2 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +22 -4
- package/src/server/host/dedicated/gridCells.ts +5 -3
- package/src/server/host/dedicated/main.ts +6 -4
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- package/src/server/host/dedicated/workerTable.ts +0 -10
- package/src/server/host/dedicated/world.ts +39 -5
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/server/host/standalone/gridServer.ts +1 -1
- package/src/shared/engine/boot/loadingWaits.ts +10 -2
- package/src/shared/engine/core/config.ts +3 -0
- package/src/shared/engine/player/hoverSpeed.ts +3 -3
- package/src/shared/engine/saves/shape.ts +17 -2
- package/src/shared/engine/strings.ts +22 -1
- package/src/shared/game/grid/placementRows.ts +4 -3
- package/src/shared/game/grid/rules.ts +12 -0
- package/src/client/game/grid/cellLoading.ts +0 -110
- package/src/client/game/grid/cellScreens.ts +0 -48
|
@@ -15,11 +15,32 @@ const importKey = async (publicKey: string): Promise<CryptoKey> => {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
/** FM5: why a release read failed, as the page can measure it. A browser never says DNS or TLS, so `network` is all an opaque fetch
|
|
19
|
+
* failure is; `offline` is one the browser itself calls offline; `portal` is an answer that isn't the file (HTML, an unapproved redirect,
|
|
20
|
+
* malformed text), which could be a captive portal or a broken origin. */
|
|
21
|
+
export type ReleaseFault =
|
|
22
|
+
| { readonly kind: 'offline' } | { readonly kind: 'network' } | { readonly kind: 'timeout'; readonly ms: number }
|
|
23
|
+
| { readonly kind: 'status'; readonly status: number; readonly retryAfterMs: number | null }
|
|
24
|
+
| { readonly kind: 'portal'; readonly why: 'html' | 'redirect' | 'malformed' } | { readonly kind: 'unsigned' };
|
|
25
|
+
/** A failed release read and what failed. Its message keeps the technical words for Details; a player's screen never shows it raw. */
|
|
26
|
+
export class ReleaseReadError extends Error {
|
|
27
|
+
readonly fault: ReleaseFault;
|
|
28
|
+
constructor(message: string, fault: ReleaseFault, cause?: unknown) { super(message, cause === undefined ? undefined : { cause }); this.name = 'ReleaseReadError'; this.fault = fault; }
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
/** The file's text as what it says. It throws on a bad signature, and where a browser has no Ed25519. `publicKey` is SPKI DER in hex. */
|
|
19
32
|
export async function readSignedRelease(text: string, publicKey: string): Promise<ReleaseFile> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
let signed: v.InferOutput<typeof SignedSchema>;
|
|
34
|
+
try { signed = v.parse(SignedSchema, JSON.parse(text)); } catch (error) { throw new ReleaseReadError('A release file that is not a signed file', { kind: 'portal', why: 'malformed' }, error); }
|
|
35
|
+
const key = await importKey(publicKey);
|
|
36
|
+
if (!await crypto.subtle.verify({ name: 'Ed25519' }, key, hexBytes(signed.signature), new TextEncoder().encode(signed.body))) throw new ReleaseReadError('A release file has a bad signature', { kind: 'unsigned' });
|
|
37
|
+
try { return v.parse(ReleaseSchema, JSON.parse(signed.body)); } catch (error) { throw new ReleaseReadError('A signed release file this page cannot read', { kind: 'portal', why: 'malformed' }, error); }
|
|
38
|
+
}
|
|
39
|
+
/** FM5 mode 12: a `Retry-After` of seconds or an HTTP date, in ms from `now`; anything else (or past 10 min) is no answer. */
|
|
40
|
+
export function retryAfterMs(header: string | null, now: number = Date.now()): number | null {
|
|
41
|
+
if (header === null) return null;
|
|
42
|
+
const text = header.trim(), ms = /^\d{1,6}$/u.test(text) ? Number(text) * 1000 : /[a-z]/iu.test(text) ? Date.parse(text) - now : Number.NaN;
|
|
43
|
+
return Number.isFinite(ms) && ms >= 0 && ms <= 600_000 ? Math.round(ms) : null;
|
|
23
44
|
}
|
|
24
45
|
/** FM5 (catalogue mode 11): a release read that has not answered, body and all, in 8 s has failed. */
|
|
25
46
|
export const RELEASE_DEADLINE_MS = 8000;
|
|
@@ -30,19 +51,24 @@ export const KEPT_RELEASE_MS: number = 7 * 24 * 60 * 60 * 1000;
|
|
|
30
51
|
export async function fetchSignedRelease(url: string, publicKey: string, deadlineMs: number = RELEASE_DEADLINE_MS, read: typeof fetch = fetch): Promise<ReleaseFile> {
|
|
31
52
|
return readSignedRelease(await fetchReleaseText(url, deadlineMs, read), publicKey);
|
|
32
53
|
}
|
|
33
|
-
|
|
54
|
+
const browserOnline = (): boolean => typeof navigator === 'undefined' || navigator.onLine;
|
|
55
|
+
async function fetchReleaseText(url: string, deadlineMs: number, read: typeof fetch, online: () => boolean = browserOnline): Promise<string> {
|
|
34
56
|
const abort = new AbortController(), scope = new Scope('online.release-read');
|
|
35
57
|
scope.timeout(deadlineMs, () => { abort.abort(); });
|
|
36
58
|
try {
|
|
37
59
|
const response = await read(url, { cache: 'no-store', signal: abort.signal });
|
|
38
|
-
if (!response.ok) throw new
|
|
39
|
-
|
|
60
|
+
if (!response.ok) throw new ReleaseReadError(`No release file at ${url}: ${String(response.status)}`, { kind: 'status', status: response.status, retryAfterMs: retryAfterMs(response.headers.get('retry-after')) });
|
|
61
|
+
// FM5 mode 38: an answer from somewhere else, or a page instead of the file, isn't the world's file; nothing in it is followed
|
|
62
|
+
if (response.redirected && response.url !== '' && new URL(response.url).origin !== new URL(url).origin) throw new ReleaseReadError(`The release read was sent to another address (${String(response.status)})`, { kind: 'portal', why: 'redirect' });
|
|
63
|
+
const text = await response.text();
|
|
64
|
+
if (/html/iu.test(response.headers.get('content-type') ?? '') || /^\s*</u.test(text)) throw new ReleaseReadError(`A page instead of the release file (${response.headers.get('content-type') ?? 'no type'})`, { kind: 'portal', why: 'html' });
|
|
65
|
+
return text;
|
|
40
66
|
} catch (error) {
|
|
41
|
-
if (
|
|
42
|
-
throw error;
|
|
67
|
+
if (error instanceof ReleaseReadError) throw error;
|
|
68
|
+
if (abort.signal.aborted) throw new ReleaseReadError(`No release file at ${url} in ${String(deadlineMs)} ms`, { kind: 'timeout', ms: deadlineMs }, error);
|
|
69
|
+
throw new ReleaseReadError(error instanceof Error ? error.message : String(error), online() ? { kind: 'network' } : { kind: 'offline' }, error);
|
|
43
70
|
} finally { scope.dispose(); }
|
|
44
71
|
}
|
|
45
|
-
|
|
46
72
|
/** OF4: the last release file a page read and believed: which release, when, and its text as signed. */
|
|
47
73
|
export interface KeptRelease { readonly of: string; readonly at: number; readonly text: string }
|
|
48
74
|
export interface ReleaseKeep { readonly read: () => KeptRelease | null; readonly write: (kept: KeptRelease) => void }
|
|
@@ -58,17 +84,62 @@ export async function keptRelease(url: string, publicKey: string, keep: ReleaseK
|
|
|
58
84
|
|
|
59
85
|
/** What a page dials from: the file, and when that was the kept copy, the fresh read still under way (null if it fails). */
|
|
60
86
|
export interface ReleaseToDial { readonly file: ReleaseFile; readonly fresh: Promise<ReleaseFile | null> | null }
|
|
87
|
+
|
|
88
|
+
/** FM5: the screen a failed read with no kept copy shows (meta MMO-FAILURE-MODES-PLAN modes 1, 11, 12, 37 to 39). */
|
|
89
|
+
export type ReleaseScreen = 'offline-launch' | 'release-5xx' | 'release-429' | 'release-404' | 'captive-portal' | 'release-unsigned';
|
|
90
|
+
export function releaseScreen(fault: ReleaseFault): ReleaseScreen {
|
|
91
|
+
if (fault.kind === 'offline') return 'offline-launch';
|
|
92
|
+
if (fault.kind === 'portal') return 'captive-portal';
|
|
93
|
+
if (fault.kind === 'unsigned') return 'release-unsigned';
|
|
94
|
+
if (fault.kind === 'status' && fault.status === 429) return 'release-429';
|
|
95
|
+
if (fault.kind === 'status' && fault.status === 404) return 'release-404';
|
|
96
|
+
return 'release-5xx';
|
|
97
|
+
}
|
|
98
|
+
/** Mode 11's ladder: 2, 4, 8, 16 s, then every 30 s. */
|
|
99
|
+
const LADDER_MS: readonly number[] = [2000, 4000, 8000, 16_000], LADDER_END_MS = 30_000;
|
|
100
|
+
/** Mode 12: a 429 with no readable Retry-After waits this long first. Mode 37: a 404 is read again each minute. */
|
|
101
|
+
const BUSY_MS = 20_000, MISSING_MS = 60_000;
|
|
102
|
+
/** FM5's retry policy: how long after the `attempt`th failed read (from 0) the page reads again by itself, or null when only the player
|
|
103
|
+
* (Try again), the network coming back or the page coming into view reads again: offline, a captive portal, a file that fails its
|
|
104
|
+
* signature (no retry loop on a file we can't verify). */
|
|
105
|
+
export function releaseRetryMs(fault: ReleaseFault, attempt: number): number | null {
|
|
106
|
+
const ladder = LADDER_MS[attempt] ?? LADDER_END_MS;
|
|
107
|
+
if (fault.kind === 'offline' || fault.kind === 'portal' || fault.kind === 'unsigned') return null;
|
|
108
|
+
if (fault.kind !== 'status') return ladder;
|
|
109
|
+
// a Retry-After of 0 is no licence to loop: never sooner than the ladder's first step, and never sooner than the first refusal's wait
|
|
110
|
+
if (fault.status === 429) return Math.max(fault.retryAfterMs ?? BUSY_MS, LADDER_MS[0] ?? 2000, fault.retryAfterMs === null ? ladder : 0);
|
|
111
|
+
return fault.status === 404 ? MISSING_MS : ladder;
|
|
112
|
+
}
|
|
113
|
+
/** FM5: what a page shows while it has no release file to dial from. `after` shows the fault and settles when the page should read again
|
|
114
|
+
* (the policy's wait, Try again, the network back); it rejects when the player leaves. `done` closes whatever it showed. */
|
|
115
|
+
export interface ReleaseWait {
|
|
116
|
+
readonly after: (fault: ReleaseFault, attempt: number, retryMs: number | null, detail: string) => Promise<void>;
|
|
117
|
+
readonly done: () => void;
|
|
118
|
+
}
|
|
119
|
+
|
|
61
120
|
/** OF4: the release file a page dials from. A verified kept copy answers at once, so a load never waits on the read; the fresh read
|
|
62
|
-
* replaces it once its own signature holds. With no copy the page waits for the read (8 s at most), and a failed read throws
|
|
63
|
-
|
|
121
|
+
* replaces it once its own signature holds. With no copy the page waits for the read (8 s at most each), and a failed read throws, or,
|
|
122
|
+
* given `wait` (FM5), shows why and reads again by its policy until a verified file answers or the player leaves. */
|
|
123
|
+
export async function releaseToDial(url: string, publicKey: string, ports: { readonly keep: ReleaseKeep; readonly fetch?: typeof fetch; readonly now?: () => number; readonly deadlineMs?: number; readonly wait?: ReleaseWait; readonly online?: () => boolean }): Promise<ReleaseToDial> {
|
|
64
124
|
const now = ports.now ?? Date.now, kept = await keptRelease(url, publicKey, ports.keep, now());
|
|
65
|
-
const reading =
|
|
66
|
-
const text = await fetchReleaseText(url, ports.deadlineMs ?? RELEASE_DEADLINE_MS, ports.fetch ?? fetch), file = await readSignedRelease(text, publicKey);
|
|
125
|
+
const reading = async (): Promise<ReleaseFile> => {
|
|
126
|
+
const text = await fetchReleaseText(url, ports.deadlineMs ?? RELEASE_DEADLINE_MS, ports.fetch ?? fetch, ports.online), file = await readSignedRelease(text, publicKey);
|
|
67
127
|
// a release only moves forward (J179, the server's own rule in releaseFile.ts): an older signed file never replaces the kept one
|
|
68
128
|
if (kept !== null && file.serial < kept.serial) throw new Error(`A release file older than the kept one (${String(file.serial)} < ${String(kept.serial)})`);
|
|
69
129
|
try { ports.keep.write({ of: url, at: now(), text }); } catch { /* a page that can keep nothing reads again next time */ }
|
|
70
130
|
return file;
|
|
71
|
-
}
|
|
72
|
-
if (kept
|
|
73
|
-
|
|
131
|
+
};
|
|
132
|
+
if (kept !== null) return { file: kept, fresh: reading().catch(() => null) };
|
|
133
|
+
const { wait } = ports;
|
|
134
|
+
if (wait === undefined) return { file: await reading(), fresh: null };
|
|
135
|
+
for (let attempt = 0; ; attempt++) {
|
|
136
|
+
try {
|
|
137
|
+
const file = await reading();
|
|
138
|
+
wait.done();
|
|
139
|
+
return { file, fresh: null };
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (!(error instanceof ReleaseReadError)) { wait.done(); throw error; }
|
|
142
|
+
await wait.after(error.fault, attempt, releaseRetryMs(error.fault, attempt), error.message);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
74
145
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// FM5 (meta docs/plans/MMO-FAILURE-MODES-PLAN.md): what a player sees while the page has no release file to dial from. Modes 1, 11, 12,
|
|
2
|
+
// 37, 38 and 39 are **pages** (the plan's first style): before the world, over the loading card, the whole screen, one button that does
|
|
3
|
+
// something, and they move on by themselves when the file answers. Mode 46 is the staging **mark**: a quiet line for the session.
|
|
4
|
+
// The waits are release.ts's policy (`releaseRetryMs`); this file only says so and counts down the real scheduled read.
|
|
5
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
6
|
+
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
7
|
+
import { captureBrowserError } from '@wildshard/engine/telemetry/browserErrors';
|
|
8
|
+
import { buttons, card, linkStyle, make, ring } from './linkScreens';
|
|
9
|
+
import { releaseScreen, type ReleaseFault, type ReleaseScreen, type ReleaseWait } from './release';
|
|
10
|
+
|
|
11
|
+
/** The words of each page: a tag, a headline and the key line. No status code, address or exception is primary copy (Details holds them). */
|
|
12
|
+
const WORDS: Readonly<Record<ReleaseScreen, { readonly tag: string; readonly title: string; readonly body: string; readonly tone: 'warn' | 'bad' | 'info' }>> = {
|
|
13
|
+
'offline-launch': { tag: 'Offline', title: 'You\'re offline', body: 'We\'ll connect as soon as you\'re back.', tone: 'warn' },
|
|
14
|
+
'release-5xx': { tag: 'Can\'t find the world', title: 'Can\'t find the world', body: 'The world\'s information didn\'t arrive. We\'ll try again by ourselves.', tone: 'warn' },
|
|
15
|
+
'release-429': { tag: 'Busy', title: 'Lots of players joining', body: 'You don\'t need to do anything: we\'ll try again when the world says to.', tone: 'info' },
|
|
16
|
+
'release-404': { tag: 'Not available', title: 'World information isn\'t available', body: 'Check your connection, or try again later. We\'ll look again every minute.', tone: 'warn' },
|
|
17
|
+
'captive-portal': { tag: 'Network sign-in', title: 'This network may need sign-in', body: 'Something other than the world answered. If this network has a sign-in page, sign in, then try again.', tone: 'warn' },
|
|
18
|
+
'release-unsigned': { tag: 'Not verified', title: 'Couldn\'t check the world', body: 'We won\'t connect to a world we can\'t verify.', tone: 'bad' },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Details: what was measured, never a guess (a browser can't tell DNS from TLS from a reset). */
|
|
22
|
+
function measured(fault: ReleaseFault): string {
|
|
23
|
+
if (fault.kind === 'offline') return 'The browser says this device is offline.';
|
|
24
|
+
if (fault.kind === 'network') return 'No HTTP response. Check the connection.';
|
|
25
|
+
if (fault.kind === 'timeout') return `No answer in ${String(Math.round(fault.ms / 1000))} s.`;
|
|
26
|
+
if (fault.kind === 'status') return `HTTP ${String(fault.status)}${fault.retryAfterMs === null ? '' : `, Retry-After ${String(Math.round(fault.retryAfterMs / 1000))} s`}.`;
|
|
27
|
+
if (fault.kind === 'unsigned') return 'The world\'s file failed its signature check.';
|
|
28
|
+
return fault.why === 'redirect' ? 'The read was sent to another address.' : fault.why === 'html' ? 'A web page answered instead of the world\'s file.' : 'The answer was not a signed world file.';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ReleaseScreenHooks {
|
|
32
|
+
/** Open the Connection doctor (E7.5), naming the screen that asked. */
|
|
33
|
+
readonly doctor?: (from: string) => void;
|
|
34
|
+
/** Leave for the title screen. */
|
|
35
|
+
readonly title: () => void;
|
|
36
|
+
/** Where mode 39 reports (the browser error tracker; a test observes its own). */
|
|
37
|
+
readonly report?: typeof captureBrowserError;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* FM5: the release pages, as release.ts's `ReleaseWait`. Each failed read shows its page and settles when the page should read again:
|
|
42
|
+
* the policy's scheduled time (counted down on the page), Try again, the network coming back, or (a portal) the page coming into view.
|
|
43
|
+
* Title screen rejects, so the load stops and the player leaves. `done` closes the page.
|
|
44
|
+
*
|
|
45
|
+
* await releaseToDial(url, key, { keep, wait: releaseScreens(scope, { doctor, title }) });
|
|
46
|
+
*/
|
|
47
|
+
export function releaseScreens(scope: Scope, hooks: ReleaseScreenHooks, parent: HTMLElement = document.body): ReleaseWait {
|
|
48
|
+
const report = hooks.report ?? captureBrowserError;
|
|
49
|
+
let shown: Scope | null = null, reported = false;
|
|
50
|
+
const close = (): void => { shown?.dispose(); shown = null; };
|
|
51
|
+
scope.onDispose(close);
|
|
52
|
+
return {
|
|
53
|
+
done: close,
|
|
54
|
+
after: (fault, attempt, retryMs, detail) => new Promise<void>((resolve, reject) => {
|
|
55
|
+
close();
|
|
56
|
+
linkStyle();
|
|
57
|
+
const id = releaseScreen(fault), words = WORDS[id], page = new Scope(`online.release-${id}`, scope);
|
|
58
|
+
shown = page;
|
|
59
|
+
const { root, box } = card(page, id, words.tone, words.tag, words.title);
|
|
60
|
+
root.classList.add('ws-link-page');
|
|
61
|
+
box.append(make('p', 'ws-link-body', words.body));
|
|
62
|
+
let settled = false;
|
|
63
|
+
let trying = (): void => undefined;
|
|
64
|
+
const go = (): void => { if (settled) return; settled = true; trying(); resolve(); };
|
|
65
|
+
const leave = (): void => { if (settled) return; settled = true; reject(new Error('The player left the release wait for the title')); hooks.title(); };
|
|
66
|
+
page.onDispose(() => { if (!settled) { settled = true; resolve(); } });
|
|
67
|
+
// the next read, counted from what is actually scheduled: never a made-up clock
|
|
68
|
+
const status = make('p', 'ws-link-auto');
|
|
69
|
+
if (retryMs !== null) {
|
|
70
|
+
const due = diagnosticNow() + retryMs, line = make('span');
|
|
71
|
+
const tick = (): void => { const left = Math.max(0, Math.ceil((due - diagnosticNow()) / 1000)); line.textContent = `Next try in ${String(left)} s · ${attempt === 0 ? 'first try failed' : `${String(attempt + 1)} tries so far`}`; };
|
|
72
|
+
const counting = page.interval(500, tick);
|
|
73
|
+
trying = () => { page.cancelTimer(counting); line.textContent = 'Trying…'; };
|
|
74
|
+
tick(); page.timeout(retryMs, go);
|
|
75
|
+
status.append(ring(), line);
|
|
76
|
+
box.append(status);
|
|
77
|
+
} else if (id === 'offline-launch') {
|
|
78
|
+
status.append(ring(), make('span', '', 'Waiting for the network'));
|
|
79
|
+
box.append(status);
|
|
80
|
+
}
|
|
81
|
+
// the network back, or a portal's page back in view after a sign-in elsewhere: read again now
|
|
82
|
+
page.listen(window, 'online', go);
|
|
83
|
+
if (id === 'captive-portal') page.listen(document, 'visibilitychange', () => { if (document.visibilityState === 'visible') go(); });
|
|
84
|
+
const actions: { label: string; primary?: true; busy?: string; act: () => void }[] = [];
|
|
85
|
+
// mode 12 waits what the world asked; a tap doesn't jump that queue
|
|
86
|
+
if (id !== 'release-429') actions.push({ label: retryMs === null ? 'Try again' : 'Try now', primary: true, busy: 'Trying…', act: go });
|
|
87
|
+
if (hooks.doctor !== undefined && id !== 'offline-launch') { const { doctor } = hooks; actions.push({ label: 'Check connection', act: () => { doctor(id); } }); }
|
|
88
|
+
actions.push({ label: 'Title screen', act: leave });
|
|
89
|
+
box.append(buttons(page, actions));
|
|
90
|
+
const details = make('details'), summary = make('summary', '', 'Details');
|
|
91
|
+
details.append(summary, make('p', '', `${measured(fault)} ${detail}`));
|
|
92
|
+
box.append(details);
|
|
93
|
+
parent.append(root);
|
|
94
|
+
root.querySelector<HTMLButtonElement>('button')?.focus(); // the first action takes focus; card() keeps Tab inside
|
|
95
|
+
// mode 39 goes to the error report queue, once a page
|
|
96
|
+
if (id === 'release-unsigned' && !reported) { reported = true; try { report(new Error(`Release file failed its signature: ${detail}`), { system: 'link', build: '', shard: '', bootStage: 'loading', fatal: false, screen: 'release-unsigned', diagnostic: { detail } }); } catch { /* telemetry never stops the page */ } }
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** FM5 mode 46: a page on the staging world says so, for the whole session. Returns its node (owned by `scope`). */
|
|
102
|
+
export function stagingMark(scope: Scope, parent: HTMLElement = document.body): HTMLElement {
|
|
103
|
+
linkStyle();
|
|
104
|
+
const mark = scope.ownNode(make('div', 'ws-link ws-link-mark', 'Staging · not the live world'));
|
|
105
|
+
mark.dataset['failmode'] = 'staging'; mark.dataset['tone'] = 'warn'; mark.setAttribute('role', 'status');
|
|
106
|
+
parent.append(mark);
|
|
107
|
+
return mark;
|
|
108
|
+
}
|
|
@@ -18,6 +18,7 @@ import { chatLines } from './chatLines';
|
|
|
18
18
|
import { VoiceChat, type VoiceHeard, type VoiceLink } from './voice';
|
|
19
19
|
import { voiceUi } from './voiceUi';
|
|
20
20
|
import { fetchSignedRelease, releaseToDial, type ReleaseKeep } from './release';
|
|
21
|
+
import { releaseScreens, stagingMark } from './releaseScreens';
|
|
21
22
|
import { newBuildPanel } from './reconnectStrip';
|
|
22
23
|
import { linkScreens } from './linkScreens';
|
|
23
24
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
@@ -178,10 +179,32 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
|
|
|
178
179
|
dispose: () => { records?.dispose(); redial.dispose(); client.dispose(); link?.close('disposed'); } };
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
/** FM3's proof (mode 23, 2026-11-15): how the page leaves this document on purpose. This bundle's saves have no storage (OF4's
|
|
183
|
+
* `keep`), so the tap it hands the next document (`setTitleArrival`), the unload it marks (`lastEnd`) and the reload claims it
|
|
184
|
+
* settles were written nowhere: the new-build Reload came back as a "player reload" and landed on the title. The page lends its own
|
|
185
|
+
* (clientWorker.ts `onlineLeaving`); this module's copies are the fallback for a page that lends none (tests). */
|
|
186
|
+
export interface OnlineLeaving {
|
|
187
|
+
/** QA row 16: the tap that brought the player here, for this tab's next document only */
|
|
188
|
+
readonly arrive: (slug: string) => void;
|
|
189
|
+
/** that tap, when the reload it was for didn't happen */
|
|
190
|
+
readonly unarrive: () => void;
|
|
191
|
+
/** the game is about to navigate on purpose (lastEnd) */
|
|
192
|
+
readonly unload: (reason: string) => void;
|
|
193
|
+
/** J54/J174: reload into the server's build, once per tab; false when there is none to reload into, or this tab already did */
|
|
194
|
+
readonly reloadStale: () => Promise<boolean>;
|
|
195
|
+
/** a player's tap on a stale tab: the next document comes from the network */
|
|
196
|
+
readonly reloadByHand: () => Promise<void>;
|
|
197
|
+
/** a seat on this build settles the reload that brought this tab here */
|
|
198
|
+
readonly settle: () => void;
|
|
199
|
+
}
|
|
200
|
+
const OWN_LEAVING: OnlineLeaving = {
|
|
201
|
+
arrive: slug => { setTitleArrival({ slug, mode: 'enter' }, { tab: true }); }, unarrive: dropTabArrival, unload: reason => { markUnload(reason); },
|
|
202
|
+
reloadStale: async () => (await import('@wildshard/engine/boot/browserChunkRecovery')).reloadRefusedBuild(true),
|
|
203
|
+
reloadByHand: async () => { await (await import('@wildshard/engine/boot/browserChunkRecovery')).reloadPastWorker(); },
|
|
204
|
+
settle: () => { void (async () => { (await import('@wildshard/engine/boot/browserChunkRecovery')).settleRefusedBuild(); })(); },
|
|
205
|
+
};
|
|
183
206
|
/** A seat on this build settles any reload that brought this tab here, so a sitting can ride more than one deploy. */
|
|
184
|
-
async function settled(booted: OnlineShell['booted']): Promise<void> { await booted;
|
|
207
|
+
async function settled(booted: OnlineShell['booted'], leaving: OnlineLeaving): Promise<void> { await booted; leaving.settle(); }
|
|
185
208
|
/** J174: the next build's files, while play goes on. The worker that installs is what the reload lands on. */
|
|
186
209
|
function preload(): void {
|
|
187
210
|
if ('serviceWorker' in navigator) void navigator.serviceWorker.getRegistration().then(found => found?.update()).catch(() => undefined);
|
|
@@ -209,6 +232,8 @@ export interface StartOnline {
|
|
|
209
232
|
* a second store writing the page's device save would drop the keys it doesn't define. */
|
|
210
233
|
readonly keep?: ReleaseKeep;
|
|
211
234
|
readonly recordTag?:string;
|
|
235
|
+
/** mode 23: how the page leaves on purpose, in its own saves (see OnlineLeaving) */
|
|
236
|
+
readonly leaving?: OnlineLeaving;
|
|
212
237
|
}
|
|
213
238
|
/** E7.5 prep: ask the page to leave for the Connection doctor, saying which screen asked. The page's own bundle answers
|
|
214
239
|
* (src/client/engine/ui/errorScreen.ts): it holds the save hold and the loading card's report, which this module can't see. */
|
|
@@ -293,14 +318,23 @@ async function askWorld(config: { readonly release: string; readonly key: string
|
|
|
293
318
|
/** Enter the one world this build names. A stale tab reloads into the server's build once, and only then gives up. */
|
|
294
319
|
export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
295
320
|
// OF4: a verified kept release file dials at once (offline too), and the fresh read follows; with none, the page waits for the read
|
|
296
|
-
const { release: at, key, keep, identity, recordTag, grid,
|
|
321
|
+
const { release: at, key, keep, identity, recordTag, grid, leaving = OWN_LEAVING, ...link } = config;
|
|
322
|
+
// FM5: with no kept copy and no file, the page says why (offline, the file's server down or busy, a portal, a bad signature) and
|
|
323
|
+
// reads again by release.ts's policy until a verified file answers; Title screen stops the load
|
|
324
|
+
const waiting = new Scope('online.release-wait');
|
|
325
|
+
const toTitle = (): void => { leaving.unload('release page: title screen'); location.replace(new URL('/', location.origin).toString()); };
|
|
326
|
+
let dial: Awaited<ReturnType<typeof releaseToDial>>;
|
|
327
|
+
try { dial = await releaseToDial(at, key, { keep: keep ?? NO_KEEP, wait: releaseScreens(waiting, { doctor, title: toTitle }) }); } finally { waiting.dispose(); }
|
|
328
|
+
const { file: release, fresh } = dial, { socket } = release;
|
|
297
329
|
// QA row 16: a level page enters only from a tap. A reload this page makes itself carries the tap that brought it here.
|
|
298
|
-
const entering = (slug: string): void => {
|
|
299
|
-
const stale = async (): Promise<boolean> => { entering(link.loaded); const going = await reloadStale(); if (!going)
|
|
330
|
+
const entering = (slug: string): void => { leaving.arrive(slug); };
|
|
331
|
+
const stale = async (): Promise<boolean> => { entering(link.loaded); const going = await leaving.reloadStale(); if (!going) leaving.unarrive(); return going; };
|
|
300
332
|
// only a fresh read says the world moved on: a kept copy's build is the past, and an offline page can't reload anyway
|
|
301
333
|
if (fresh === null && release.engineBuild !== link.build) await stale();
|
|
302
334
|
if (socket === undefined) throw new Error('The release file names no address');
|
|
303
335
|
const scope = new Scope('online.page');
|
|
336
|
+
// FM5 mode 46: the staging world says so for the session (the release file's own verified channel)
|
|
337
|
+
if (release.channel === 'staging') stagingMark(scope);
|
|
304
338
|
const goto = grid?.goto === true ? grid.cell : undefined;
|
|
305
339
|
let dialing = socket;
|
|
306
340
|
// MP2.4: the page asked for the Name before it got here (namePrompt.ts, once per device); Skip keeps the device's own (Guest)
|
|
@@ -311,23 +345,23 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
|
311
345
|
const screens = linkScreens(scope, {
|
|
312
346
|
retry: () => { shellNow?.retry(); }, dialNow: () => { shellNow?.dialNow(); }, doctor,
|
|
313
347
|
// Play here / Play again reload into the world: the tap that brought the player here comes along (QA row 16)
|
|
314
|
-
reload: () => { entering(link.loaded); void reloadByHand(); },
|
|
348
|
+
reload: () => { entering(link.loaded); void leaving.reloadByHand(); },
|
|
315
349
|
progress: () => shellNow?.progress() ?? { dials: 0, nextDialMs: null, downMs: 0 }, why: () => shellNow?.why() ?? 'closed',
|
|
316
350
|
// FM4b modes 21 and 22: the Slow and Unstable chips read the link's own measurements
|
|
317
351
|
stats: () => shellNow?.client.stats,
|
|
318
352
|
});
|
|
319
353
|
// `reload` is the one ending a screen doesn't answer: the page reloads into the world's build, once (J174)
|
|
320
|
-
const ended = async (): Promise<void> => { if (!await stale()) newBuildPanel(scope, stale, () => { entering(link.loaded); void reloadByHand(); }); };
|
|
354
|
+
const ended = async (): Promise<void> => { if (!await stale()) newBuildPanel(scope, stale, () => { entering(link.loaded); void leaving.reloadByHand(); }); };
|
|
321
355
|
const telemetry=onlineTelemetry(),tag=recordTag??release.channel;
|
|
322
356
|
const shell = connectOnline({ ...link, ...(grid === undefined ? {} : { gridCell: grid.cell, gridCells: grid.cells }), socket: gotoSocket(socket, goto), address: () => gotoSocket(dialing, goto), identity: named,record:{install:telemetry.install,session:crypto.randomUUID(),send:telemetry.send,...(tag===undefined?{}:{tag})} }, {
|
|
323
357
|
link: (state, reason) => { waitingForSeat = state === 'full'; screens.link(state, reason); if (state === 'ended' && reason === 'reload') void ended(); },
|
|
324
358
|
// The cut (5.5): an old server refused a v1 hello. Reload only into another build; on this one, the server is updating.
|
|
325
|
-
cut: () => { void reloadStale(); },
|
|
359
|
+
cut: () => { void leaving.reloadStale(); },
|
|
326
360
|
countdown: said => { screens.countdown(said); preload(); },
|
|
327
361
|
placed: (cell, stand) => { if (stand !== undefined) grid?.placed(cell, stand); },
|
|
328
362
|
// A grid page re-enters the grid in the seat's cell: the tap that brought it here comes along (QA row 16), and the URL stays bare.
|
|
329
|
-
regrid: cell => { entering(link.loaded);
|
|
330
|
-
elsewhere: seat => { entering(seat); const url = new URL(location.href); url.searchParams.set('chunk', seat);
|
|
363
|
+
regrid: cell => { entering(link.loaded); leaving.unload(`online seat in another grid cell (${cell})`); grid?.reenter(cell); },
|
|
364
|
+
elsewhere: seat => { entering(seat); const url = new URL(location.href); url.searchParams.set('chunk', seat); leaving.unload(`online seat elsewhere (${seat})`); location.replace(url); },
|
|
331
365
|
});
|
|
332
366
|
shellNow = shell;
|
|
333
367
|
// the fresh read behind a kept copy: another build reloads into it, as a fresh read before the dial would (two reloads share one
|
|
@@ -341,7 +375,7 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
|
341
375
|
});
|
|
342
376
|
// a tap the world must hear waits for the link: the hold card says so, and the tap is never sent late
|
|
343
377
|
shell.client.gateActions(what => screens.allow(what));
|
|
344
|
-
void settled(shell.booted);
|
|
378
|
+
void settled(shell.booted, leaving);
|
|
345
379
|
const chat = chatLines(scope, shell.client, document.body, screens.holdChat);
|
|
346
380
|
voiceUi(scope, new VoiceChat(scope, shell.voice), chat);
|
|
347
381
|
scope.listen(window,'pagehide',()=>{shell.flushRecords();});
|
|
@@ -30,12 +30,17 @@ export interface VoiceLink {
|
|
|
30
30
|
/** Where voice stands for this player. */
|
|
31
31
|
export type VoiceState = 'off' | 'asking' | 'joining' | 'on' | 'denied' | 'unsupported' | 'full' | 'failed';
|
|
32
32
|
/** One other player on voice; `body` is their player row's id (V7, V8), and `far` is out of earshot: 40 m or more away or out of sight. */
|
|
33
|
-
export interface VoicePeer { readonly id: string; readonly name: string; body?: string | null; speaking: boolean; muted: boolean; linked: boolean; far: boolean
|
|
33
|
+
export interface VoicePeer { readonly id: string; readonly name: string; body?: string | null; speaking: boolean; muted: boolean; linked: boolean; far: boolean;
|
|
34
|
+
/** FM8 mode 32: on voice, still not linked after every offer retry had its time (`VOICE_GIVE_UP_MS`). */
|
|
35
|
+
unreachable?: boolean }
|
|
34
36
|
|
|
35
37
|
/** A remote level past this is talking; held this long after it drops, so a word's gaps don't flicker. */
|
|
36
38
|
const SPEAKING_LEVEL = 0.03, SPEAKING_HOLD_MS = 450, LEVEL_POLL_MS = 150;
|
|
37
39
|
/** An offerer retries a failed or silent link this many times, the silent one after this long. */
|
|
38
40
|
const RETRIES = 3, UNANSWERED_MS = 15_000;
|
|
41
|
+
/** FM8 mode 32: a peer on voice still unlinked this long has had every retry (four offers, 15 s each) and some slack: voice can't
|
|
42
|
+
* reach it on this network. No peers, an empty room or a TURN list that didn't arrive is never this on its own. */
|
|
43
|
+
export const VOICE_GIVE_UP_MS: number = (RETRIES + 1) * UNANSWERED_MS + 10_000;
|
|
39
44
|
/** Signalling in pieces: a half-heard message is dropped after this long, and no peer holds more than a few at once. */
|
|
40
45
|
const PIECES_MS = 10_000, PIECES_PER_PEER = 4, MAX_PIECES = 64;
|
|
41
46
|
/** Pieces sent per 50 ms: signalling shares the game socket's message budget, so a burst is spread out. */
|
|
@@ -109,6 +114,8 @@ export class VoiceChat {
|
|
|
109
114
|
/** Bumped on every new seat, stop and disposal: an await that comes back to an older one does nothing. */
|
|
110
115
|
private session = 0;
|
|
111
116
|
private readonly muted = new Set<string>();
|
|
117
|
+
/** FM8 mode 32: since when each peer on voice has been unlinked */
|
|
118
|
+
private readonly waiting = new Map<string, number>();
|
|
112
119
|
private readonly changes = new Set<() => void>();
|
|
113
120
|
private me: string | null = null;
|
|
114
121
|
private mic: MediaStream | null = null;
|
|
@@ -308,6 +315,9 @@ export class VoiceChat {
|
|
|
308
315
|
return;
|
|
309
316
|
}
|
|
310
317
|
if (signal.sdp.type === 'offer') {
|
|
318
|
+
// Two offers crossed (both sides pressed FM8's Try again): the lower id keeps its own and the other side answers it.
|
|
319
|
+
const held = this.links.get(from);
|
|
320
|
+
if (held?.offerer === true && held.pc.signalingState === 'have-local-offer' && this.me !== null && this.me < from) return;
|
|
311
321
|
// A fresh offer replaces whatever link there was: the offerer started again.
|
|
312
322
|
this.drop(from);
|
|
313
323
|
const link = this.open(from, false);
|
|
@@ -447,9 +457,43 @@ export class VoiceChat {
|
|
|
447
457
|
if (speaking !== peer.speaking) { peer.speaking = speaking; moved = true; }
|
|
448
458
|
}
|
|
449
459
|
for (const peer of this.roster.values()) if (!this.links.has(peer.id)) { const far = voiceNear.gain(talker(peer)) === 0; if (far !== peer.far) { peer.far = far; moved = true; } }
|
|
460
|
+
if (this.reach(now)) moved = true;
|
|
450
461
|
this.tellTalking();
|
|
451
462
|
if (moved) this.changed();
|
|
452
463
|
}
|
|
464
|
+
/** FM8 mode 32: mark the peers voice can't reach. True when any mark changed. */
|
|
465
|
+
private reach(now: number): boolean {
|
|
466
|
+
let moved = false;
|
|
467
|
+
for (const id of this.waiting.keys()) if (!this.roster.has(id)) this.waiting.delete(id);
|
|
468
|
+
for (const peer of this.roster.values()) {
|
|
469
|
+
if (this.state !== 'on' || peer.linked) this.waiting.delete(peer.id);
|
|
470
|
+
else if (!this.waiting.has(peer.id)) this.waiting.set(peer.id, now);
|
|
471
|
+
const since = this.waiting.get(peer.id), unreachable = since !== undefined && now - since >= VOICE_GIVE_UP_MS;
|
|
472
|
+
if (unreachable !== (peer.unreachable === true)) { peer.unreachable = unreachable; moved = true; }
|
|
473
|
+
}
|
|
474
|
+
return moved;
|
|
475
|
+
}
|
|
476
|
+
/** FM8 mode 32: the peers on voice it couldn't reach on this network. */
|
|
477
|
+
get unreachable(): readonly VoicePeer[] { return [...this.roster.values()].filter(peer => peer.unreachable === true); }
|
|
478
|
+
/** FM8 mode 32's Try again: ask for the TURN list afresh, then offer again to each peer it couldn't reach
|
|
479
|
+
* (a fresh offer replaces whatever link the other side held, so this side may start it). Text chat never waited on any of it. */
|
|
480
|
+
async retryUnreachable(): Promise<void> {
|
|
481
|
+
const stuck = this.unreachable;
|
|
482
|
+
if (stuck.length === 0 || this.state !== 'on') return;
|
|
483
|
+
const session = this.session, me = this.me;
|
|
484
|
+
this.turn = null;
|
|
485
|
+
const fresh = await this.ask();
|
|
486
|
+
// voice off, or a new seat, while the list loaded: nothing of this attempt is anyone's any more
|
|
487
|
+
if (session !== this.session || me !== this.me || this.state !== 'on') return;
|
|
488
|
+
if (fresh !== null && fresh.length > 0) { this.turned = fresh; this.ice = fresh; }
|
|
489
|
+
const now = diagnosticNow();
|
|
490
|
+
for (const peer of stuck) {
|
|
491
|
+
if (this.roster.get(peer.id) !== peer) continue;
|
|
492
|
+
this.waiting.set(peer.id, now); peer.unreachable = false;
|
|
493
|
+
void this.offer(peer.id);
|
|
494
|
+
}
|
|
495
|
+
this.changed();
|
|
496
|
+
}
|
|
453
497
|
private set(state: VoiceState): void { this.state = state; this.changed(); }
|
|
454
498
|
private changed(): void { for (const listener of this.changes) listener(); }
|
|
455
499
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
2
2
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
3
3
|
import { listenPage } from '@wildshard/engine/input/dom';
|
|
4
4
|
import type { ChatBox } from './chatLines';
|
|
@@ -22,7 +22,7 @@ import { voiceTalkKey, voiceTalkKeys } from '@wildshard/engine/ui/voiceSettings'
|
|
|
22
22
|
|
|
23
23
|
const CYAN = '#8fe3ff', NAVY = 'rgba(9,22,36,.86)', RED = '#ff7a7a', AMBER = '#ffc56b';
|
|
24
24
|
/** The first-time tip, the "you're on, alone" tip and the "voice off" tip go after this long. */
|
|
25
|
-
const FIRST_TIP_MS = 15_000, ALONE_TIP_MS = 5000, OFF_TIP_MS = 3000;
|
|
25
|
+
const FIRST_TIP_MS = 15_000, ALONE_TIP_MS = 5000, OFF_TIP_MS = 3000, BLOCKED_TIP_MS = 6000;
|
|
26
26
|
const CSS = `
|
|
27
27
|
#ws-voice{flex:none;position:relative;width:38px;height:38px;border-radius:50%;border:1.5px solid rgba(143,227,255,.5);background:${NAVY};color:#9fb3c8;display:grid;place-items:center;padding:0;pointer-events:auto;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation;transition:box-shadow .12s,background .2s,border-color .2s}
|
|
28
28
|
#ws-voice svg{width:20px;height:20px}
|
|
@@ -98,13 +98,19 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
98
98
|
chat.form.append(button); chat.box.append(tip, peers);
|
|
99
99
|
const touch = touchFirst(), act = (): string => touch ? 'Tap the mic' : `${voice.mode === 'hold' ? 'Hold' : 'Press'} ${voiceTalkKey()}`;
|
|
100
100
|
// the first-time tip's clock starts when the corner first shows (NaN: not yet)
|
|
101
|
-
let dismissed = '', firstUntil = voicePrefs.read().seen ? 0 : Number.NaN, aloneUntil = 0, offUntil = 0, was: VoiceState = voice.state;
|
|
101
|
+
let blockedUntil = 0, dismissed = '', firstUntil = voicePrefs.read().seen ? 0 : Number.NaN, aloneUntil = 0, offUntil = 0, was: VoiceState = voice.state;
|
|
102
102
|
const seen = (): void => { voicePrefs.write({ seen: true }); firstUntil = 0; };
|
|
103
103
|
// A press is a fresh question: whatever it leads to shows, even a tip the player closed before (a second "blocked").
|
|
104
104
|
const pressed = (): void => { seen(); dismissed = ''; voice.toggle(); };
|
|
105
105
|
scope.listen(button, 'click', event => { event.preventDefault(); pressed(); button.blur(); });
|
|
106
106
|
// V11: the key presses (toggle mode: on or off; hold mode: open while held), and its release closes a held mic wherever focus is
|
|
107
|
-
|
|
107
|
+
// FM8 32b: holding talk while voice reaches no one on voice says so (the voice-failed-blocked card); the mic still opens, so
|
|
108
|
+
// a link that comes up mid-hold carries the voice. Toggle mode's press turns voice off, which is 32's own recovery.
|
|
109
|
+
const press = (): void => {
|
|
110
|
+
seen(); dismissed = '';
|
|
111
|
+
if (voice.mode === 'hold' && voice.state === 'on' && voice.roster.size > 0 && voice.unreachable.length === voice.roster.size) blockedUntil = diagnosticNow() + BLOCKED_TIP_MS;
|
|
112
|
+
voice.press();
|
|
113
|
+
};
|
|
108
114
|
listenPage(scope, 'keydown', event => { if (voiceKey(event)) press(); }, { capture: true });
|
|
109
115
|
listenPage(scope, 'keyup', event => { if (isTalkKey(event.code)) voice.release(); }, { capture: true });
|
|
110
116
|
listenPage(scope, 'pointerdown', event => { if (event instanceof PointerEvent && event.pointerType === 'mouse' && isTalkKey(`Mouse${String(event.button)}`) && cornerShown(document.documentElement.dataset)) press(); }, { capture: true });
|
|
@@ -121,6 +127,10 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
121
127
|
if (state === 'denied') return { key: 'denied', text: deniedHelp(), tone: 'bad' };
|
|
122
128
|
if (state === 'failed') return { key: 'failed', text: 'No microphone was found. Check it is plugged in and allowed.', tone: 'bad' };
|
|
123
129
|
if (state === 'full') return { key: 'full', text: 'Voice is full here: 8 players are on it already.', tone: 'bad' };
|
|
130
|
+
// FM8 mode 32: a peer voice couldn't reach after every retry; text chat goes on, and Try again asks afresh
|
|
131
|
+
const stuck = voice.unreachable;
|
|
132
|
+
if (state === 'on' && stuck.length > 0 && now < blockedUntil) return { key: 'voice-failed-blocked', text: 'Voice can\'t connect here, so no one hears you. Text chat still works.', tone: 'bad' };
|
|
133
|
+
if (state === 'on' && stuck.length > 0) return { key: `voice-failed:${stuck.map(peer => peer.id).join(',')}`, text: `Voice couldn't connect${stuck.length === 1 ? ` to ${stuck[0]?.name ?? 'a player'}` : ` to ${String(stuck.length)} players`} on this network. Text chat still works.`, tone: 'bad' };
|
|
124
134
|
if (state === 'on') return others.length === 0 && now < aloneUntil ? { key: 'alone', text: voice.mode === 'hold' && !touch ? `You're on voice. Hold ${voiceTalkKey()} to talk.` : 'You\'re on voice. Players here hear you once they join.', tone: 'ok' } : null;
|
|
125
135
|
if (state !== 'off') return null;
|
|
126
136
|
if (now < offUntil) return { key: 'off', text: `Voice off. ${act()} to talk again.`, tone: 'ok' };
|
|
@@ -128,7 +138,7 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
128
138
|
if (now < firstUntil) return { key: 'first', text: touch ? 'Tap the mic to talk with players here.' : `${act()} (or click the mic) to talk with players here.`, tone: 'ok' };
|
|
129
139
|
return null;
|
|
130
140
|
};
|
|
131
|
-
let drawnOff: string | null = null, drawnTip: string | null = null;
|
|
141
|
+
let drawnOff: string | null = null, drawnTip: string | null = null, tipScope: Scope | null = null;
|
|
132
142
|
const chips = new Map<string, { readonly chip: HTMLButtonElement; readonly label: HTMLSpanElement; readonly action: HTMLElement }>();
|
|
133
143
|
const chipFor = (peer: VoicePeer): HTMLButtonElement => {
|
|
134
144
|
let held = chips.get(peer.id);
|
|
@@ -171,9 +181,17 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
171
181
|
tip.dataset['tone'] = shown.tone; tip.dataset['key'] = shown.key.split(':')[0] ?? shown.key;
|
|
172
182
|
const text = document.createElement('span'), close = document.createElement('button');
|
|
173
183
|
text.textContent = shown.text; close.type = 'button'; close.textContent = '×'; close.setAttribute('aria-label', 'Dismiss');
|
|
174
|
-
|
|
184
|
+
tipScope?.dispose(); tipScope = new Scope('voice-tip', scope);
|
|
185
|
+
tipScope.listen(close, 'click', () => { dismissed = shown.key; if (shown.key === 'first') seen(); render(); });
|
|
175
186
|
tip.replaceChildren(text, close);
|
|
187
|
+
if (tip.dataset['key'] === 'voice-failed' || tip.dataset['key'] === 'voice-failed-blocked') {
|
|
188
|
+
const again = document.createElement('button'); again.type = 'button'; again.textContent = 'Try again'; again.dataset['action'] = 'retry';
|
|
189
|
+
tipScope.listen(again, 'click', () => { again.disabled = true; again.textContent = 'Trying…'; void voice.retryUnreachable(); });
|
|
190
|
+
close.before(again);
|
|
191
|
+
}
|
|
176
192
|
}
|
|
193
|
+
const failmode = shown?.key.split(':')[0];
|
|
194
|
+
if (failmode === 'voice-failed' || failmode === 'voice-failed-blocked') tip.dataset['failmode'] = failmode; else delete tip.dataset['failmode'];
|
|
177
195
|
}
|
|
178
196
|
for (const id of chips.keys()) if (!voice.roster.has(id)) { chips.get(id)?.chip.remove(); chips.delete(id); }
|
|
179
197
|
peers.hidden = voice.state !== 'on' || voice.roster.size === 0;
|
|
@@ -25,7 +25,7 @@ import type { SimCommand, SimExternalPlayer, SimHost, SimPlayerBody, SimPlayerDr
|
|
|
25
25
|
/** The world-space command a tick's input means. */
|
|
26
26
|
/** Developer boost is a Developer page's, on its own server: a standalone worker says so at boot, and any other host ignores the button. */
|
|
27
27
|
let developerBoost = false;
|
|
28
|
-
export function allowDeveloperBoost(): void { developerBoost =
|
|
28
|
+
export function allowDeveloperBoost(on = true): void { developerBoost = on; }
|
|
29
29
|
export function simCommandOf(input: SimTickCommand): SimCommand { return 'seq' in input ? netSimCommand(input) : input; }
|
|
30
30
|
/** A board whose "riding near the ride height" is the fall's ground. */
|
|
31
31
|
function boardOn(fall: { grounded: boolean }): BoardState & { on: boolean } {
|
|
@@ -4,12 +4,6 @@ import type { GridAssembly, GridPoint } from '../../../shared/game/grid/assembly
|
|
|
4
4
|
import { installGridCrossing, type GridCrossingSession } from '../../../shared/game/grid/crossing';
|
|
5
5
|
import type { GridSimulation } from './simulation';
|
|
6
6
|
import type { GridLoadout } from '../../../shared/game/grid/wallet';
|
|
7
|
-
import { CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
8
|
-
|
|
9
|
-
/** How far from a cell's edge a player on the road has its world opened (the road between two cells is 62.5 m). */
|
|
10
|
-
const WARM_ROAD_METRES = 55;
|
|
11
|
-
/** The least a tick's move toward it counts as heading there (a walk is 0.07 m a tick); a capsule settling is not. */
|
|
12
|
-
const WARM_STEP_METRES = 0.02;
|
|
13
7
|
|
|
14
8
|
/** A player's completed hand-off: the `travel` a client's view follows (E5-REPLICATION §6.3.4). */
|
|
15
9
|
export interface GridTravel { readonly player: string; readonly from: string | null; readonly to: string | null }
|
|
@@ -28,12 +22,6 @@ export class GridRoom {
|
|
|
28
22
|
private readonly crossings = new Map<string, { readonly session: GridCrossingSession; readonly scope: Scope }>();
|
|
29
23
|
private readonly travels: GridTravel[] = [];
|
|
30
24
|
private readonly scope = new Scope('grid-room');
|
|
31
|
-
/** each player's last cell left for the road, and the cells opened ahead of them on this stretch of road (GC5): each at
|
|
32
|
-
* most once a stretch, so two players on the road never evict each other's cell tick after tick, and a failed open is not
|
|
33
|
-
* retried every tick (the crossing still prepares it at the line and reports a failure) */
|
|
34
|
-
private readonly departed = new Map<string, string>();
|
|
35
|
-
private readonly opened = new Map<string, Set<string>>();
|
|
36
|
-
private readonly feet = new Map<string, { x: number; z: number }>();
|
|
37
25
|
constructor(grid: GridSimulation, assembly: GridAssembly, ports: GridRoomPorts) {
|
|
38
26
|
this.grid = grid; this.assembly = assembly; this.ports = ports;
|
|
39
27
|
for (const player of grid.players()) this.watch(player);
|
|
@@ -42,7 +30,7 @@ export class GridRoom {
|
|
|
42
30
|
const { grid } = this, scope = this.scope.child(`crossing:${player}`);
|
|
43
31
|
const session = installGridCrossing({ current: () => grid.current(player), prepare: (from, to) => grid.prepare(from, to, player), ready: instance => grid.ready(instance),
|
|
44
32
|
checkpoint: instance => grid.checkpoint(instance), target: feet => grid.target(feet, player) }, this.assembly, instance => this.ports.loadout(player, instance), scope,
|
|
45
|
-
(from, to) => { this.travels.push({ player, from, to });
|
|
33
|
+
(from, to) => { this.travels.push({ player, from, to }); });
|
|
46
34
|
this.crossings.set(player, { session, scope });
|
|
47
35
|
}
|
|
48
36
|
/** Another player comes onto the highway at `at`, world coordinates, or into the world at `site`, in its own. */
|
|
@@ -51,40 +39,16 @@ export class GridRoom {
|
|
|
51
39
|
leave(player: string): boolean {
|
|
52
40
|
const crossing = this.crossings.get(player);
|
|
53
41
|
if (crossing === undefined || !this.grid.leave(player)) return false;
|
|
54
|
-
crossing.scope.dispose(); this.crossings.delete(player);
|
|
42
|
+
crossing.scope.dispose(); this.crossings.delete(player);
|
|
55
43
|
return true;
|
|
56
44
|
}
|
|
57
45
|
/** Everyone's own crossing, once per fixed tick, before any world steps. */
|
|
58
46
|
cross(): void {
|
|
59
47
|
for (const [player, { session }] of this.crossings) {
|
|
60
48
|
const feet = this.grid.worldFeet(player);
|
|
61
|
-
this.warm(player, feet);
|
|
62
49
|
session.step(feet);
|
|
63
50
|
}
|
|
64
51
|
}
|
|
65
|
-
/** GC5 (preview's in-page server, J311): a player on the road has the nearest cell ahead opened before they reach its line,
|
|
66
|
-
* as the page builds its own: opened only at the 6 m line, a cell's world held them at its wall for its whole load. The
|
|
67
|
-
* cell they left is not ahead. A failed open stays the crossing's to report. */
|
|
68
|
-
private warm(player: string, feet: Readonly<GridPoint>): void {
|
|
69
|
-
const previous = this.feet.get(player);
|
|
70
|
-
this.feet.set(player, { x: feet.x, z: feet.z });
|
|
71
|
-
if (this.grid.current(player) !== null) { this.opened.delete(player); return; }
|
|
72
|
-
if (previous === undefined) return;
|
|
73
|
-
const left = this.departed.get(player), edge = (p: Readonly<{ x: number; z: number }>, cell: { readonly origin: GridPoint }): number =>
|
|
74
|
-
Math.max(Math.abs(p.x - cell.origin.x), Math.abs(p.z - cell.origin.z)) - CHUNK_HALF;
|
|
75
|
-
let best: string | undefined, bestDistance = WARM_ROAD_METRES;
|
|
76
|
-
for (const cell of this.assembly.cells) {
|
|
77
|
-
// only a cell they draw nearer to: not one behind them, nor the one they left
|
|
78
|
-
const distance = edge(feet, cell);
|
|
79
|
-
if (cell.instance === left || distance > bestDistance || distance > edge(previous, cell) - WARM_STEP_METRES) continue;
|
|
80
|
-
best = cell.instance; bestDistance = distance;
|
|
81
|
-
}
|
|
82
|
-
if (best === undefined || this.grid.ready(best)) return;
|
|
83
|
-
const opened = this.opened.get(player) ?? new Set<string>();
|
|
84
|
-
if (opened.has(best)) return;
|
|
85
|
-
opened.add(best); this.opened.set(player, opened);
|
|
86
|
-
void this.grid.prefetch([best]).catch(() => undefined);
|
|
87
|
-
}
|
|
88
52
|
/** One fixed tick: everyone's own crossing, then every occupied world. */
|
|
89
53
|
step(commands?: ReadonlyMap<string, SimTickCommand>): void { this.cross(); this.grid.stepAll(commands); }
|
|
90
54
|
/** Every hand-off since the last call. */
|