aorecomp

Anarchy Online classic in the browser

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


commit 1c9c7298515ac02946ec16a2dfd7f09bbf1afe3b
parent 406b12534fb5dabc8e7e8d546cff966090eadc9b
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 19:00:03 +0000

Restore worn icons after refused ordinary removals

Diffstat:
MTODO.md | 10++++++++++
Mdocs/inventory.md | 47++++++++++++++++++++++++++++++++++++++---------
Mserver/browser_pending_equipment_test.go | 17++++++++++++++---
Mserver/equipment.go | 9++++++++-
Mserver/equipment_conservation_test.go | 10++++------
Aserver/pending_worn_drag_test.go | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/client/test_pending_equipment.mjs | 53+++++++++++++++++++++++++++++++++++++++++++----------
7 files changed, 191 insertions(+), 29 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4442,6 +4442,16 @@ and server restarts. Turn every reproduced bug into a focused regression test. again, removes/deposits normally and retains all three IDs and exact armor effects through page/cold recovery. Direct transfer acceptance remains P1; see [worn deposit refusals](docs/backpacks.md#direct-worn-deposit-refusals). +- [x] [P0] Restore worn icons after refused ordinary inventory removal. + Reproduction: hold an axe equip, drag a worn vest into inventory, then try to + pick it again. The same-slot reply leaves its icon blank while ownership and + AC remain worn. Check: explicit cancellation restores a second real pickup, + preserves effects and the original move/deadline, and retains every instance + through completion/retry, page replay and cold ownership loading. + The shared worn correction now uses146. A 33-second native check proves the + second pickup, unchanged armor and pending replacements, and all three IDs + after page/cold recovery. Five wear families and failed-save retry have exact + public-handler checks; see [worn drag refusals](docs/inventory.md#worn-drag-refusals). - [x] [P0] Clear empty stale worn sources after direct container deposits. A controlled committed transfer leaves the old vest and its eight AC effects visible; a real chest-to-backpack drag previously received no correction. diff --git a/docs/inventory.md b/docs/inventory.md @@ -719,20 +719,49 @@ Accepted native captures: `local/pending-equipment/20261102-205402/`. The same fixture also removes the occupied hand while a replacement awaits its server acknowledgement. After the local action ends, a real page101/slot6 -request receives one same-slot MoveItem reply. Unlike ordinary source repair, -this worn-source reply restores the hand without transient slot exchanges. +request receives one source-scoped cancellation146. The admitted replacement, displaced identity and exact deadline remain unchanged. Completing that replacement and reversing it retain both physical -IDs through page replay and the fixture's cold database read. No production -change was needed for this path; concurrent-equipment permission in the original -server remains outside this controlled late-acknowledgement check. +IDs through page replay and the fixture's cold database read. Concurrent +equipment permission in the original server remains outside this controlled +late-acknowledgement check. -The extended run `local/pending-equipment/20261103-091503` passes in30.15s -(Go37.738s). Six native requests, the one worn-source refusal, the later swaps +The earlier run `local/pending-equipment/20261103-091503` passed in30.15s +(Go37.738s). Its six native requests, one same-slot worn-source reply, later swaps and final IDs1/2 are independently checked in `local/replacing-hand/verification.json`. All six traces have empty error lists -and no dropped events. The added case waits for native action completion before -starting another move, rather than relying on screenshot timing. +and no dropped events. That right-click case did not establish icon recovery +after a real worn drag; the source correction below now covers both inputs. + +#### Worn drag refusals + +A real chest102:21 drag into ordinary inventory while an axe equip was pending +reproduced another blank source icon. Its same-slot MoveItem reply left the +physical vest and all eight AC bonuses worn, but a second real pickup failed. +The controlled native baseline fails in24.13 seconds, with unchanged server +inventory and the original pending deadline. Raw native inventory still lists +the vest, so that list alone cannot prove its icon is usable. + +Shared worn-source correction now sends CharacterAction146 with the actual +page101/102/103 and source slot. It cancels the rejected drag without unwear, +wear-effect replay, transient slot exchanges or ownership writes. Packed bag +and ordinary carried corrections keep their existing forms. Duplicate admitted +sources remain pending through their existing identity guard. + +The expanded native fixture picks the corrected vest again, returns it to its +original wear position, and verifies all eight AC bonuses are unchanged. It +then exercises the second carried weapon refusal, retry, occupied-hand removal +refusal and later replacements. Page replay and cold ownership loading retain +both weapons and vest3/slot21. Public-handler checks cover weapon, HUD, deck, +armor and implant sources during unrelated wear/removal, explicit/automatic +ordinary destinations, repeats, exact cancellation, zero writes, unchanged +cached inverses and original completion. Artifacts and independent audits are +under `local/pending-worn-drag/`. This is a controlled checkpoint, not earned +progression or original-server scheduling evidence. +The accepted run `local/pending-equipment/20261104-105833` passes in33.39s, +including the explicit cold allocator check. All eight native captures have +no errors/drops. Related normal checks pass54 roots/612 results in135.589s; +race checks pass42 roots/290 results in159.756s, and vet/driver syntax pass. The public-handler carried/worn refusal check passes all three Go results in 7.809s; JavaScript syntax and whitespace checks pass. Refused-hand and retained inventory captures were reviewed. diff --git a/server/browser_pending_equipment_test.go b/server/browser_pending_equipment_test.go @@ -36,6 +36,15 @@ func TestBrowserSecondEquipmentMove(t *testing.T) { t.Fatal(granted, err) } } + if granted, err := world.grantItem_locked(player, 85481); err != nil || !granted { + t.Fatal(granted, err) + } + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + inventory.Items[2].Slot = 21 + 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) { @@ -63,15 +72,17 @@ func TestBrowserSecondEquipmentMove(t *testing.T) { 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 + t.Logf("Browser artifacts: %s", output) 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) { + {ID: 2, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}, + {ID: 3, Type: 51022, Template: 85481, Quality: 1, Slot: 21, Count: 1}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + world.nextItem != 3 || cold.nextItem != 3 { t.Fatal("pending move refusal/retry lost the exact equipment instances") } - t.Logf("Browser artifacts: %s", output) } diff --git a/server/equipment.go b/server/equipment.go @@ -165,7 +165,14 @@ func equipmentCorrectionPackets(owner, source uint32) [][]byte { return [][]byte{characterActionPacket(owner, [5]uint32{146, 107, source})} } if source < 64 { - return [][]byte{itemMovePacket(owner, source, source)} + page := uint32(101) + if source >= 16 { + page = 102 + } + if source >= 33 { + page = 103 + } + return [][]byte{characterActionPacket(owner, [5]uint32{146, page, source})} } // kkr.dll FUN_100614e0 skips GUI notifications for same-slot replies. // Swap ordinary entries twice to restore their icons and final placement, diff --git a/server/equipment_conservation_test.go b/server/equipment_conservation_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "encoding/binary" "reflect" "testing" ) @@ -60,12 +59,11 @@ func TestEquipmentPlacementFailurePreservesEveryItemThenRetries(t *testing.T) { !reflect.DeepEqual(items, cold.characters[1].inventory.Items) || client.equipment != nil || len(observer.packets) != 0 { t.Fatal("failed placement changed an item or published pending equipment", err) } - for _, packet := range owner.packets { - if binary.BigEndian.Uint32(packet[16:20]) != 0x47537a24 { - t.Fatalf("failed placement emitted more than inventory correction: %x", packet) - } + expected := [][]byte{targetPacket(characterActionPacket(1, [5]uint32{146, 101, 6}))} + if direction == "wear" { + expected = [][]byte{targetPacket(itemMovePacket(1, 64, 65)), targetPacket(itemMovePacket(1, 65, 64))} } - if len(owner.packets) != 1 && direction == "remove" || len(owner.packets) != 2 && direction == "wear" { + if !reflect.DeepEqual(owner.packets, expected) { t.Fatal("failed placement did not restore the native source") } diff --git a/server/pending_worn_drag_test.go b/server/pending_worn_drag_test.go @@ -0,0 +1,74 @@ +package main + +import ( + "bytes" + "fmt" + "reflect" + "slices" + "testing" +) + +func TestPendingWornRemovalCancelsOnlyItsUnrelatedSource(t *testing.T) { + for _, worn := range [][3]uint32{{101, 6, 209283}, {101, 3, 161699}, {101, 9, 36779}, {102, 21, 85481}, {103, 37, 101173}} { + for _, removing := range []bool{false, true} { + for _, destination := range []uint32{93, 111} { + t.Run(fmt.Sprintf("page%d/source%d/removing%v/destination%d", worn[0], worn[1], removing, destination), func(t *testing.T) { + world, output := newBackpackWearWorld(t, worn[2], 0) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, backpackMoveRequest(107, 65536, 50000, 1, worn[1])[20:]); err != nil || client.equipment == nil { + t.Fatal("fixture wear did not begin", err) + } + world.advanceEquipment(client.equipment.readyAt) + source, target := uint32(64), uint32(6) + if worn[1] == 6 { + if granted, err := world.grantItem_locked(player, 85481); err != nil || !granted { + t.Fatal(granted, err) + } + source, target = player.inventory.Items[len(player.inventory.Items)-1].Slot, 21 + } + if err := world.handleInventory(client, inventoryMovePacket(1, source, target)[20:]); err != nil || client.equipment == nil { + t.Fatal("unrelated equipment did not begin", err) + } + if removing { + world.advanceEquipment(client.equipment.readyAt) + if err := world.handleInventory(client, itemMovePacket(1, target, source)[20:]); err != nil || client.equipment == nil { + t.Fatal("unrelated removal did not begin", err) + } + } + pending, inventory := *client.equipment, player.inventory + inverse := slices.Clone(client.wornRemoval[worn[1]]) + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + auditCheckpointWrites(t, world) + output.packets = nil + + for range 2 { + if err := world.handleInventory(client, backpackMoveRequest(worn[0], worn[1], 50000, 1, destination)[20:]); err != nil { + t.Fatal(err) + } + } + after, err := readTestItemStore(world) + + packet := targetPacket(characterActionPacket(1, [5]uint32{146, worn[0], worn[1]})) + if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || + !reflect.DeepEqual(output.packets, [][]byte{packet, packet}) || client.equipment == nil || *client.equipment != pending || + !reflect.DeepEqual(player.inventory, inventory) || !bytes.Equal(client.wornRemoval[worn[1]], inverse) { + t.Fatal("unrelated worn refusal changed effects, ownership, writes or the admitted move", err) + } + world.advanceEquipment(pending.readyAt) + expected := inventory + expected.Items = slices.Clone(inventory.Items) + index := slices.IndexFunc(expected.Items, func(item ownedItem) bool { return item.ID == pending.itemID }) + expected.Items[index].Slot = pending.destination + cold := newTestInventoryServer(t) + if client.equipment != nil || !reflect.DeepEqual(player.inventory, expected) || + !reflect.DeepEqual(cold.characters[1].inventory, expected) || world.nextItem != inventory.LastID || cold.nextItem != inventory.LastID { + t.Fatal("source cancellation changed the original completion or cold identities") + } + }) + } + } + } +} diff --git a/tools/client/test_pending_equipment.mjs b/tools/client/test_pending_equipment.mjs @@ -37,6 +37,36 @@ try { 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)); + + // Refusing an unrelated worn drag must retain its usable icon and wear effects. + const armor = [5, 5, 1, 1, 5, 5, 1, 5]; + assert.deepEqual(game.local().effectiveArmor, armor); + await game.click(953, 53); + const worn = game.sequence; + await game.click(927, 148); + await game.wait('actual worn vest picked during pending equip', state => state.dragged[0] === 102 && state.dragged[1] === 21); + const empty = game.state.grids.find(grid => grid.totalCells === 30).cells[2]; + assert.equal(empty.identity[0], 0); + await game.click((empty.bounds[0] + empty.bounds[2]) / 2, (empty.bounds[1] + empty.bounds[3]) / 2); + await game.wait('actual worn removal refused during pending equip', () => game.events.some(event => event.sequence > worn && + event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 102) && + game.events.some(event => event.sequence > worn && event.direction === 'framereceived' && ['47537a24', '5e477770'].includes(event.opcode))); + evidence.wornRefused = await server(); + assert.deepEqual(evidence.wornRefused, evidence.pending); + assert.deepEqual(game.events.filter(event => event.sequence > worn && event.direction === 'framereceived' && + event.opcode === '5e477770').map(event => Array.from({length: 5}, (_, index) => Buffer.from(event.hex, 'hex').readUInt32BE(29 + index * 4))), + [[146, 102, 21, 0, 0]]); + assert.deepEqual(game.local().effectiveArmor, armor); + await game.save(output + '/worn-refused'); + await game.wait('local refused removal action ended', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + await game.click(927, 148); + await game.wait('corrected worn icon can actually be picked again', state => state.dragged[0] === 102 && state.dragged[1] === 21); + await game.click(927, 148); + await game.wait('corrected worn pickup returns to its original slot', state => state.dragged[0] === 0 && state.dragged[1] === 0); + assert.deepEqual(await server(), evidence.pending); + assert.deepEqual(game.local().effectiveArmor, armor); + await game.save(output + '/worn-usable'); + await game.click(867, 53); const sequence = await equip(49); evidence.refused = await server(); assert.deepEqual(evidence.refused, evidence.pending); @@ -60,14 +90,15 @@ try { 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]]); + {...evidence.pending.inventory.Items[0], Slot: 6}, evidence.pending.inventory.Items[1], evidence.pending.inventory.Items[2]]); 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); + {...evidence.pending.inventory.Items[0], Slot: 65}, {...evidence.pending.inventory.Items[1], Slot: 6}, evidence.pending.inventory.Items[2]]); + assert.equal(game.events.filter(event => event.direction === 'framesent' && event.opcode === '47537a24' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) !== 102).length, 3); await game.save(output + '/retried'); // Removing the occupied hand must not interrupt a pending replacement. @@ -81,14 +112,14 @@ try { const hand = game.sequence; await game.click(867, 206, 'right'); await game.wait('occupied hand refusal acknowledged', () => game.events.some(event => - event.sequence > hand && event.direction === 'framereceived' && event.opcode === '47537a24')); + event.sequence > hand && event.direction === 'framereceived' && event.opcode === '5e477770')); evidence.handRefused = await server(); assert.deepEqual(evidence.handRefused, evidence.replacement); assert.deepEqual(game.events.filter(event => event.sequence > hand && event.direction === 'framereceived' && - event.opcode === '47537a24').map(event => { + event.opcode === '5e477770').map(event => { const packet = Buffer.from(event.hex, 'hex'); - return [packet.readUInt32BE(29), packet.readUInt32BE(33), packet.readUInt32BE(45)]; - }), [[101, 6, 6]]); + return Array.from({length: 5}, (_, index) => packet.readUInt32BE(29 + index * 4)); + }), [[146, 101, 6, 0, 0]]); assert.deepEqual(game.state.dragged, [0, 0]); await game.save(output + '/occupied-hand-refused'); assert((await page.request.post(url + '/test-complete')).ok()); @@ -102,7 +133,8 @@ try { assert((await page.request.post(url + '/test-complete')).ok()); await game.wait('both instances remain usable', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 6)); - assert.equal(game.events.filter(event => event.direction === 'framesent' && event.opcode === '47537a24').length, 6); + assert.equal(game.events.filter(event => event.direction === 'framesent' && event.opcode === '47537a24' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) !== 102).length, 6); await game.save(output + '/occupied-hand-retained'); await page.reload(); await game.ready(); @@ -112,9 +144,10 @@ try { 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]]); + [[1, 49, 1, 1], [2, 6, 1, 1], [3, 21, 1, 1]]); + assert.deepEqual(game.local().effectiveArmor, armor); 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'); + console.log('PASS: worn drag refusal restores a real second pickup; pending replacements retain both weapons and the worn vest through page/cold recovery'); } finally { try { await fs.mkdir(output, {recursive: true});