commit cfad4e81cf774fe0832f3e7837b8d3ffb2278d62
parent cc5caadd84d5025ec1866d47637cec111485696a
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 16:42:10 +0000
Verify persistent ownership under competing loot pickups
Diffstat:
3 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/TODO.md b/TODO.md
@@ -182,7 +182,7 @@ are recorded in [reclaim](docs/reclaim.md).
shows that item's identity and QL.
- [x] Take that corpse item. Check: it moves into inventory, disappears from the
corpse and remains owned after restart.
-- [ ] Resolve simultaneous pickup attempts. Check: two clients requesting the
+- [x] Resolve simultaneous pickup attempts. Check: two clients requesting the
same item produce one owner and no duplicate or lost item.
- [ ] Enforce individual loot rights. Check: the entitled player can loot and
an unrelated player cannot; expiry follows an explicit policy.
diff --git a/docs/corpse-loot.md b/docs/corpse-loot.md
@@ -139,6 +139,27 @@ survives reconnect and server restart. Killer-only access is an initial policy:
public loot rights, team loot, credits and random drops remain separate
milestones. The level-1 Leet's corpse expiry is described below.
+The two-player pickup check exercises the current killer-only policy.
+`TestLootConcurrentPlayersHaveOnePersistentOwner` releases two authenticated
+players' requests together, including a stale or forged container handle for
+the competitor. Only the entitled player's request is acknowledged; its
+single item remains owned after loading both inventories from disk. The
+existing same-session duplicate-request test covers repeated eligible claims.
+
+Two WASM clients also sent native pickup requests for corpse slot 0 in the
+same logged second. The competitor's request arrived first. A fixture supplied
+its stale open loot window, while the server retained the killer's rights.
+The killer alone acquired Monster Parts item 201, Count 1, and the corpse slot
+became empty. Both native inventories agreed with the server: the killer's
+item occupied native slot 48, while the competitor's inventory was empty.
+Both page reconnects and a server restart preserved those inventories; native
+probes after restart still found exactly one copy. The run had no page
+exceptions or adapter failures. Refused socket connections occurred during
+the intentional server restart.
+This verifies pickup serialization and ownership checks, not historical public
+or team loot eligibility. Captures and read-only native inventory probes are
+retained in `local/loot-race-smoke/`.
+
## Corpse expiry
The shipped 14.9.1 `cd_image/text/help/combat.txt` states that an unlooted
diff --git a/server/loot_test.go b/server/loot_test.go
@@ -271,3 +271,56 @@ func TestLootConcurrentRepeatPickupHasOneOwner(t *testing.T) {
t.Fatal("concurrent pickup duplicated or lost the item")
}
}
+
+func TestLootConcurrentPlayersHaveOnePersistentOwner(t *testing.T) {
+ t.Chdir(t.TempDir())
+ world, ownerConn := newLootWorld(t)
+ competitor := world.newCharacter()
+ competitor.position = world.characters[1].position
+ competitor.playfield = world.characters[1].playfield
+ if err := world.saveUser_locked(competitor); err != nil {
+ t.Fatal(err)
+ }
+ competitorConn := &combatTestConn{}
+ world.clients[2] = &worldClient{id: 2, conn: competitorConn, ready: true, npcs: map[uint32]bool{1000000: true}}
+ if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ ownerConn.packets = nil
+ // Even a stale or forged open-container handle cannot grant ownership.
+ world.clients[2].lootCorpse = 1000000
+ competingRequest := lootTakeRequest()
+ binary.BigEndian.PutUint32(competingRequest[8:12], 2)
+ binary.BigEndian.PutUint32(competingRequest[28:32], 2)
+ start := make(chan struct{})
+ errors := make(chan error, 2)
+ var workers sync.WaitGroup
+
+ workers.Go(func() {
+ <-start
+ errors <- world.handleInventory(world.clients[1], lootTakeRequest())
+ })
+ workers.Go(func() {
+ <-start
+ errors <- world.handleInventory(world.clients[2], competingRequest)
+ })
+ close(start)
+ workers.Wait()
+ close(errors)
+ restarted := newTestInventoryServer(t)
+
+ for err := range errors {
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ expected := []ownedItem{{ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
+ if !slices.Equal(world.characters[1].inventory.Items, expected) || !slices.Equal(restarted.characters[1].inventory.Items, expected) ||
+ len(competitor.inventory.Items) != 0 || len(restarted.characters[2].inventory.Items) != 0 ||
+ len(world.characters[1000000].corpse.items) != 0 {
+ t.Fatal("competing players duplicated, lost or transferred the item to the wrong owner")
+ }
+ if len(ownerConn.packets) != 1 || binary.BigEndian.Uint32(ownerConn.packets[0][16:20]) != 0x47537a24 || len(competitorConn.packets) != 0 {
+ t.Fatal("pickup did not acknowledge only the entitled player")
+ }
+}