aorecomp

Anarchy Online classic in the browser

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


commit e768452357b2f9aff18f91b46a99d0eb8a78af29
parent 6d9165ad53f1a284609889235483278efc83ae34
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 18:57:21 +0000

Cover backpack stack joins during pending equipment

Diffstat:
MTODO.md | 6++++++
Mdocs/backpacks.md | 35+++++++++++++++++++++++++++++++++++
Aserver/browser_pending_bag_stack_test.go | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/pending_bag_stack_test.go | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_pending_bag_stack.mjs | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 291 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3904,6 +3904,12 @@ and server restarts. Turn every reproduced bug into a focused regression test. and fresh-server recovery; the giver retains its separate ammunition stack. This path passes without a product fix; the broader disappearance report remains open. See [loaded weapon trade](docs/player-trading.md#instantiated-loaded-weapons). + A held-equip owned-backpack join now has a short native regression: refusal + retains both usable icons, completion permits a same-window six-charge join, + and page/cold recovery retains the axe, bag and survivor. Handler checks cover + both directions during wear/removal without writes or deadline changes. + No product defect reproduced on this path; see + [backpack joins](docs/backpacks.md#stack-join-during-pending-equipment). - [x] [P0] Preserve selected-quality stack contracts after a refused split. Reproduction: a real QL2 Ctrl-split during a controlled pending equip rebuilt its native endpoints as 25811/25811 instead of 25812/25811. Resolve the shared diff --git a/docs/backpacks.md b/docs/backpacks.md @@ -171,6 +171,41 @@ for the weapon, bag and contained item through page and cold recovery. Its controlled delayed completion is not earned progression. Captures are retained in `local/pending-backpack/`; the broader equipment audit remains open. +## Stack join during pending equipment + +A controlled native check holds server completion after the local equipment +bar ends, then joins two three-charge Essence of Pure Jealousy stacks inside an open +owned backpack. The real page107 action53 is ignored while equipment is pending, +but both source cells remain usable, the cursor clears, and neither count nor +the admitted move/deadline changes. After completion, the same join succeeds +without reopening the bag, retaining one six-charge instance. Page replay +reopens the bag with that same survivor; a fresh database reader retains the +axe, bag and six charges. No production change was required. This differs from +the reproduced hidden ordinary-grid source in +[pending ordinary joins](inventory-stacks.md#join-during-pending-equipment). + +`TestPendingBackpackStackJoinPreservesOwnershipAndRetries` covers both merge +directions during wear and removal, unchanged database bytes and zero writes, +the existing handle/deadline, retry and cold identity. The actual client check +is `TestBrowserBackpackStackJoinDuringPendingEquipment`, driven by +`tools/client/test_pending_bag_stack.mjs`; controlled items and the held server +deadline isolate ownership rather than earned progression or original +concurrent-inventory permission. Evidence is under `local/pending-bag-stack/`. + +The related bank probe did not produce a join: normal bank clicks sent +withdrawals, and both icons restored on refusal. Existing original DDR +`10045110` analysis excludes a non-owned bank from `JoinItems`; see +[bank gestures](bank-storage.md#original-evidence). Do not infer a native +bank source-loss defect from a synthetic action53 request alone. Its bounded +negative trace is `local/pending-bank-stack/20261103-105149/`. + +The accepted backpack run is `local/pending-bag-stack/20261103-105608/`,21.37s +native/29.117s including Go. Independent packet/state checks confirm the actual +join request, absence of a successful join or timer-cancel response during +refusal, both usable sources,3+3 ->6 charges, and3 complete clean traces. +All5 focused handler results, native syntax checking and vet pass. See +`local/pending-bag-stack/verification-summary.json`. + ## Deposit during pending equipment Carried-item deposits into an open bag also need a refusal while equipment is diff --git a/server/browser_pending_bag_stack_test.go b/server/browser_pending_bag_stack_test.go @@ -0,0 +1,86 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserBackpackStackJoinDuringPendingEquipment(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for stack joining during pending equipment") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/pending-bag-stack", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.stats = testCharacterStats() + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-bag-stack"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, template := range []uint32{209283, 99228, 152030, 152030} { + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + inventory := player.inventory + contents := slices.Clone(inventory.Items[2:]) + contents[0].Slot, contents[1].Slot = 0, 1 + inventory.Items = slices.Clone(inventory.Items[:2]) + inventory.Containers = map[uint32][]ownedItem{2: contents} + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(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, "readyAt": client.equipment.readyAt} + } + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "pending": pending}) + }) + 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_bag_stack.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) + expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}, + {ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1}} + expectedContents := []ownedItem{{ID: 4, Type: 51005, Template: 152030, Quality: 42, Slot: 1, Count: 6}} + if !slices.Equal(cold.characters[1].inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Containers[2], expectedContents) { + t.Fatal("backpack join refusal/retry changed equipment or lost charges") + } +} diff --git a/server/pending_bag_stack_test.go b/server/pending_bag_stack_test.go @@ -0,0 +1,76 @@ +package main + +import ( + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestPendingBackpackStackJoinPreservesOwnershipAndRetries(t *testing.T) { + for _, removing := range []bool{false, true} { + for _, kept := range []uint32{0, 1} { + t.Run(fmt.Sprintf("removing%v/kept%d", removing, kept), func(t *testing.T) { + world, output := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + for _, template := range []uint32{99228, 152030, 152030} { + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + inventory := player.inventory + contents := slices.Clone(inventory.Items[2:]) + contents[0].Slot, contents[1].Slot = 0, 1 + inventory.Items = slices.Clone(inventory.Items[:2]) + inventory.Containers = map[uint32][]ownedItem{2: contents} + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 1)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil { + t.Fatal(err) + } + if removing { + world.advanceEquipment(client.equipment.readyAt) + if err := world.handleInventory(client, itemMovePacket(1, 6, 64)[20:]); err != nil { + t.Fatal(err) + } + } + pending, handle := *client.equipment, client.backpacks[1] + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + output.packets = nil + auditCheckpointWrites(t, world) + request := characterActionPacket(1, [5]uint32{53, 107, 65536 + kept, 107, 65537 - kept})[20:] + + err = world.handleInventory(client, request) + after, readErr := readTestItemStore(world) + + if err != nil || readErr != nil || !bytes.Equal(before, after) || *client.equipment != pending || client.backpacks[1] != handle || + world.nextItem != 4 || len(output.packets) != 0 { + t.Fatal("refused backpack join changed equipment, handle, storage or sent a completion", err, readErr) + } + if writes := checkpointWrites(t, world); len(writes) != 0 { + t.Fatal("refused join wrote durable state", writes) + } + world.advanceEquipment(pending.readyAt) + if err := world.handleInventory(client, request); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1] + expected := []ownedItem{{ID: kept + 3, Type: 51005, Template: 152030, Quality: 42, Slot: kept, Count: 6}} + if !slices.Equal(player.inventory.Containers[2], expected) || !slices.Equal(cold.inventory.Containers[2], expected) || + len(cold.inventory.Items) != 2 || cold.inventory.Items[0].ID != 1 || cold.inventory.Items[0].Slot != player.inventory.Items[0].Slot || + cold.inventory.Items[1].ID != 2 || cold.inventory.Items[1].Slot != 65 || + binary.BigEndian.Uint32(output.packets[len(output.packets)-1][29:33]) != 53 { + t.Fatal("same-window retry lost charges or an owned instance", player.inventory, cold.inventory) + } + }) + } + } +} diff --git a/tools/client/test_pending_bag_stack.mjs b/tools/client/test_pending_bag_stack.mjs @@ -0,0 +1,88 @@ +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-bag-stack', 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(); + const cell = (page, slot) => game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === page && cell.identity[1] === slot && !cell.dummy); + const click = async (page, slot) => { + const source = cell(page, slot); + assert(source, 'the exact inventory source must be visible'); + await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2); + }; + await game.key('i'); + await game.click(735, 45, 'right'); + await game.wait('owned backpack opens', () => cell(107, 65536) && cell(107, 65537)); + await page.keyboard.press('Control+1'); + await click(104, 48); + await game.click(867, 206); + await game.wait('admitted weapon move', () => game.events.some(event => + event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104)); + const deadline = Date.now() + 10000; + do { + evidence.pending = await server(); + if (evidence.pending.pending) break; + await game.snapshot(); + } while (Date.now() < deadline); + assert(evidence.pending.pending); + await game.wait('local equipment animation ends', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const join = async () => { + const sequence = game.sequence; + await click(107, 65536); + await click(107, 65537); + await game.wait('actual native join request', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53)); + }; + await join(); + evidence.refused = await server(); + assert.deepEqual(evidence.refused, evidence.pending); + await game.save(output + '/refused'); + await game.wait('both refused stack icons remain usable', () => cell(107, 65536) && cell(107, 65537)); + evidence.pendingWeaponVisible = Boolean(cell(104, 48)); + assert.deepEqual(game.state.dragged, [0, 0]); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('weapon completes unchanged', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6)); + await join(); + await game.wait('normal backpack join retry acknowledged', () => game.events.some(event => event.direction === 'framereceived' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53)); + evidence.after = await server(); + assert.equal(evidence.after.pending, null); + assert.deepEqual(evidence.after.inventory.Items, [ + {...evidence.pending.inventory.Items[0], Slot: 6}, evidence.pending.inventory.Items[1]]); + assert.deepEqual(evidence.after.inventory.Containers[2], [{...evidence.pending.inventory.Containers[2][1], Count: 6}]); + await game.save(output + '/retried'); + await page.reload(); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.count]).sort((a, b) => a[0] - b[0]), + [[1, 6, 1], [2, 49, 1]]); + await game.key('i'); + await game.wait('carried backpack visible', () => cell(104, 49)); + await game.click(735, 45, 'right'); + await game.wait('retained backpack opens', () => cell(107, 65537)); + assert(!cell(107, 65536)); + assert.deepEqual(game.errors, []); + console.log('PASS: pending equipment backpack join refusal preserves usable stacks and permits six-charge retry'); +} 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(); } +}