commit 6da7ccc2548f661fd0985253aa45db69a9441107
parent 4f1980ccd112eed3a771553b566cacd1b691fa7e
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 23:50:14 +0000
Reply to owned item Use during pending equipment
Diffstat:
7 files changed, 250 insertions(+), 3 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -4036,6 +4036,13 @@ and server restarts. Turn every reproduced bug into a focused regression test.
both directions during wear/removal without writes or deadline changes.
No product defect reproduced on this path; see
[backpack joins](docs/backpacks.md#stack-join-during-pending-equipment).
+- [x] Explicitly refuse owned-item Use during pending equipment. Reproduction:
+ real backpack Use after the local equip animation receives no response while
+ server completion remains pending. Completion: matching Use failure, unchanged
+ equip deadline and inventory, normal completion and same-page backpack retry.
+ A short controlled WASM check, native page replay and cold database load retain
+ both physical instances; handler checks also cover duplicate sequences and
+ busy remote-bank refusal. See [pending Use](docs/inventory.md#owned-item-use-during-pending-equipment).
- [x] [P0] Cancel and refresh stale bank withdrawals. Reproduction: a controlled
earlier transfer empties bank slot0 while its native window still shows the
source; clicking it sends a real request that receives no reply and hides the
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -509,6 +509,32 @@ inventory captures were reviewed.
AO_GAME_TEST=1 go test ./server -run '^TestBrowserSecondEquipmentMove$' -count=1 -timeout=4m -v
```
+### Owned-item Use during pending equipment
+
+An authenticated owned-item Use arriving during an admitted equipment move now
+receives the ordinary `52526858` failure reply (result2), echoing its sequence,
+mode and source. Previously the early equipment guard silently discarded it.
+This preserves the existing busy restriction while completing the native Use
+request. It neither opens a backpack nor changes the admitted move or its deadline.
+Replayed sequences remain ignored. The same refusal covers remote-bank use;
+unready, dead, foreign and malformed requests keep their existing rejection gates.
+
+`TestOwnedItemUseDuringEquipmentRepliesWithoutChangingPendingMove` checks the
+public handler, native slot65 -> 49 translation, unchanged storage and pending
+move, duplicate refusal suppression, later completion and backpack use. The
+controlled `TestBrowserOwnedItemUseDuringEquipment` holds server completion past
+the local animation, then uses real input to open the bag. The baseline
+`local/pending-owned-use/20261103-154525` sends Use but receives no reply.
+The fixed run `local/pending-owned-use/20261103-154639` passes in19.89s: matching
+failure, unchanged inventory/deadline, normal completion, same-page backpack
+retry and another successful open after page replay. Cold database loading
+retains the same axe in slot6 and backpack in slot65. This fixture is not earned
+progression evidence and does not close the broader disappearance audit.
+The related owned-item, backpack, recovery-kit and remote-bank checks pass;
+the pending-Use and session-rejection checks also pass with the race detector.
+Vet and JavaScript syntax checks pass. Packet/deadline/item conservation is
+independently checked by `local/pending-owned-use/tmp_verify.py`.
+
### Live edits during pending equipment
`TestBrowserPendingEquipmentEdit` admits a real native Kinetic Axe equip and
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -63,7 +63,7 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error
defer server.mutex.Unlock()
player := server.characters[client.id]
page := binary.BigEndian.Uint32(body[40:44])
- if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || client.equipment != nil ||
+ if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 ||
binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
binary.BigEndian.Uint32(body[16:20]) != 0 || binary.BigEndian.Uint32(body[24:28]) != 3 || binary.BigEndian.Uint32(body[28:32]) > 1 ||
binary.BigEndian.Uint32(body[32:36]) != 50000 || binary.BigEndian.Uint32(body[36:40]) != client.id ||
@@ -75,7 +75,7 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error
return nil
}
client.useSequence = sequence
- if client.trade != nil {
+ if client.trade != nil || client.equipment != nil {
reply := append([]byte(nil), body[16:]...)
binary.BigEndian.PutUint32(reply, 2)
return client.send(n3Packet(0x52526858, 50000, client.id, reply))
diff --git a/server/browser_pending_owned_use_test.go b/server/browser_pending_owned_use_test.go
@@ -0,0 +1,80 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserOwnedItemUseDuringEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for owned-item Use during pending equipment")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-owned-use", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.stats = testCharacterStats()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-owned-use")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{209283, 99228} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, 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()
+ var pending any
+ bagOpen := false
+ if client := world.clients[1]; client != nil {
+ bagOpen = client.backpacks[1].open
+ if client.equipment != nil {
+ pending = map[string]any{"itemID": client.equipment.itemID, "source": client.equipment.source,
+ "destination": client.equipment.destination, "readyAt": client.equipment.readyAt}
+ }
+ }
+ json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "pending": pending, "bagOpen": bagOpen})
+ })
+ // Hold completion beyond the native animation to exercise the busy reply.
+ 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(), 2*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_owned_use.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)
+ }
+ 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}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(newTestInventoryServer(t).characters[1].inventory.Items, expected) {
+ t.Fatal("busy Use or retry changed equipment or backpack ownership")
+ }
+}
diff --git a/server/owned_item_use_test.go b/server/owned_item_use_test.go
@@ -4,9 +4,53 @@ import (
"bytes"
"encoding/binary"
"fmt"
+ "reflect"
"testing"
)
+func TestOwnedItemUseDuringEquipmentRepliesWithoutChangingPendingMove(t *testing.T) {
+ world, owner := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if granted, err := world.grantItem_locked(player, 99228); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("weapon move did not begin", err)
+ }
+ pending := *client.equipment
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ request := backpackUseRequest(1, 65, 1)[20:]
+ owner.packets = nil
+
+ if err := world.handleOwnedItemUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleOwnedItemUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ after, err := readTestItemStore(world)
+
+ want := bytes.Clone(request[16:])
+ binary.BigEndian.PutUint32(want, 2)
+ binary.BigEndian.PutUint32(want[28:32], 49)
+ if err != nil || !bytes.Equal(before, after) || !reflect.DeepEqual(client.equipment, &pending) ||
+ len(client.backpacks) != 0 || len(owner.packets) != 1 ||
+ binary.BigEndian.Uint32(owner.packets[0][16:20]) != 0x52526858 || !bytes.Equal(owner.packets[0][29:61], want) {
+ t.Fatal("pending equipment use did not refuse once without changing ownership or the admitted move", err)
+ }
+ world.advanceEquipment(pending.readyAt)
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 2)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if client.backpacks[1] != (backpackHandle{2, true}) || player.inventory.Items[0].Slot != 6 ||
+ newTestInventoryServer(t).characters[1].inventory.Items[0].Slot != 6 {
+ t.Fatal("refused use blocked later equipment completion or normal backpack use")
+ }
+}
+
func TestUnsupportedWornItemUseRepliesWithoutChangingEquipment(t *testing.T) {
world, owner := newEquipmentWorld(t)
player, client := world.characters[1], world.clients[1]
diff --git a/server/remote_bank_test.go b/server/remote_bank_test.go
@@ -247,9 +247,17 @@ func TestRemoteBankUseRejectsInvalidSessionAndActor(t *testing.T) {
err := world.handleOwnedItemUse(client, request)
after, _ := readTestItemStore(world)
- if err != nil || !bytes.Equal(before, after) || client.bank != nil || len(conn.packets) != 0 {
+ wantPackets := 0
+ if scenario == "equipment" {
+ wantPackets = 1
+ }
+ if err != nil || !bytes.Equal(before, after) || client.bank != nil || len(conn.packets) != wantPackets {
t.Fatal("invalid remote use changed storage or acknowledged success", err)
}
+ if scenario == "equipment" && (binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x52526858 ||
+ binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2) {
+ t.Fatal("busy remote use did not receive its explicit refusal")
+ }
})
}
}
diff --git a/tools/client/test_pending_owned_use.mjs b/tools/client/test_pending_owned_use.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-owned-use', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const cell = (state, slot) => state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy);
+ const click = async (source, button = 'left') => game.click(
+ (source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2, button);
+ await page.goto(url);
+ await game.ready();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await game.snapshot();
+ await game.key('KeyI');
+ await page.keyboard.press('Control+1');
+ await click(cell(game.state, 48));
+ await game.click(867, 206);
+ await game.wait('native equipment request', () => game.events.some(event =>
+ event.direction === 'framesent' && event.opcode === '47537a24'));
+ await game.wait('local equipment animation ends', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ evidence.pending = await server();
+ assert(evidence.pending.pending);
+ const sequence = game.sequence;
+ await click(cell(game.state, 49), 'right');
+ await game.wait('actual backpack Use request while equipment is pending', () => game.events.some(event =>
+ event.sequence > sequence && event.direction === 'framesent' && event.opcode === '52526858'));
+ const request = game.events.find(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '52526858');
+ const packet = Buffer.from(request.hex, 'hex');
+ assert.deepEqual([packet.readUInt32BE(53), packet.readUInt32BE(57)], [104, 49]);
+ await game.wait('matching explicit Use refusal', () => game.events.some(event => {
+ if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '52526858') return false;
+ const reply = Buffer.from(event.hex, 'hex');
+ return reply.readUInt32BE(29) === 2 && reply.readUInt32BE(33) === packet.readUInt32BE(33);
+ }));
+ evidence.refused = await server();
+ assert.deepEqual(evidence.refused, evidence.pending);
+ assert(!game.state.grids.some(grid => grid.totalCells === 21));
+ assert(cell(game.state, 49));
+ await game.save(output + '/refused');
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('admitted weapon completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ await click(cell(game.state, 49), 'right');
+ await game.wait('same backpack opens after completion', state => state.grids.some(grid => grid.totalCells === 21));
+ evidence.after = await server();
+ assert.equal(evidence.after.pending, null);
+ assert.equal(evidence.after.bagOpen, true);
+ assert.deepEqual(evidence.after.inventory.Items, [
+ {...evidence.pending.inventory.Items[0], Slot: 6}, evidence.pending.inventory.Items[1]]);
+ await game.save(output + '/retried');
+ await page.reload();
+ await game.ready();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await game.snapshot();
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]).sort((a, b) => a[0] - b[0]), [[1, 6], [2, 49]]);
+ assert.deepEqual((await server()).inventory, evidence.after.inventory);
+ await game.key('KeyI');
+ await click(cell(game.state, 49), 'right');
+ await game.wait('retained backpack opens after page replay', state => state.grids.some(grid => grid.totalCells === 21));
+ assert.deepEqual(game.errors, []);
+ console.log('PASS: pending owned-item Use receives a refusal, preserves equipment and allows backpack retry/reload');
+} 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(); }
+}