aorecomp

Anarchy Online classic in the browser

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


commit b3be4c7cea6b10477890877b9edda6442b5bbff1
parent bc7920d0e51500d86b5afd56dfea0f1c88d9f5d3
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 08:57:42 +0000

Restore bank source after busy withdrawal refusal

Diffstat:
MTODO.md | 7+++++++
Mdocs/bank-storage.md | 36+++++++++++++++++++++++-------------
Mserver/backpacks.go | 4++--
Mserver/bank_test.go | 28+++++++++++++++++++++-------
Mserver/browser_pending_bank_test.go | 12++++++------
Mtools/client/test_pending_bank.mjs | 58+++++++++++++++++++++++++++++++++++++++++++++++++++-------
6 files changed, 110 insertions(+), 35 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3790,6 +3790,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. admitted-source duplicate remains pending. Public-handler and WASM retry, page replay and cold recovery retain the same axe, bag and contained part. See [pending backpack deposit](docs/backpacks.md#deposit-during-pending-equipment). +- [x] [P0] Restore a bank icon after withdrawal refused during pending equipment. + A short controlled WASM reproduction sends a real page-105 withdrawal after + the local equip bar ends; replaying BankIIR leaves the source marked dummy. + Native source cancellation now preserves the admitted move/deadline and bank + anchor, with same-window retry, page replay and all four cold-owned identities + verified. The related Go checks pass 31 roots/88 results, focused race checks + pass, and nine native traces are clean. Evidence: `local/pending-bank-withdrawal/`. - [x] [P0] Restore a carried icon after a bank deposit refused during pending equipment. The controlled late-completion case reproduced a hidden source after the server silently ignored its request. Validated carried deposits now diff --git a/docs/bank-storage.md b/docs/bank-storage.md @@ -45,7 +45,8 @@ this contract. Original addresses below use image base 0x10000000. bank window `0x10044c60` independently sets 102 slots and IconPositionSystem map 3. Same-grid drops in `0x10045110` only change the local visual layout; they send no server reorder request. UpdateContainer `0x100441e0` rebuilds - the grid through `0x10045320`, restoring optimistic dummy icons on rejection. + the grid through `0x10045320`. Snapshot replacement restores optimistic split + quantities; a pending withdrawal still requires source cancellation below. - Default CCR container bindings support Ctrl-left-release splitting and held-right item menus. Normal left-click withdraws from the bank. DDR's `JoinItems` call in `0x10045110` requires an owned container, excluding the @@ -127,24 +128,33 @@ is not established. A rejected optimistic bank split replaces the bank snapshot; the server retains the original opening anchor even though native BankIIR activation refreshes its local anchor. The server locality remains authoritative. -Bank transfers cannot overlap pending equipment work. A busy withdrawal uses -BankIIR to restore the bank view. A busy carried deposit validates its source -and uses the shared ordinary-slot correction to restore the picked icon; -silence previously left that source hidden. Neither sends action 146, which -would cancel the native equip bar while leaving the server's delayed operation -pending. This is a reconstruction policy, not recovered original-server packet -selection. +Bank transfers cannot overlap pending equipment work. A busy withdrawal sends +CharacterAction 146 with its page-105 source slot to restore the picked icon; +replaying BankIIR alone leaves that cell marked dummy. This also stops the native +equip bar, while retaining the admitted server move and deadline. A busy carried +deposit validates its source and uses the shared ordinary-slot correction. +These refusals use native source-refresh contracts; the original server's +packet selection is not established. `TestBankTransferRejectionPreservesPendingEquipmentTimer` checks both replies, unchanged database bytes, move/deadline and bank opening anchor. Completing the -move permits a deposit retry with exact stack and weapon ownership after cold -recovery. `TestBrowserBankDepositDuringEquipment` holds a real axe placement -after the native bar ends, attempts a native deposit, verifies source restoration -with the bank still open, then completes and retries. Page replay and cold -recovery retain both physical instances. This is a controlled late-completion +move permits deposit and withdrawal retries with exact stack and weapon +ownership after cold recovery. `TestBrowserBankDepositDuringEquipment` holds +a real axe placement after the native bar ends, attempts a native deposit, +verifies source restoration with the bank still open, then completes and +retries. Page replay and cold recovery retain all four physical instances. +This is a controlled late-completion fixture, not earned progression. Captures and packet checks are retained in `local/pending-bank/`; the broader disappearance audit remains open. +The same WASM fixture also refuses withdrawal of the deposited part while a +later axe equip awaits server completion. It waits for actual server admission, +then for the local bar to end, checks source cancellation and unchanged durable +ownership, completes the original move and retries from the same bank window. +Page replay and cold database loading account for all four physical instances. +The original hidden-icon reproduction is retained in +`local/pending-bank-withdrawal/`. + Contained deposits also validate their open carried bag, handle and member before refusing a busy transfer. CharacterAction 146 retains the full packed page-107 source slot and restores its icon. This stops the native equipment diff --git a/server/backpacks.go b/server/backpacks.go @@ -190,9 +190,9 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte) items := inventory.Items bank := sourcePage == 105 || binary.BigEndian.Uint32(body[24:28]) == 57005 if sourcePage == 105 && client.equipment != nil { - // Replay the bank without stopping the native equipment timer. + // Cancel the picked bank source while retaining the admitted server move. if server.bankAvailable_locked(client) { - return client.send(bankInventoryPacket(player)) + return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, sourceSlot})) } return nil } diff --git a/server/bank_test.go b/server/bank_test.go @@ -3,6 +3,7 @@ package main import ( "ao/server/gamedata" "bytes" + "cmp" "encoding/binary" "fmt" "reflect" @@ -634,20 +635,33 @@ func TestBankTransferRejectionPreservesPendingEquipmentTimer(t *testing.T) { } if page == 104 && !reflect.DeepEqual(conn.packets, [][]byte{ targetPacket(itemMovePacket(1, 65, 64)), targetPacket(itemMovePacket(1, 64, 65)), - }) || page == 105 && (len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x343c287f) { + }) || page == 105 && !reflect.DeepEqual(conn.packets, [][]byte{ + targetPacket(characterActionPacket(1, [5]uint32{146, 105, 0})), + }) { t.Fatalf("busy rejection did not restore its source without stopping equipment: %x", conn.packets) } + world.advanceEquipment(move.readyAt) + if err := world.handleInventory(client, request[20:]); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1] + // Compare durable contents without live append order or empty-slice differences. + retained := player.inventory + retained.Items = slices.Clone(retained.Items) + slices.SortFunc(retained.Items, func(a, b ownedItem) int { return cmp.Compare(a.ID, b.ID) }) + if len(retained.Bank) == 0 { + retained.Bank = nil + } if page == 104 { - world.advanceEquipment(move.readyAt) - if err := world.handleInventory(client, request[20:]); err != nil { - t.Fatal(err) - } - cold := newTestInventoryServer(t).characters[1] - if !reflect.DeepEqual(player.inventory, cold.inventory) || len(cold.inventory.Bank) != 2 || + if !reflect.DeepEqual(retained, cold.inventory) || len(cold.inventory.Bank) != 2 || cold.inventory.Bank[1].ID != 2 || cold.inventory.Bank[1].Slot != 1 || cold.inventory.Bank[1].Count != 3 || cold.inventory.Items[3].ID != 6 || cold.inventory.Items[3].Slot != 6 { t.Fatal("busy deposit retry lost the carried stack or admitted weapon") } + } else if !reflect.DeepEqual(retained, cold.inventory) || len(cold.inventory.Bank) != 0 || + len(cold.inventory.Items) != 6 || cold.inventory.Items[0].ID != 1 || cold.inventory.Items[0].Slot != 64 || + cold.inventory.Items[0].Count != 3 || cold.inventory.Items[5].ID != 6 || cold.inventory.Items[5].Slot != 6 { + t.Fatalf("busy withdrawal retry lost the banked stack or admitted weapon: live=%+v cold=%+v", retained, cold.inventory) } }) } diff --git a/server/browser_pending_bank_test.go b/server/browser_pending_bank_test.go @@ -18,7 +18,7 @@ import ( func TestBrowserBankDepositDuringEquipment(t *testing.T) { if os.Getenv("AO_GAME_TEST") != "1" { - t.Skip("set AO_GAME_TEST=1 for bank deposit during pending equipment") + t.Skip("set AO_GAME_TEST=1 for bank transfers during pending equipment") } _, source, _, _ := runtime.Caller(0) @@ -85,13 +85,13 @@ func TestBrowserBankDepositDuringEquipment(t *testing.T) { t.Fatal(err) } cold := newTestInventoryServer(t).characters[1] - expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 64, Count: 1}, + expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}, + {ID: 2, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}, {ID: 3, Type: 51017, Template: 99228, Quality: 1, Slot: 66, Count: 1}} - bank := []ownedItem{{ID: 2, Type: 51005, Template: 42640, Quality: 1, Count: 1}, - {ID: 4, Type: 51005, Template: 42640, Quality: 1, Slot: 1, Count: 1}} - if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.inventory.Items, expected) || + bank := []ownedItem{{ID: 4, Type: 51005, Template: 42640, Quality: 1, Slot: 1, Count: 1}} + if !slices.Equal(player.inventory.Items, []ownedItem{expected[0], expected[2], expected[1]}) || !slices.Equal(cold.inventory.Items, expected) || !slices.Equal(player.inventory.Bank, bank) || !slices.Equal(cold.inventory.Bank, bank) || len(player.inventory.Containers) != 0 || len(cold.inventory.Containers) != 0 { - t.Fatal("busy deposit retry lost or duplicated the weapon or part") + t.Fatal("busy bank transfer retry lost or duplicated the weapon or part") } } diff --git a/tools/client/test_pending_bank.mjs b/tools/client/test_pending_bank.mjs @@ -18,6 +18,15 @@ try { await page.goto(url); await game.ready(); const server = async () => (await page.request.get(url + '/test-state')).json(); + const admitted = async () => { + const deadline = Date.now() + 10000; + do { + const state = await server(); + if (state.pending) return state; + await game.snapshot(); + } while (Date.now() < deadline); + assert.fail('server did not admit the native equipment request'); + }; const carried = state => state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy); const clickCell = async cell => game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); @@ -30,8 +39,7 @@ try { cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy); await clickCell(weapon); await game.click(867, 206); - await page.waitForFunction(async () => (await (await fetch('/test-state')).json()).pending); - evidence.pending = await server(); + evidence.pending = await admitted(); assert(evidence.pending.pending); assert(evidence.pending.bank); await game.wait('local equip ends while server completion remains pending', state => @@ -96,8 +104,7 @@ try { await game.click(867, 206, 'right'); await game.wait('native weapon removal requested', () => game.events.some(event => event.sequence > removal && event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 101)); - await page.waitForFunction(async () => (await (await fetch('/test-state')).json()).pending); - evidence.containedPending = await server(); + evidence.containedPending = await admitted(); assert(evidence.containedPending.pending); await game.wait('local removal ends before server completion', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); @@ -134,16 +141,53 @@ try { assert.deepEqual(evidence.containedAfter.inventory.Bank, [ evidence.after.inventory.Bank[0], {...evidence.containedPending.inventory.Containers[3][0], Slot: 1}]); await game.save(output + '/contained-deposited'); + + // Withdraw a banked part while another native weapon move awaits completion. + await game.click(681, 45); + await game.click(867, 206); + evidence.withdrawPending = await admitted(); + await game.wait('local equip ends before bank withdrawal', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const withdraw = async () => { + const bankCell = game.state.grids.find(grid => grid.totalCells === 102).cells[0]; + await clickCell(bankCell); + }; + const withdrawal = game.sequence; + await withdraw(); + await game.wait('actual bank withdrawal reaches server', () => game.events.some(event => event.sequence > withdrawal && + event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 105)); + await game.wait('native bank withdrawal cancelled', () => game.events.some(event => event.sequence > withdrawal && + event.direction === 'framereceived' && event.opcode === '5e477770' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) === 146 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 105 && + Buffer.from(event.hex, 'hex').readUInt32BE(37) === 0)); + await game.wait('bank source restored after refused withdrawal', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 105 && cell.identity[1] === 0 && !cell.dummy))); + evidence.withdrawRefused = await server(); + assert.deepEqual(evidence.withdrawRefused, evidence.withdrawPending); + assert.deepEqual(game.state.dragged, [0, 0]); + await game.save(output + '/withdraw-refused'); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('original axe equip completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6)); + await withdraw(); + await game.wait('same-window withdrawal retry succeeds', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 48)); + evidence.withdrawAfter = await server(); + assert.equal(evidence.withdrawAfter.pending, null); + assert.deepEqual(evidence.withdrawAfter.bank, evidence.withdrawPending.bank); + assert.deepEqual(evidence.withdrawAfter.inventory.Items, [ + {...evidence.containedAfter.inventory.Items[0], Slot: 6}, evidence.containedAfter.inventory.Items[1], + {...evidence.containedAfter.inventory.Bank[0], Slot: 64}]); + assert.deepEqual(evidence.withdrawAfter.inventory.Bank, [evidence.containedAfter.inventory.Bank[1]]); + await game.save(output + '/withdraw-retried'); await page.reload(); await game.ready(); - assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]), [[1, 48, 1, 1], [3, 50, 1, 1]]); + assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]), [[1, 6, 1, 1], [2, 48, 1, 1], [3, 50, 1, 1]]); if (!game.state.camera.firstPerson) await game.key('F8'); await game.click(...await game.pick(51005, 3221357727), 'right'); await game.wait('banked part retained after page replay', state => state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 105 && cell.identity[1] === 1 && !cell.dummy))); - assert.deepEqual((await server()).inventory, evidence.containedAfter.inventory); + assert.deepEqual((await server()).inventory, evidence.withdrawAfter.inventory); assert.equal(game.errors.length, 0); - console.log('PASS: pending carried/contained bank deposits restore sources, preserve bank/moves and retry with exact page/cold recovery'); + console.log('PASS: pending bank deposits and withdrawal restore sources, preserve bank/moves and retry with exact page/cold recovery'); } finally { try { await fs.mkdir(output, {recursive: true});