aorecomp

Anarchy Online classic in the browser

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


commit 54cbaad2c76103e0dca744c4b3a524ea22bfd6d7
parent 7795ded2e70250f61c491fbdf6d922c8aee5ae72
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 12:29:31 +0000

Match stack joins by reviewed selected endpoints

Diffstat:
MTODO.md | 9+++++++++
Mdocs/inventory-stacks.md | 30++++++++++++++++++++++++++++++
Aserver/browser_stack_family_test.go | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/stack_family_test.go | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/stacks.go | 7++++++-
Mserver/stacks_test.go | 10+++++++++-
Atools/client/test_stack_family.mjs | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 250 insertions(+), 2 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3782,6 +3782,15 @@ and server restarts. Turn every reproduced bug into a focused regression test. cases, native completion/retry, page replay and exact cold ownership pass; this leaves the broader audit open. See [pending equipment](docs/inventory.md#another-move-while-equipment-is-pending). +- [x] [P0] Join same-quality stacks stored against opposite reviewed anchors. + Native QL2 laboratories exposed the same low/high pair and sent action 53, + but a raw stored-template comparison refused the join and hid its source. + Compare resolved endpoints while retaining page/type/QL/ownership and count + guards. Three medical families now pass both directions, QL1/2/101/200, + ordinary/bank/backpack handler paths, repeats and cold identity checks. A short + WASM check joins QL2/101 in opposite directions and conserves sixteen charges + through page/cold recovery. Different families and unreviewed pairs stay + incompatible; see [reviewed stack anchors](docs/inventory-stacks.md#reviewed-family-anchors). - [x] [P0] Restore a carried stack source after unsigned-short overflow refusal. A controlled native 1 + 65535 join sent action 53 and left the removed source hidden with an empty cursor. Explicit GUI correction now preserves both diff --git a/docs/inventory-stacks.md b/docs/inventory-stacks.md @@ -109,6 +109,36 @@ removed slot empty. The wire cannot distinguish every replay after subsequent slot reuse or a later merge; it has no previous-count or operation token. Every accepted operation still conserves the total quantity. +### Reviewed family anchors + +Same-QL stacks identified by opposite endpoints of one reviewed family now join +through the shared stack handler. Compatibility follows the native selected +low/high template pair and quality, rather than equality of stored anchors. +The kept physical instance retains its own stored anchor, slot and selected QL; +only its count changes, and the removed physical instance is retired atomically. +Different endpoint pairs, qualities, types and pages remain incompatible. + +The baseline native reproduction used QL2 laboratories stored as 25812 and +25811. Both native entries had endpoints 25812/25811, so ordinary input sent +action 53, but the server's raw-ID comparison silently refused it and left the +removed source hidden. A second QL101 case reverses the kept anchor. Controlled +three- and five-charge fixtures verify sixteen conserved charges across both +joins, exact page replay and cold ownership. These are selected-quality +contracts, not historical acquisition evidence. + +Public-handler checks cover all three reviewed medical families at QL1/2/101/200, +both kept anchors, ordinary/bank/packed-backpack pages and repeated requests. +Bank cases exercise the shared server handler; the original bank UI does not +produce a same-bank join gesture. Original DDR evidence and its limits remain +in [bank gestures](bank-storage.md#original-evidence). Baseline failures, +native captures and source checks are retained under `local/stack-family/`. + +Related Go checks pass 20 roots and 181 results; the expanded negative checks +pass another root and 18 results. Focused race checks pass three roots and 94 +results in 147.079 seconds. Vet and Node syntax checks pass. The native run +completes in 17.68 seconds with five clean, complete traces. Independent request, +acknowledgement and identity checks are in `local/stack-family/verification.json`. + The original client does not roll back a rejected optimistic split. A plain FullCharacter overlays only non-null rows and reapplies equipment, so it cannot remove a provisional clone safely. That behavior is supported by diff --git a/server/browser_stack_family_test.go b/server/browser_stack_family_test.go @@ -0,0 +1,65 @@ +package main + +import ( + "context" + "crypto/sha256" + "fmt" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserStackJoinReviewedAnchors(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for reviewed stack anchors") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/stack-family", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("stack-family"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, item := range []struct { + template, quality uint32 + count uint16 + }{{25812, 2, 3}, {25811, 2, 5}, {25812, 101, 3}, {25811, 101, 5}} { + if granted, err := world.grantItem_locked(player, item.template); err != nil || !granted { + t.Fatal(granted, err) + } + player.inventory.Items[len(player.inventory.Items)-1].Quality = item.quality + player.inventory.Items[len(player.inventory.Items)-1].Count = item.count + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + host := httptest.NewServer(world.httpHandler()) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_stack_family.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) + expected := []ownedItem{{ID: 2, Type: 51005, Template: 25811, Quality: 2, Slot: 65, Count: 8}, + {ID: 3, Type: 51005, Template: 25812, Quality: 101, Slot: 66, Count: 8}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + world.nextItem != 4 || cold.nextItem != 4 { + t.Fatal("reviewed-anchor join lost quantities, identity or placement") + } +} diff --git a/server/stack_family_test.go b/server/stack_family_test.go @@ -0,0 +1,79 @@ +package main + +import ( + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestStackJoinUsesReviewedSelectedEndpoints(t *testing.T) { + for _, family := range [][2]uint32{{25812, 25811}, {85366, 85367}, {25820, 25821}} { + for _, quality := range []uint32{1, 2, 101, 200} { + for _, location := range []string{"carried", "bank", "backpack"} { + for _, kept := range []int{0, 1} { + t.Run(fmt.Sprintf("%d/QL%d/%s/keep%d", family[0], quality, location, kept), func(t *testing.T) { + world, conn := newStackWorld(t) + player, client := world.characters[1], world.clients[1] + player.inventory.Items[0].Template, player.inventory.Items[1].Template = family[0], family[1] + player.inventory.Items[0].Quality, player.inventory.Items[1].Quality = quality, quality + player.inventory.Items[0].Count, player.inventory.Items[1].Count = 3, 5 + items := slices.Clone(player.inventory.Items) + page, packed := uint32(104), uint32(0) + switch location { + case "bank": + page = 105 + items[0].Slot, items[1].Slot = 0, 1 + player.inventory.Items, player.inventory.Bank = nil, items + client.bank = &bankSession{player.playfield, player.position} + case "backpack": + if granted, err := world.grantItem_locked(player, 99228); err != nil || !granted { + t.Fatal(granted, err) + } + page, packed = 107, 1<<16 + items[0].Slot, items[1].Slot = 0, 1 + player.inventory.Items = player.inventory.Items[2:] + player.inventory.Containers = map[uint32][]ownedItem{3: items} + client.backpacks = map[uint32]backpackHandle{1: {3, true}} + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + removed := 1 - kept + request := characterActionPacket(1, [5]uint32{53, page, packed | items[kept].Slot, page, packed | items[removed].Slot})[20:] + expected := items[kept] + expected.Count = 8 + conn.packets = nil + + for range 2 { + if err := world.handleInventory(client, request); err != nil { + t.Fatal(err) + } + } + cold := newTestInventoryServer(t) + + for _, current := range []*server{world, cold} { + actual := current.characters[1].inventory.Items + switch location { + case "bank": + actual = current.characters[1].inventory.Bank + case "backpack": + actual = current.characters[1].inventory.Containers[3] + } + if !slices.Equal(actual, []ownedItem{expected}) || current.nextItem != world.nextItem { + t.Fatal("reviewed-anchor join lost selected quantities or identity", actual) + } + if _, exists := current.items[items[removed].ID]; exists { + t.Fatal("joined source retained a duplicate physical instance") + } + } + if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x5e477770 || + binary.BigEndian.Uint32(conn.packets[0][29:33]) != 53 { + t.Fatal("reviewed-anchor join lost its single native acknowledgement") + } + }) + } + } + } + } +} diff --git a/server/stacks.go b/server/stacks.go @@ -67,7 +67,12 @@ func (server *server) changeStack_locked(client *worldClient, index int, body [] } other := slices.IndexFunc(items, func(item ownedItem) bool { return item.Slot == otherSlot }) if binary.BigEndian.Uint32(body[28:32]) != binary.BigEndian.Uint32(body[20:24]) || other < 0 || other == index || items[other].Type != items[index].Type || - items[other].Template != items[index].Template || items[other].Quality != items[index].Quality { + items[other].Quality != items[index].Quality { + return nil + } + low, high := items[index].templateIDs() + otherLow, otherHigh := items[other].templateIDs() + if low != otherLow || high != otherHigh { return nil } count := uint32(items[index].Count) + uint32(items[other].Count) diff --git a/server/stacks_test.go b/server/stacks_test.go @@ -125,7 +125,7 @@ func TestStackNativeWireDoesNotTranslateRetainedCountAsASlot(t *testing.T) { } func TestStackRejectsInvalidQuantitiesAndOwnership(t *testing.T) { - for _, scenario := range []string{"zero", "same count", "too many", "negative", "empty", "same slot", "other quality", "other item", "foreign owner", "foreign source page", "foreign destination page", "loading", "dead", "stale session", "pending equipment"} { + for _, scenario := range []string{"zero", "same count", "too many", "negative", "empty", "same slot", "other quality", "other item", "other medical family", "unreviewed selected quality", "foreign owner", "foreign source page", "foreign destination page", "loading", "dead", "stale session", "pending equipment"} { t.Run(scenario, func(t *testing.T) { world, _ := newStackWorld(t) player, client := world.characters[1], world.clients[1] @@ -149,6 +149,14 @@ func TestStackRejectsInvalidQuantitiesAndOwnership(t *testing.T) { case "other item": request = stackActionPacket(1, 53, 64, 65)[20:] player.inventory.Items[1] = ownedItem{ID: 2, Type: 51018, Template: 121567, Quality: 1, Slot: 65, Count: 1} + case "other medical family": + request = stackActionPacket(1, 53, 64, 65)[20:] + player.inventory.Items[0].Template, player.inventory.Items[1].Template = 25812, 85367 + player.inventory.Items[0].Quality, player.inventory.Items[1].Quality = 2, 2 + case "unreviewed selected quality": + request = stackActionPacket(1, 53, 64, 65)[20:] + player.inventory.Items[0].Template, player.inventory.Items[1].Template = 25812, 25811 + player.inventory.Items[0].Quality, player.inventory.Items[1].Quality = 201, 201 case "foreign owner": request = stackActionPacket(2, 52, 64, 1)[20:] case "foreign source page": diff --git a/tools/client/test_stack_family.mjs b/tools/client/test_stack_family.mjs @@ -0,0 +1,52 @@ +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; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'stack-family', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + await game.key('i'); + const click = async slot => { + const source = game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy); + assert(source, 'the exact selected-quality source must be usable'); + await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2); + }; + + // Opposite stored anchors describe the same selected native contract. + for (const [removed, kept, quality] of [[48, 49, 2], [51, 50, 101]]) { + const sequence = game.sequence; + await click(removed); + await click(kept); + await game.wait('native selected-family join request', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53)); + await game.save(output + '/requested-' + quality); + await game.wait('eight charges retained in the kept source', state => game.local(state).inventory.some(item => + item.slot === kept && item.quality === quality && item.count === 8) && + !game.local(state).inventory.some(item => item.slot === removed)); + assert.deepEqual(game.state.dragged, [0, 0]); + await game.save(output + '/joined-' + quality); + } + await page.reload(); + await game.ready(); + assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count, ...item.templates]).sort((a, b) => a[0] - b[0]), + [[2, 49, 2, 8, 25812, 25811], [3, 50, 101, 8, 25812, 25811]]); + assert.deepEqual(game.errors, []); + console.log('PASS: native reviewed-anchor joins conserve sixteen charges and exact page/cold identities'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}