aorecomp

Anarchy Online classic in the browser

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


docs/research-notes/team-loot-research/server-audit.md (15826B)


Team loot: current server and integration audit

Independent read-only audit. No production edits, REA sessions, browsers, game clients or servers were started. Current Go/SQLite source is authoritative; some older loot documentation predates the world-database work.

Established contract versus policy

The shipped14.9.1 files under server/assets/anarchy-assets-14.9.1/cd_image/text/ establish:

Rule Exact source Confidence
The leader may change team loot order help/Team Commands.txt:3 and help/TeamHelp.txt:3 Direct shipped help
All allows anyone in the team and is the default help/Team Commands.txt:7 Direct shipped help
Leader allows only the leader to loot monster remains help/Team Commands.txt:6 Direct shipped help
Alpha is alphabetical and repeats help/Team Commands.txt:8, help/TeamHelp.txt:8 Direct shipped help
Rights go to the player or team inflicting the majority of damage tips/OnSelectRemains.txt:3 Direct shipped help

SHA-256 values, respectively: 0680f4282ae7c16f57c1b05387a5d652c9fb8acf7e2ffe6496c00a601f1ececa, e8d8eed01c4b0c7981c157956242fa5c5f6ad951a71a61b81fd504ecbacf228d, dab6691c2c11ee5bf85273d761894ee649363731108a578db051ba564094d88d.

These do not settle strict majority versus greatest-group plurality, tied groups, credit bucketing when membership changes during combat, post-kill joiners, mode changes affecting existing remains, leader-transfer effects on old remains, alphabetical case/collation, empty-corpse turns, disconnected or cross-zone assignees, or the event that advances Alpha. Native wire evidence must supply mode numbers and the /team loot request/result shape; do not infer those integers from English order names.

The existing documented solo policies are greatest applied-damage total, overkill capped at remaining HP, first-to-reach tie retention and no reset when attacks stop. Those policies can be preserved for solo participants, but do not become original server proof merely by extending them to teams.

Current ownership and authorization

server/combat.go::prepareDamage records damageContributors[playerID] and leadingContributor. It runs after target HP has been reduced; all callers cap damage to remaining HP. On a supported NPC death it creates npcCorpse, assigns the individual leading contributor to looter, clears contribution totals and sets expiry from the creature profile. Normal hits, direct nano damage and Fling all use this preparation. Respawn constructs a fresh character/identity in server/respawn.go, naturally clearing contributions and corpse ownership.

server/loot.go::canLoot_locked currently requires that exact individual looter, corpse existence/death, known NPC interest, matching playfield, unexpired deadline and five-metre predicted-position range. handleLootUse also validates the current world connection, ready/loading/life state, native owner fields and monotonically increasing use sequence. handleInventory applies corresponding owner/session/life checks before takeLoot_locked. Crucially, pickup calls canLoot_locked again; an old open window is not an authorization token.

Page107 pickup requests contain a corpse slot, not a corpse identity. The server's worldClient.lootCorpse binds that request to the single open corpse. Switching corpses closes the previous registration before opening the next. Reclaim is a distinct page106 route, and backpack page107 handles have nonzero high words; preserve these distinctions when adding team access.

corpsePacket currently writes a zero team ID, hardcoded loot mode3 and looter identity50000/player. That matches the existing individual path only. The tail after original-actor identity/cloth/texture fields contains one team ID DWORD, a mode DWORD, looter identity and reward count. A team identity pair57001/teamID must not be inserted there without the native reader proving that shape. The native use predicate described in docs/corpse-loot.md does not enforce looter authorization; server checks remain essential even if the client permits a click or displays outdated entitlement text.

Current durability and transaction boundaries

Corpses are now durable. server/world_store.go stores looter, credits, expiry, present/dead state, respawn deadline, leading contributor and contribution rows. server/item_database.go stores corpse item locations and container children. loadNPCs runs before users/teams are loaded, so historical team IDs in NPC state should be retained as scalar references and resolved only for live authorization after startup completes.

Routine NPC checkpoints are staggered20..40seconds, then20seconds, and skipped for unobserved zones. writeNPCs_locked writes significant corpse-state changes immediately when included in an inventory transaction; it deliberately avoids per-movement or per-tick churn. Do not turn group damage tracking into a write on every swing. Current NPC regeneration does restore HP (server/npc_regeneration.go), while contributions remain accumulated. Older documentation saying NPCs never heal is also stale.

Pickup and cash collection already use a single SQLite transaction through saveInventory_locked -> itemStore_locked -> persistItems_locked. Pickup temporarily removes the corpse item, builds the owner's candidate inventory, persists both locations and restores the old corpse slice on save failure. The item/location cache changes only after commit. Cash collection similarly temporarily zeros corpse cash and restores it on failure. Preserve filled-bag children, global instance IDs and count/ammunition metadata through these paths.

