aorecomp

Anarchy Online classic in the browser

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


commit 529239813f0f470e5c9fd822f85903f007b5783a
parent 19e2c9c9fae32eaa7fdf17d12ae8f0df5d3b3eaf
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 11:25:57 +0000

Verify partial corpse loot across native scene reentry

Diffstat:
MTODO.md | 11+++++++----
Mdocs/corpse-scene-audit.md | 25+++++++++++++++++++++++++
Aserver/browser_corpse_reentry_test.go | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_corpse_reentry.mjs | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 228 insertions(+), 4 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3995,10 +3995,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. and page replay reopens the empty corpse. This does not resolve slope placement. Distinguish camera/fixture placement from mesh creation, original-actor prerequisites and interest replay order. - Include walking out of native scene sections and returning before corpse - expiry, with untaken and partially looted items. Compare typed native - identities with server NPC interest; a successful shop-reentry fix does not - establish corpse or actor reentry correctness. + A short controlled WASM regression now collects slot 0, crosses an observed + native section boundary and returns to pick/collect the exact remaining slot 1. + Native remains and server interest survive; cash is awarded once and cold + ownership retains both instances. This supplies partial-loot section coverage, + separately from the earlier earned untaken-item case. Open-window transitions, + slope placement and broader streaming still need checks. See + [focused partial reentry](docs/corpse-scene-audit.md#focused-partial-slot-reentry). The ordinary Omni boss run instantiated nine native corpses using mesh 25717 and death resource 25721. Some showed only two small mesh portions above a slope; backing away exposed clickable portions. An independent original-clip diff --git a/docs/corpse-scene-audit.md b/docs/corpse-scene-audit.md @@ -30,6 +30,31 @@ reproduces the old pointer-probe failure nor establishes its cause, and supplies no basis for changing corpse creation, replay ordering or the original animation. Slope placement remains in the broader P0 audit. +## Focused partial-slot reentry + +`TestBrowserPartiallyLootedCorpseSceneReentry` supplies a repeatable controlled +checkpoint beside an observed native section boundary near X=160 in Omni +Training. A one-HP killing outcome creates the corpse; fixture setup adds a +second item, places the checkpoint and extends its observation window. These +conditions isolate reentry and are not earned progression, a drop-table +measurement or evidence for the historical corpse lifetime. + +Real WASM input opens the remains and collects slot 0 and its one credit. +The client closes the window, walks across the nearby section boundary and +returns. Outbound and return `CharZoneMoveIIR` messages establish both crossings; +the server retains NPC interest and the native directory retains the corpse. +Native camera input frames the same remains above chat. Picking and reopening +then collect its exact nonzero slot 1 without another cash award. A fresh database +reader verifies physical items 1/2 in player slots 64/65 and no remaining corpse +contents. No production change or scene-triggered corpse replay is needed. + +The maintained driver is `tools/client/test_corpse_reentry.mjs`. The short +checkpoint completes in about 17 seconds. Captures, exact ledgers, source hashes, +fixture failures and limits are retained in +`local/corpse-scene-reentry/focused-partial-verification.json` and +`local/corpse-scene-reentry/focused-partial-reentry.md`. The loot window is closed +during travel; open-window transitions and generic slope placement remain open. + ## Ordinary earned controls The earned level5 Omni Enforcer5 and ordinary observer21 used the sole LAN diff --git a/server/browser_corpse_reentry_test.go b/server/browser_corpse_reentry_test.go @@ -0,0 +1,96 @@ +package main + +import ( + "ao/server/gamedata" + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "testing" + "time" +) + +func TestBrowserPartiallyLootedCorpseSceneReentry(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for native corpse scene reentry") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/corpse-scene-reentry", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.name = "Corpsewalker" + player.playfield, player.position = 950, [3]float32{173, 14, 59.5} + player.rotation = [4]float32{0, 1, 0, 0} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("corpse-walker"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + world.characters = map[uint32]*character{1: player, 1000000: { + id: 1000000, name: "Reentry Leet", npc: true, level: 1, health: 1, + playfield: 950, position: [3]float32{173, 14, 55}, rotation: [4]float32{0, 0, 0, 1}, + appearance: 229, monsterData: 17655, npcDefinitionID: "950/district/2/group/0/authored_point", + combatProfile: gamedata.NPCCombatProfiles[17655][1], + }} + world.clients[1] = &worldClient{id: 1, target: true, ready: true, conn: &combatTestConn{}, npcs: map[uint32]bool{1000000: true}} + world.combatRoll = func(uint32) uint32 { return 0 } + if err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + corpse := world.characters[1000000].corpse + if corpse == nil || len(corpse.items) != 1 { + t.Fatal("controlled killing blow did not generate its corpse") + } + // Place this controlled checkpoint beside the captured X=160 section boundary. + player.position = [3]float32{161, 14, 67.125} + world.characters[1000000].position = [3]float32{161, 13.6, 63.125} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + // A second fixture item and longer observation window isolate partial reentry. + world.nextItem++ + corpse.items = append(corpse.items, ownedItem{ID: world.nextItem, Type: 51005, Template: 42640, Quality: 1, Slot: 1, Count: 1}) + corpse.expiresAt = time.Now().Add(10 * time.Minute) + items := append([]ownedItem(nil), corpse.items...) + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + delete(world.clients, 1) + 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() + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "items": corpse.items, + "credits": corpse.credits, "interest": world.clients[1].npcs[1000000], "position": player.position}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_corpse_reentry.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + t.Logf("Browser artifacts: %s", output) + + if err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + items[0].Slot, items[1].Slot = 64, 65 + if !reflect.DeepEqual(cold.characters[1].inventory.Items, items) || cold.characters[1].inventory.Credits != 1 || + len(cold.characters[1000000].corpse.items) != 0 || cold.characters[1000000].corpse.credits != 0 { + t.Fatal("scene reentry changed exact cold ownership or repeated cash") + } +} diff --git a/tools/client/test_corpse_reentry.mjs b/tools/client/test_corpse_reentry.mjs @@ -0,0 +1,100 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +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); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +let game; +const evidence = {}; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'corpse-walker', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + if (!game.state.camera.firstPerson) await game.key('F8'); + const server = async () => (await page.request.get(url + '/test-state')).json(); + const open = async () => { + // Frame the remains above the transparent chat region with native camera input. + const point = await game.point(512, 300); + let mouseY = point.y, sequence = game.sequence; + await page.mouse.move(point.x, mouseY); + await page.mouse.down({button: 'right'}); + try { + await game.waitInput(sequence, 1025); + const deadline = Date.now() + 10000; + for (;;) { + await game.snapshot(); + const y = game.state.actors.find(actor => actor.type === 51050 && actor.id === 1000000).screenPosition[1]; + if (y >= 350 && y <= 540) break; + assert(Date.now() < deadline, 'Camera did not frame the corpse above chat'); + mouseY += y > 540 ? 20 : -20; + await page.mouse.move(point.x, mouseY, {steps: 2}); + } + } finally { + sequence = game.sequence; + await page.mouse.up({button: 'right'}); + } + await game.waitInput(sequence, 1026); + await game.click(...await game.pick(51050, 1000000), 'right'); + await game.wait('corpse loot window', state => state.regions.some(region => + region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); + }; + const take = async slot => { + await game.wait('exact corpse source icon', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 107 && cell.identity[1] === slot && !cell.dummy))); + const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === 107 && cell.identity[1] === slot && !cell.dummy); + await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); + }; + evidence.before = await server(); + assert.equal(evidence.before.items.length, 2); + await open(); + await take(0); + await game.wait('first exact item collected', state => game.local(state).inventory.length === 1); + evidence.partial = await server(); + assert.equal(evidence.partial.items.length, 1); + assert.equal(evidence.partial.inventory.Credits, 1); + await game.save(output + '/partial'); + await game.click(170, 8); + + // Walk the previously observed scene boundary without zoning or teleporting. + const sequence = game.sequence; + await game.walk(157, 67.125); + evidence.away = await server(); + evidence.awayNative = game.state.actors.some(actor => actor.type === 51050 && actor.id === 1000000); + evidence.transitions = game.events.filter(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '2d2b2169').length; + assert(evidence.transitions > 0, 'The route must cross an actual native scene section'); + assert.equal(evidence.away.interest, true, 'Scene retirement must be distinguished from server interest removal'); + assert.deepEqual(evidence.away.items, evidence.partial.items); + await game.save(output + '/away'); + await game.walk(161, 67.125); + await game.walk(161, 66.625); + evidence.returned = await server(); + evidence.returnTransitions = game.events.filter(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '2d2b2169').length; + assert(evidence.returnTransitions > evidence.transitions, 'The return must cross the native section boundary again'); + await game.save(output + '/returned'); + await open(); + await take(1); + await game.wait('second exact item collected', state => game.local(state).inventory.length === 2); + evidence.after = await server(); + assert.deepEqual(evidence.after.items, []); + assert.equal(evidence.after.inventory.Credits, 1); + assert.deepEqual(evidence.after.inventory.Items.map(item => item.ID), evidence.before.items.map(item => item.ID)); + await game.save(output + '/collected'); + assert.deepEqual(game.errors, []); + console.log('PASS: partial corpse loot survives a real scene-section round trip with exact items and one cash award'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}