commit f4b8d42f6250e19afc4b35bbf1b714478f032666
parent 5f83e3aaec0c1c3464dd422611536abcb6454b23
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 04:04:26 +0000
Restore corpse pickup icons while equipment is pending
Diffstat:
7 files changed, 235 insertions(+), 1 deletion(-)
diff --git a/TODO.md b/TODO.md
@@ -3864,6 +3864,14 @@ and server restarts. Turn every reproduced bug into a focused regression test.
untaken gloves expired before pickup committed. Evidence:
[earned creature upgrades](docs/earned-creature-upgrade.md) and
`local/earned-creature-upgrade/`.
+- [x] [P0] Restore a corpse source after pickup during a pending equipment move.
+ Reproduced with explicit native axe placement followed by corpse pickup: the
+ server ignores the pickup and its icon becomes dummy/hidden. Check explicit
+ cancellation and source refresh without disturbing the original equip,
+ same-window pickup retry, native page replay and exact cold ownership now
+ pass. The controlled checkpoint holds server completion past the local equip
+ animation; it does not establish original concurrent-looting permission.
+ See [corpse pickup](docs/corpse-loot.md).
- [x] Acknowledge stale corpse slots after an already committed pickup.
Reproduced with two entitled native looters and a controlled missed refresh:
the teammate takes slot2, then the first looter's stale request receives no
diff --git a/docs/corpse-loot.md b/docs/corpse-loot.md
@@ -164,6 +164,17 @@ same-window retry; page replay and cold loading retain the first looter's
31 instances and the original corpse credit. This is controlled failure-path evidence,
rather than earned-progression evidence.
+A pickup arriving during an admitted equipment move also receives
+CharacterAction146 and refreshed contents, without changing the equipment
+deadline or closing the corpse. Ignoring it leaves the native source icon
+dummy/hidden. `TestBrowserLootDuringEquipment` reproduces this using explicit
+axe placement and a real corpse pickup after the local equip animation ends,
+with server completion held at a controlled checkpoint. After refusal restores
+the icon, the original move completes and a same-window retry transfers the
+exact part once. Native page replay and cold store loading retain both instances.
+This preserves the current busy refusal policy; original-server permission for
+concurrent looting and equipping remains an evidence gap.
+
An eligible pickup of an already-taken slot also needs CharacterAction146 and
fresh contents, while retaining the usable window. The fixture withholds one
looter's refresh during a teammate's real pickup, then checks that the stale
diff --git a/server/browser_pending_loot_test.go b/server/browser_pending_loot_test.go
@@ -0,0 +1,78 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserLootDuringEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for pickup during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-loot", time.Now().Format("20060102-150405"))
+ world, _ := newLootWorld(t)
+ player, corpse := world.characters[1], world.characters[1000000]
+ player.playfield, player.position = 705, [3]float32{960, 16.5, 511}
+ player.rotation = [4]float32{0, 0, 0, 1}
+ player.stats = testCharacterStats()
+ player.rechargeUntil = time.Time{}
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-loot")))
+ corpse.playfield, corpse.position = 705, [3]float32{960, 16.5, 514}
+ corpse.corpse.expiresAt = time.Now().Add(time.Hour)
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ world.clients = make(map[uint32]*worldClient)
+ 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()
+ pending := world.clients[1] != nil && world.clients[1].equipment != nil
+ json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "corpse": corpse.corpse.items, "pending": pending})
+ })
+ // Hold the admitted move at a controlled checkpoint until the rejected pickup.
+ mux.HandleFunc("POST /test-complete", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ finish := world.clients[1].equipment.readyAt
+ world.mutex.Unlock()
+ world.advanceEquipment(finish)
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_loot.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ if err := command.Run(); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+
+ expected := []ownedItem{{ID: 18, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1},
+ {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, []ownedItem{expected[1], expected[0]}) ||
+ len(cold.characters[1000000].corpse.items) != 0 {
+ t.Fatal("pending equipment pickup retry did not retain both exact items")
+ }
+ t.Logf("Browser artifacts: %s", output)
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -252,6 +252,10 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
return server.moveContainerItem_locked(client, body)
}
if client.equipment != nil {
+ // A separate corpse pickup still needs a reply while equipment is pending.
+ if key == 0x47537a24 && binary.BigEndian.Uint32(body[16:20]) == 107 && binary.BigEndian.Uint32(body[20:24])>>16 == 0 {
+ return server.takeLoot_locked(client, body)
+ }
if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 52 {
return server.syncStacks_locked(client)
}
diff --git a/server/loot.go b/server/loot.go
@@ -229,7 +229,7 @@ func (server *server) takeLoot_locked(client *worldClient, body []byte) error {
break
}
}
- if slot == 94 {
+ if slot == 94 || client.equipment != nil {
if err := client.send(characterActionPacket(client.id, [5]uint32{146, 107, item.Slot})); err != nil {
return err
}
diff --git a/server/loot_refusal_test.go b/server/loot_refusal_test.go
@@ -131,3 +131,54 @@ func TestLootStaleSlotCancelsPickupWithoutDuplicatingTransfer(t *testing.T) {
t.Fatal("stale pickup did not cancel the pending move and refresh its empty source")
}
}
+
+func TestLootPendingEquipmentRestoresPickupForRetry(t *testing.T) {
+ world, conn := newLootWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.stats = testCharacterStats()
+ player.rechargeUntil = time.Time{}
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("weapon move did not begin", err)
+ }
+ move := *client.equipment
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ if err := world.handleInventory(client, lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ after, err := readTestItemStore(world)
+
+ if err != nil || !bytes.Equal(before, after) || *client.equipment != move || client.lootCorpse != 1000000 ||
+ len(player.inventory.Items) != 1 || len(world.characters[1000000].corpse.items) != 1 {
+ t.Fatal("busy pickup changed ownership, the open corpse or the original equipment move", err)
+ }
+ if len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x5e477770 ||
+ binary.BigEndian.Uint32(conn.packets[0][29:33]) != 146 || binary.BigEndian.Uint32(conn.packets[0][33:37]) != 107 ||
+ binary.BigEndian.Uint32(conn.packets[0][37:41]) != 0 || binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x4e536976 {
+ t.Fatal("busy pickup did not cancel the pending native move and restore the usable source")
+ }
+ world.advanceEquipment(move.readyAt)
+ if err := world.handleInventory(client, lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ expected := []ownedItem{{ID: 18, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1},
+ {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, []ownedItem{expected[1], expected[0]}) ||
+ len(cold.characters[1000000].corpse.items) != 0 {
+ t.Fatalf("pickup retry did not retain the weapon and exact corpse item once: live=%+v cold=%+v corpse=%+v", player.inventory.Items, cold.characters[1].inventory.Items, cold.characters[1000000].corpse.items)
+ }
+}
diff --git a/tools/client/test_pending_loot.mjs b/tools/client/test_pending_loot.mjs
@@ -0,0 +1,82 @@
+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: 'pending-loot', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ await page.bringToFront();
+ await page.locator('#canvas').focus();
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const [x, y] = await game.pick(51050, 1000000);
+ await game.click(x, y, 'right');
+ await game.wait('corpse icon', state => state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 107 && !cell.dummy)));
+ await game.key('i');
+ await page.keyboard.press('Control+1');
+ const weapon = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && !cell.dummy);
+ assert(weapon);
+ const equipSequence = game.sequence;
+ await game.click((weapon.bounds[0] + weapon.bounds[2]) / 2, (weapon.bounds[1] + weapon.bounds[3]) / 2);
+ await game.click(867, 206);
+ await game.wait('actual equipment request', () => game.events.some(event => event.sequence > equipSequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104));
+ evidence.pending = await server();
+ assert.equal(evidence.pending.pending, true);
+ await game.wait('local equip animation finishes before the held server move', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ const sequence = game.sequence;
+ await game.click(30, 45);
+ await game.wait('actual pickup during pending equipment', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 107));
+ evidence.refused = await server();
+ await game.save(output + '/pending');
+ assert.deepEqual(evidence.refused, evidence.pending);
+ await game.wait('pending pickup explicitly cancelled', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framereceived' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 146));
+ await game.wait('corpse source icon restored', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 107 && cell.identity[1] === 0 && !cell.dummy)));
+ assert.deepEqual(game.state.dragged, [0, 0]);
+ await game.save(output + '/refused');
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('original equipment completes', state => game.local(state).inventory.some(item => item.slot === 6));
+ await game.click(30, 45);
+ await game.wait('same-window pickup retry succeeds', state => game.local(state).inventory.some(item => item.id === 17));
+ evidence.after = await server();
+ assert.equal(evidence.after.corpse.length, 0);
+ assert.equal(evidence.after.pending, false);
+ assert.deepEqual(evidence.after.inventory.Items, [
+ {...evidence.pending.inventory.Items[0], Slot: 6}, {...evidence.pending.corpse[0], Slot: 64}]);
+ const pickups = game.events.filter(event => event.sequence > sequence && event.direction === 'framesent' &&
+ event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 107);
+ assert.equal(pickups.length, 2);
+ await game.save(output + '/picked');
+ await page.reload();
+ await game.ready();
+ 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.wait('retained part visible after page replay', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]).sort((a, b) => a[0] - b[0]),
+ [[17, 48, 1, 1], [18, 6, 1, 1]]);
+ assert.equal(game.errors.length, 0);
+ console.log('PASS: pending equipment refuses pickup explicitly, retains its move and permits the same-window retry');
+} 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(); }
+}