Fling has a stricter immediate outcome transaction: server/fling_shot.go copies the target and contribution map, calls prepareDamage on that detached result, then saveSpecialAttack_locked commits the cooldown, target HP, contributions and corpse/respawn state together. Only after success does it install the live candidate and publish packets. Any winning-team assignment or Alpha advance arising from a Fling death must participate in that same transaction; an out-of-band team cursor write would leave the sequence advanced after an otherwise rolled-back hit.

Normal/nano damage currently mutates live HP and publishes death without a dedicated immediate outcome save. If creating a team corpse also advances durable Alpha state, prepare that death as a candidate and commit corpse assignment and cursor together before publishing. Keep routine simulation damage/checkpoints separate from this significant transition; do not force a complete world flush on every attack. Shared target-state persistence with the existing special-outcome path is a justified narrow reuse, whereas a new general event/transaction framework is unnecessary.

Small coherent model

Keep live-team configuration distinct from the corpse's awarded rights:

Store corpse team ID, not *playerTeam: saveTeam_locked replaces team pointers after every roster/leader mutation. An old pointer would silently retain departed members and stale leadership. Do not cascade historical corpse or contribution rights away when the live team row is deleted. Team IDs are AUTOINCREMENT and not reused; that prevents a newly formed team inheriting an old team's corpse or contributions.

For aggregation, choose and explicitly document one membership-time policy:

  1. Hit-time beneficiary: each applied hit belongs to the attacker's team at that hit (or the solo actor). Team damage totals naturally compete against other team/solo totals. Leaving never retroactively moves credited damage; current membership still controls whether the resulting team award may be used. This requires persistently distinguishing the beneficiary namespace.
  2. Death-time rebucketing: retain individual totals and group them by current teams at death. This is smaller but transfers earlier solo damage into a just-joined team and takes earlier team damage away when someone leaves.

Neither is established by the help. Hit-time credit is the more explicit stable accounting choice; do not present it as recovered behavior. A first-to-reach tie rule needs a retained leading-beneficiary identity during updates, rather than choosing a random Go map entry at death. Applying one corpse's Alpha turn must happen once after choosing the winning aggregate, including a last hit by an unrelated smaller contributor.

Per-corpse rights and bounded policy choices

The following is a coherent candidate, with unresolved parts labeled:

Alphabetical collation, starting point, cursor reset on mode change, new names, member insertion/removal, empty corpses and unavailable assignees need explicit tests and policy text. A monotonic index over the current sorted roster is minimal but roster changes can repeat/skip names. A last-assigned-name cursor can continue naturally after removal but requires a stated collation/rename rule. Neither is historical proof. Avoid speculative availability skipping or automatic reassignment without evidence.

If a team dissolves, current-membership authorization means its old team corpse can become unlootable until expiry. No public unlock is implemented. Falling back to the old solo looter or treating missing teams as public would violate outsider exclusion. Explicitly document/test stranded rights rather than adding a hidden unlock policy. Membership retention across disconnect remains the existing provisional team policy; ordinary offline status must not itself be confused with voluntary departure.

Live windows, credits and atomic team changes

All affected handlers already serialize through updateMutex -> mutex: handleTeamAction, handleLootUse, handleInventory, combat and expiry. Reuse that order. After a successful leave/kick/leader change, scan the small set of connected open loot handles; close and clear any handle whose current rights no longer pass. Queue these closes after the membership commit and before accepting a subsequent slot-only pickup. A failed team save must neither change rights nor close windows. Rechecking Use/pickup remains the security boundary even if a close cannot be delivered.

All mode permits multiple legitimate windows. Current takeLoot_locked sends only the taker's transfer ACK, which was enough for solo rights. After commit, refresh other clients with that same corpse open using its authoritative lootInventoryPacket(..., false); the existing full-inventory correction uses that non-opening update. Preserve the taker's native transfer ACK ordering. Test simultaneous eligible takes, stale slot replay after another member takes an item, partial loot and close/reopen; do not trust a displayed stale icon.

Cash is collected by native successful corpse Use, including window close. The first authorized Use currently receives the whole normalized amount; other observers receive corpse Cash0 before later Use. The accepted owner is excluded from that zero update because its deferred native Use must consume the old amount itself. Sending an immediate absolute owner balance can double the displayed gain. Preserve these ordering contracts while broadening rights.

Neither All nor Alpha establishes team money splitting. Keeping first eligible Use collection is an explicit unsplit-money policy, not proof of original team cash behavior. Split money would need multi-owner atomic credits and matching native receipt/accounting evidence and belongs in a separate sourced milestone.

Required verification before calling the integration complete

Documentation corrections in scope

Update docs/corpse-loot.md and docs/corpse-credits.md statements that corpses and untaken items are nonpersistent/runtime-only; SQLite now restores them. Replace the old no-NPC-healing statement with current recovery behavior while retaining the unresolved contribution-reset policy. Keep team cash splitting, public rights release, exact historical membership/tie/Alpha edge rules and loot tables open rather than implying this milestone settles them.