aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit d0b1a280cbe22aecf71c03621450eac7e26409cf
parent 53c68ea8d37a92a52327c61024bae21dcda751ba
Author: anon <anon@example.com>
Date:   Thu, 22 Oct 2026 04:55:00 +0000

Keep pthread worker startup independent of server connectivity

Diffstat:
Mclient/browser/index.html | 5++++-
Mclient/tests/browser_loading.mjs | 22+++++++++++++++++++++-
Mclient/tests/browser_network.mjs | 4+++-
Mdocs/inventory.md | 10++++++----
4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/client/browser/index.html b/client/browser/index.html @@ -351,8 +351,11 @@ show(); Module.arguments = (await response.text()).trim().split(' ').slice(1); // The render worker owns the backing canvas after startup. [canvas.width, canvas.height] = renderSize(); + // Keep the script available when later pthreads start during a server outage. + const clientScript = await fetch('wasm/game.js'); + if (!clientScript.ok) throw new Error(`Client script: HTTP ${clientScript.status}`); const script = document.createElement('script'); - script.src = 'wasm/game.js'; + script.src = URL.createObjectURL(await clientScript.blob()); script.onerror = () => { status.textContent = 'Could not load the client'; }; document.body.append(script); } diff --git a/client/tests/browser_loading.mjs b/client/tests/browser_loading.mjs @@ -130,11 +130,14 @@ async function startsWithMainThreadGraphicsWithoutOffscreenCanvas() { canvas.clientWidth = 1024; canvas.clientHeight = 768; const scripts = []; + let clientScript; + test.context.URL = {createObjectURL(blob) { clientScript = blob; return 'blob:client'; }}; test.context.AudioContext = class {}; test.context.document.addEventListener = () => {}; test.context.document.createElement = () => ({}); test.context.document.body = {append: script => scripts.push(script.src)}; test.context.fetch = async (url, options) => { + if (url === 'wasm/game.js') return new Response('client code', {headers: {'Content-Type': 'text/javascript'}}); assert.equal(url, 'browser-launch'); assert.equal(options.method, 'POST'); return new Response('Clientr.exe localtest localtest 73'); @@ -142,16 +145,33 @@ async function startsWithMainThreadGraphicsWithoutOffscreenCanvas() { await test.context.startGame(); - assert.deepEqual(scripts, ['wasm/game.js']); + assert.deepEqual(scripts, ['blob:client']); + assert.equal(await clientScript.text(), 'client code'); + assert.equal(clientScript.type, 'text/javascript'); assert.equal(canvas.transferControlToOffscreen, undefined); assert.equal(canvas.width, 1024); assert.equal(canvas.height, 768); } +async function rejectsFailedClientScript() { + const test = fixture(); + test.context.document.querySelector('#canvas').getContext = () => ({}); + test.context.AudioContext = class {}; + test.context.document.addEventListener = () => {}; + test.context.fetch = async url => { + if (url === 'browser-launch') return new Response('Clientr.exe localtest localtest 73'); + assert.equal(url, 'wasm/game.js'); + return new Response('missing', {status: 404}); + }; + + await assert.rejects(test.context.startGame(), /Client script: HTTP 404/); +} + await streamsDecodedClientAndTracksProgress(); hidesProgressWhenDownloadStops(); await rejectsFailedClientDownload(); await reportsMissingWebGL(); await reportsUnavailableWebGLOnBothThreadsBeforeDownloading(); await startsWithMainThreadGraphicsWithoutOffscreenCanvas(); +await rejectsFailedClientScript(); console.log('PASS: loading progress, streaming compilation, first frame, download failure and missing browser graphics'); diff --git a/client/tests/browser_network.mjs b/client/tests/browser_network.mjs @@ -6,9 +6,11 @@ import test from 'node:test'; function network(arguments_, protocol = 'https:') { const connections = [], sockets = [], timers = [], stopped = [], timeouts = new Map(); let nextTimeout = 0; + const document = new EventTarget(); + document.baseURI = `${protocol}//game.example/`; const context = vm.createContext({ Module: {arguments: arguments_}, - document: new EventTarget(), window: new EventTarget(), + document, window: new EventTarget(), crypto, ArrayBuffer, DataView, Uint8Array, HEAPU8: new Uint8Array(64), Math: Object.assign(Object.create(Math), {random: () => 0.5}), location: {href: `${protocol}//game.example/`, protocol}, diff --git a/docs/inventory.md b/docs/inventory.md @@ -180,7 +180,9 @@ Two WASM clients verified axe appearance, matching combat text and damage, unequip icons and removal for the observer, and subsequent 3..5 fist hits. Repeated equipment and equipped reconnect/server-restart checks retained item ID 1, template 209283 and QL 1. The active-combat unequip attempt retained the -weapon; removal succeeded after disengaging. During forced server downtime, -one worker startup emitted an `Event` error; both clients subsequently loaded -and completed the equipped combat/removal checks. That startup failure is a -separate browser reconnect issue to investigate. +weapon; removal succeeded after disengaging. Forced server downtime also +exposed an extra pthread fetching `game.js` after the initial worker pool was +exhausted. That failed fetch emitted an `Event` error. The page now retains +the script for later workers. +The same Chromium outage test created the extra worker without that error, +reconnected automatically, rendered the world and accepted movement input.