aorecomp

Anarchy Online classic in the browser

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


commit 4c65869246e53aaee3046667fda7341fb6305c9c
parent 9df11c7e57b65b57279497ac41340a409e0f63d4
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 12:15:54 +0000

Clear stale carried sources after container deposits

Diffstat:
MTODO.md | 11+++++++++++
Mdocs/backpacks.md | 35+++++++++++++++++++++++++++++++++++
Mdocs/bank-storage.md | 6++++++
Mserver/backpacks.go | 9+++++++++
Aserver/browser_stale_container_deposit_test.go | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/stale_container_deposit_test.go | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_stale_container_deposit.mjs | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 355 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4287,6 +4287,17 @@ and server restarts. Turn every reproduced bug into a focused regression test. three loaded rounds through page and fresh-server WASM recovery. These checks pass, with no ownership writes for repeated refusals. See [stale backpack sources](docs/backpacks.md#stale-withdrawal-sources). +- [x] [P0] Clear empty carried sources after stale backpack or bank deposits. + An earlier controlled transfer leaves the old carried icon visible; a real + native deposit received no reply and left that cell hidden and marked dummy. + Cancellation146 followed by clearing112 now removes only the empty row, + without ownership writes or false transfer success. Public-handler checks + cover both destinations, first/last carried rows, repeats, invalid sources + and unchanged pending equipment. A 17-second WASM check recovers the exact + loaded pistol from its earlier destination, retries on the same page and + retains all three IDs/three rounds through page replay and cold Go loading. + This controlled checkpoint leaves the broader disappearance audit open; see + [stale carried deposits](docs/backpacks.md#stale-carried-deposit-sources). - [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 @@ -335,6 +335,41 @@ and driver syntax checks pass. The report is `local/stale-backpack/verification.json`. The broader disappearance audit stays open; no client or published-bundle change is needed for this server refusal. +## Stale carried deposit sources + +An earlier committed transfer can leave an old carried icon visible while its +ordinary source row is empty on the server. Backpack and bank deposits shared +a silent return for that case. Real native pickup/place then hid the icon and +left its cell marked dummy, even though the physical item remained owned in +another container. A current living session without pending equipment now +receives CharacterAction146 followed by CharacterAction112 for only that empty +page104 row. This reuses the native GUI correction described under +[stale carried moves](inventory.md#stale-carried-move-sources). The refusal sends +no successful transfer, changes no container session and performs no ownership +writes or item allocation. + +`TestStaleCarriedContainerDepositClearsOnlyEmptySource` uses public opening and +transfer handlers before repeating the stale deposit into a backpack or bank. +It checks both carried boundaries, ordered repeated replies, exact cold +ownership, unchanged sessions and zero checkpoint writes. Its companion keeps +invalid source rows ignored and preserves a real pending equipment move and +deadline. + +`TestBrowserStaleCarriedContainerDeposit` commits an earlier transfer of a loaded +QL2 pistol into a second bag without publishing the carried removal. Real native +pickup/place reproduces the missing reply. Correction clears the empty row; +the same page opens the second bag, withdraws that exact pistol and deposits it +into the first bag. Page replay retains usable contents, and a fresh Go database +reader retains both bags, the pistol's selected endpoints and its three rounds. +This is controlled missed-publication evidence, separate from earned progression +and the original server's unrecovered refusal policy. Captures and checks are +retained under `local/stale-container-deposit/`; the broader disappearance audit +remains open. +The native baseline fails in 22.51 seconds; the fixed check passes in 16.69. +Related Go checks pass 12 roots and 44 results both normally and under the race +detector. Vet and driver syntax checks pass. The independent packet, snapshot +and ledger report is `local/stale-container-deposit/verification.json`. + ## Verification `server/backpacks_test.go` exercises the actual world connection for opening and diff --git a/docs/bank-storage.md b/docs/bank-storage.md @@ -424,3 +424,9 @@ and driver syntax checks pass. `local/stale-bank/verification.json` independentl checks the actual request, cancellation-before-refresh, both contents snapshots, four clean native traces and exact item ledgers. The broader disappearance audit remains open. + +Empty carried sources on bank deposits share the focused correction and +first/last-row regression described under +[stale carried deposits](backpacks.md#stale-carried-deposit-sources). An available +bank session is retained, with no ownership write or item allocation. Existing +unavailable-bank and pending-equipment refusal policies remain in effect. diff --git a/server/backpacks.go b/server/backpacks.go @@ -207,6 +207,15 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte) } index := slices.IndexFunc(items, func(item ownedItem) bool { return item.Slot == sourceSlot }) if index < 0 { + // Cancel a stale carried deposit before clearing only its empty source row. + if sourcePage == 104 && client.equipment == nil { + for _, action := range []uint32{146, 112} { + if err := client.send(characterActionPacket(client.id, [5]uint32{action, 104, sourceSlot})); err != nil { + return err + } + } + return nil + } // Stale container windows hide their picked source until cancellation. if sourcePage == 105 && sourceSlot < bankCapacity { if err := client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, sourceSlot})); err != nil { diff --git a/server/browser_stale_container_deposit_test.go b/server/browser_stale_container_deposit_test.go @@ -0,0 +1,84 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserStaleCarriedContainerDeposit(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for stale carried container deposits") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/stale-container-deposit", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.playfield, player.position = 1183, [3]float32{193.79826, 5.01, 136.83983} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("stale-container-deposit"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + inventory := playerInventory{LastID: 3, Items: []ownedItem{ + {ID: 1, Type: 51017, Template: 99228, Quality: 1, Slot: 64, Count: 1}, + {ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1}, + {ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 66, Count: 1, Ammo: 3}}} + 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() + json.NewEncoder(w).Encode(player.inventory) + }) + // Commit an earlier transfer without publishing the carried source removal. + mux.HandleFunc("POST /test-stale-view", func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + defer world.updateMutex.Unlock() + world.mutex.Lock() + defer world.mutex.Unlock() + inventory := player.inventory + item := inventory.Items[2] + item.Slot = 0 + inventory.Items = slices.Clone(inventory.Items[:2]) + inventory.Containers = map[uint32][]ownedItem{2: {item}} + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + } + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_stale_container_deposit.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).characters[1].inventory + if !reflect.DeepEqual(player.inventory, cold) || world.nextItem != 3 || len(cold.Items) != 2 || len(cold.Containers) != 1 || + !slices.Equal(cold.Containers[1], []ownedItem{{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}}) { + t.Fatal("stale carried deposit/retry lost a physical instance or loaded rounds") + } +} diff --git a/server/stale_container_deposit_test.go b/server/stale_container_deposit_test.go @@ -0,0 +1,117 @@ +package main + +import ( + "bytes" + "fmt" + "maps" + "reflect" + "slices" + "testing" +) + +func TestStaleCarriedContainerDepositClearsOnlyEmptySource(t *testing.T) { + for _, destination := range []uint32{51017, 57005} { + for _, source := range []uint32{64, 93} { + t.Run(fmt.Sprintf("%d/%d", destination, source), func(t *testing.T) { + world, output := newBankWorld(t) + player, client := world.characters[1], world.clients[1] + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + inventory.Items[0].Slot, inventory.Items[4].Slot = 68, source + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + for index, slot := range []uint32{66, 67} { + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, slot, uint32(index+2))[20:]); err != nil { + t.Fatal(err) + } + } + if err := world.handleInventory(client, backpackMoveRequest(104, source, 51017, 4, 111)[20:]); err != nil { + t.Fatal(err) + } + target := uint32(3) + if destination == 57005 { + target = 1 + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + handles, bank, inventory := maps.Clone(client.backpacks), *client.bank, player.inventory + auditCheckpointWrites(t, world) + output.packets = nil + + for range 2 { + if err := world.handleInventory(client, backpackMoveRequest(104, source, destination, target, 111)[20:]); err != nil { + t.Fatal(err) + } + } + after, err := readTestItemStore(world) + cold := newTestInventoryServer(t) + + if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || + !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || + !reflect.DeepEqual(client.backpacks, handles) || *client.bank != bank || client.equipment != nil || world.nextItem != 5 || cold.nextItem != 5 { + t.Fatal("stale carried deposit changed ownership, allocation or container sessions", err) + } + var expected [][]byte + for range 2 { + for _, action := range []uint32{146, 112} { + expected = append(expected, targetPacket(characterActionPacket(1, [5]uint32{action, 104, source}))) + } + } + if !reflect.DeepEqual(output.packets, expected) { + t.Fatalf("stale carried deposit needs cancellation then only its empty row cleared: got %d replies", len(output.packets)) + } + }) + } + } +} + +func TestStaleCarriedContainerDepositIgnoresInvalidOrPendingSources(t *testing.T) { + for _, destination := range []uint32{51017, 57005} { + for _, scenario := range []string{"below carried range", "above carried range", "pending equipment"} { + t.Run(fmt.Sprintf("%d/%s", destination, scenario), func(t *testing.T) { + world, output := newBankWorld(t) + client := world.clients[1] + if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 2)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, backpackMoveRequest(104, 64, 51017, 3, 111)[20:]); err != nil { + t.Fatal(err) + } + source, target := uint32(64), uint32(3) + if destination == 57005 { + target = 1 + } + switch scenario { + case "below carried range": + source = 63 + case "above carried range": + source = 94 + case "pending equipment": + if err := world.handleInventory(client, inventoryMovePacket(1, 68, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("fixture did not begin weapon equipment", err) + } + } + var pending equipmentMove + if client.equipment != nil { + pending = *client.equipment + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + output.packets = nil + + err = world.handleInventory(client, backpackMoveRequest(104, source, destination, target, 111)[20:]) + after, readErr := readTestItemStore(world) + + if err != nil || readErr != nil || !bytes.Equal(before, after) || len(output.packets) != 0 || + (scenario == "pending equipment") != (client.equipment != nil) || client.equipment != nil && *client.equipment != pending { + t.Fatal("invalid/pending stale deposit changed storage, replies or the admitted equipment move", err, readErr) + } + }) + } + } +} diff --git a/tools/client/test_stale_container_deposit.mjs b/tools/client/test_stale_container_deposit.mjs @@ -0,0 +1,93 @@ +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: 'stale-container-deposit', 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 = (state, page, slot) => state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === page && cell.identity[1] === slot && !cell.dummy); + const click = async (cell, button = 'left') => { + assert(cell, 'native inventory cell exists'); + await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2, button); + }; + const bagGrid = state => state.grids.find(grid => grid.totalCells === 21); + const toggle = async (slot, open) => { + await click(cell(game.state, 104, slot), 'right'); + await game.wait(open ? 'bag window opens' : 'bag window closes', state => Boolean(bagGrid(state)) === open); + }; + const deposit = async () => { + const sequence = game.sequence; + await click(cell(game.state, 104, 50)); + await game.wait('carried source picked', state => state.dragged[0] === 104 && state.dragged[1] === 50); + await click(bagGrid(game.state).cells.find(cell => cell.identity[0] === 0)); + await game.wait('actual native carried-to-backpack deposit', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '47537a24' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 50 && + Buffer.from(event.hex, 'hex').readUInt32BE(37) === 51017)); + return sequence; + }; + + await game.key('KeyI'); + await toggle(48, true); + assert((await page.request.post(url + '/test-stale-view')).ok()); + evidence.transferred = await server(); + assert.deepEqual(evidence.transferred.Containers[2], [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]); + await game.save(output + '/stale'); + const sequence = await deposit(); + await game.save(output + '/requested'); + await game.wait('stale carried deposit cancelled and empty row cleared', state => !cell(state, 104, 50) && + game.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '5e477770' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) === 112)); + assert.deepEqual(game.state.dragged, [0, 0]); + evidence.refused = await server(); + assert.deepEqual(evidence.refused, evidence.transferred); + await game.save(output + '/refused'); + + // Recover the exact earlier-transferred instance and retry on the same page. + await toggle(48, false); + await toggle(49, true); + await game.wait('earlier transferred pistol visible', state => cell(state, 107, 2 << 16)); + await click(cell(game.state, 107, 2 << 16)); + await game.wait('contained pistol picked', state => state.dragged[0] === 107 && state.dragged[1] === (2 << 16)); + await click(game.state.grids.find(grid => grid.totalCells === 30).cells.find(cell => cell.identity[0] === 0)); + await game.wait('exact pistol withdrawn', state => game.local(state).inventory.some(item => item.id === 3 && item.slot === 50)); + await toggle(49, false); + await toggle(48, true); + await deposit(); + await game.wait('same-page deposit succeeds', state => cell(state, 107, 1 << 16) && !cell(state, 104, 50)); + evidence.after = await server(); + assert.deepEqual(evidence.after.Items.map(item => [item.ID, item.Slot]), [[1, 64], [2, 65]]); + assert.deepEqual(evidence.after.Containers, {1: [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]}); + await game.save(output + '/retried'); + await page.reload(); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + if (!game.state.grids.some(grid => grid.totalCells === 30)) await game.key('KeyI'); + await toggle(48, true); + await game.wait('retained loaded pistol visible after page replay', state => cell(state, 107, 1 << 16)); + assert.deepEqual(await server(), evidence.after); + assert.deepEqual(game.errors, []); + assert.equal(game.dropped, 0); + console.log('PASS: stale carried deposit clears only its empty row; same-page recovery/retry and page/cold retain the loaded pistol'); +} 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(); } +}