aorecomp

Anarchy Online classic in the browser

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


commit f1d160c7a58bc840ac137021579cde470032e36c
parent ec714f5898c7395e7532148b64e651639f35d111
Author: anon <anon@example.com>
Date:   Thu, 29 Oct 2026 21:02:01 +0000

Audit partial corpse loot conservation and native reentry

Diffstat:
MTODO.md | 10++++++++++
Adocs/corpse-scene-audit.md | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/partial_loot_test.go | 201+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 294 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3180,6 +3180,16 @@ 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] Verify ordinary foreign corpse Use and credit reuse across native section + changes. An unrelated ordinary observer now picks the actual typed corpse, + sends a real Use request and receives an explicit rejection without rewards. + A successful section10 ->13 ->10 round trip preserves another corpse and its + zeroed cash; native close/reopen awards its five credits only once. A separate + item-bearing corpse remains typed/rendered after section10 ->7 ->10, but its + unpicked part expires before pickup, so item transfer after that round trip + remains open. New partial-loot regressions cover second-transfer write failures, + full-inventory retry, stale slots, selected qualities and cold expiry of only + untaken items. See [native corpse audit](docs/corpse-scene-audit.md). - [x] Commit corpse expiry before native removal. Check: unclaimed loot and filled bags retire atomically before close/delete packets; failed or ignored writes and failed COMMIT preserve state and retry. Cover both respawn/expiry orderings, diff --git a/docs/corpse-scene-audit.md b/docs/corpse-scene-audit.md @@ -0,0 +1,83 @@ +# Native corpse authorization and scene reentry + +The earned level5 Omni Enforcer5 and ordinary observer21 used the sole LAN +preview in headless Chromium with GPU OpenGL. Combat, walking, picking and +Use were ordinary native controls. There were no grants, forced drops, enemy +resets or edits to health, position, equipment, skills or wallets. + +## Foreign Use + +After an ordinary full-health Snake kill, observer21 approached to3.47metres +and the native picker identified `51050:1068772`. Its real GenericCmd Use request +carried sequence1 and that typed corpse identity. The server returned state2 +for the same actor, sequence and target. The observer received no open window, +item or credits. The corpse retained its five credits until normal expiry. +Both clients then lost the typed object at the unchanged180-second deadline. + +This proves an actual rejected request, rather than inferring rejection from a +click on terrain. The original item counts and balances were unchanged. + +## Section round trips + +An untaken QL1 part234 and one credit remained on Snake corpse1067313 during a +round trip from native section10 through section7 and back. Both clients kept +their original typed corpse objects; the returning fighter also rendered the +remains. This particular corpse did not retire like a vending machine. +The return left insufficient time for successful pickup: the click hit terrain, +and the still-unowned part and credit expired. Neither was player-owned, and no +pickup success is claimed. + +A second corpse1068777 rolled five credits and no item. Native Use collected +the cash, and closing the window left it at zero on both replicas. The fighter +walked from section10 through section13 and back while the observer stayed +nearby. Native picking reopened the same corpse before expiry. Four actual +open/close requests succeeded across the round trip; the cash was awarded only +once. Its typed object remained present throughout, without another corpse +creation packet. The fighter's native and durable balance was221; the observer +remained at zero. + +The first attempted route hit terrain and did not complete its intended round +trip. Its captures are retained separately. A later pointer-grid search failed +after another kill and closed both owned browsers in its `finally` block. The +last fight snapshot had zero displayed NPC HP but no typed corpse yet; the +captured creation packet and the grid's failure do not establish its root +cause. The harness now waits for an actual typed corpse and retains failed +picker samples instead of treating displayed zero HP as a completed kill. + +These results do not justify adding corpse replay to the shop's section fix. +Successful pickup of an item-bearing corpse after section reentry, native +full-inventory rejection/retry, open-window transitions and generic placement +on slopes remain part of the broader P0 audit. + +## Partial-loot regressions + +`server/partial_loot_test.go` adds public-handler checks for: + +- A committed first item and cash surviving failed or ignored placement writes + for a second item, with no success publication, exact cold ownership and retry. +- A selected-quality untaken item retaining its own corpse slot after another + slot is taken; delayed requests cannot take its place, and expiry destroys + only the untaken instance while retaining cash and an unrelated owned item. +- Filling the last inventory slot, safely refusing the next item, explicitly + destroying one unrelated fixture item, and retrying the same open corpse slot + without duplicating either taken instance, including after expiry/restart. + +The focused run passes all three roots/seven results; the related selection +passes101 roots/342results. The same complete selection passes under the race +detector, with no race warnings or skipped tests. Vet passes. The final race +run used a30-minute allowance; the earlier default-timeout log is retained as +incomplete evidence. + +A guarded restart preserved every global player, wallet, item, placement, +mission, encounter and learned nano exactly against the stopped snapshot. +Both tested clients then reconstructed all41 inventory instances by ID, slot, +quantity, QL and template endpoints, with full health and the correct XP/IP and +221/0credit balances. All56 previously owned instances remain in SQLite; the +only earned-wallet change is the five collected credits. No WASM page exception +was recorded. The console includes uncategorized HTTP404 responses, whose cause +has not been established by these captures. + +All owned test browser profiles are closed, with no connected test sessions. +The sole preview remains healthy on HTTPS8443 and the other default ports. +Complete private ledgers, native screenshots, reassembled packet records, +failed attempts and audit scripts are under `local/corpse-scene-reentry/`. diff --git a/server/partial_loot_test.go b/server/partial_loot_test.go @@ -0,0 +1,201 @@ +package main + +import ( + "encoding/binary" + "fmt" + "slices" + "testing" + "time" +) + +func TestPartialCorpseLootFailedSecondPickupKeepsTheFirstCommit(t *testing.T) { + for _, operation := range []string{"DELETE", "INSERT"} { + for _, failure := range []string{"FAIL", "IGNORE"} { + t.Run(operation+"/"+failure, func(t *testing.T) { + world, output, _ := newExpiringCorpseWorld(t) + world.characters[1].inventory.LastID, world.nextItem = 18, 18 + corpse := world.characters[1000000] + corpse.corpse.credits = 7 + corpse.corpse.items = []ownedItem{ + {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 0, Count: 1}, + {ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}, + } + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil { + t.Fatal(err) + } + row, raise := "OLD", "RAISE(FAIL,'second pickup')" + if operation == "INSERT" { + row = "NEW" + } + if failure == "IGNORE" { + raise = "RAISE(IGNORE)" + } + if _, err := world.db.Exec(fmt.Sprintf("CREATE TRIGGER fail_second_pickup BEFORE %s ON item_locations WHEN %s.item_id=18 BEGIN SELECT %s; END", operation, row, raise)); err != nil { + t.Fatal(err) + } + request := lootTakeRequest() + binary.BigEndian.PutUint32(request[20:24], 1) + output.packets = nil + + if err := world.handleInventory(world.clients[1], request); err == nil { + t.Fatal("second pickup reported success despite its placement failure") + } + published := len(output.packets) + failed := newTestInventoryServer(t) + if _, err := world.db.Exec("DROP TRIGGER fail_second_pickup"); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], request); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + + first := ownedItem{ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1} + second := ownedItem{ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 65, Count: 1} + if published != 0 || failed.characters[1].inventory.Credits != 7 || !slices.Equal(failed.characters[1].inventory.Items, []ownedItem{first}) || + !slices.Equal(failed.characters[1000000].corpse.items, []ownedItem{{ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}}) { + t.Fatal("failed second pickup changed the already committed item/cash or lost the untaken slot") + } + for _, current := range []*server{world, cold} { + if current.characters[1].inventory.Credits != 7 || !slices.Equal(current.characters[1].inventory.Items, []ownedItem{first, second}) || + len(current.characters[1000000].corpse.items) != 0 || current.characters[1000000].corpse.credits != 0 { + t.Fatal("retry duplicated cash, changed selected qualities or retained a second owner") + } + } + }) + } + } +} + +func TestPartialCorpseLootRetainsUnclaimedQualityUntilColdExpiry(t *testing.T) { + world, _, killed := newExpiringCorpseWorld(t) + player := world.characters[1] + player.inventory.Credits = 11 + player.inventory.Items = []ownedItem{{ID: 30, Type: 51022, Template: 99719, Quality: 1, Slot: 64, Count: 1}} + player.inventory.LastID, world.nextItem = 30, 30 + corpse := world.characters[1000000] + corpse.corpse.credits = 7 + corpse.corpse.items = []ownedItem{ + {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 0, Count: 1}, + {ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}, + } + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + + if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil { + t.Fatal(err) + } + partial := newTestInventoryServer(t) + for _, sequence := range []uint32{2, 3} { + if err := world.handleLootUse(world.clients[1], lootUseRequest(sequence)); err != nil { + t.Fatal(err) + } + } + // A delayed request for the taken slot cannot acquire the remaining slot. + if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil { + t.Fatal(err) + } + world.advanceCorpseExpiry(killed.Add(180 * time.Second)) + request := lootTakeRequest() + binary.BigEndian.PutUint32(request[20:24], 1) + if err := world.handleInventory(world.clients[1], request); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + + remaining := []ownedItem{{ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}} + if !slices.Equal(partial.characters[1000000].corpse.items, remaining) || partial.characters[1000000].corpse.credits != 0 { + t.Fatal("partial cold load changed the untaken instance, selected quality, slot or collected cash") + } + expected := []ownedItem{ + {ID: 30, Type: 51022, Template: 99719, Quality: 1, Slot: 64, Count: 1}, + {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 65, Count: 1}, + } + for _, current := range []*server{world, partial, cold} { + if current.characters[1].inventory.Credits != 18 || len(current.characters[1].inventory.Items) != 2 || + !slices.Contains(current.characters[1].inventory.Items, expected[0]) || !slices.Contains(current.characters[1].inventory.Items, expected[1]) || current.nextItem != 30 { + t.Fatal("partial pickup, replay or expiry changed committed cash, taken loot or the unrelated item", + current.characters[1].inventory.Credits, current.nextItem, current.characters[1].inventory.Items) + } + } + if world.characters[1000000] != nil || cold.characters[1000000] != nil || world.clients[1].lootCorpse != 0 { + t.Fatal("expiry retained the old corpse or its open handle") + } + var count int + if err := cold.db.QueryRow("SELECT COUNT(*) FROM items WHERE id=18").Scan(&count); err != nil || count != 0 { + t.Fatal("untaken loot survived its corpse", count, err) + } +} + +func TestPartialCorpseLootFullInventoryRetryRetainsBothInstances(t *testing.T) { + world, _, killed := newExpiringCorpseWorld(t) + player := world.characters[1] + for slot := uint32(64); slot < 93; slot++ { + player.inventory.Items = append(player.inventory.Items, + ownedItem{ID: slot + 100, Type: 51018, Template: 121567, Quality: 1, Slot: slot, Count: 1}) + } + player.inventory.LastID, world.nextItem = 192, 192 + world.characters[1000000].corpse.items = []ownedItem{ + {ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 0, Count: 1}, + {ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}, + } + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + second := lootTakeRequest() + binary.BigEndian.PutUint32(second[20:24], 1) + + if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], second); err != nil { + t.Fatal(err) + } + full := newTestInventoryServer(t) + // Destroy one specific unrelated instance, then retry the same open slot. + if err := world.handleInventory(world.clients[1], inventoryDeletePacket(1, 64)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], second); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(world.clients[1], second); err != nil { + t.Fatal(err) + } + world.advanceCorpseExpiry(killed.Add(180 * time.Second)) + cold := newTestInventoryServer(t) + + if len(full.characters[1].inventory.Items) != 30 || !slices.Equal(full.characters[1000000].corpse.items, + []ownedItem{{ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 1, Count: 1}}) { + t.Fatal("full-inventory refusal lost the remaining corpse slot or changed ownership") + } + for _, current := range []*server{world, cold} { + if len(current.characters[1].inventory.Items) != 30 || current.nextItem != 192 || + !slices.Contains(current.characters[1].inventory.Items, ownedItem{ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 93, Count: 1}) || + !slices.Contains(current.characters[1].inventory.Items, ownedItem{ID: 18, Type: 51005, Template: 42640, Quality: 2, Slot: 64, Count: 1}) { + t.Fatal("retry or empty-corpse expiry lost or duplicated one of the two taken instances") + } + for slot := uint32(65); slot < 93; slot++ { + if !slices.Contains(current.characters[1].inventory.Items, ownedItem{ID: slot + 100, Type: 51018, Template: 121567, Quality: 1, Slot: slot, Count: 1}) { + t.Fatal("retry changed an unrelated item", slot) + } + } + } + var count int + if err := cold.db.QueryRow("SELECT COUNT(*) FROM items WHERE id=164").Scan(&count); err != nil || count != 0 { + t.Fatal("explicitly destroyed instance returned", count, err) + } +}