@wildshard/engine 0.1.17 → 0.1.19
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/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +21 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/no-base64.mjs +3 -1
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/lint/shard-imports.mjs +6 -7
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +22 -23
- package/package.json +25 -16
- package/scripts/agent-sync.mjs +27 -8
- package/scripts/app-build/appCook.ts +8 -2
- package/scripts/app-build/catalogue.ts +10 -7
- package/scripts/app-build/gen.ts +22 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +35 -0
- package/scripts/app-build/previousDeploy.d.mts +2 -0
- package/scripts/app-build/previousDeploy.mjs +10 -1
- package/scripts/app-build/serviceWorker.ts +10 -3
- package/scripts/app-build/splitOutput.mjs +4 -2
- package/scripts/app-build/standaloneOutput.d.mts +1 -1
- package/scripts/app-build/standaloneOutput.mjs +5 -3
- package/scripts/app-build/titlePreloads.d.mts +8 -0
- package/scripts/app-build/titlePreloads.mjs +69 -0
- package/scripts/app-build/worldMapAtlas.ts +10 -6
- package/scripts/app-build-pipeline.mjs +34 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +81 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +3 -1
- package/scripts/check-models.mjs +2 -0
- package/scripts/check-paths.allow.json +0 -115
- package/scripts/check-paths.mjs +2 -2
- package/scripts/check-platform-ratchets.mjs +2 -3
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.d.mts +1 -1
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/ci-static.sh +1 -1
- package/scripts/committed-fast-checks.mjs +0 -2
- package/scripts/content-sw-proof.mjs +2 -1
- package/scripts/cook-worker.mjs +9 -3
- package/scripts/cook.mjs +20 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +4 -2
- package/scripts/devserver-client.mjs +25 -8
- package/scripts/docs-inputs-proof.mjs +6 -6
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/e7-voice-staging-proof.mjs +1 -1
- package/scripts/gate-related-tests.mjs +1 -1
- package/scripts/git-source-view.mjs +1 -1
- package/scripts/goldens/capture.mjs +17 -5
- package/scripts/grid-crossing-nightly.mjs +59 -0
- package/scripts/grid-crossing-qa.mjs +44 -0
- package/scripts/grid-crossing-ratchet.d.mts +6 -0
- package/scripts/grid-crossing-ratchet.mjs +52 -0
- package/scripts/grid-crossing-report.mjs +122 -0
- package/scripts/grid-crossing-stages.mjs +47 -0
- package/scripts/grid-crossing-tour.mjs +277 -0
- package/scripts/grid-crossing-walk-proof.mjs +136 -18
- package/scripts/host-ruler/roots.mjs +2 -2
- package/scripts/host-ruler.d.mts +91 -0
- package/scripts/host-ruler.mjs +565 -0
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +3 -1
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +213 -0
- package/scripts/mmo-bots.mjs +8 -2
- package/scripts/net-lag-proof.mjs +219 -0
- package/scripts/night-market-kit-budget.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +5 -3
- package/scripts/offline-proof-rules.mjs +34 -7
- package/scripts/offline-proof.mjs +88 -18
- package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
- package/scripts/page-release/content.d.mts +9 -1
- package/scripts/page-release/content.mjs +131 -17
- package/scripts/page-release/flow.mjs +36 -10
- package/scripts/page-release/stamp-content.mjs +24 -0
- package/scripts/page-release.mjs +28 -6
- package/scripts/page-size.mjs +2 -1
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +78 -0
- package/scripts/tile-bake-report.mjs +1 -1
- package/scripts/tile-bakes.mjs +1 -1
- package/scripts/title-assets.generated.json +2 -0
- package/scripts/tsconfig.json +1 -2
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +176 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +84 -24
- package/scripts/worker-client-play.mjs +7 -2
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/scripts/worktree-reap.mjs +5 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +47 -12
- package/src/client/engine/boot/bootCache.ts +2 -2
- package/src/client/engine/boot/bootTrace.ts +12 -4
- package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
- package/src/client/engine/boot/clearDownloads.ts +5 -2
- package/src/client/engine/boot/contentRead.ts +11 -0
- package/src/client/engine/boot/gpuFiles.ts +4 -2
- package/src/client/engine/boot/lastEnd.ts +99 -12
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/boot/texturePack.ts +2 -2
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +18 -0
- package/src/client/engine/core/bootstrap.ts +4 -1
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +29 -6
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +53 -14
- package/src/client/engine/render/dataLook.ts +152 -40
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +7 -1
- package/src/client/engine/render/look.ts +6 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +28 -4
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
- package/src/client/engine/ui/debugOptions.ts +1 -1
- package/src/client/engine/ui/lookLightOption.ts +10 -6
- package/src/client/engine/ui/namePrompt.ts +7 -0
- package/src/client/game/boot/audio.generated.ts +114 -216
- package/src/client/game/boot/bytes.generated.ts +118 -238
- package/src/client/game/boot/placedSpawn.ts +35 -0
- package/src/client/game/boot/spawnDownload.ts +25 -6
- package/src/client/game/boot/versions.generated.ts +7 -7
- package/src/client/game/devScene/hook.ts +291 -0
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +134 -12
- package/src/client/game/grid/liveSession.ts +47 -5
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +233 -0
- package/src/client/game/grid/placedContent.ts +85 -0
- package/src/client/game/grid/prefetch.ts +9 -1
- package/src/client/game/grid/productInputs.ts +3 -1
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadLook.ts +24 -15
- package/src/client/game/grid/roadLookPlatform.ts +4 -2
- package/src/client/game/grid/roadResources.ts +24 -0
- package/src/client/game/grid/roadSign.worker.ts +4 -3
- package/src/client/game/grid/roadSignPaint.ts +16 -5
- package/src/client/game/grid/roadSignPreparation.ts +4 -3
- package/src/client/game/grid/roadSignScale.ts +8 -0
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
- package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
- package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
- package/src/client/game/grid/roadTileWriter.ts +2 -1
- package/src/client/game/grid/screenReports.ts +39 -0
- package/src/client/game/grid/session.ts +29 -4
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/grid/softWallLook.ts +25 -8
- package/src/client/game/mainMenu.ts +6 -2
- package/src/client/game/plugin/context.ts +2 -1
- package/src/client/game/plugin/followedMovers.ts +7 -1
- package/src/client/game/quest/figures.ts +2 -0
- package/src/client/game/session/finish.ts +11 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +4 -1
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +21 -8
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/game/titleDeck.ts +4 -3
- package/src/client/host/online/doctor.ts +2 -0
- package/src/client/host/online/linkScreens.ts +30 -4
- package/src/client/host/online/shell.ts +14 -0
- package/src/client/host/standalone/shell.ts +4 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +67 -9
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +349 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/engine/ai/bossContenders.ts +27 -3
- package/src/server/engine/ai/phases.ts +1 -1
- package/src/server/engine/entities/creatureRefill.ts +9 -2
- package/src/server/engine/net/ledgerBook.ts +2 -0
- package/src/server/engine/net/room.ts +15 -0
- package/src/server/engine/sim/respawn.ts +8 -0
- package/src/server/game/boss/arenaRoomEntry.ts +5 -1
- package/src/server/game/boss/arenaRoomNative.ts +2 -0
- package/src/server/game/boss/native.ts +2 -1
- package/src/server/game/boss/nativeWake.ts +9 -5
- package/src/server/game/boss/openArenaNative.ts +2 -2
- package/src/server/game/boss/openArenaRoom.ts +3 -1
- package/src/server/game/grid/room.ts +44 -3
- package/src/server/game/grid/simulation.ts +23 -0
- package/src/server/game/population/mixedRoster.ts +11 -3
- package/src/server/game/population/nativeBake.ts +8 -3
- package/src/server/game/population/nativeReturns.ts +6 -3
- package/src/server/game/population/roster.ts +5 -3
- package/src/server/game/quest/eliteDrops.ts +15 -4
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +10 -6
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +98 -16
- package/src/server/host/dedicated/cellProtocol.ts +16 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +4 -19
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +126 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/workerTable.ts +15 -4
- package/src/server/host/dedicated/world.ts +95 -8
- package/src/server/host/headless.ts +1 -1
- package/src/server/host/headlessRuntime.ts +1 -1
- package/src/server/host/standalone/roadWorld.ts +15 -3
- package/src/server/host/standalone/serverHost.ts +4 -1
- package/src/server/host/standalone/serverProduct.ts +41 -11
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +47 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/catalogueSlot.ts +7 -0
- package/src/shared/game/grid/placementRows.ts +36 -0
- package/src/shared/game/plugin/bossRecord.ts +3 -2
- package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
- package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
- package/src/shared/game/shardfile/packReads.ts +28 -3
- package/src/shared/game/shardfile/serverPack.ts +9 -0
- package/src/shared/game/systems/looks/trampleField.ts +2 -0
- package/src/shared/host/formatJsonSchema.ts +2 -2
- package/src/tsconfig.json +1 -27
- package/lint/host-reviews.json +0 -14
- package/lint/listed-view-code.json +0 -13
- package/lint/platform-pending-users.json +0 -2520
- package/lint/platform-pending-users.md +0 -18
- package/scripts/cell-mem/metrics-preload.mjs +0 -65
- package/scripts/check-closed-components.d.mts +0 -7
- package/scripts/check-closed-components.mjs +0 -87
- package/scripts/g571-hosts.d.mts +0 -3
- package/scripts/g571-hosts.mjs +0 -54
- package/scripts/host-ruler/register-migrate.mjs +0 -242
- package/scripts/listed-view-code.d.mts +0 -7
- package/scripts/listed-view-code.mjs +0 -93
- package/scripts/look-loop/fit-lut.py +0 -142
- package/scripts/look-loop/palette-delta.py +0 -183
- package/scripts/look-loop/regions/driftwood-isle.json +0 -25
- package/scripts/look-loop/regions/far-reach.json +0 -225
- package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
- package/scripts/look-loop/regions/pine-hollow.json +0 -22
- package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
- package/scripts/platform-chargebacks.d.mts +0 -9
- package/scripts/platform-chargebacks.mjs +0 -135
- package/scripts/shard-component-spans.d.mts +0 -15
- package/scripts/shard-component-spans.mjs +0 -18
- package/scripts/shard-components.d.mts +0 -16
- package/scripts/shard-components.mjs +0 -363
- package/scripts/shard-platform-hosts.d.mts +0 -2
- package/scripts/shard-platform-hosts.mjs +0 -93
- package/scripts/shard-platform-sections.d.mts +0 -2
- package/scripts/shard-platform-sections.mjs +0 -9
- package/scripts/shard-platform.d.mts +0 -76
- package/scripts/shard-platform.mjs +0 -1072
- package/src/.oxfmtrc.json +0 -48
- package/src/scripts/ask-new.sh +0 -29
- package/src/scripts/asks.mjs +0 -142
- package/src/scripts/herdr-prompt.sh +0 -34
- package/src/scripts/herdr-question-open.sh +0 -67
- package/src/scripts/md-wrap.mjs +0 -229
- /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
- /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
- /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
|
@@ -16,10 +16,12 @@ import { NetIdentitySchema } from '@wildshard/engine/net/identity';
|
|
|
16
16
|
import { decodeFirstMessage } from '@wildshard/wire/handshake';
|
|
17
17
|
import { WIRE_MINOR } from '@wildshard/wire/major';
|
|
18
18
|
import { encodeCountdown, type WorldWord } from '@wildshard/engine/net/socketFrames';
|
|
19
|
+
import { deviceLine, readDeviceWord, type DeviceSnapshot, type DeviceWho } from '@wildshard/engine/net/deviceWord';
|
|
19
20
|
import {CorrectionSchema} from '@wildshard/engine/net/measurements';
|
|
20
21
|
import type {PlaytestRow} from './playtest';
|
|
21
22
|
import type { ChatReport } from '@wildshard/engine/net/chat';
|
|
22
23
|
import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
24
|
+
import type { MotionSnapshot } from '@wildshard/engine/game/grid/simulation';
|
|
23
25
|
import { bodyId } from './seats';
|
|
24
26
|
import { SaveNewerError, type PlayerDoc } from './playerDoc';
|
|
25
27
|
import { LEAVE_FLAG, LEFT, pumpSocket } from './socketPump';
|
|
@@ -106,8 +108,12 @@ export interface WorldOptions {
|
|
|
106
108
|
readonly crashed: (error: unknown) => void;
|
|
107
109
|
/** The grace ran out: stop, and let systemd start what is on disk. */
|
|
108
110
|
readonly restart: () => void;
|
|
109
|
-
/** One worker's 10 s reading, for what leaves the box (E7.8a). */
|
|
111
|
+
/** One worker's 10 s reading, for what leaves the box (E7.8a) and `/metrics` (SC1). */
|
|
110
112
|
readonly reading?: (index: number, reading: WorkerReading) => void;
|
|
113
|
+
/** SERVER-CELLS SC1: a cell (or a worker's road) opened in `ms`, as `cell.booted` logs it. */
|
|
114
|
+
readonly booted?: (index: number, slug: string, ms: number) => void;
|
|
115
|
+
/** SC1: a crossing's time from its source's ask to its worker's answer, and whether the seat moved. */
|
|
116
|
+
readonly crossed?: (ms: number, moved: boolean) => void;
|
|
111
117
|
readonly playtest?:(row:PlaytestRow)=>void;
|
|
112
118
|
/** J218: the ICE servers voice chat hands a player who joins; public STUN when absent. */
|
|
113
119
|
readonly voiceIce?: () => Promise<readonly VoiceIceServer[]>;
|
|
@@ -145,6 +151,8 @@ export class World {
|
|
|
145
151
|
private readonly ends = new Set<SocketTransport>();
|
|
146
152
|
/** Links whose player quit (`ready` with `LEAVE_FLAG`) before a body was theirs. */
|
|
147
153
|
private readonly quits = new WeakSet<SocketTransport>();
|
|
154
|
+
/** DEVICE-TELEMETRY DT4: each socket's device word and the player its hello named, until the one `client.device` line is written. */
|
|
155
|
+
private readonly devices = new WeakMap<SocketTransport, { said?: DeviceSnapshot; who?: DeviceWho; done: boolean }>();
|
|
148
156
|
/** Clients loading: each holds a seat, and has no body yet. */
|
|
149
157
|
private readonly pending = new Map<string, PendingSeat>();
|
|
150
158
|
/** Who has a body, by link or by hold, and in which cell. */
|
|
@@ -155,8 +163,14 @@ export class World {
|
|
|
155
163
|
private readonly voiceBodies = new Map<string, (body: string) => void>();
|
|
156
164
|
private readonly finds = new Map<number, (found: { held: boolean; spawn: ResumeAt }) => void>();
|
|
157
165
|
private readonly drains = new Map<number, () => void>();
|
|
158
|
-
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered. */
|
|
159
|
-
private readonly crossings = new
|
|
166
|
+
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered, and when it began (SC1). */
|
|
167
|
+
private readonly crossings = new Map<string, number>();
|
|
168
|
+
/** GC15 (3): each seated device's socket and a copy of the hello it was seated with, so a crossing onto another worker can move both. */
|
|
169
|
+
private readonly seatSockets = new Map<string, { readonly end: SocketTransport; readonly hello: ArrayBuffer }>();
|
|
170
|
+
/** GC15 (3): a crossing onto another worker, between the source's `handOut` and the socket's `out`: where it arrives and with what save. */
|
|
171
|
+
private readonly outs = new Map<string, { readonly from: string; readonly to: string; readonly at: ResumeAt; readonly entry: SeatEntry }>();
|
|
172
|
+
/** GC15 (3): each worker's grid cells whose entryways stand, as its `booted` said. */
|
|
173
|
+
private readonly stands = new Map<WorkerLink, readonly string[]>();
|
|
160
174
|
/** GC15: devices whose source said `left` while their crossing was in flight: applied if the crossing is abandoned before `cross`. */
|
|
161
175
|
private readonly leftCrossing = new Set<string>();
|
|
162
176
|
private asked = 0;
|
|
@@ -198,7 +212,7 @@ export class World {
|
|
|
198
212
|
this.options.crashed(new Error(reason));
|
|
199
213
|
};
|
|
200
214
|
link.listen(news => {
|
|
201
|
-
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
215
|
+
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (news.stands !== undefined) { this.stands.set(link, news.stands); this.openRoads(); } if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
202
216
|
else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news);
|
|
203
217
|
}, ended);
|
|
204
218
|
});
|
|
@@ -253,7 +267,7 @@ export class World {
|
|
|
253
267
|
else if (news.kind === 'report') { if (!this.options.saves.report(news.report, cellShard(news.slug))) this.refuse('report-backlog'); }
|
|
254
268
|
else if (news.kind === 'chat') { for (const link of this.workers) link.send({ kind: 'chat', from: news.slug, line: news.line }); }
|
|
255
269
|
else if(news.kind==='playtest')this.options.playtest?.(news.row);
|
|
256
|
-
else if (news.kind === 'cell') this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms });
|
|
270
|
+
else if (news.kind === 'cell') { this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms }); this.options.booted?.(index, news.slug, news.ms); }
|
|
257
271
|
else if (news.kind === 'reading') { this.options.log({ at: 'worker', index, ...news.reading, refusals: this.refusals, connections: this.connectionStats, saves: this.options.saves.stats?.() }); this.options.reading?.(index, news.reading); }
|
|
258
272
|
else if (news.kind === 'placed') {
|
|
259
273
|
const link = this.workers[index];
|
|
@@ -264,7 +278,10 @@ export class World {
|
|
|
264
278
|
}
|
|
265
279
|
else if (news.kind === 'drained') { this.drains.get(index)?.(); this.drains.delete(index); }
|
|
266
280
|
else if (news.kind === 'crossing') void this.crossing(news.slug, news.device, news.to, news.at);
|
|
281
|
+
else if (news.kind === 'handedOut') { if (!news.out && this.outs.get(news.device)?.from === news.from) { this.outs.delete(news.device); this.abandon(news.device, news.from); } }
|
|
267
282
|
else if (news.kind === 'crossed') {
|
|
283
|
+
const begun = this.crossings.get(news.device);
|
|
284
|
+
if (begun !== undefined) this.options.crossed?.(diagnosticNow() - begun, news.moved);
|
|
268
285
|
this.crossings.delete(news.device); this.leftCrossing.delete(news.device);
|
|
269
286
|
// A moved seat stands in the target, on the same link; one the target refused after the source let it go is in neither.
|
|
270
287
|
if (this.seated.get(news.device) === news.from) {
|
|
@@ -324,11 +341,35 @@ export class World {
|
|
|
324
341
|
// GO4: the door's first word, before any hello: how many cells it hosts, and (opus-route2) the shard each runs, so a one-shard
|
|
325
342
|
// page joins only a world that opens its shard. D7 keeps `/health` private on the rooms address, and a
|
|
326
343
|
// grid page asks this on a socket of its own (`worldWord`). No build, serial or player data.
|
|
327
|
-
|
|
344
|
+
// DEVICE-TELEMETRY DT3: `device: 1` says this door reads the client's device word; a client sends it only then.
|
|
345
|
+
end.control('world', new TextEncoder().encode(JSON.stringify({ cells: this.links.size, shards: [...new Set([...this.links.keys()].map(cellShard))], device: 1 } satisfies WorldWord)).buffer);
|
|
346
|
+
end.onControl((control, bytes) => { if (control === 'device') this.deviceWord(end, bytes); });
|
|
328
347
|
const timer = this.scope.timeout(this.options.helloMs ?? HELLO_MS, () => { this.refuse('hello-timeout'); end.close('refused'); });
|
|
329
348
|
const off = end.onMessage((_channel, bytes) => { off(); this.scope.cancelTimer(timer); void this.joining(end, bytes, goto); });
|
|
330
349
|
end.onClose(() => { off(); this.scope.cancelTimer(timer); });
|
|
331
350
|
}
|
|
351
|
+
/** DT4: a client's device word, untrusted: one per socket, read and bounded by `readDeviceWord`. A junk or oversized word is counted
|
|
352
|
+
* and dropped, and the connect goes on. */
|
|
353
|
+
private deviceWord(end: SocketTransport, bytes: ArrayBuffer): void {
|
|
354
|
+
const seen = this.devices.get(end) ?? { done: false };
|
|
355
|
+
if (seen.said !== undefined || seen.done) return;
|
|
356
|
+
const said = readDeviceWord(bytes);
|
|
357
|
+
if (said === null) { this.refuse('device-word'); this.options.log({ at: 'client.device-refused', bytes: bytes.byteLength }); seen.done = true; this.devices.set(end, seen); return; }
|
|
358
|
+
seen.said = said; this.devices.set(end, seen); this.deviceSeen(end);
|
|
359
|
+
}
|
|
360
|
+
/** DT4: the hello named this socket's player. */
|
|
361
|
+
private devicePlayer(end: SocketTransport, who: DeviceWho): void {
|
|
362
|
+
const seen = this.devices.get(end) ?? { done: false };
|
|
363
|
+
seen.who ??= who; this.devices.set(end, seen); this.deviceSeen(end);
|
|
364
|
+
}
|
|
365
|
+
/** DT4: one `client.device` journal line per connect, once both the word and the hello's player are in. Privacy: the player id the
|
|
366
|
+
* hello already carries and device characteristics only; never the address, which the door keeps for its limits alone. */
|
|
367
|
+
private deviceSeen(end: SocketTransport): void {
|
|
368
|
+
const seen = this.devices.get(end);
|
|
369
|
+
if (seen === undefined || seen.done || seen.said === undefined || seen.who === undefined) return;
|
|
370
|
+
seen.done = true;
|
|
371
|
+
this.options.log(deviceLine(seen.who, seen.said));
|
|
372
|
+
}
|
|
332
373
|
private async joining(end: SocketTransport, bytes: ArrayBuffer, goto: string | null): Promise<void> {
|
|
333
374
|
try { await this.hello(end, bytes, goto); }
|
|
334
375
|
catch (error) { if (!end.isOpen) return; this.options.log({ at: 'world.join', error: String(error) }); this.refuse(error instanceof SaveNewerError ? 'save-newer' : 'join-failed'); end.close(error instanceof SaveQuarantinedError ? 'refused' : 'retry'); }
|
|
@@ -336,6 +377,13 @@ export class World {
|
|
|
336
377
|
/** Everyone in the grid or on their way: the cap counts all of them, whichever cell they stand in (J182). */
|
|
337
378
|
private get taken(): number { return this.seated.size + this.pending.size; }
|
|
338
379
|
/** The worker a cell runs on, or (GC15) whose road a name is. */
|
|
380
|
+
/** GC15 (3): every worker's road hears which cells on the other workers a walker can stand in, and drops its walls round them. */
|
|
381
|
+
private openRoads(): void {
|
|
382
|
+
for (const link of this.up) {
|
|
383
|
+
const cells = [...this.stands].filter(([other]) => other !== link && this.up.has(other)).flatMap(([, list]) => list);
|
|
384
|
+
if (cells.length > 0) link.send({ kind: 'open', cells });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
339
387
|
private linkOf(slug: string): WorkerLink | undefined { return this.links.get(roadHome(slug) ?? slug); }
|
|
340
388
|
private link(slug: string): WorkerLink {
|
|
341
389
|
const link = this.linkOf(slug);
|
|
@@ -368,6 +416,8 @@ export class World {
|
|
|
368
416
|
const said = v.safeParse(NetIdentitySchema, { player: hello.player, name: hello.name });
|
|
369
417
|
if (!said.success) { this.refuse('identity'); end.close('refused'); return; }
|
|
370
418
|
const device = said.output.player, typed = cleanName(said.output.name), body = bodyId(this.options.secret, device), { saves } = this.options, holding = this.seated.get(device);
|
|
419
|
+
// DT4: the Name everyone sees and the secret-keyed body id; never the raw player id, which is a bearer credential
|
|
420
|
+
this.devicePlayer(end, { name: this.names.get(device) ?? typed, body });
|
|
371
421
|
// GC15: a seat mid-crossing is in neither cell for the door to ask: the client dials again in a moment.
|
|
372
422
|
if (this.crossings.has(device)) { end.close('retry'); return; }
|
|
373
423
|
if (holding !== undefined) {
|
|
@@ -414,8 +464,10 @@ export class World {
|
|
|
414
464
|
*/
|
|
415
465
|
private async crossing(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
416
466
|
const link = this.linkOf(to), name = this.names.get(device);
|
|
467
|
+
// GC15 (3): from a worker's road into a cell another worker hosts
|
|
468
|
+
if (link !== undefined && link !== this.linkOf(from) && roadHome(from) !== null && roadHome(to) === null) { await this.crossWorkers(from, device, to, at); return; }
|
|
417
469
|
if (link === undefined || link !== this.linkOf(from) || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device)) return;
|
|
418
|
-
this.crossings.
|
|
470
|
+
this.crossings.set(device, diagnosticNow());
|
|
419
471
|
try {
|
|
420
472
|
// The road keeps no progress: a seat walks onto it with nothing to read.
|
|
421
473
|
const saved: SavedPlayer = roadHome(to) === null ? await this.options.saves.read(device, cellShard(to)) : { doc: null, seq: 0 };
|
|
@@ -424,6 +476,32 @@ export class World {
|
|
|
424
476
|
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) });
|
|
425
477
|
} catch (error) { this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
426
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* GC15 (3): a seat on one worker's road walks into a cell on another worker. The door reads their save on that cell's shard, the road
|
|
481
|
+
* sends the client `travel` and lets the seat go (`handOut`), and when its port says `out` the door points the same socket at a new port
|
|
482
|
+
* into the target's worker, which seats them at `at` and hears their hello again (`arrive`). The socket never closes.
|
|
483
|
+
*/
|
|
484
|
+
private async crossWorkers(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
485
|
+
const source = this.linkOf(from), name = this.names.get(device);
|
|
486
|
+
if (source === undefined || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device) || !this.seatSockets.has(device)) return;
|
|
487
|
+
this.crossings.set(device, diagnosticNow());
|
|
488
|
+
try {
|
|
489
|
+
const saved = await this.options.saves.read(device, cellShard(to));
|
|
490
|
+
if (this.seated.get(device) !== from || this.draining || !this.seatSockets.has(device)) { this.abandon(device, from); return; }
|
|
491
|
+
this.outs.set(device, { from, to, at, entry: { device, name, body: bodyId(this.options.secret, device), doc: saved.doc, seq: saved.seq,
|
|
492
|
+
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) } });
|
|
493
|
+
source.send({ kind: 'handOut', from, device, to });
|
|
494
|
+
} catch (error) { this.outs.delete(device); this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
495
|
+
}
|
|
496
|
+
/** GC15 (3): the source let the seat go and everything it said is on its way: the socket now pumps into the target's worker. */
|
|
497
|
+
private movedOut(device: string, end: SocketTransport, motion: unknown): void {
|
|
498
|
+
const out = this.outs.get(device), kept = this.seatSockets.get(device), link = out === undefined ? undefined : this.linkOf(out.to);
|
|
499
|
+
this.outs.delete(device);
|
|
500
|
+
if (out === undefined || kept?.end !== end || link === undefined || !end.isOpen || this.draining) { this.abandon(device, out?.from ?? ''); end.close(this.draining ? 'restart' : 'retry'); return; }
|
|
501
|
+
const { port1, port2 } = new MessageChannel(), hello = kept.hello.slice(0);
|
|
502
|
+
pumpSocket(end, port1, undefined, next => { this.movedOut(device, end, next); });
|
|
503
|
+
link.send({ kind: 'arrive', from: out.from, to: out.to, at: out.at, port: port2, hello, motion: motion as MotionSnapshot | null, ...out.entry }, [port2, hello]);
|
|
504
|
+
}
|
|
427
505
|
/** A crossing that never reached its worker: a `left` the source said meanwhile counts now. */
|
|
428
506
|
private abandon(device: string, from: string): void {
|
|
429
507
|
this.crossings.delete(device);
|
|
@@ -450,7 +528,16 @@ export class World {
|
|
|
450
528
|
});
|
|
451
529
|
end.onClose(off);end.control('playtest');
|
|
452
530
|
}
|
|
453
|
-
|
|
531
|
+
this.seatSockets.set(entry.device, { end, hello: hello.slice(0) });
|
|
532
|
+
end.onClose(() => {
|
|
533
|
+
if (this.seatSockets.get(entry.device)?.end !== end) return;
|
|
534
|
+
this.seatSockets.delete(entry.device);
|
|
535
|
+
// GC15 (3), review MUST: the socket went while a crossing onto another worker waited for its `out`, which this close swallowed:
|
|
536
|
+
// the crossing is off, and a `left` the road said (or says next) frees the seat
|
|
537
|
+
const out = this.outs.get(entry.device);
|
|
538
|
+
if (out !== undefined) { this.outs.delete(entry.device); this.abandon(entry.device, out.from); }
|
|
539
|
+
});
|
|
540
|
+
pumpSocket(end, port1, undefined, motion => { this.movedOut(entry.device, end, motion); });
|
|
454
541
|
const rebody = this.voice.attach(end, slug, entry.name, entry.body);
|
|
455
542
|
this.voiceBodies.set(entry.device, rebody);
|
|
456
543
|
end.onClose(() => { if (this.voiceBodies.get(entry.device) === rebody) this.voiceBodies.delete(entry.device); });
|
|
@@ -14,7 +14,7 @@ import { createHash } from 'node:crypto';
|
|
|
14
14
|
import { pathToFileURL } from 'node:url';
|
|
15
15
|
import { validateShardfileAssets } from '@wildshard/format/assetAdmission';
|
|
16
16
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
17
|
-
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/
|
|
17
|
+
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
18
18
|
import { TickWorkerHost } from './tickWorkerHost';
|
|
19
19
|
import { AuthorProofPlanSchema, TickCommandSchema, type HeadlessCommand, type AuthorProofPlan, type AuthorProofReport, type HeadlessCommandSource, type HeadlessTickCommit, type HeadlessTapePartReport } from '../../shared/host/tickProtocol';
|
|
20
20
|
import * as v from 'valibot';
|
|
@@ -3,7 +3,7 @@ import * as v from 'valibot';
|
|
|
3
3
|
import { runHeadlessJourney } from '../../shared/host/headlessJourney';
|
|
4
4
|
import { registerNativeQuestInputs } from '@wildshard/engine/game/quest/nativeInputs';
|
|
5
5
|
import { hasDeclaredClientPage } from '@wildshard/format/runtimeBinds';
|
|
6
|
-
import { prepareAssetDecoders } from '@wildshard/format/
|
|
6
|
+
import { prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
7
7
|
import { parseNativeRuntimePlan } from '@wildshard/format/nativeRuntimePlan';
|
|
8
8
|
import { MoverScriptDriver, type MoverRuntime } from '@wildshard/engine/game/plugin/mover';
|
|
9
9
|
import { installRopeDecks } from './ropeDecks';
|
|
@@ -23,19 +23,31 @@ const WALL = 0.5, WALL_HEIGHT = 30;
|
|
|
23
23
|
const WALL_OFF = 2;
|
|
24
24
|
export const ROAD: SimLevel = { version: SIM_API_VERSION, id: 'grid-road', seed: 1, ground: { size: ROAD_HALF_SIZE * 2, height: FALL_FLOOR }, player: { at: { x: 0, y: 0, z: 0 }, yaw: 0, speed: ROAD_SPEED }, entities: [], quests: [], weapon: HOST_PROBE };
|
|
25
25
|
|
|
26
|
+
/** Each road world's cell walls, by the cell they stand round, so GC15 (3) can open one a walker can now cross into. */
|
|
27
|
+
const walls = new WeakMap<SimHost, Map<string, Collider[]>>();
|
|
26
28
|
/**
|
|
27
29
|
* A wall around every cell in the road's own world, as the page's readiness walls are while a cell loads. A player stops just short of
|
|
28
30
|
* a cell until its world is ready and the crossing takes them in, 6 m out at most; the road never runs on under a cell's own
|
|
29
31
|
* hills, where a late hand-off would set them down inside one. A cell's terrain can end in a bank above road level at its very edge,
|
|
30
32
|
* and a capsule set down touching that bank stays stuck in it, so the wall stands clear of it.
|
|
31
33
|
*/
|
|
32
|
-
export function addCellWalls(road: SimHost, cells: readonly Pick<GridCell, 'origin'>[]): void {
|
|
34
|
+
export function addCellWalls(road: SimHost, cells: readonly (Pick<GridCell, 'origin'> & { readonly instance?: string })[]): void {
|
|
33
35
|
const { R, world } = road.physics, reach = CHUNK_HALF + WALL_OFF + WALL / 2, long = reach + WALL / 2;
|
|
36
|
+
const kept = walls.get(road) ?? new Map<string, Collider[]>();
|
|
37
|
+
walls.set(road, kept);
|
|
34
38
|
withOwner(road.scope, () => {
|
|
35
|
-
for (const { origin } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const)
|
|
36
|
-
world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
39
|
+
for (const { origin, instance } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const) {
|
|
40
|
+
const collider = world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
41
|
+
if (instance !== undefined) kept.set(instance, [...kept.get(instance) ?? [], collider]);
|
|
42
|
+
}
|
|
37
43
|
});
|
|
38
44
|
}
|
|
45
|
+
/** GC15 (3): take down the walls round these cells (on another worker, their entryways standing): the road crosses into them now. */
|
|
46
|
+
export function openCellWalls(road: SimHost, instances: readonly string[]): void {
|
|
47
|
+
const kept = walls.get(road);
|
|
48
|
+
if (kept === undefined) return;
|
|
49
|
+
for (const instance of instances) { for (const collider of kept.get(instance) ?? []) if (collider.isValid()) road.physics.world.removeCollider(collider, false); kept.delete(instance); }
|
|
50
|
+
}
|
|
39
51
|
/** Each road world's void floor colliders, so a placement can lift them (SA34a). */
|
|
40
52
|
const floors = new WeakMap<SimHost, readonly Collider[]>();
|
|
41
53
|
/** SA34: the 7 × 7's void, walkable: a road-level floor over every empty cell and out to the rail, and the rim on the rail. */
|
|
@@ -20,6 +20,7 @@ import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
|
20
20
|
import { StandaloneGrid } from './gridServer';
|
|
21
21
|
import { isHarnessFlag, isHarnessGod, isHarnessHits, isHarnessJoin, isHarnessMove, isHarnessPlace } from '../../../shared/host/standalone/harnessPlace';
|
|
22
22
|
import { WorkerLoopback } from '../../../shared/host/standalone/workerLoopback';
|
|
23
|
+
import { isDevColliders, swapDevBoxes } from '@wildshard/engine/game/devColliders';
|
|
23
24
|
import { ProgressSaves, ProgressWatch } from './progressWatch';
|
|
24
25
|
|
|
25
26
|
type Boot = Extract<ShellMessage, { kind: 'boot' }>;
|
|
@@ -98,7 +99,9 @@ export function runStandaloneServer(options: StandaloneServerOptions): { dispose
|
|
|
98
99
|
if (restored?.ledger !== undefined) book.restore(restored.ledger);
|
|
99
100
|
server.connect(new WorkerLoopback(game));
|
|
100
101
|
watch.look(server.host, book.filed); // where the world stands before its first tick: what that tick moves is progress
|
|
101
|
-
|
|
102
|
+
// SHARD-SOURCE AP5: `wildshard watch`'s part colliders, in this world as in the page's (DEVSERVER only: the define folds it away)
|
|
103
|
+
const devBoxes = new Map<string, Scope>();
|
|
104
|
+
if (options.harness !== undefined) options.harness.onmessage = (event: MessageEvent<unknown>): void => { const [port] = event.ports; if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__ && isDevColliders(event.data)) swapDevBoxes(server.host.physics, server.host.scope, devBoxes, event.data.wildshardDevColliders, event.data.boxes); else if (isHarnessJoin(event.data) && port !== undefined) server.join(event.data, new WorkerLoopback(port)); else if (isHarnessFlag(event.data)) server.raise(event.data.flag); else if (isHarnessMove(event.data)) server.place(event.data, event.data.move); else if (isHarnessPlace(event.data)) server.place(event.data); else if (isHarnessHits(event.data)) server.hardHits(event.data.hits); else if (isHarnessGod(event.data)) server.bossGod(); };
|
|
102
105
|
clock = new ServerClock({ now: diagnosticNow, wait: (ms, run) => { const timer = scope.timeout(ms, run); return () => { scope.cancelTimer(timer); }; },
|
|
103
106
|
step: () => { try { server.tick(); progress(server); } catch (error) { fail(error); } } });
|
|
104
107
|
options.proof?.booted?.(server);
|
|
@@ -7,7 +7,7 @@ import { nodeNamedJsonCheck, nodeOutputDescriptorChecks } from '@wildshard/engin
|
|
|
7
7
|
import { carryOutputDescriptor, isBuildValidatedOutput, outputDescriptor, resolveOutputDescriptor, serverReadsFile } from '@wildshard/engine/game/shardfile/outputDescriptor';
|
|
8
8
|
import { shardProductData } from '@wildshard/engine/game/shardfile/productData';
|
|
9
9
|
import { GRID_COLLISION_BODY, GRID_COLLISION_HEADER, readGridCollision, type GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
10
|
-
import { readServerPackBook, serverPackBookPath, serverPackFile, serverPackPart, type ServerPackBook, type ServerPackPart } from '@wildshard/engine/game/shardfile/serverPack';
|
|
10
|
+
import { cookIndexPath, readCookedServerIndex, readServerPack, readServerPackBook, serverPackBookPath, serverPackFile, serverPackPart, type ServerPack, type ServerPackBook, type ServerPackPart } from '@wildshard/engine/game/shardfile/serverPack';
|
|
11
11
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
12
12
|
import type { HeldRead } from '../../../shared/host/standalone/heldReads';
|
|
13
13
|
|
|
@@ -51,10 +51,29 @@ function besideShard(path: string, root: string): URL {
|
|
|
51
51
|
if (!path.startsWith('/') || path.startsWith('//') || at === -1) return new URL(path, base);
|
|
52
52
|
return new URL(`.${path}`, new URL(base.pathname.slice(0, at + 1), base));
|
|
53
53
|
}
|
|
54
|
+
/** A JSON file beside a shard's base, by its path from the origin's root. `fresh` asks past any cache with a query of its own: a CDN keeps a
|
|
55
|
+
* 404 for a while, and a cook index that is missing now may be written a minute later. A `file:` origin reads `path` and ignores it. */
|
|
56
|
+
async function originJson(root: string, path: string, read: ServerRead, fresh = false): Promise<unknown> {
|
|
57
|
+
const url = besideShard(`/${path}`, root);
|
|
58
|
+
if (fresh) url.search = `?t=${String(Date.now())}`;
|
|
59
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(await read(url, path)));
|
|
60
|
+
}
|
|
54
61
|
/** This build's server book. */
|
|
55
62
|
async function serverBook(root: string, build: string, read: ServerRead): Promise<ServerPackBook> {
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
return readServerPackBook(await originJson(root, serverPackBookPath(build), read));
|
|
64
|
+
}
|
|
65
|
+
/** The leading `_` a grid slug may carry is not the shard's (shard-format `shardSlugOf`). */
|
|
66
|
+
const shardOf = (slug: string): string => slug.replace(/^_/u, '');
|
|
67
|
+
/**
|
|
68
|
+
* SA47: a placed slug this build's book has no row for (a new author's, uploaded after the build), from the cook's index for this build
|
|
69
|
+
* and these bytes (MMO-SERVER MS2.4): `index/<build>/<hash>.json` names the pack the cook wrote beside its parts. The parts are read by
|
|
70
|
+
* their hash as a book's are, so the index only says where they are. A missing index throws, as a missing row does.
|
|
71
|
+
*/
|
|
72
|
+
async function cookedPack(root: string, slug: string, cooked: Readonly<{ build: string; hash: string }>, read: ServerRead): Promise<ServerPack> {
|
|
73
|
+
const { build, hash } = cooked, path = cookIndexPath(build, hash), index = readCookedServerIndex(await originJson(root, path, read, true));
|
|
74
|
+
if (index.build !== build || index.hash !== hash || shardOf(index.slug) !== shardOf(slug)) throw new Error(`The cook's ${path} is not ${slug}'s`);
|
|
75
|
+
if (index.serverPack === undefined) throw new Error(`No server pack for ${slug} in the cook's ${path}`);
|
|
76
|
+
return readServerPack(await originJson(root, index.serverPack.index.slice(1), read));
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
/** C2: the road's collision from this build's grid pack: nothing a page reads, and no shard's. */
|
|
@@ -79,9 +98,21 @@ export async function readGridCollisionPack(root: string, build: string, read: S
|
|
|
79
98
|
/** C2: reads a server file from its product's pack, fetching the book once and a part only for a file it holds. The browser
|
|
80
99
|
* undoes `br`. A read file is copied out and its part left to the collector: a phone's worker shouldn't hold a level's worth
|
|
81
100
|
* of them, and reading one again is a cache hit. */
|
|
82
|
-
function serverPackReader(root: string, slug: string, build: () => string, source: ServerRead): (path: string) => Promise<Uint8Array> {
|
|
101
|
+
function serverPackReader(root: string, slug: string, build: () => string, source: ServerRead, hash?: string): (path: string) => Promise<Uint8Array> {
|
|
83
102
|
const opening = new Map<string, Promise<Uint8Array>>(), opened = new Map<string, WeakRef<Uint8Array>>();
|
|
84
|
-
let book: Promise<ServerPackBook> | undefined;
|
|
103
|
+
let pack: Promise<ServerPack> | undefined, book: Promise<ServerPackBook> | undefined;
|
|
104
|
+
// SA47: the book wins; only a slug it has no row for, with the shardfile hash its placement names, reads the cook's index. The book
|
|
105
|
+
// is read once, as before SA47; only a refused index is asked again (review)
|
|
106
|
+
const packOf = async (): Promise<ServerPack> => {
|
|
107
|
+
const row = (await (book ??= serverBook(root, build(), source))).shards[slug];
|
|
108
|
+
if (row !== undefined) return row;
|
|
109
|
+
if (hash === undefined) throw new Error(`No server pack for ${slug}`);
|
|
110
|
+
return cookedPack(root, slug, { build: build(), hash }, source);
|
|
111
|
+
};
|
|
112
|
+
// A refusal is not kept: the next read (the next look, SA33) asks again.
|
|
113
|
+
const packOnce = async (): Promise<ServerPack> => {
|
|
114
|
+
try { return await packOf(); } catch (error) { pack = undefined; throw error; }
|
|
115
|
+
};
|
|
85
116
|
const body = (part: ServerPackPart): Promise<Uint8Array> => {
|
|
86
117
|
const kept = opened.get(part.url)?.deref();
|
|
87
118
|
if (kept !== undefined) return Promise.resolve(kept);
|
|
@@ -92,9 +123,7 @@ function serverPackReader(root: string, slug: string, build: () => string, sourc
|
|
|
92
123
|
return read;
|
|
93
124
|
};
|
|
94
125
|
return async path => {
|
|
95
|
-
const
|
|
96
|
-
if (pack === undefined) throw new Error(`No server pack for ${slug}`);
|
|
97
|
-
const part = serverPackPart(pack, path), bytes = part === undefined ? undefined : serverPackFile(part, await body(part), path);
|
|
126
|
+
const part = serverPackPart(await (pack ??= packOnce()), path), bytes = part === undefined ? undefined : serverPackFile(part, await body(part), path);
|
|
98
127
|
if (bytes === undefined) throw new Error(`Missing server input ${path}`);
|
|
99
128
|
return bytes.slice();
|
|
100
129
|
};
|
|
@@ -107,12 +136,13 @@ function serverPackReader(root: string, slug: string, build: () => string, sourc
|
|
|
107
136
|
export function fetchServerProduct(base: string, rapier: Rapier, held?: HeldRead): Promise<HeadlessRuntimeInput> {
|
|
108
137
|
return readServerProduct(new URL(base, globalThis.location.href).href, workerBuild, serverBytes, rapier, held);
|
|
109
138
|
}
|
|
110
|
-
/** A shard's server inputs under `root`, whichever server is reading: `source` is what differs.
|
|
111
|
-
|
|
139
|
+
/** A shard's server inputs under `root`, whichever server is reading: `source` is what differs. `hash`, a placed slug's shardfile (SA47),
|
|
140
|
+
* lets a slug the build's book lacks open from the cook's index. */
|
|
141
|
+
export async function readServerProduct(root: string, build: () => string, source: ServerRead, rapier: Rapier, held?: HeldRead, hash?: string): Promise<HeadlessRuntimeInput> {
|
|
112
142
|
const slug = new URL('.', root).pathname.split('/').at(-2) ?? '';
|
|
113
143
|
// C2: all of it is in the pack this build's book names, the server class only there (J91). The page lends what it holds
|
|
114
144
|
// (DL25), so that moves no bytes. A host with no book, or one offline after a new build, reads what the device kept.
|
|
115
|
-
const serverFile = serverPackReader(root, slug, build, source);
|
|
145
|
+
const serverFile = serverPackReader(root, slug, build, source, hash);
|
|
116
146
|
const read = async (path: string): Promise<Uint8Array> => {
|
|
117
147
|
if (path.startsWith('server/')) return serverFile(path);
|
|
118
148
|
const url = new URL(path, root), lent = await held?.(url.href);
|
|
@@ -156,6 +156,14 @@ export class BossBrain {
|
|
|
156
156
|
this.state = 'dormant';
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/** SERVER-CELLS SC5 (J328): a served world's beaten boss comes back (its world is never rebuilt): forgotten as `disarm` does, and its
|
|
160
|
+
* record is a fresh world's (SC10: not beaten, so a record's world flags clear; its reward stands again for the next win). Who is
|
|
161
|
+
* paid stays the bounty's, once per player. */
|
|
162
|
+
returnBeaten(): void {
|
|
163
|
+
this.disarm();
|
|
164
|
+
this.saved.defeated = false; this.saved.rewardTaken = false; this.save();
|
|
165
|
+
}
|
|
166
|
+
|
|
159
167
|
/** the player died. In this fight → back at the checkpoint (true); anywhere else → not ours (false) */
|
|
160
168
|
onPlayerDeath(): boolean {
|
|
161
169
|
if (!this.engaged) return false;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// DEVICE-TELEMETRY DT3/DT4 (meta docs/plans/DEVICE-TELEMETRY-PLAN.md; Jake, 2026-11-13: "start gathering metadata for every single
|
|
2
|
+
// client that connects [...] so we can kind of reverse engineer what device is up playing"): the device word a client sends once per
|
|
3
|
+
// socket, and the one shape both sides bound it to. The client cuts its snapshot with `cleanDevice` before it sends; the door reads the
|
|
4
|
+
// word as untrusted input with `readDeviceWord` and logs `deviceLine`.
|
|
5
|
+
//
|
|
6
|
+
// Privacy line: device characteristics only, the ones any page can read (Client Hints, the User-Agent, the GPU name, screen, cores,
|
|
7
|
+
// memory, locale, connection type). No IP address, no new persistent identifier, no fingerprint hash, and nothing that reads files,
|
|
8
|
+
// contacts, sensors, the camera, the microphone or location.
|
|
9
|
+
|
|
10
|
+
/** The most bytes a device word may hold; a longer one is refused whole. Under the room's 1024-byte message cap
|
|
11
|
+
* (room.ts MAX_CLIENT_MESSAGE_BYTES), past which the socket itself closes `refused`. */
|
|
12
|
+
export const DEVICE_WORD_MAX_BYTES = 1000;
|
|
13
|
+
/** The `world` word's flag that says this door reads the device word. An older door never says it, so a client never sends one there:
|
|
14
|
+
* an older door closes `refused` on a control prefix it does not know (socketTransport.ts `receive`). */
|
|
15
|
+
export const DEVICE_WORD_FLAG = 'device';
|
|
16
|
+
|
|
17
|
+
/** Whether the door's `world` word says it reads the device word. Never throws. */
|
|
18
|
+
export function worldReadsDevice(bytes: ArrayBuffer): boolean {
|
|
19
|
+
try { const said: unknown = JSON.parse(new TextDecoder().decode(bytes)); return typeof said === 'object' && said !== null && DEVICE_WORD_FLAG in said && said[DEVICE_WORD_FLAG] === 1; }
|
|
20
|
+
catch { return false; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Kind = 'text' | 'long' | 'number' | 'flag' | 'list';
|
|
24
|
+
/** A device snapshot: every field optional. Nothing else crosses the wire. */
|
|
25
|
+
export interface DeviceSnapshot {
|
|
26
|
+
readonly build?: string;
|
|
27
|
+
// User-Agent Client Hints (Chromium): `model` names an Android phone ("Pixel 8", "SM-S918B")
|
|
28
|
+
readonly ua?: string; readonly model?: string; readonly platform?: string; readonly platformVersion?: string; readonly architecture?: string;
|
|
29
|
+
readonly bitness?: string; readonly wow64?: boolean; readonly mobile?: boolean;
|
|
30
|
+
readonly brands?: readonly string[]; readonly fullVersionList?: readonly string[]; readonly formFactors?: readonly string[];
|
|
31
|
+
// the game's own WebGL context
|
|
32
|
+
readonly gpu?: string; readonly gpuVendor?: string; readonly maxTexture?: number; readonly astc?: boolean; readonly etc2?: boolean; readonly bptc?: boolean;
|
|
33
|
+
readonly screenW?: number; readonly screenH?: number; readonly availW?: number; readonly availH?: number; readonly dpr?: number; readonly orientation?: string;
|
|
34
|
+
readonly cores?: number; readonly memory?: number; readonly touch?: number; readonly pointer?: string; readonly hover?: boolean;
|
|
35
|
+
readonly language?: string; readonly languages?: readonly string[]; readonly timeZone?: string;
|
|
36
|
+
readonly net?: string; readonly downlink?: number; readonly saveData?: boolean;
|
|
37
|
+
readonly display?: string;
|
|
38
|
+
}
|
|
39
|
+
type Field = keyof DeviceSnapshot;
|
|
40
|
+
/** Each field's kind, which `cleanDevice` bounds it by. */
|
|
41
|
+
const FIELDS: Readonly<Record<Field, Kind>> = {
|
|
42
|
+
build: 'text',
|
|
43
|
+
ua: 'long', model: 'text', platform: 'text', platformVersion: 'text', architecture: 'text', bitness: 'text', wow64: 'flag', mobile: 'flag',
|
|
44
|
+
brands: 'list', fullVersionList: 'list', formFactors: 'list',
|
|
45
|
+
gpu: 'text', gpuVendor: 'text', maxTexture: 'number', astc: 'flag', etc2: 'flag', bptc: 'flag',
|
|
46
|
+
screenW: 'number', screenH: 'number', availW: 'number', availH: 'number', dpr: 'number', orientation: 'text',
|
|
47
|
+
cores: 'number', memory: 'number', touch: 'number', pointer: 'text', hover: 'flag',
|
|
48
|
+
language: 'text', languages: 'list', timeZone: 'text',
|
|
49
|
+
net: 'text', downlink: 'number', saveData: 'flag',
|
|
50
|
+
display: 'text',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const TEXT_MAX = 96, LONG_MAX = 320, LIST_ITEMS = 6, ITEM_MAX = 48;
|
|
54
|
+
// Control, format (bidi, zero-width, soft hyphen), private-use and line/paragraph separators would let a junk word reorder or hide
|
|
55
|
+
// text in a journal line
|
|
56
|
+
const UNPRINTABLE = /[\p{Cc}\p{Cf}\p{Co}\p{Zl}\p{Zp}]/gu;
|
|
57
|
+
const text = (value: unknown, max: number): string | undefined => {
|
|
58
|
+
if (typeof value !== 'string') return undefined;
|
|
59
|
+
const cut = value.replaceAll(UNPRINTABLE, '').trim().slice(0, max);
|
|
60
|
+
return cut === '' ? undefined : cut;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** A snapshot cut to the known fields and their bounds: unknown fields, wrong types and non-finite numbers drop. Never throws. */
|
|
64
|
+
export function cleanDevice(raw: unknown): DeviceSnapshot {
|
|
65
|
+
const out: Record<string, unknown> = {};
|
|
66
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return out;
|
|
67
|
+
for (const [field, kind] of Object.entries(FIELDS) as [Field, Kind][]) {
|
|
68
|
+
let value: unknown;
|
|
69
|
+
try { value = (raw as Record<string, unknown>)[field]; } catch { continue; }
|
|
70
|
+
if (kind === 'text' || kind === 'long') { const said = text(value, kind === 'long' ? LONG_MAX : TEXT_MAX); if (said !== undefined) out[field] = said; }
|
|
71
|
+
else if (kind === 'number') { if (typeof value === 'number' && Number.isFinite(value) && Math.abs(value) < 1e9) out[field] = Math.round(value * 1000) / 1000; }
|
|
72
|
+
else if (kind === 'flag') { if (typeof value === 'boolean') out[field] = value; }
|
|
73
|
+
else if (Array.isArray(value)) {
|
|
74
|
+
const items = value.slice(0, LIST_ITEMS).map(item => text(item, ITEM_MAX)).filter((item): item is string => item !== undefined);
|
|
75
|
+
if (items.length > 0) out[field] = items;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** What a word too long sheds first, in order: the least telling fields go, the model and GPU stay. */
|
|
82
|
+
const SHED: readonly Field[] = ['fullVersionList', 'languages', 'brands', 'formFactors', 'ua', 'availW', 'availH', 'downlink', 'orientation', 'timeZone', 'gpuVendor'];
|
|
83
|
+
/** The word a client sends: its cleaned snapshot as JSON, under DEVICE_WORD_MAX_BYTES (fields shed in SHED's order until it fits). */
|
|
84
|
+
export function encodeDeviceWord(snapshot: DeviceSnapshot): ArrayBuffer {
|
|
85
|
+
const encoder = new TextEncoder(), clean: Record<string, unknown> = { ...cleanDevice(snapshot) };
|
|
86
|
+
let bytes = encoder.encode(JSON.stringify(clean));
|
|
87
|
+
for (const field of SHED) {
|
|
88
|
+
if (bytes.byteLength <= DEVICE_WORD_MAX_BYTES) break;
|
|
89
|
+
delete clean[field]; bytes = encoder.encode(JSON.stringify(clean));
|
|
90
|
+
}
|
|
91
|
+
return bytes.byteLength > DEVICE_WORD_MAX_BYTES ? encoder.encode('{}').buffer : bytes.buffer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The door's read of a device word: untrusted bytes, so an oversized, non-JSON or non-object word is null. Never throws. */
|
|
95
|
+
export function readDeviceWord(bytes: ArrayBuffer): DeviceSnapshot | null {
|
|
96
|
+
if (bytes.byteLength === 0 || bytes.byteLength > DEVICE_WORD_MAX_BYTES) return null;
|
|
97
|
+
let said: unknown;
|
|
98
|
+
try { said = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); } catch { return null; }
|
|
99
|
+
if (typeof said !== 'object' || said === null || Array.isArray(said)) return null;
|
|
100
|
+
return cleanDevice(said);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The browser and its major version, from the Client Hints brands, else the User-Agent. */
|
|
104
|
+
export function deviceBrowser(device: DeviceSnapshot): string | undefined {
|
|
105
|
+
const brand = [...(device.fullVersionList ?? []), ...(device.brands ?? [])].find(entry => !/not.?a.?brand|chromium/iu.test(entry));
|
|
106
|
+
if (brand !== undefined) return brand;
|
|
107
|
+
const ua = device.ua ?? '';
|
|
108
|
+
const found = /(Firefox|FxiOS|EdgA?|SamsungBrowser|OPR|CriOS|Chrome)\/(\d+)/u.exec(ua) ?? /Version\/(\d+)[^ ]* (?:Mobile\/\S+ )?Safari/u.exec(ua);
|
|
109
|
+
if (found === null) return undefined;
|
|
110
|
+
return found.length === 3 ? `${found[1] ?? ''} ${found[2] ?? ''}` : `Safari ${found[1] ?? ''}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Who a device line names: the player's Name (what everyone in the world sees) and their body id (the door's secret-keyed hash of the
|
|
114
|
+
* player id, `seats.ts` bodyId). Never the raw player id, which whoever holds it can play as, and never an address. */
|
|
115
|
+
export interface DeviceWho { readonly name: string; readonly body: string }
|
|
116
|
+
/** The door's one journal line per connect: who and what device. */
|
|
117
|
+
export function deviceLine(who: DeviceWho, device: DeviceSnapshot): Record<string, unknown> {
|
|
118
|
+
const line: Record<string, unknown> = { at: 'client.device', name: who.name, body: who.body };
|
|
119
|
+
const put = (key: string, value: unknown): void => { if (value !== undefined) line[key] = value; };
|
|
120
|
+
put('model', device.model); put('platform', device.platform); put('platformVersion', device.platformVersion);
|
|
121
|
+
put('browser', deviceBrowser(device)); put('gpu', device.gpu); put('gpuVendor', device.gpuVendor);
|
|
122
|
+
put('screen', device.screenW !== undefined && device.screenH !== undefined ? `${String(device.screenW)}x${String(device.screenH)}` : undefined);
|
|
123
|
+
put('dpr', device.dpr); put('memory', device.memory); put('cores', device.cores); put('touch', device.touch); put('mobile', device.mobile);
|
|
124
|
+
put('formFactors', device.formFactors?.join(',')); put('architecture', device.architecture); put('maxTexture', device.maxTexture);
|
|
125
|
+
put('textures', [device.astc === true ? 'astc' : '', device.etc2 === true ? 'etc2' : '', device.bptc === true ? 'bptc' : ''].filter(Boolean).join(',') || undefined);
|
|
126
|
+
put('language', device.language); put('timeZone', device.timeZone); put('net', device.net); put('display', device.display);
|
|
127
|
+
put('clientBuild', device.build); put('ua', device.ua);
|
|
128
|
+
return line;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** SENTRY: the searchable tags (`device.model:*`), each under Sentry's 200-character tag value limit. */
|
|
132
|
+
export function deviceTags(device: DeviceSnapshot): Record<string, string> {
|
|
133
|
+
const tags: Record<string, string> = {};
|
|
134
|
+
const put = (key: string, value: string | number | undefined): void => { if (value !== undefined && value !== '') tags[key] = String(value).slice(0, 200); };
|
|
135
|
+
put('device.model', device.model); put('device.gpu', device.gpu); put('device.platform', device.platform);
|
|
136
|
+
put('device.platform_version', device.platformVersion); put('device.memory', device.memory);
|
|
137
|
+
return tags;
|
|
138
|
+
}
|
|
@@ -6,13 +6,16 @@ import type { NetChannel } from './transport';
|
|
|
6
6
|
// `NET_SCHEMA_HASH` does not move.
|
|
7
7
|
|
|
8
8
|
/** The prefix byte of every message on a game socket. */
|
|
9
|
-
export const SOCKET_RELIABLE = 0, SOCKET_UNRELIABLE = 1, SOCKET_PING = 2, SOCKET_PONG = 3, SOCKET_RESUME = 4, SOCKET_READY = 5, SOCKET_COUNTDOWN = 6, SOCKET_PLAYTEST=7, SOCKET_VOICE = 8, SOCKET_WORLD = 9;
|
|
9
|
+
export const SOCKET_RELIABLE = 0, SOCKET_UNRELIABLE = 1, SOCKET_PING = 2, SOCKET_PONG = 3, SOCKET_RESUME = 4, SOCKET_READY = 5, SOCKET_COUNTDOWN = 6, SOCKET_PLAYTEST=7, SOCKET_VOICE = 8, SOCKET_WORLD = 9, SOCKET_DEVICE = 10;
|
|
10
10
|
/** The messages outside the game protocol: the server's word on where to load, the client's that it has, and the server's that a new build is coming (J174). */
|
|
11
|
-
export type SocketControl = 'resume' | 'ready' | 'countdown' | 'playtest' | 'voice' | 'world';
|
|
11
|
+
export type SocketControl = 'resume' | 'ready' | 'countdown' | 'playtest' | 'voice' | 'world' | 'device';
|
|
12
12
|
/** GO4: the door's first word on every socket, before any hello: how many grid cells it hosts and, since opus-route2, the shard each
|
|
13
13
|
* one runs, and nothing else (D7 keeps `/health` off the rooms address, so a page learns this here). A one-shard page joins only a
|
|
14
14
|
* world that names its shard. A build from before it ignores the prefix. */
|
|
15
|
-
export interface WorldWord { readonly cells: number; readonly shards: readonly string[]
|
|
15
|
+
export interface WorldWord { readonly cells: number; readonly shards: readonly string[];
|
|
16
|
+
/** DEVICE-TELEMETRY DT3: 1 when this door reads the client's `device` word (deviceWord.ts). An older door never says it, and closes
|
|
17
|
+
* `refused` on a prefix it does not know, so a client sends the word only after hearing this. */
|
|
18
|
+
readonly device?: 1 }
|
|
16
19
|
/** J218: a voice word is JSON in a few hundred bytes; an SDP travels in pieces of this many characters, under the room's 1024-byte cap. */
|
|
17
20
|
export const VOICE_PIECE_CHARS = 400;
|
|
18
21
|
/** The server sends no frame while this much is waiting (E7.1). Delta-against-ack heals, and the next frame is just bigger. */
|
|
@@ -43,7 +46,7 @@ export function closeReason(code: number): string {
|
|
|
43
46
|
/** The prefix of a game message on `channel`. */
|
|
44
47
|
export const channelPrefix = (channel: NetChannel): number => channel === 'reliable' ? SOCKET_RELIABLE : SOCKET_UNRELIABLE;
|
|
45
48
|
/** The prefix of a control message. */
|
|
46
|
-
export const controlPrefix = (control: SocketControl): number => control === 'resume' ? SOCKET_RESUME : control === 'ready' ? SOCKET_READY : control==='playtest'?SOCKET_PLAYTEST:control === 'voice' ? SOCKET_VOICE : control === 'world' ? SOCKET_WORLD : SOCKET_COUNTDOWN;
|
|
49
|
+
export const controlPrefix = (control: SocketControl): number => control === 'resume' ? SOCKET_RESUME : control === 'ready' ? SOCKET_READY : control==='playtest'?SOCKET_PLAYTEST:control === 'voice' ? SOCKET_VOICE : control === 'world' ? SOCKET_WORLD : control === 'device' ? SOCKET_DEVICE : SOCKET_COUNTDOWN;
|
|
47
50
|
/** J174: seconds until everyone moves, and the build they move to, which a client preloads. */
|
|
48
51
|
export interface Countdown { readonly seconds: number; readonly build: string }
|
|
49
52
|
/** A `countdown` word. */
|
|
@@ -43,6 +43,12 @@ export class WakeBossEncounter {
|
|
|
43
43
|
private near(player: { readonly x: number; readonly z: number }): boolean { return Math.hypot(player.x - this.center.x, player.z - this.center.z) < this.row.arena.radius; }
|
|
44
44
|
private finish(outcome: 'won' | 'lost' | 'left'): void { if (this.attempt) { this.attempt = false; this.effects.push({ kind: 'outcome', outcome }); } }
|
|
45
45
|
arm(observation: WakeBossObservation): void { this.wake(observation); }
|
|
46
|
+
/** SERVER-CELLS SC10 (J328): a served world's beaten fight stands again, as a fresh world's would: no attempt, nobody waited for. */
|
|
47
|
+
returnBeaten(): void {
|
|
48
|
+
this.attempt = false; this.waitForReturn = false; this.state = 'dormant'; this.phase = 0;
|
|
49
|
+
this.boss = { ...this.boss, state: 'dormant', phase: 0, checkpoint: 0, attempts: 1, t: 0, skipT: 0 };
|
|
50
|
+
this.effects.push({ kind: 'hide' });
|
|
51
|
+
}
|
|
46
52
|
disarm(): void { this.finish('left'); this.effects.push({ kind: 'hide' }); this.state = 'dormant'; }
|
|
47
53
|
onPlayerDeath(player: { readonly x: number; readonly z: number }): false {
|
|
48
54
|
if (this.attempt && this.near(player)) { this.finish('lost'); this.waitForReturn = true; this.effects.push({ kind: 'hide' }); this.state = 'dormant'; }
|