aorecomp

Anarchy Online classic in the browser

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


docs/corpse-credits.md (8479B)


Corpse credits

Cash is native stat 61. The server persists a player's balance in the same world database transaction as owned items and supplies it in FullCharacter on login. New characters start at zero. Creature cash amounts remain unconfigured; controlled fixtures supply known amounts for this milestone.

Native collection

The selected 14.9.1 kkr.dll SHA256 is a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0. Addresses below use its original 0x10000000 base; maintained generated C uses 0x36000000. The corpse constructor 1008bf80 initializes Cash 61 to zero and marks it for replication. CorpseFullUpdate carries a supplied amount in its SimpleItem stat list.

There is no separate collection request in this path. Successful corpse Use 3 calls 1008c510, after base Chest Use toggles the loot window. It reads the corpse's cash, adds it to the local character, prints the native receipt and zeros the corpse's cash. Opening, closing and reopening therefore cannot collect the same local amount twice. Zero cash produces no receipt. The shipped cd_image/text/help/combat.txt associates the credit bonus with looting the corpse, consistent with this path.

The request is GenericCmd 0x52526858, outer identity 50000/playerID, body {0, sequence, 3, 1, 50000, playerID, 51050, corpseID}. Success echoes state 1; failure state 2 does not invoke Use. Success reaches 10087a70 -> 1004ccc0 -> 1004d780, schedules category 4 completion, and later executes through 1004d880 -> 1004c9f0 to the corpse's Use virtual method. An absolute owner Cash update immediately after ACK can precede this deferred addition and cause a second displayed gain. Packet order alone does not establish callback completion.

The server saves the resulting balance before success and clears the authoritative corpse amount only after the save succeeds. It relies on the accepted native Use to update the owner's balance and receipt. The Cash setter emits the native stat-change event that refreshes the HUD. No separate server receipt or immediate owner balance correction is sent. Reconnect and restart initialize the durable authoritative balance again.

Other ready observers who know the corpse receive StatIIR 0x2b333d6e, outer identity 51050/corpseID, body {61,0}. Its noncharacter branch 100b2e60 resolves the visual dynel, adjusts to the underlying item and calls its stat setter. The owner is excluded: clearing its amount before deferred Use would suppress the native addition. Later interest snapshots publish zero cash.

Amount and balance boundaries

1008c510 treats signed corpse amounts outside 0..100000 as 100. This includes negative bit patterns and positive values above 100000. The server mirrors that conversion. No source establishes a historical creature cash-drop formula or proves that such invalid amounts occurred in ordinary play.

Character setter 1006e030 maps stat 61 through the compressed switch table to 1006e198. It accepts 0..1,000,000,000 inclusive and rejects negative or larger assignments. The exact table entries and original comparison bytes are retained in local/corpse-credit-smoke/cash-stat-switch.json.

The server mirrors the recovered whole-addition behavior: if adding the corpse amount would exceed 1,000,000,000, the balance stays unchanged and the corpse amount is consumed. Native Use still prints its receipt in this case, even though the setter rejected the increase. This is a verified client quirk; the original server's overflow, partial-collection and team-sharing policies remain unknown. Inventories above the native accepted balance range are rejected during loading.

Ownership and remaining scope

Use shares the existing corpse visibility, playfield, range, life, expiry and session checks and individual or aggregate team damage rights. In default All mode, the first eligible current teammate to use the corpse receives its cash. Team loot describes the accounting and policy limits. Team money splitting and public unlock rules remain unimplemented.

Credits and item ownership share one SQLite transaction, so collecting an item after cash does not erase the balance. Failed saves preserve both the previous balance and corpse cash. Repeated sequences, later close/reopen and competing users cannot repeat the award. Corpses, untaken contents and taken credits survive restart in the world database.

Ignored checkpoint writes

Corpse cash collection also requires both prepared NPC checkpoint upserts to return their saved row. Previously, a database trigger ignoring the npcs update could commit the player's new wallet while retaining the corpse's old cash after restart. A controlled 250-credit wallet became 373 while cold loading still found 123 credits on the corpse. The in-memory checkpoint cache and native success incorrectly treated that transaction as complete.

The existing prepared character/NPC writes now use RETURNING id and require that result before continuing the transaction. An ignored required write rolls back the wallet and corpse together, preserves the saved checkpoint basis, and publishes no native Use success or observer cash clearance. Statement reuse and the existing checkpoint cadence remain intact. Retrying after the fault clears commits one award; sequence replay and subsequent close/reopen cannot repeat it.

TestCorpseCreditIgnoredNPCCheckpointRollsBackAndRetries checks ignored character and NPC rows, unchanged durable items/cash, no output, unchanged checkpoint cache, retry and cold ownership of the untaken item. A controlled two-client WASM check uses the actual corpse, verifies the requesting connection's existing storage failure/reload behavior, retries normally and retains the 373/77 owner/observer wallets and untaken item across page/cold recovery. Initial funds, corpse cash and the database fault are fixtures, not earned progression. Evidence is retained under local/corpse-credit-write/.

Related Go checks pass 48 roots and 128 results. Five checkpoint/cadence roots also pass; focused race checks pass five roots and seven results in 103.416 seconds. Vet and Node syntax checks pass. The native check completes in 29.61 seconds with five clean, complete traces. Its four Use requests, three success replies, one observer clearance and exact retained balances are independently checked in local/corpse-credit-write/verification.json.

Native source streams, switch tables, shipped help, fixtures, packet logs and read-only probes are retained under local/corpse-credit-smoke/. See corpse and loot protocol for the surrounding container flow.

Verification

Go tests exercise durable collection, replay, item pickup, amount boundaries, invalid and competing requests, failed saves, closed owner output and invalid persistent balances. The full maintained server suite and three race-detector repetitions of all credit tests and the concurrent pickup and expiry tests pass. An initial broad race run exceeded Go's time limit while repeatedly parsing zone-link YAML during fixture setup. Credit tests now use a focused corpse fixture; existing loot tests and WASM checks cover the combat kill.

Two real WASM clients exercised a known 123-credit corpse after an actual combat kill. The entitled player's native Cash and HUD changed 250 -> 373; the other player's balance stayed 77 and its corpse Cash changed 123 -> 0. Close/reopen did not grant again. A later contested Use had both clients send actual requests in the same second, with the unauthorized request first; only the entitled player received the award. Item pickup preserved the cash. Reconnect and server restart restored 373 and 77 in both server state and the respective clients' native stats, alongside the taken item.

Native Use also verified 0 + 100000, 250 + 100001, 250 + 0xffffffff, 999999999 + 1 and 999999999 + 2. Results matched the boundaries above, including the overflow receipt without an increase. Selecting the corpse and pressing the shipped E=Use binding verified collection from a zero starting balance. Read-only native probes, screenshots and packet logs distinguish actual Use from clicks that missed the corpse. The retained tmp_verify.py checks 32 conditions and writes verification.json. No browser exceptions occurred; the only console errors were 15 connection refusals during intentional server restart. Test clients and the temporary server were closed afterward.