aorecomp

Anarchy Online classic in the browser

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


commit bfb98cdff5a3bf018f43fbb91f258cc9a7c222d4
parent 74933ebbf38ec4e5ace8ba0cabe5a40f32cf12eb
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 22:53:05 +0000

Close optimistic backpack splits after source removal

Diffstat:
MTODO.md | 11+++++++++++
Mdocs/backpacks.md | 24++++++++++++++++++++++++
Mserver/backpacks.go | 4++--
Mserver/browser_replaced_backpack_split_test.go | 20+++++++++++++++++++-
Mserver/replaced_backpack_split_test.go | 17++++++++++++++++-
Mtools/client/test_replaced_backpack_split.mjs | 36+++++++++++++++++++++++++-----------
6 files changed, 97 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4556,6 +4556,17 @@ and server restarts. Turn every reproduced bug into a focused regression test. checks pass 44 roots/124 results, focused race checks pass 5/19, and ten native traces are clean. See [session and destination refusals](docs/backpacks.md#session-and-destination-policy-refusals) and `local/backpack-refusals/verification-summary.json`. +- [x] [P0] Correct an optimistic split after an open backpack's source becomes + empty. Reproduction: retain a three-charge native row while an earlier + controlled transfer moves that stack to another owned bag, then Ctrl-click + the stale source. Check: remove the optimistic clone, reopen the empty source + normally and withdraw both retained items from their actual bag, preserving + exact IDs, charges and loaded ammunition across page/cold recovery. Empty + contents alone reproduce the phantom on the unchanged handler. In-range + session/window closure now passes a 19.67-second native check; the existing + replacement check also passes. Both boundaries, repeated refusals and unrelated + pending equipment retain ownership/deadlines without writes or allocation. + See [empty split sources](docs/backpacks.md#optimistic-splits-after-source-removal). - [x] [P0] Correct an optimistic split after an open backpack's stack is replaced by a nonstackable item. Reproduction: retain the original three-charge native row while a controlled earlier transfer swaps its source with a retained diff --git a/docs/backpacks.md b/docs/backpacks.md @@ -369,6 +369,30 @@ Related Go coverage passes 49 roots / 339 results; focused race checks pass three roots / 18 results. The independent audit matches the exact close packet, native identities, selected endpoints and four clean stage traces. +### Optimistic splits after source removal + +An empty source has the same native failure: after a controlled earlier transfer +moves the stack into another bag, the old window's real Ctrl-split creates an +unowned row. The former missing-row branch replies with empty BackpackIIR contents, +but that alone leaves the selected source and clone. An in-range missing source +now uses the same session/window closure as a nonstackable replacement, before +the pending-equipment guard. Unknown/unowned bag validation remains in place. + +`TestBrowserEmptyBackpackSplit` shares the maintained replacement fixture/driver. +The unchanged handler fails in 20.87 seconds; the corrected check takes 19.67. +Ordinary Use reopens the empty source without ghost rows, then normal input +withdraws the retained pistol and three-charge laboratory from their actual bag. +All four IDs, selected qualities/endpoints, charges and loaded rounds survive +page replay and cold loading. Both source variants pass boundary/repeated-refusal +checks with and without an actual pending equip, without writes, allocation or +deadline changes. The replacement native check also passes in 19.84 seconds. +This is controlled ownership evidence, not earned progression or original-server +refusal policy. Captures and independent packet checks are in +`local/empty-backpack-split/`; the broader disappearance audit stays open. +Related Go checks pass 50 roots / 344 results in 63.029 seconds. +Focused race checks pass four roots / 23 results; the independent audit checks +the original empty refresh, both native recoveries and eight clean stage traces. + ## Stale withdrawal sources A known carried bag can have an empty slot behind a stale native window. The diff --git a/server/backpacks.go b/server/backpacks.go @@ -450,8 +450,8 @@ func (server *server) handleBackpackAction_locked(client *worldClient, body []by } items := player.inventory.Containers[handle.id] index := slices.IndexFunc(items, func(item ownedItem) bool { return item.Slot == position&65535 }) - if action == 52 && index >= 0 && !items[index].isStackable() { - // Contents alone cannot remove an optimistic split of a replaced source. + if action == 52 && position&65535 < 21 && (index < 0 || !items[index].isStackable()) { + // Contents alone cannot remove an optimistic split of a stale source. client.backpacks[position>>16] = backpackHandle{handle.id, false} return client.send(backpackClosePacket(client.id, handle.id)) } diff --git a/server/browser_replaced_backpack_split_test.go b/server/browser_replaced_backpack_split_test.go @@ -17,12 +17,24 @@ import ( ) func TestBrowserReplacedBackpackSplit(t *testing.T) { + testBrowserStaleBackpackSplit(t, false) +} + +func TestBrowserEmptyBackpackSplit(t *testing.T) { + testBrowserStaleBackpackSplit(t, true) +} + +func testBrowserStaleBackpackSplit(t *testing.T, empty bool) { + t.Helper() if os.Getenv("AO_GAME_TEST") != "1" { - t.Skip("set AO_GAME_TEST=1 for replaced backpack split") + t.Skip("set AO_GAME_TEST=1 for stale backpack split") } _, source, _, _ := runtime.Caller(0) root := filepath.Dir(filepath.Dir(source)) output := filepath.Join(root, "local/replaced-backpack-split", time.Now().Format("20060102-150405")) + if empty { + output = filepath.Join(root, "local/empty-backpack-split", time.Now().Format("20060102-150405")) + } world := newTestServer(t) player := world.newCharacter() player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("replaced-backpack-split"))) @@ -53,6 +65,12 @@ func TestBrowserReplacedBackpackSplit(t *testing.T) { defer world.mutex.Unlock() inventory := player.inventory inventory.Containers = map[uint32][]ownedItem{1: slices.Clone(inventory.Containers[3]), 3: slices.Clone(inventory.Containers[1])} + if empty { + stack := inventory.Containers[3][0] + stack.Slot = 1 + inventory.Containers[3] = []ownedItem{inventory.Containers[1][0], stack} + delete(inventory.Containers, 1) + } if err := world.saveInventory_locked(player, inventory); err != nil { t.Error(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/server/replaced_backpack_split_test.go b/server/replaced_backpack_split_test.go @@ -8,6 +8,15 @@ import ( ) func TestReplacedBackpackSplitClosesWithoutWriting(t *testing.T) { + testStaleBackpackSplitClosesWithoutWriting(t, false) +} + +func TestEmptyBackpackSplitClosesWithoutWriting(t *testing.T) { + testStaleBackpackSplitClosesWithoutWriting(t, true) +} + +func testStaleBackpackSplitClosesWithoutWriting(t *testing.T, empty bool) { + t.Helper() for _, slot := range []uint32{0, 20} { for _, pending := range []bool{false, true} { t.Run(fmt.Sprintf("slot%d/pending%v", slot, pending), func(t *testing.T) { @@ -20,6 +29,12 @@ func TestReplacedBackpackSplitClosesWithoutWriting(t *testing.T) { Containers: map[uint32][]ownedItem{ 1: {{ID: 4, Type: 51018, Template: 123742, Quality: 2, Slot: slot, Count: 1, Ammo: 3}}, 3: {{ID: 2, Type: 51005, Template: 25812, Quality: 2, Slot: 0, Count: 3}}}} + if empty { + pistol := inventory.Containers[1][0] + pistol.Slot = 1 + inventory.Containers[3] = append(inventory.Containers[3], pistol) + delete(inventory.Containers, 1) + } if err := world.saveInventory_locked(player, inventory); err != nil { t.Fatal(err) } @@ -55,7 +70,7 @@ func TestReplacedBackpackSplitClosesWithoutWriting(t *testing.T) { !reflect.DeepEqual(player.inventory, cold.characters[1].inventory) || !reflect.DeepEqual(client.equipment, move) || world.nextItem != 5 || cold.nextItem != 5 || client.backpacks[1] != (backpackHandle{1, false}) || !reflect.DeepEqual(output.packets, [][]byte{close, close}) { - t.Fatal("replaced-source split changed storage, allocation, handle or authoritative correction", err) + t.Fatal("stale-source split changed storage, allocation, handle or authoritative correction", err) } }) } diff --git a/tools/client/test_replaced_backpack_split.mjs b/tools/client/test_replaced_backpack_split.mjs @@ -31,15 +31,16 @@ try { assert((await page.request.post(url + '/test-move-source')).ok()); evidence.replaced = await server(); assert.equal(evidence.replaced.open, true); - assert.equal(evidence.replaced.inventory.Containers[1][0].ID, 4); - assert.equal(evidence.replaced.inventory.Containers[3][0].ID, 2); + const empty = !evidence.replaced.inventory.Containers[1]; + if (!empty) assert.equal(evidence.replaced.inventory.Containers[1][0].ID, 4); + assert(evidence.replaced.inventory.Containers[3].some(item => item.ID === 2 && item.Count === 3)); const sequence = game.sequence; await page.keyboard.down('Control'); try { await click(cell(65536)); } finally { await page.keyboard.up('Control'); } - await game.wait('real split from the replaced source', () => game.events.some(event => event.sequence > sequence && + await game.wait('real split from the stale source', () => game.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 52)); await game.save(output + '/requested'); - await game.wait('replaced-source split window closes', state => + await game.wait('stale-source split window closes', state => !state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 107))); assert(game.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '2049527c')); if (game.state.dragged[0] !== 0) { @@ -51,16 +52,29 @@ try { await game.save(output + '/refused'); // Reopen current contents and withdraw both actual items through normal input. + const reopen = game.sequence; await game.click(681, 45, 'right'); - await game.wait('actual replacement pistol opens', () => cell(65536)); - assert(!cell(65537)); - await click(cell(65536)); + if (empty) { + await game.wait('empty source bag reopens', () => game.events.some(event => event.sequence > reopen && + event.direction === 'framereceived' && event.opcode === '4e536976' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 1009)); + assert(!cell(65536) && !cell(65537)); + assert.equal((await server()).open, true); + await game.click(735, 45, 'right'); + await game.wait('both retained items open in their actual bag', () => cell(131072) && cell(131073)); + await click(cell(131072)); + } else { + await game.wait('actual replacement pistol opens', () => cell(65536)); + assert(!cell(65537)); + await click(cell(65536)); + } await game.click(789, 45); await game.wait('actual replacement pistol withdrawn', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 50 && item.count === 1)); - await game.click(735, 45, 'right'); - await game.wait('retained stack opens in its actual bag', () => cell(131072)); - await click(cell(131072)); + if (!empty) { + await game.click(735, 45, 'right'); + await game.wait('retained stack opens in its actual bag', () => cell(131072)); + } + await click(cell(empty ? 131073 : 131072)); await click(game.state.grids.find(grid => grid.totalCells === 30).cells.find(cell => cell.identity[0] === 0)); await game.wait('retained three-charge stack withdrawn', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 51 && item.count === 3)); @@ -74,7 +88,7 @@ try { [[1, 48, 1, 1], [2, 51, 2, 3], [3, 49, 1, 1], [4, 50, 2, 1]]); assert.deepEqual((await server()).inventory, evidence.recovered.inventory); assert.deepEqual(game.errors, []); - console.log('PASS: replaced-source split closes its stale window and retains four IDs, three charges and three loaded rounds through reopening, normal withdrawals and page/cold recovery'); + console.log('PASS: stale-source split closes its window and retains four IDs, three charges and three loaded rounds through reopening, normal withdrawals and page/cold recovery'); } finally { try { await fs.mkdir(output, {recursive: true});