aorecomp

Anarchy Online classic in the browser

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


commit 78bff5681aee81b6f8cf7e78b7eaaeb8918dc7ff
parent 6e9377b12d66301d6f7c80538b27b0f2123aee0d
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 06:03:44 +0000

Restore backpack deposit refused during equipment delay

Diffstat:
MTODO.md | 7+++++++
Mdocs/backpacks.md | 21+++++++++++++++++++++
Mserver/backpack_pending_test.go | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/backpacks.go | 15+++++++++++++--
Mserver/browser_pending_backpack_test.go | 8++++----
Mserver/inventory.go | 13+++++--------
Mtools/client/test_pending_backpack.mjs | 53+++++++++++++++++++++++++++++++++++++++++++++++++++--
7 files changed, 157 insertions(+), 16 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3751,6 +3751,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. open handle or durable inventory. Public-handler and WASM completion/retry, page replay and cold recovery retain all three exact instances. See [pending backpack withdrawal](docs/backpacks.md#withdrawal-during-pending-equipment). +- [x] [P0] Restore a carried icon after a backpack deposit refused during pending + equipment. The matching controlled late-completion reproduction silently hid + its source. Validated deposits now use the existing carried-item correction, + preserving the admitted move/deadline, open bag and durable ownership. An + 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). - [ ] [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/backpacks.md b/docs/backpacks.md @@ -171,6 +171,27 @@ 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. +## Deposit during pending equipment + +Carried-item deposits into an open bag also need a refusal while equipment is +pending. The early inventory gate previously ignored that destination, leaving +the carried source hidden. Backpack transfers now reach their existing source +validation before the busy check. A separate carried item receives the shared +two-swap inventory correction; a request for the admitted equipment identity +leaves its pending source alone. Neither refusal changes durable placement or +the admitted move/deadline. The native correction policy and its original client +notification contract are described in [inventory transfers](inventory.md#inventory-transfers). + +`TestBackpackPendingDepositRestoresSourceForRetry` checks the ignored admitted +source, exact correction for the separate item, unchanged database bytes and +bag handle, completion/retry and cold ownership. The existing WASM fixture now +also removes the worn axe, holds that server completion after the native bar +ends, and attempts a real deposit. The correction keeps the same bag open and +restores the carried part. Completing removal permits a same-window retry; +page replay and cold recovery retain the axe, bag and contained part. This is +controlled late-completion evidence. Captures and packet checks are retained +in `local/pending-backpack-deposit/`. + ## Verification `server/backpacks_test.go` exercises the actual world connection for opening and diff --git a/server/backpack_pending_test.go b/server/backpack_pending_test.go @@ -62,3 +62,59 @@ func TestBackpackPendingWithdrawalRestoresSourceForRetry(t *testing.T) { t.Fatal("withdrawal retry lost or duplicated an instance") } } + +func TestBackpackPendingDepositRestoresSourceForRetry(t *testing.T) { + world, conn := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + for _, template := range []uint32{99228, 42640} { + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 1)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, itemMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("weapon move was not admitted", err) + } + move := *client.equipment + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + conn.packets = nil + request := backpackMoveRequest(104, 66, 51017, 2, 111)[20:] + + // A duplicate of the admitted source must not restore its pending icon. + if err := world.handleInventory(client, backpackMoveRequest(104, 64, 51017, 2, 111)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, request); err != nil { + t.Fatal(err) + } + after, err := readTestItemStore(world) + + if err != nil || !bytes.Equal(before, after) || *client.equipment != move || + !reflect.DeepEqual(client.backpacks, map[uint32]backpackHandle{1: {2, true}}) { + t.Fatal("refused deposit changed ownership, the bag or pending move", err) + } + expectedPackets := equipmentCorrectionPackets(1, 66) + for i := range expectedPackets { + expectedPackets[i] = targetPacket(expectedPackets[i]) + } + if !reflect.DeepEqual(conn.packets, expectedPackets) { + t.Fatalf("refused deposit did not restore its separate native source: %x", conn.packets) + } + world.advanceEquipment(move.readyAt) + if err := world.handleInventory(client, request); 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}} + contents := map[uint32][]ownedItem{2: {{ID: 3, Type: 51005, Template: 42640, Quality: 1, Count: 1}}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + !reflect.DeepEqual(player.inventory.Containers, contents) || !reflect.DeepEqual(cold.characters[1].inventory.Containers, contents) { + t.Fatal("deposit retry lost or duplicated an instance") + } +} diff --git a/server/backpacks.go b/server/backpacks.go @@ -216,8 +216,19 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte) return nil } item := items[index] - if sourceBag != 0 && client.equipment != nil { - return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, binary.BigEndian.Uint32(body[20:24])})) + if client.equipment != nil { + if sourceBag != 0 { + return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, binary.BigEndian.Uint32(body[20:24])})) + } + // Keep the admitted source pending and restore a separate carried icon. + if item.ID != client.equipment.itemID { + for _, packet := range equipmentCorrectionPackets(client.id, sourceSlot) { + if err := client.send(packet); err != nil { + return err + } + } + } + return nil } if bank && itemStat(item.templateDefinition(), 8) > 0 { return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, binary.BigEndian.Uint32(body[20:24])})) diff --git a/server/browser_pending_backpack_test.go b/server/browser_pending_backpack_test.go @@ -78,11 +78,11 @@ func TestBrowserBackpackDuringEquipment(t *testing.T) { 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}, - {ID: 3, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}} + expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 66, Count: 1}, + {ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1}} if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || - len(player.inventory.Containers) != 0 || len(cold.characters[1].inventory.Containers) != 0 { + !slices.Equal(player.inventory.Containers[2], []ownedItem{{ID: 3, Type: 51005, Template: 42640, Quality: 1, Count: 1}}) || + !slices.Equal(cold.characters[1].inventory.Containers[2], player.inventory.Containers[2]) { t.Fatal("pending equipment backpack retry lost an item or retained a duplicate source") } } diff --git a/server/inventory.go b/server/inventory.go @@ -251,12 +251,13 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { if key == 0x47537a24 && (binary.BigEndian.Uint32(body[16:20]) == 105 || binary.BigEndian.Uint32(body[24:28]) == 57005) { return server.moveContainerItem_locked(client, body) } + 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) { + return server.moveContainerItem_locked(client, body) + } if client.equipment != nil { - // Separate container pickups still need a reply while equipment is pending. + // A separate corpse pickup still needs a reply while equipment is pending. if key == 0x47537a24 && binary.BigEndian.Uint32(body[16:20]) == 107 { - if binary.BigEndian.Uint32(body[20:24])>>16 != 0 { - return server.moveContainerItem_locked(client, body) - } return server.takeLoot_locked(client, body) } if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 52 { @@ -269,10 +270,6 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { 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) { - return server.moveContainerItem_locked(client, body) - } // Page identities must agree with this owner's actual logical slot. sourceType, sourceSlot := binary.BigEndian.Uint32(body[16:20]), binary.BigEndian.Uint32(body[20:24]) diff --git a/tools/client/test_pending_backpack.mjs b/tools/client/test_pending_backpack.mjs @@ -70,12 +70,61 @@ try { assert.equal(game.events.filter(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 107).length, 2); await game.save(output + '/picked'); + + // Exercise the matching deposit after a second real equipment request. + await game.wait('local equip action ended', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const removal = game.sequence; + await game.click(867, 206, 'right'); + await game.wait('actual weapon removal request', () => game.events.some(event => event.sequence > removal && + event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 101)); + evidence.depositPending = await server(); + assert(evidence.depositPending.pending); + await game.wait('local removal ends while server completion remains pending', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const deposit = async () => { + const sequence = game.sequence; + const part = game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy); + assert(part, 'carried part source is visible'); + await clickCell(part); + await game.wait('carried part picked', state => state.dragged[0] === 104 && state.dragged[1] === 48); + await game.click(30, 45); + await game.wait('actual backpack deposit', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(37) === 51017)); + return sequence; + }; + const depositSequence = await deposit(); + evidence.depositRefused = await server(); + assert.deepEqual(evidence.depositRefused, evidence.depositPending); + await game.save(output + '/deposit-pending'); + await game.wait('refused deposit source restored', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)) && + game.events.some(event => event.sequence > depositSequence && event.direction === 'framereceived' && event.opcode === '47537a24')); + assert.deepEqual(game.state.dragged, [0, 0]); + await game.save(output + '/deposit-refused'); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('original weapon removal completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 50)); + await deposit(); + await game.wait('same-window deposit retry succeeds', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 107 && cell.identity[1] === (1 << 16) && !cell.dummy))); + evidence.depositAfter = await server(); + assert.equal(evidence.depositAfter.pending, null); + assert.deepEqual(evidence.depositAfter.inventory.Items, [ + {...evidence.depositPending.inventory.Items[0], Slot: 66}, evidence.depositPending.inventory.Items[1]]); + assert.deepEqual(evidence.depositAfter.inventory.Containers, {2: [{...evidence.depositPending.inventory.Items[2], Slot: 0}]}); + await game.save(output + '/deposited'); await page.reload(); await game.ready(); assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]).sort((a, b) => a[0] - b[0]), - [[1, 6, 1, 1], [2, 49, 1, 1], [3, 48, 1, 1]]); + [[1, 50, 1, 1], [2, 49, 1, 1]]); + 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.click(735, 45, 'right'); + await game.wait('deposited part retained after page replay', state => state.grids.some(grid => grid.cells.some(cell => + cell.identity[0] === 107 && cell.identity[1] === (1 << 16) && !cell.dummy))); assert.equal(game.errors.length, 0); - console.log('PASS: pending equipment backpack refusal restores its source and permits exact same-window retry/page/cold recovery'); + console.log('PASS: pending equipment backpack withdrawal/deposit refusals restore sources and permit exact same-window retry/page/cold recovery'); } finally { try { await fs.mkdir(output, {recursive: true});