aorecomp

Anarchy Online classic in the browser

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


commit e40a3e1450189481effbdecd987aadcec72241dc
parent aec9781256d7628f548f71a81bf394974c02bdc9
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 04:56:05 +0000

Restore separate equipment sources while a move is pending

Diffstat:
MTODO.md | 6++++++
Mdocs/inventory.md | 24++++++++++++++++++++++++
Aserver/browser_pending_equipment_test.go | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/equipment_test.go | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/inventory.go | 18+++++++++++++++++-
Atools/client/test_pending_equipment.mjs | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 273 insertions(+), 1 deletion(-)

diff --git a/TODO.md b/TODO.md @@ -3705,6 +3705,12 @@ and server restarts. Turn every reproduced bug into a focused regression test. stack and exactly-once Psychic bonus through fresh-server native recovery. This isolates ownership; resurrection-shock rules remain open below. See [weapon reclaim](docs/inventory.md#retained-weapon-death-and-reclaim). + A focused controlled checkpoint now also reproduces a hidden second equipment + source while a first move awaits server completion. Explicit refusal restores + the second icon without changing the first move/deadline. Carried/worn handler + cases, native completion/retry, page replay and exact cold ownership pass; + this leaves the broader audit open. See + [pending equipment](docs/inventory.md#another-move-while-equipment-is-pending). - [ ] [P2] Review nearly invisible original item icons separately from ownership loss. Low-Tech sleeves 70561/85744 reference icon 1010008/13228: the original 14.9.1 PNG is almost entirely chroma-key green, with only a tiny shoulder in diff --git a/docs/inventory.md b/docs/inventory.md @@ -439,6 +439,30 @@ P0 equipment-conservation audit. AO_GAME_TEST=1 go test ./server -run '^TestBrowserEquipmentReplacement$' -count=1 -timeout=12m -v ``` +### Another move while equipment is pending + +An owned-item move arriving while another equipment move is pending is refused +with the existing native equipment correction. The requested source must match +the owner's actual page and logical slot. A duplicate of the admitted move is +left pending; correction of a different item leaves the admitted identity, +destination and completion deadline unchanged. Refusal does not write inventory. + +`TestEquipmentPendingMoveRestoresAnotherSourceForRetry` covers carried and worn +sources through the public inventory handler, byte-identical durable state, +completion, retry and cold ownership. `TestBrowserSecondEquipmentMove` holds a +real axe placement at a controlled server checkpoint, waits for its local +animation to end, then places a second axe with real native input. Previously +the second request received no response and its source stayed hidden. The +correction restores that icon; completing the first move and retrying the second +retains both exact weapons after page replay and cold loading. This fixture +tests late completion and ownership, rather than earned progression or original +server permission for concurrent equipment moves. +Accepted native captures: `local/pending-equipment/20261102-205402/`. + +```sh +AO_GAME_TEST=1 go test ./server -run '^TestBrowserSecondEquipmentMove$' -count=1 -timeout=4m -v +``` + ### Weapon instance delivery The native `WeaponItemFullUpdate` (`0x3b1d2268`) creates the visible owned weapon diff --git a/server/browser_pending_equipment_test.go b/server/browser_pending_equipment_test.go @@ -0,0 +1,77 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserSecondEquipmentMove(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for a second move during pending equipment") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/pending-equipment", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.stats = testCharacterStats() + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-equipment"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for range 2 { + if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted { + t.Fatal(granted, err) + } + } + 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() + var pending any + if client := world.clients[1]; client != nil && client.equipment != nil { + pending = map[string]any{"itemID": client.equipment.itemID, "source": client.equipment.source, + "destination": client.equipment.destination, "replacedID": client.equipment.replacedID, "readyAt": client.equipment.readyAt} + } + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "pending": pending}) + }) + // Hold each admitted move until the native refusal or retry has been observed. + mux.HandleFunc("POST /test-complete", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + finish := world.clients[1].equipment.readyAt + world.mutex.Unlock() + world.advanceEquipment(finish) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_equipment.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + if err := command.Run(); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + + expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 65, Count: 1}, + {ID: 2, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) { + t.Fatal("pending move refusal/retry lost the exact equipment instances") + } + t.Logf("Browser artifacts: %s", output) +} diff --git a/server/equipment_test.go b/server/equipment_test.go @@ -203,6 +203,66 @@ func TestEquipmentUnsupportedWearSlotRestoresInventoryItem(t *testing.T) { } } +func TestEquipmentPendingMoveRestoresAnotherSourceForRetry(t *testing.T) { + for _, source := range []uint32{65, 6} { + t.Run(fmt.Sprint(source), func(t *testing.T) { + world, conn := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted { + t.Fatal(granted, err) + } + player.inventory.Items[1].Slot = source + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, itemMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("first move was not admitted", err) + } + move := *client.equipment + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + conn.packets = nil + destination := uint32(6) + if source == 6 { + destination = 111 + } + + if err := world.handleInventory(client, itemMovePacket(1, source, destination)[20:]); err != nil { + t.Fatal(err) + } + after, err := readTestItemStore(world) + + if err != nil || !bytes.Equal(before, after) || *client.equipment != move { + t.Fatal("busy refusal changed the durable inventory or admitted move", err) + } + expected := equipmentCorrectionPackets(1, source) + for i := range expected { + expected[i] = targetPacket(expected[i]) + } + if !reflect.DeepEqual(conn.packets, expected) { + t.Fatalf("second move did not restore its native source: %x", conn.packets) + } + world.advanceEquipment(move.readyAt) + if source == 6 { + // The replaced second weapon now occupies the first weapon's former slot. + source, destination = 64, 6 + } + if err := world.handleInventory(client, itemMovePacket(1, source, destination)[20:]); err != nil || client.equipment == nil { + t.Fatal("second move could not be retried", err) + } + world.advanceEquipment(client.equipment.readyAt) + cold := newTestInventoryServer(t) + if len(player.inventory.Items) != 2 || !reflect.DeepEqual(player.inventory.Items, cold.characters[1].inventory.Items) || + player.inventory.Items[0].ID != 1 || player.inventory.Items[0].Slot != source || + player.inventory.Items[1].ID != 2 || player.inventory.Items[1].Slot != 6 { + t.Fatalf("retry lost either exact weapon: %+v", player.inventory.Items) + } + }) + } +} + func TestEquipmentRejectedWearRestoresFullNativeInventory(t *testing.T) { for _, source := range []uint32{64, 65, 93} { t.Run(fmt.Sprint(source), func(t *testing.T) { diff --git a/server/inventory.go b/server/inventory.go @@ -259,7 +259,12 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 52 { return server.syncStacks_locked(client) } - return nil + // Validate a separate owned-item move before restoring its native source. + if key != 0x47537a24 || binary.BigEndian.Uint32(body[24:28]) != 50000 || + binary.BigEndian.Uint32(body[28:32]) != client.id || + binary.BigEndian.Uint32(body[16:20]) < 101 || binary.BigEndian.Uint32(body[16:20]) > 104 { + return nil + } } if key == 0x47537a24 && (binary.BigEndian.Uint32(body[24:28]) == 51017 || binary.BigEndian.Uint32(body[16:20]) == 107 && binary.BigEndian.Uint32(body[20:24])>>16 != 0) { @@ -285,6 +290,17 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { (sourceSlot >= 16 && sourceSlot < 32 && sourceType != 102) { return nil } + if client.equipment != nil { + // A duplicate of the admitted move must retain its pending native source. + if character.inventory.Items[index].ID != client.equipment.itemID { + for _, packet := range equipmentCorrectionPackets(client.id, sourceSlot) { + if err := client.send(packet); err != nil { + return err + } + } + } + return nil + } destination := binary.BigEndian.Uint32(body[32:36]) if key == 0x47537a24 && (sourceSlot < 64 || destination < 64) { if binary.BigEndian.Uint32(body[24:28]) != 50000 || binary.BigEndian.Uint32(body[28:32]) != client.id { diff --git a/tools/client/test_pending_equipment.mjs b/tools/client/test_pending_equipment.mjs @@ -0,0 +1,89 @@ +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: 'pending-equipment', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + const server = async () => (await page.request.get(url + '/test-state')).json(); + await game.key('i'); + await page.keyboard.press('Control+1'); + const equip = async slot => { + const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy); + assert(cell, 'equipment source is visible'); + const sequence = game.sequence; + await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); + await game.click(867, 206); + await game.wait('actual equipment request', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '47537a24' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === slot)); + return sequence; + }; + await equip(48); + evidence.pending = await server(); + assert(evidence.pending.pending); + await game.wait('local animation finishes while server move remains pending', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const sequence = await equip(49); + evidence.refused = await server(); + assert.deepEqual(evidence.refused, evidence.pending); + await game.save(output + '/pending'); + await game.wait('second equipment source restored', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy)) && + game.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && + (event.opcode === '47537a24' || event.opcode === '5e477770'))); + assert.deepEqual(game.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' && + event.opcode === '47537a24').map(event => { + const packet = Buffer.from(event.hex, 'hex'); + return [packet.readUInt32BE(29), packet.readUInt32BE(33), packet.readUInt32BE(45)]; + }), [[104, 49, 48], [104, 48, 49]]); + assert.deepEqual(game.state.dragged, [0, 0]); + await game.save(output + '/refused'); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('original equipment completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6)); + await game.wait('local second animation has ended', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + await equip(49); + evidence.retry = await server(); + assert(evidence.retry.pending); + assert.deepEqual(evidence.retry.inventory.Items, [ + {...evidence.pending.inventory.Items[0], Slot: 6}, evidence.pending.inventory.Items[1]]); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('retry replaces the original weapon', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 6)); + evidence.after = await server(); + assert.equal(evidence.after.pending, null); + assert.deepEqual(evidence.after.inventory.Items, [ + {...evidence.pending.inventory.Items[0], Slot: 65}, {...evidence.pending.inventory.Items[1], Slot: 6}]); + assert.equal(game.events.filter(event => event.direction === 'framesent' && event.opcode === '47537a24').length, 3); + await game.save(output + '/retried'); + await page.reload(); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104 && !cell.dummy))) await game.key('i'); + await game.wait('retained weapon visible after page replay', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy))); + assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]).sort((a, b) => a[0] - b[0]), + [[1, 49, 1, 1], [2, 6, 1, 1]]); + assert.equal(game.errors.length, 0); + console.log('PASS: second equipment move restores its source, preserves the first move and retries without losing either weapon'); +} 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(); } +}