aorecomp

Anarchy Online classic in the browser

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


commit 387a684f32cd32df11b76f799989d22c07cc116e
parent 7b5ce0f85511c7bd49ba59770887a1d66996c67b
Author: anon <anon@example.com>
Date:   Fri, 30 Oct 2026 08:26:31 +0000

Fix local WASM snapshot identity and verify starter equipment

Diffstat:
MDEVELOPERS.md | 10+++++++++-
MTODO.md | 27++++++++++++++++++++++++++-
Mclient/runtime/browser_testing.c | 18++++++++++--------
Mclient/tests/browser_testing.c | 3+--
Mserver/browser_game_test.go | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_starter_equipment.mjs | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 205 insertions(+), 12 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -452,7 +452,7 @@ available (`node` on PATH, `playwright` installed locally or on NODE_PATH, `/usr/bin/chromium` installed): ```sh -AO_GAME_TEST=1 go test ./server -run '^TestBrowserGameHarness$' -count=1 -timeout=10m -v +AO_GAME_TEST=1 go test ./server -run '^TestBrowser(GameHarness|StarterEquipment)$' -count=1 -timeout=15m -v ``` This starts an HTTP server on a random loopback port and uses a disposable @@ -464,6 +464,14 @@ browser, streams and HTTP server even after failures. Reports and screenshots remain in `local/game-tests/<run>/`. On the Linux desktop, use the same working DISPLAY/XAUTHORITY environment as the other GPU browser checks. +`TestBrowserStarterEquipment` creates two Atrox Enforcers through Options with +their normal Omni starter loadouts and the production training-ground population. +It checks native equipment ownership against authoritative inventory state, +observer isolation, page reconnect and cold database loading. It does not grant +items or change character stats, cash or enemies. This is the equipment slice +of the larger progression regression; earned combat, purchases and recovery +remain separate checks. + For a new scenario, attach before navigation so protocol capture includes the initial stream handshake: diff --git a/TODO.md b/TODO.md @@ -2957,8 +2957,25 @@ behavior. The source includes later expansion data and uncertain effect notes; Auno's advertised XML dump is 17.10.3. Use the existing catalog access and current SQLite storage when applying these findings. +The public [Simula AO trace](https://datasets.simula.no/ao/) contains packet +headers only. Its [MMSys 2012 paper, section 3](https://web-backend.simula.no/sites/default/files/publications/Simula.simula.1162.pdf) +explicitly excludes payloads, so this recording cannot recover game messages, +mission reward fields or combat/healing ordering. Continue seeking recordings +with payloads and known client/server provenance. + ## Thorough gameplay regression testing +- [x] Resolve the browser snapshot's incorrect local identity for normally + created characters. The first repeatable starter run reported local ID1 + while directory actor2 had seven issued items and exchanged CharacterReady. + The engine's local pointer now resolves through the native directory. + The focused WASM fixture fails against the old code and passes with the fix, + including an absent directory entry. `TestBrowserStarterEquipment` normally + creates Atrox Enforcers2/4, equips/removes/re-equips the same issued bat and + verifies page reconnect, unchanged observer items and cold database loading. + All fourteen issued items and their charges remain accounted for. The general + browser regression also passes against the rebuilt published bundle. Captures: + `local/game-tests/starter-20261030-012218/` and `local/todo-progression/`. - [x] Fix the reproducible bitmap-clear WASM abort found when reopening the mission terminal. The 16-bit fill translated a one-past address for a zero-count REP STOSW; skip translation when no trailing pixel exists. A @@ -3187,7 +3204,11 @@ and server restarts. Turn every reproduced bug into a focused regression test. terrain. Native use and pickup succeeded despite this burial. Recover the original generic corpse placement / slope-conformance policy; changing the held endpoint or adding species height offsets is not supported by this - evidence. See [corpse pose and terrain](docs/corpse-pose.md), including a + evidence. A focused original-client trace now establishes world-bound + clamping and a ground-colliding DummyVehicle with world-up orientation; + the traced path does not request surface-normal rotation. Original server + anchors and the remaining runtime comparisons are still unresolved. + See [corpse pose and terrain](docs/corpse-pose.md), including a visible opposite-facing control and successful picking after page reconnect. Retain the open-window expiry case where credits were collected but the untaken gloves expired before pickup committed. Evidence: @@ -3292,6 +3313,10 @@ and server restarts. Turn every reproduced bug into a focused regression test. instance in slot6, with no page errors or admin edits. Combat, earned loot, leveling and purchases are not yet verified in this normal-play run. Retained evidence: `local/gameplay-loop-smoke/`; owned characters/items were cleaned up. + `TestBrowserStarterEquipment` now repeats normal two-client creation and the + issued bat's equip/remove/re-equip, owner reconnect and cold ownership checks + against production training-ground resources. This is an automated equipment + slice; it does not complete the earned combat, purchases or recovery gate. A subsequent normal Omni Enforcer run trained Body Development/Stamina, equipped the issued bat/shirt and used a startup treatment lab. Solo combat ended in death; a two-player kill generated real loot/cash but its leading diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c @@ -83,16 +83,17 @@ static void actor(FILE *output, uint32_t object, uint32_t type, uint32_t id, int fputc('}', output); } -static void directory(FILE *output, uint32_t node, uint32_t nil, uint32_t local, unsigned *count) +static void directory(FILE *output, uint32_t node, uint32_t nil, uint32_t local, unsigned *count, unsigned *local_id) { if (node == nil) return; - directory(output, MEM32(node), nil, local, count); + directory(output, MEM32(node), nil, local, count, local_id); uint32_t type = MEM32(node + 12), id = MEM32(node + 16), object = MEM32(node + 20); if ((type == 50000 || type == 51005 || type == 51035 || type == 51050) && MEM32(object + 0x60)) { if ((*count)++) fputc(',', output); actor(output, object, type, id, object == local); + if (object == local) *local_id = id; } - directory(output, MEM32(node + 8), nil, local, count); + directory(output, MEM32(node + 8), nil, local, count, local_id); } void browser_test_frame(void) @@ -107,8 +108,8 @@ void browser_test_frame(void) uint32_t engine = MEM32(0x2d01752c), local = engine ? MEM32(engine + 0x88) : 0; /* KKR sub_36072000 owns selection in the local actor's command helper. */ uint32_t commands = local ? MEM32(local + 0x168) : 0; - fprintf(output, "{\"frame\":%u,\"screen\":[%u,%u],\"localId\":%u,\"hover\":[%u,%u],\"selected\":[%u,%u],", - frame, MEM32(0x27048be8), MEM32(0x27048bec), local ? MEM32(local + 0x10) : 0, + fprintf(output, "{\"frame\":%u,\"screen\":[%u,%u],\"hover\":[%u,%u],\"selected\":[%u,%u],", + frame, MEM32(0x27048be8), MEM32(0x27048bec), engine ? MEM32(engine + 0xd8) : 0, engine ? MEM32(engine + 0xdc) : 0, commands ? MEM32(commands + 0x70) : 0, commands ? MEM32(commands + 0x74) : 0); @@ -122,9 +123,10 @@ void browser_test_frame(void) fputs(",\"actors\":[", output); uint32_t actors = MEM32(0x3806c110); - unsigned count = 0; - if (actors) directory(output, MEM32(MEM32(actors + 4) + 4), MEM32(actors + 8), local, &count); - fputs("],\"regions\":[", output); + /* Resolve the engine's local actor pointer through the same directory. */ + unsigned count = 0, local_id = 0; + if (actors) directory(output, MEM32(MEM32(actors + 4) + 4), MEM32(actors + 8), local, &count, &local_id); + fprintf(output, "],\"localId\":%u,\"regions\":[", local_id); /* CCR sub_27010890 walks this list in native hit-test order. */ uint32_t module = MEM32(0x27048b7c); uint32_t head = module && MEM8(module + 4) ? MEM32(MEM32(module) + 4) : 0; diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c @@ -36,7 +36,7 @@ static void snapshot_copies_native_state_without_changing_guest_registers(void) MEM32(0x50000208) = 0x50000400; MEM32(0x50000304) = 0x50000500; memcpy((void *)ADDR(0x50000500), (uint32_t[]){0x50000400, 0, 0x50000400, 50000, 7, 0x50001000}, 24); - MEM32(0x50001010) = 7; + MEM32(0x50001010) = 1; MEM32(0x50001060) = 0x50002000; MEM32(0x50001078) = 705; MEM32(0x500010e8) = 0x50003000; @@ -72,7 +72,6 @@ static void snapshot_copies_native_state_without_changing_guest_registers(void) static void snapshots_observe_directory_clear_and_new_frames(void) { MEM32(0x50000304) = 0x50000400; - MEM32(0x50000088) = 0; browser_test_request(); browser_test_frame(); diff --git a/server/browser_game_test.go b/server/browser_game_test.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "reflect" "runtime" "testing" "time" @@ -77,3 +78,73 @@ func TestBrowserGameHarness(t *testing.T) { t.Fatalf("browser controls did not produce their authoritative outcomes: sitting=%t position=%v inventory=%+v", player.sitting, player.position, player.inventory) } } + +func TestBrowserStarterEquipment(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 to run the real WASM client in Chromium") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local", "game-tests", "starter-"+time.Now().Format("20060102-150405")) + world := newTestServer(t) + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + player := world.browserCharacter_locked(r) + json.NewEncoder(w).Encode(player.inventory) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + + // Advance actual equipment delays while keeping the test's simulation stoppable. + ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute) + defer cancel() + stopped := make(chan struct{}) + go func() { + defer close(stopped) + ticker := time.NewTicker(250 * time.Millisecond) + defer ticker.Stop() + for { + select { + case now := <-ticker.C: + world.advanceEquipment(now) + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_starter_equipment.mjs"), host.URL, output) + command.Dir = root + command.Stdout, command.Stderr = os.Stdout, os.Stderr + err := command.Run() + t.Logf("Browser artifacts: %s", output) + if err != nil { + t.Fatal(err) + } + + restored := newServer() + defer restored.db.Close() + world.mutex.Lock() + defer world.mutex.Unlock() + players := 0 + for _, player := range world.characters { + if player.name != "Starterowner" && player.name != "Starterwatch" { + continue + } + players++ + if len(player.inventory.Items) != 7 || player.inventory.Credits != 0 || player.level != 1 || player.experience != 0 || + !reflect.DeepEqual(player.inventory.Items, restored.characters[player.id].inventory.Items) || + !reflect.DeepEqual(player.inventory.references(), restored.characters[player.id].inventory.references()) { + t.Fatalf("starter ownership changed across cold loading for %s: %+v", player.name, player.inventory) + } + } + if players != 2 { + t.Fatalf("created %d ordinary characters, want 2", players) + } +} diff --git a/tools/client/test_starter_equipment.mjs b/tools/client/test_starter_equipment.mjs @@ -0,0 +1,88 @@ +import assert from 'node:assert/strict'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +assert(url && output, 'Run through TestBrowserStarterEquipment'); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']}); +const games = []; +try { + // Create both characters through the same Options form used during ordinary play. + for (const name of ['Starterowner', 'Starterwatch']) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + await page.keyboard.press('Control+Alt+M'); + await page.locator('#create-button').click(); + await page.locator('#creation-breed').selectOption('4'); + await page.locator('#creation-profession').selectOption('9'); + await page.locator('#creation-side').selectOption('2'); + await page.locator('#account-name').fill(name); + await page.locator('#account-password').fill('starter regression password'); + await Promise.all([page.waitForEvent('load'), page.locator('#account-submit').click()]); + console.log('Created ' + name + '; waiting for its native training-ground actor'); + await game.ready(); + assert.equal(game.local().playfield, 950); + assert.equal(game.local().inventory.length, 7); + assert.equal(game.local().stats[54], 1); + assert.equal(game.local().stats[52], 0); + await game.save(output + '/' + name + '/created'); + } + const [owner, observer] = games; + await owner.wait('ordinary observer in the training ground', state => + state.actors.some(actor => actor.id === observer.state.localId)); + const issued = owner.local().inventory; + const watched = observer.local().inventory; + const bat = issued.find(item => item.templates[0] === 121564); + assert(bat); + const before = await (await owner.page.request.get(url + '/test-state')).json(); + + // The native inventory's initial three-column layout puts the issued bat fourth. + await owner.key('i'); + await owner.save(output + '/inventory'); + await owner.click(681, 99, 'right'); + await owner.wait('issued bat equipped', state => owner.local(state).inventory.some(item => item.id === bat.id && item.slot === 6)); + const equipped = await (await owner.page.request.get(url + '/test-state')).json(); + assert.deepEqual(equipped.Items, before.Items.map(item => item.ID === bat.id ? {...item, Slot: 6} : item)); + assert.deepEqual(owner.local().inventory.map(item => item.id).sort(), issued.map(item => item.id).sort()); + await observer.snapshot(); + assert.deepEqual(observer.local().inventory, watched); + console.log('PASS: normally issued bat equips without changing any owned identity or observer inventory'); + + await owner.page.reload(); + await owner.ready(); + assert(owner.local().inventory.some(item => item.id === bat.id && item.slot === 6)); + await owner.page.keyboard.press('Control+1'); + await owner.snapshot(); + await owner.save(output + '/wear'); + console.log('PASS: page reconnect retains the same equipped starter instance'); + + // Remove through Wear, then equip the same instance from its original inventory cell. + await owner.click(867, 206, 'right'); + await owner.wait('issued bat returned to inventory', state => owner.local(state).inventory.some(item => item.id === bat.id && item.slot === 51)); + const removed = await (await owner.page.request.get(url + '/test-state')).json(); + assert.deepEqual(removed.Items, before.Items); + assert.deepEqual(owner.local().inventory, issued); + await owner.page.keyboard.press('Control+1'); + await owner.key('i'); + await owner.save(output + '/removed'); + await owner.click(681, 99, 'right'); + await owner.wait('same issued bat equipped again', state => owner.local(state).inventory.some(item => item.id === bat.id && item.slot === 6)); + const reworn = await (await owner.page.request.get(url + '/test-state')).json(); + assert.deepEqual(reworn.Items, equipped.Items); + await observer.snapshot(); + assert.deepEqual(observer.local().inventory, watched); + for (const game of games) assert.deepEqual(game.events.filter(event => event.kind === 'error'), []); + console.log('PASS: native remove/rewear preserves both starter loadouts and charges'); +} finally { + try { + for (const [index, game] of games.entries()) await game.save(output + '/client-' + index); + } finally { + await browser.close(); + } +}