commit 8d5a92e9b348a0ef1a71bd9fe33c7b104a52cc92
parent 8506e1a0ab535f3df24f6b68b7e4f31800806a5f
Author: anon <anon@example.com>
Date: Tue, 27 Oct 2026 21:28:33 +0000
Persist and collect bound mission objective items
Diffstat:
15 files changed, 724 insertions(+), 23 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -59,7 +59,8 @@ tool funds; ordinary funding and higher-QL recipe rules remain open. See
[Blood Plasma](docs/blood-plasma.md).
Starter mission contracts can now be browsed, accepted, abandoned and expired,
with durable journals and bound keys. A fixed private interior supports real
-entry, traversal, reconnect and return; objectives and mission rewards remain open.
+entry, traversal, reconnect and return. Its bound book can be collected and
+survives restart without respawning; objective completion and rewards remain open.
After fixing an inactive-mesh projectile that blocked repeated native casts,
a fresh Atrox Nano-Technician completed fifteen ordinary Leet kills without
a death, reaching level 2 with 1500 cumulative XP and exactly 4000 new IP.
@@ -1517,7 +1518,7 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
poses and correct owners without applying observer yaw twice. GPU WASM
verifies normal acceptance, real exterior entry, both rooms, reconnect and exit
without substituting client world packets. The fixed prototype has open native
- room links, no enemies/objective and no completion rewards. The approach volume
+ room links, no enemies and no completion rewards. The approach volume
and 2.5-unit arrival offsets remain provisional.
See [mission interiors](docs/mission-interiors.md#key-gated-live-entry-and-atomic-return).
- [ ] [P0] Verify private-instance boundaries across the complete playable loop.
@@ -1552,6 +1553,21 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
Commit completion with XP, credits and any item reward atomically through the
shared progression/inventory paths. Verify full inventory, duplicate completion,
failed writes/commit, disconnect and restart without lost or repeated rewards.
+- [x] Spawn and collect the fixed mission's bound objective instance. Check:
+ first entry atomically allocates one original Blue Book on the native room
+ floor; reconnect and reentry retain it without respawning collected items.
+ Native R/Pick Up transfers that same instance into main inventory through the
+ shared transaction. Tests cover full inventory, range, wrong world/identity,
+ stale sessions, pending inventory interactions, concurrent duplicate/two-player
+ pickup, output failure and SQLite rollback/retry. Retirement destroys remaining
+ floor items while retaining collected books. Completion/rewards remain separate.
+ GPU WASM verifies the visible floor model, immediate native pickup icon,
+ page reconnect, exit/reentry and cold-server recovery with no respawn.
+ See [mission floor items](docs/mission-objectives.md).
+- [ ] [P1] Execute supported world-item Use descriptors through reusable item
+ effects. The original book's right-click emits GenericCmd action3, while its
+ explicit R/Pick Up emits InventoryMove; preserve that distinction and resolve
+ actual instances before the existing type51005 terminal handling.
- [ ] [P0] Recover objective completion and token/XP eligibility rules. Action19
matches the objective item's template/QL, but its pickup/inspection/return
trigger remains unverified. The original offer details qualify XP with
@@ -1569,7 +1585,8 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
requests, concurrent expiry/abandonment and output failure. Native WASM verifies
online expiry and empty inventory/journal after a cold server restart.
Player evacuation is now atomic with retirement; cleanup of future spawned
- NPCs, objectives and corpses remains part of the instance work above.
+ NPCs and corpses remains part of the instance work above; floor objectives
+ now retire in the same transaction.
See [mission retirement](docs/mission-retirement.md).
- [ ] [P2] Retire uploaded waypoints when their mission expires. Native
QuestEvent1 now reports "Quest expired.." and removes the journal/key, but the
diff --git a/docs/mission-interiors.md b/docs/mission-interiors.md
@@ -586,15 +586,17 @@ and copied-key guests. Full character edits use the existing shared transaction
as a batch. Failed writes, ignored updates and failed commits retain the world,
players, keys and journal for retry. Geometry is removed only after committed
returns are published, and the owner's journal retirement precedes its redirect.
-Startup expiry loads the saved scene before evacuating occupants. NPCs, spawned
-objectives and mission corpses do not exist in this prototype; their eventual
-retirement remains part of population/objective work.
+Startup expiry loads the saved scene before evacuating occupants. Remaining
+floor objectives now retire in that same transaction; collected books keep
+ordinary inventory ownership. NPCs and mission corpses do not exist in this
+prototype; their eventual retirement remains part of population work.
The two rooms retain empty native door identities, which mean open passages.
This establishes a usable fixed prototype, not recovered style selection or
locked internal doors. Their actual templates, automatic opening and access
-policy remain open in [mission doors](mission-doors.md). The mission still has
-no objective interaction, enemies or completion rewards.
+policy remain open in [mission doors](mission-doors.md). The mission now supports
+[bound floor-item collection](mission-objectives.md); enemies, objective
+completion and rewards remain open.
An owned GPU WASM client on the single HTTPS8443 preview accepted the mission
through the normal terminal, walked through the Surveillance Office entrance
diff --git a/docs/mission-objectives.md b/docs/mission-objectives.md
@@ -0,0 +1,113 @@
+# Mission floor items
+
+The fixed Surveillance Office contract now creates one original QL1 Blue Book
+of Secrets (40822) on first entry. Its position is five metres inward from an
+actual doorway in the last prototype room, using the shared native portal and
+floor calculations. Room model anchors can lie inside cave scenery and are
+unsuitable as object spawn positions. This placement is a
+reconstruction choice, not a recovered original mission layout or loot table.
+
+The item uses the global instance registry. `item_locations` records either a
+mission-floor placement or an ordinary owner/container placement, enforced by
+the same single-location constraint. The accepted contract keeps its allocated
+objective instance ID even after collection or destruction. Entering again or
+restarting cannot regenerate a collected book. Allocation, binding, global item
+counter and the entering player's zone change commit together.
+
+The native client receives SimpleItem11 through packet 0x3b11256f, restricted to
+the assignment's private world. Its original blue mission-object model renders
+from the existing template; no replacement client asset is needed. Control-panel
+instance pages identify mission-floor placement and prevent ordinary assignment
+of an item already on the floor.
+
+## Pickup protocol
+
+The shipped `keyboard map.GIF` binds R to Pick Up. The original help file
+`cd_image/text/help/The Control Window.txt` also distinguishes Pick Up from Use.
+The actual 14.9.1 WASM client emits InventoryMove (0x47537a24) when R is pressed
+with the book selected:
+
+| Field | Value |
+| --- | --- |
+| Source | Type51005, the exact world item instance |
+| Destination identity | 0/0 |
+| Requested destination slot | 111, automatic inventory placement |
+
+Right-clicking this usable book emits GenericCmd action3 instead. Treating that
+Use request as a pickup would conflate distinct native actions. Existing terminal
+handling denies that unsupported world-item Use; descriptor-driven world-item
+Use is still open work.
+
+Pickup checks the current session, life/loading state, private assignment,
+expiry, original Carry permission, five-metre three-dimensional distance,
+Unique ownership, free main-inventory space and pending inventory interactions.
+It transfers the same instance through the shared inventory transaction before
+acknowledging success. Other clients in that world receive its removal. The
+collector retains the world dynel until InventoryMove reparents it; removing it
+before that native callback would discard the source of the transfer.
+
+The acknowledgement preserves destination0/0 and sentinel111. The original
+inventory dispatcher (`kkr.dll`0x100614e0) routes that destination to world pickup
+0x1005f7c0, which checks the live parentless item and picks the first free main
+slot. Changing the reply destination to the player identity selects ordinary
+inventory-slot movement0x1005dd60 instead; it interprets the world instance ID as
+a slot and cannot collect the book. Native source identity and destination
+semantics therefore both matter, beyond durable server ownership.
+
+Abandonment and expiry destroy remaining floor items with their assignment.
+Already collected books retain ordinary inventory ownership. Rewards and
+objective completion are deliberately separate from this ownership transfer.
+
+## Remaining completion rules
+
+Native `QuestAction_t` action19 matches item template endpoints and QL in
+`client/game/kkr.dll/lifted-0057.c`, `sub_360C5960`. Its observed caller belongs
+to action84, UseItemOnMission, rather than proving that any book pickup completes
+the current contract. The fixed offer's displayed Retrieve label does not
+establish whether it corresponds to a historical find-item or return-item
+contract. Arbitrary copies of40822 must never redeem an accepted contract.
+
+The original mission details condition displayed XP on receiving a token.
+[Funcom's14.0 release notes, republished in2002](https://www.gamereactor.no/anarchy-online-oppdaterer-til-v140/)
+state that token chance rises with kills, without recovering the exact server
+formula. The empty prototype therefore does not award unconditional100XP.
+The20-credit amount is also authored reconstruction data; completion settlement
+has not yet been connected.
+
+[Meiyen's2004 guide, preserved as an unedited repost](https://forums.funcom.com/t/rubi-ka-mission-settings-101/6664)
+distinguishes finding/picking up an item from returning it to the issuing booth.
+It also describes killing a mission target after completing find-person,
+supporting continued occupancy after success. This is near-period player
+evidence, not an original14.9.1 server capture. Completion settlement/key
+revocation must be separate from abandonment's immediate occupant evacuation.
+Exact XP/token eligibility, neutral exceptions and completed-world lifetime
+remain explicit fidelity work.
+
+## Verification
+
+Focused Go tests cover single allocation, exact native identity/world replay,
+cold reload, no respawn after collection, range/vertical distance, full inventory,
+forged source/destination, wrong world, expired/dead/loading/stale sessions,
+pending trades/shops/bank/equipment, concurrent duplicate and two-player pickup,
+observer isolation, output failure and collected/uncollected retirement.
+Injected SQLite abort, ignored insert/delete/update, late binding rewrite and
+commit failure verify rollback before success packets, followed by retry.
+
+Native runtime evidence and packet logs are retained under
+`local/mission-objective-research/`; the research probe and the final ordinary
+client run are separate. Reward findings and their confidence/unknowns are in
+`reward-rules.md` there.
+
+The GPU WASM check uses ordinary terminal acceptance and native movement
+through the real entrance, with no WebSocket rewriting. It verifies a visible,
+reachable floor book; R emits the source instance and0/0 destination above.
+After the corrected acknowledgement, the model disappears and the inventory
+icon appears immediately. A page reconnect restores the exact item identities
+and logical slots: the existing book2, new contract key3 and objective4.
+The mission journal remains active and credits remain3 after the request fee;
+collection alone does not settle completion rewards. Native exit and reentry
+retain the collected objective without creating another instance.
+A cold server restart also restores the private world, journal and all three
+inventory identities with no floor-item creation packet. Both ordinary and cold
+runs have no page exceptions or adapter failures; existing unattributed HTTP404
+console messages are retained in the logs rather than counted as game crashes.
diff --git a/server/control.go b/server/control.go
@@ -307,6 +307,14 @@ func (server *server) updateUser_locked(destination userData) error {
return err
}
store.edited = append(store.edited, updated)
+ if character.playfield != updated.playfield {
+ if mission := server.missionWorld_locked(updated.playfield); mission != nil {
+ if err := server.stageMissionObjective_locked(&store, mission); err != nil {
+ server.mutex.Unlock()
+ return err
+ }
+ }
+ }
if err := server.writeItemStore_locked(store); err != nil {
server.mutex.Unlock()
return err
diff --git a/server/inventory.go b/server/inventory.go
@@ -217,6 +217,9 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id {
return nil
}
+ if key == 0x47537a24 && binary.BigEndian.Uint32(body[16:20]) == 51005 {
+ return server.takeWorldItem_locked(client, body)
+ }
if client.trade != nil {
if err := server.abortPlayerTrade_locked(client); err != nil {
return err
diff --git a/server/item_database.go b/server/item_database.go
@@ -9,8 +9,9 @@ import (
)
type itemPlacement struct {
- Player, Bank, Backpack, Corpse, Slot uint32
- ReclaimAt string
+ Player, Bank, Backpack, Corpse, Mission, Slot uint32
+ Position [3]float32
+ ReclaimAt string
}
func (server *server) persistItems_locked(store itemStore) error {
@@ -112,6 +113,9 @@ func (server *server) persistItems_locked(store itemStore) error {
placements[item.ID] = itemPlacement{Corpse: id, Slot: item.Slot}
}
}
+ for id, item := range store.WorldItems {
+ placements[id] = itemPlacement{Mission: item.mission, Position: item.position}
+ }
// Delete changed locations first so swaps respect the unique slot constraints.
for id, previous := range server.itemPlacements {
@@ -153,7 +157,7 @@ func (server *server) persistItems_locked(store itemStore) error {
if previous, exists := server.itemPlacements[id]; exists && previous == placement {
continue
}
- var player, bank, backpack, corpse, reclaim any
+ var player, bank, backpack, corpse, mission, reclaim any
if placement.Player != 0 {
player = placement.Player
}
@@ -166,11 +170,14 @@ func (server *server) persistItems_locked(store itemStore) error {
if placement.Corpse != 0 {
corpse = placement.Corpse
}
+ if placement.Mission != 0 {
+ mission = placement.Mission
+ }
if placement.ReclaimAt != "" {
reclaim = placement.ReclaimAt
}
var savedID uint32
- if err := tx.QueryRow("INSERT INTO item_locations (item_id, player_id, bank_player_id, backpack_id, corpse_id, slot, reclaim_at) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING item_id", id, player, bank, backpack, corpse, placement.Slot, reclaim).Scan(&savedID); err != nil {
+ if err := tx.QueryRow("INSERT INTO item_locations (item_id, player_id, bank_player_id, backpack_id, corpse_id, mission_id, position_x, position_y, position_z, slot, reclaim_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING item_id", id, player, bank, backpack, corpse, mission, placement.Position[0], placement.Position[1], placement.Position[2], placement.Slot, reclaim).Scan(&savedID); err != nil {
return fmt.Errorf("save item %d placement: %w", id, err)
}
}
@@ -185,6 +192,12 @@ func (server *server) persistItems_locked(store itemStore) error {
return err
}
}
+ if store.updatedMission != nil {
+ mission := store.updatedMission
+ if err := updateRecord(tx, "missions", mission.id, "objective_id", []any{mission.objective}); err != nil {
+ return err
+ }
+ }
if store.removedMission != nil {
var removed uint32
if err := tx.QueryRow("DELETE FROM missions WHERE id=? AND owner_id=? RETURNING id", store.removedMission.id, store.removedMission.owner).Scan(&removed); err != nil {
@@ -233,6 +246,11 @@ func (server *server) persistItems_locked(store itemStore) error {
return fmt.Errorf("mission world allocation was not saved: %w", err)
}
}
+ if store.updatedMission != nil {
+ if err := tx.QueryRow("SELECT id FROM missions WHERE id=? AND objective_id=?", store.updatedMission.id, store.updatedMission.objective).Scan(&savedID); err != nil {
+ return fmt.Errorf("mission objective allocation was not saved: %w", err)
+ }
+ }
if err := tx.Commit(); err != nil {
return err
}
@@ -241,7 +259,7 @@ func (server *server) persistItems_locked(store itemStore) error {
}
func (server *server) readItems() (itemStore, error) {
- store := itemStore{Items: make(map[uint32]itemRecord), Players: make(map[uint32]characterItemReferences), Corpses: make(map[uint32][]ownedItem)}
+ store := itemStore{Items: make(map[uint32]itemRecord), Players: make(map[uint32]characterItemReferences), Corpses: make(map[uint32][]ownedItem), WorldItems: make(map[uint32]worldItem)}
db, err := server.database()
if err != nil {
return store, err
@@ -307,7 +325,7 @@ func (server *server) readItems() (itemStore, error) {
return store, err
}
rows.Close()
- rows, err = db.Query("SELECT item_id, player_id, bank_player_id, backpack_id, corpse_id, slot, reclaim_at FROM item_locations")
+ rows, err = db.Query("SELECT item_id, player_id, bank_player_id, backpack_id, corpse_id, mission_id, position_x, position_y, position_z, slot, reclaim_at FROM item_locations")
if err != nil {
return store, err
}
@@ -315,13 +333,16 @@ func (server *server) readItems() (itemStore, error) {
server.itemPlacements = make(map[uint32]itemPlacement)
for rows.Next() {
var id, slot uint32
- var player, bank, backpack, corpse sql.NullInt64
+ var player, bank, backpack, corpse, mission sql.NullInt64
+ var position [3]float32
var reclaim sql.NullString
- if err := rows.Scan(&id, &player, &bank, &backpack, &corpse, &slot, &reclaim); err != nil {
+ if err := rows.Scan(&id, &player, &bank, &backpack, &corpse, &mission, &position[0], &position[1], &position[2], &slot, &reclaim); err != nil {
return store, err
}
- server.itemPlacements[id] = itemPlacement{Player: uint32(player.Int64), Bank: uint32(bank.Int64), Backpack: uint32(backpack.Int64), Corpse: uint32(corpse.Int64), Slot: slot, ReclaimAt: reclaim.String}
+ server.itemPlacements[id] = itemPlacement{Player: uint32(player.Int64), Bank: uint32(bank.Int64), Backpack: uint32(backpack.Int64), Corpse: uint32(corpse.Int64), Mission: uint32(mission.Int64), Position: position, Slot: slot, ReclaimAt: reclaim.String}
switch {
+ case mission.Valid:
+ store.WorldItems[id] = worldItem{mission: uint32(mission.Int64), position: position}
case bank.Valid:
references := store.Players[uint32(bank.Int64)]
references.Bank[fmt.Sprintf("slot_%d", slot+1)] = &id
diff --git a/server/item_pages.go b/server/item_pages.go
@@ -64,6 +64,9 @@ func (server *server) itemLocations_locked() map[uint32]itemLocation {
locations[item.ID] = itemLocation{owner: player.id, label: fmt.Sprintf("Bank, slot_%d", item.Slot+1)}
}
}
+ for id, placement := range server.worldItems {
+ locations[id] = itemLocation{label: fmt.Sprintf("Mission %d floor", placement.mission)}
+ }
for id, record := range server.items {
for slot, contained := range record.Slots {
if contained != nil {
diff --git a/server/item_store.go b/server/item_store.go
@@ -4,6 +4,7 @@ import (
"cmp"
"fmt"
"maps"
+ "math"
"slices"
"strconv"
"strings"
@@ -49,10 +50,12 @@ type itemStore struct {
Items map[uint32]itemRecord `yaml:"items"`
Players map[uint32]characterItemReferences `yaml:"players"`
Corpses map[uint32][]ownedItem
+ WorldItems map[uint32]worldItem
edited []*character
vitalUpdate *playerVitalUpdate
skillLock *skillLockUpdate
mission *acceptedMission
+ updatedMission *acceptedMission
removedMission *acceptedMission
inventoryPlayers []uint32
checkpointAt time.Time
@@ -190,7 +193,7 @@ func reclaimItems(entries []reclaimItem) []ownedItem {
func (server *server) itemStore_locked(character *character, inventory playerInventory) (itemStore, error) {
store := itemStore{LastID: max(server.nextItem, inventory.LastID), Items: maps.Clone(server.items),
- Players: make(map[uint32]characterItemReferences), Corpses: make(map[uint32][]ownedItem), inventoryPlayers: []uint32{character.id}}
+ Players: make(map[uint32]characterItemReferences), Corpses: make(map[uint32][]ownedItem), WorldItems: maps.Clone(server.worldItems), inventoryPlayers: []uint32{character.id}}
if store.Items == nil {
store.Items = make(map[uint32]itemRecord)
}
@@ -262,7 +265,21 @@ func (server *server) writeItemStore_locked(store itemStore) error {
return err
}
server.items = store.Items
+ server.worldItems = store.WorldItems
server.nextItem = store.LastID
+ if store.updatedMission != nil {
+ mission := store.updatedMission
+ for index := range server.missionExpiry {
+ if server.missionExpiry[index].id == mission.id {
+ server.missionExpiry[index] = *mission
+ }
+ }
+ for index := range server.characters[mission.owner].missions {
+ if server.characters[mission.owner].missions[index].id == mission.id {
+ server.characters[mission.owner].missions[index] = *mission
+ }
+ }
+ }
for id, items := range store.Corpses {
contents := slices.Clone(items)
for index, item := range contents {
@@ -294,6 +311,7 @@ func (server *server) loadItems() error {
player.inventory = inventory
}
server.items, server.nextItem = store.Items, store.LastID
+ server.worldItems = store.WorldItems
for id, items := range store.Corpses {
server.characters[id].corpse.items = items
}
@@ -302,6 +320,17 @@ func (server *server) loadItems() error {
func (store itemStore) validate() error {
claimed := make(map[uint32]bool)
+ for id, placement := range store.WorldItems {
+ if _, exists := store.Items[id]; !exists || placement.mission == 0 {
+ return fmt.Errorf("invalid world item %d placement", id)
+ }
+ for _, coordinate := range placement.position {
+ if math.IsNaN(float64(coordinate)) || math.IsInf(float64(coordinate), 0) {
+ return fmt.Errorf("invalid world item %d position", id)
+ }
+ }
+ claimed[id] = true
+ }
for _, items := range store.Corpses {
slots := make(map[uint32]bool)
for _, item := range items {
diff --git a/server/main.go b/server/main.go
@@ -420,6 +420,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
updates = append(updates, equippedWeaponPackets(character)...)
updates = append(updates, server.combatInterest_locked(client, nil)...)
if client.target {
+ updates = append(updates, server.worldItemPackets_locked(character)...)
for id, machine := range gamedata.ShopMachines {
if machine.Playfield == character.playfield {
updates = append(updates, shopMachinePacket(id, machine))
diff --git a/server/mission_retirement.go b/server/mission_retirement.go
@@ -191,6 +191,12 @@ func (server *server) retireMission_locked(mission acceptedMission, updates map[
for id := range keys {
delete(store.Items, id)
}
+ for id, item := range store.WorldItems {
+ if item.mission == mission.id {
+ delete(store.WorldItems, id)
+ delete(store.Items, id)
+ }
+ }
// Evacuate every occupant in the same transaction that revokes the assignment.
for _, player := range server.characters {
if player.npc || player.playfield != mission.world {
diff --git a/server/missions.go b/server/missions.go
@@ -18,16 +18,17 @@ type acceptedMission struct {
expiresAt time.Time
world uint32
layout []byte
+ objective uint32
}
-const missionColumns = "owner_id, booth_id, seed, difficulty, dimension_0, dimension_1, dimension_2, dimension_3, dimension_4, dimension_5, originator, description, playfield, entrance, position_x, position_y, position_z, objective_item, credits, experience, expires_at, world_id, layout"
+const missionColumns = "owner_id, booth_id, seed, difficulty, dimension_0, dimension_1, dimension_2, dimension_3, dimension_4, dimension_5, originator, description, playfield, entrance, position_x, position_y, position_z, objective_item, credits, experience, expires_at, world_id, layout, objective_id"
func (mission *acceptedMission) fields() []any {
return []any{&mission.owner, &mission.offer.booth, &mission.offer.seed, &mission.offer.difficulty,
&mission.offer.dimensions[0], &mission.offer.dimensions[1], &mission.offer.dimensions[2], &mission.offer.dimensions[3], &mission.offer.dimensions[4], &mission.offer.dimensions[5],
&mission.offer.originator, &mission.offer.definition.Description, &mission.offer.definition.Playfield, &mission.offer.definition.Entrance,
&mission.offer.definition.Position[0], &mission.offer.definition.Position[1], &mission.offer.definition.Position[2],
- &mission.offer.definition.ObjectiveItem, &mission.offer.definition.Credits, &mission.offer.definition.Experience, &mission.expiresAt, &mission.world, &mission.layout}
+ &mission.offer.definition.ObjectiveItem, &mission.offer.definition.Credits, &mission.offer.definition.Experience, &mission.expiresAt, &mission.world, &mission.layout, &mission.objective}
}
func insertMission(tx *sql.Tx, mission *acceptedMission) error {
diff --git a/server/state.go b/server/state.go
@@ -129,6 +129,7 @@ type server struct {
nextNPC uint32
nextItem uint32
items map[uint32]itemRecord
+ worldItems map[uint32]worldItem
characters map[uint32]*character
mobileNPCs map[uint32][]*character
npcRespawns []npcRespawn
diff --git a/server/world.sql b/server/world.sql
@@ -202,13 +202,15 @@ CREATE TABLE IF NOT EXISTS item_locations (
bank_player_id INTEGER REFERENCES players(id),
backpack_id INTEGER REFERENCES items(id),
corpse_id INTEGER REFERENCES npcs(id),
+ mission_id INTEGER REFERENCES missions(id),
+ position_x REAL NOT NULL DEFAULT 0, position_y REAL NOT NULL DEFAULT 0, position_z REAL NOT NULL DEFAULT 0,
slot INTEGER NOT NULL,
reclaim_at TEXT,
- CHECK ((player_id IS NOT NULL) + (bank_player_id IS NOT NULL) + (backpack_id IS NOT NULL) + (corpse_id IS NOT NULL) = 1),
+ CHECK ((player_id IS NOT NULL) + (bank_player_id IS NOT NULL) + (backpack_id IS NOT NULL) + (corpse_id IS NOT NULL) + (mission_id IS NOT NULL) = 1),
CHECK ((player_id IS NOT NULL AND slot BETWEEN 1 AND 93) OR
(bank_player_id IS NOT NULL AND slot BETWEEN 0 AND 101) OR
(backpack_id IS NOT NULL AND slot BETWEEN 0 AND 20) OR
- (corpse_id IS NOT NULL AND slot >= 0)),
+ (corpse_id IS NOT NULL AND slot >= 0) OR (mission_id IS NOT NULL AND slot = 0)),
CHECK (reclaim_at IS NULL OR (player_id IS NOT NULL AND slot BETWEEN 64 AND 93))
);
CREATE UNIQUE INDEX IF NOT EXISTS player_slots ON item_locations(player_id, slot) WHERE reclaim_at IS NULL;
@@ -233,7 +235,8 @@ CREATE TABLE IF NOT EXISTS missions (
experience INTEGER NOT NULL,
expires_at DATETIME NOT NULL,
world_id INTEGER NOT NULL UNIQUE CHECK (world_id BETWEEN 65536 AND 4294967295),
- layout BLOB NOT NULL
+ layout BLOB NOT NULL,
+ objective_id INTEGER NOT NULL DEFAULT 0 CHECK (objective_id BETWEEN 0 AND 4294967295)
);
CREATE TABLE IF NOT EXISTS mission_keys (
item_id INTEGER PRIMARY KEY REFERENCES items(id) ON DELETE CASCADE,
diff --git a/server/world_items.go b/server/world_items.go
@@ -3,9 +3,126 @@ package main
import (
"ao/server/gamedata"
"encoding/binary"
+ "fmt"
"math"
+ "slices"
+ "time"
)
+type worldItem struct {
+ mission uint32
+ position [3]float32
+}
+
+func (server *server) stageMissionObjective_locked(store *itemStore, mission *acceptedMission) error {
+ if mission.objective != 0 {
+ return nil
+ }
+ if store.LastID == math.MaxUint32 {
+ return fmt.Errorf("item identities exhausted")
+ }
+ scene, err := server.prepareMissionWorld_locked(mission)
+ if err != nil {
+ return err
+ }
+ // Place the prototype objective inside an actual doorway, clear of its model anchor.
+ room := &scene.rooms[len(scene.rooms)-1]
+ door := slices.IndexFunc(room.template.doors, func(door [2]int16) bool { return door[0] == -1 })
+ position, direction := scene.portal(room, uint16(room.template.doors[door][1]))
+ inward := roomRotate([3]float32{0, 0, -5}, direction)
+ for axis := range position {
+ position[axis] += inward[axis]
+ }
+ origin := position
+ origin[1]++
+ var normal [3]float32
+ scene.floor(origin, &position, &normal)
+ position[1] += .01
+ if scene.roomAt(position) != room {
+ return fmt.Errorf("mission objective has no room")
+ }
+ template := gamedata.ItemTemplates[mission.offer.definition.ObjectiveItem]
+ store.LastID++
+ store.Items[store.LastID] = itemRecord{Type: template.HeaderWords[0], Template: mission.offer.definition.ObjectiveItem, Quality: *template.Quality, Count: 1}
+ if store.WorldItems == nil {
+ store.WorldItems = make(map[uint32]worldItem)
+ }
+ store.WorldItems[store.LastID] = worldItem{mission.id, position}
+ updated := *mission
+ updated.objective = store.LastID
+ store.updatedMission = &updated
+ return nil
+}
+
+func (server *server) worldItemPackets_locked(player *character) [][]byte {
+ mission := server.missionWorld_locked(player.playfield)
+ if mission == nil {
+ return nil
+ }
+ var packets [][]byte
+ for id, placement := range server.worldItems {
+ if placement.mission == mission.id {
+ item := server.items[id]
+ packets = append(packets, n3Packet(0x3b11256f, item.Type, id,
+ simpleItemBody(item.Template, player.playfield, placement.position, [4]float32{0, 0, 0, 1}, nil)))
+ }
+ }
+ return packets
+}
+
+func (server *server) takeWorldItem_locked(client *worldClient, body []byte) error {
+ id := binary.BigEndian.Uint32(body[20:24])
+ player := server.characters[client.id]
+ placement, exists := server.worldItems[id]
+ mission := server.missionWorld_locked(player.playfield)
+ denied := characterActionPacket(client.id, [5]uint32{146, 51005, id})
+ if !client.target || !exists || mission == nil || placement.mission != mission.id || !time.Now().Before(mission.expiresAt) ||
+ client.trade != nil || client.shop != nil || client.bank != nil || client.equipment != nil ||
+ binary.BigEndian.Uint32(body[24:28]) != 0 || binary.BigEndian.Uint32(body[28:32]) != 0 || binary.BigEndian.Uint32(body[32:36]) != 111 {
+ return client.send(denied)
+ }
+ position := predictedPosition_locked(player, time.Now())
+ x, y, z := position[0]-placement.position[0], position[1]-placement.position[1], position[2]-placement.position[2]
+ record := server.items[id]
+ item := ownedItem{ID: id, Type: record.Type, Template: record.Template, Quality: record.Quality, Count: record.Count, Ammo: record.Ammo}
+ if x*x+y*y+z*z > 25 || item.Type != 51005 || itemStat(item.templateDefinition(), 30)&1 == 0 ||
+ itemStat(item.templateDefinition(), 0)&0x08000000 != 0 && player.inventory.carriesUnique(item) {
+ return client.send(denied)
+ }
+ for item.Slot = 64; item.Slot < 94; item.Slot++ {
+ if !slices.ContainsFunc(player.inventory.Items, func(other ownedItem) bool { return other.Slot == item.Slot }) {
+ break
+ }
+ }
+ if item.Slot == 94 {
+ return client.send(denied)
+ }
+
+ // Move the same instance, with one durable placement and no live change on failure.
+ inventory := player.inventory
+ inventory.LastID = max(inventory.LastID, server.nextItem)
+ inventory.Items = append(slices.Clone(inventory.Items), item)
+ store, err := server.itemStore_locked(player, inventory)
+ if err != nil {
+ return err
+ }
+ delete(store.WorldItems, id)
+ if err := server.writeItemStore_locked(store); err != nil {
+ return err
+ }
+ player.inventory = inventory
+ for _, other := range server.clients {
+ if other != client && other.target && other.ready && !other.loading && server.characters[other.id].playfield == player.playfield {
+ if err := other.send(n3Packet(0x36510078, item.Type, id, nil)); err != nil {
+ other.disconnect(other.conn)
+ }
+ }
+ }
+ // client/game/kkr.dll/lifted-0029.c, sub_360614E0/sub_3605F7C0:
+ // Destination 0/0 selects world pickup and the same first-free slot locally.
+ return client.send(n3Packet(0x47537a24, 50000, client.id, slices.Clone(body[16:])))
+}
+
func simpleItemBody(template, playfield uint32, position [3]float32, rotation [4]float32, stats [][2]uint32) []byte {
// SimpleItem11: parentless world placement, owner and placement bytes.
var body []byte
diff --git a/server/world_items_test.go b/server/world_items_test.go
@@ -0,0 +1,376 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "reflect"
+ "sync"
+ "testing"
+ "time"
+)
+
+func enteredObjectiveWorld(t *testing.T) (*server, *worldClient, *combatTestConn) {
+ t.Helper()
+ world, output := newMissionEntranceWorld(t)
+ client := world.clients[1]
+ if err := world.handleMovement(client, playerMovementRequest(world.characters[1], 1)); err != nil {
+ t.Fatal(err)
+ }
+ client.ready = true
+ world.clients[1] = client
+ world.characters[1].position = world.worldItems[3].position
+ world.characters[1].movement = playerMovement{}
+ output.packets = nil
+ return world, client, output
+}
+
+func worldPickupRequest(owner, item uint32) []byte {
+ var body []byte
+ for _, value := range []uint32{51005, item, 0, 0, 111} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ return n3Packet(0x47537a24, 50000, owner, body)[20:]
+}
+
+func TestMissionObjectiveSpawnsOnceAndReplaysOnlyInItsWorld(t *testing.T) {
+ world, _ := newMissionEntranceWorld(t)
+ player, client := world.characters[1], world.clients[1]
+
+ if err := world.handleMovement(client, playerMovementRequest(player, 1)); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+ packets := cold.worldItemPackets_locked(cold.characters[1])
+ record, placement := cold.items[3], cold.worldItems[3]
+ public := cold.worldItemPackets_locked(&character{playfield: 3000})
+ foreign := cold.worldItemPackets_locked(&character{playfield: 65537})
+
+ if !reflect.DeepEqual(record, itemRecord{Type: 51005, Template: 40822, Quality: 1, Count: 1}) {
+ t.Fatal("wrong objective record", record)
+ }
+ if world.nextItem != 3 || cold.nextItem != 3 || len(cold.worldItems) != 1 || placement.mission != 2 ||
+ placement.position != ([3]float32{15, .011, 35.001007}) || cold.characters[1].missions[0].objective != 3 ||
+ !reflect.DeepEqual(world.worldItems, cold.worldItems) || len(packets) != 1 || len(public) != 0 || len(foreign) != 0 {
+ t.Fatal("objective allocation, floor or instance isolation changed", cold.worldItems, cold.characters[1].missions)
+ }
+ packet := targetPacket(packets[0])
+ if binary.BigEndian.Uint32(packet[16:]) != 0x3b11256f || binary.BigEndian.Uint32(packet[20:]) != 51005 ||
+ binary.BigEndian.Uint32(packet[24:]) != 3 || binary.BigEndian.Uint32(packet[69:73]) != 65536 {
+ t.Fatal("objective lost its native identity or private world", packets)
+ }
+
+ destination := player.userData()
+ destination.Playfield, destination.Position = 3000, [3]float32{89.3, 115.75, 154.5}
+ if err := world.updateUser_locked(destination); err != nil {
+ t.Fatal(err)
+ }
+ destination.Playfield, destination.Position = 65536, [3]float32{15, .011, 12.501}
+ if err := world.updateUser_locked(destination); err != nil {
+ t.Fatal(err)
+ }
+
+ if world.nextItem != 3 || len(world.worldItems) != 1 || world.characters[1].missions[0].objective != 3 {
+ t.Fatal("reentry respawned the objective")
+ }
+}
+
+func TestWorldPickupMovesSameInstanceAndSurvivesRestart(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ before := world.characters[1].inventory.Credits
+
+ if err := world.handleInventory(client, worldPickupRequest(1, 3)); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+ player := cold.characters[1]
+ var owner, slot uint32
+ if err := cold.db.QueryRow("SELECT player_id, slot FROM item_locations WHERE item_id=3").Scan(&owner, &slot); err != nil {
+ t.Fatal(err)
+ }
+
+ if owner != 1 || slot != 66 || world.nextItem != 3 || cold.nextItem != 3 || len(world.worldItems) != 0 || len(cold.worldItems) != 0 ||
+ len(player.inventory.Items) != 3 || player.inventory.Items[2] != (ownedItem{ID: 3, Type: 51005, Template: 40822, Quality: 1, Count: 1, Slot: 66}) ||
+ player.inventory.Credits != before || len(player.missions) != 1 || player.missions[0].objective != 3 {
+ t.Fatal("pickup lost, duplicated or rewarded an objective", owner, slot, player.inventory)
+ }
+ if len(output.packets) != 1 || !bytes.Equal(output.packets[0], inventoryWorldPickupReply(1, 3)) {
+ t.Fatal("incorrect native reparent reply", output.packets)
+ }
+
+ destination := world.characters[1].userData()
+ destination.Playfield, destination.Position = 3000, [3]float32{89.3, 115.75, 154.5}
+ if err := world.updateUser_locked(destination); err != nil {
+ t.Fatal(err)
+ }
+ destination.Playfield, destination.Position = 65536, [3]float32{15, .011, 12.501}
+ if err := world.updateUser_locked(destination); err != nil {
+ t.Fatal(err)
+ }
+
+ if world.nextItem != 3 || len(world.worldItems) != 0 || len(world.characters[1].inventory.Items) != 3 {
+ t.Fatal("collected objective respawned")
+ }
+}
+
+func inventoryWorldPickupReply(owner, item uint32) []byte {
+ var body []byte
+ for _, value := range []uint32{51005, item, 0, 0, 111} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ return targetPacket(n3Packet(0x47537a24, 50000, owner, body))
+}
+
+func TestWorldPickupRejectsUnavailableAndForgedRequests(t *testing.T) {
+ for _, scenario := range []string{"full", "far", "vertical", "foreign world", "unknown", "foreign owner", "foreign actor", "explicit destination", "wrong destination", "expired", "dead", "loading", "not ready", "stale", "legacy", "trade", "shop", "bank", "equipment"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ player := world.characters[1]
+ request := worldPickupRequest(1, 3)
+ switch scenario {
+ case "full":
+ for slot := uint32(66); slot < 94; slot++ {
+ granted, err := world.grantItem_locked(player, 121567)
+ if err != nil || !granted {
+ t.Fatal("fill inventory", granted, err)
+ }
+ }
+ case "far":
+ player.position[0] += 5.01
+ case "vertical":
+ player.position[1] += 5.01
+ case "foreign world":
+ player.playfield = 3000
+ case "unknown":
+ binary.BigEndian.PutUint32(request[20:], 9000001)
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:], 2)
+ case "foreign actor":
+ binary.BigEndian.PutUint32(request[4:], 51005)
+ case "explicit destination":
+ binary.BigEndian.PutUint32(request[24:], 50000)
+ binary.BigEndian.PutUint32(request[28:], 1)
+ case "wrong destination":
+ binary.BigEndian.PutUint32(request[32:], 64)
+ case "expired":
+ world.missionExpiry[0].expiresAt = time.Now().Add(-time.Second)
+ case "dead":
+ player.health = 0
+ case "loading":
+ client.loading = true
+ case "not ready":
+ client.ready = false
+ case "stale":
+ world.clients[1] = &worldClient{id: 1}
+ case "legacy":
+ client.target = false
+ case "trade":
+ client.trade = &playerTrade{}
+ case "shop":
+ client.shop = &shopTrade{}
+ case "bank":
+ client.bank = &bankSession{}
+ case "equipment":
+ client.equipment = &equipmentMove{}
+ }
+ before := len(player.inventory.Items)
+ output.packets = nil
+
+ if err := world.handleInventory(client, request); err != nil {
+ t.Fatal(err)
+ }
+ var owner uint32
+ if err := world.db.QueryRow("SELECT mission_id FROM item_locations WHERE item_id=3").Scan(&owner); err != nil {
+ t.Fatal(err)
+ }
+
+ denial := characterActionPacket(1, [5]uint32{146, 51005, binary.BigEndian.Uint32(request[20:24])})
+ if client.target {
+ denial = targetPacket(denial)
+ }
+ if owner != 2 || len(world.worldItems) != 1 || len(player.inventory.Items) != before || len(output.packets) > 1 ||
+ len(output.packets) == 1 && !bytes.Equal(output.packets[0], denial) {
+ t.Fatal("denied pickup changed ownership or reported success", output.packets)
+ }
+ })
+ }
+}
+
+func TestWorldPickupRollsBackAndCanRetry(t *testing.T) {
+ for _, scenario := range []struct{ name, sql string }{
+ {"abort", "CREATE TRIGGER reject_pickup BEFORE INSERT ON item_locations WHEN NEW.item_id=3 BEGIN SELECT RAISE(ABORT,'pickup'); END"},
+ {"ignored", "CREATE TRIGGER reject_pickup BEFORE INSERT ON item_locations WHEN NEW.item_id=3 BEGIN SELECT RAISE(IGNORE); END"},
+ {"delete ignored", "CREATE TRIGGER reject_pickup BEFORE DELETE ON item_locations WHEN OLD.item_id=3 BEGIN SELECT RAISE(IGNORE); END"},
+ {"commit", "CREATE TABLE pending_pickup (id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_pickup AFTER INSERT ON item_locations WHEN NEW.item_id=3 BEGIN INSERT INTO pending_pickup VALUES(999999); END"},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ if _, err := world.db.Exec(scenario.sql); err != nil {
+ t.Fatal(err)
+ }
+
+ failure := world.handleInventory(client, worldPickupRequest(1, 3))
+ cold := reloadMissionEntranceWorld(t)
+
+ if failure == nil || len(output.packets) != 0 || len(world.worldItems) != 1 || len(cold.worldItems) != 1 ||
+ len(world.characters[1].inventory.Items) != 2 || len(cold.characters[1].inventory.Items) != 2 {
+ t.Fatal("failed pickup leaked ownership or output", failure)
+ }
+
+ if _, err := world.db.Exec("DROP TRIGGER reject_pickup"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, worldPickupRequest(1, 3)); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(world.worldItems) != 0 || len(world.characters[1].inventory.Items) != 3 || len(output.packets) != 1 {
+ t.Fatal("pickup retry did not succeed once")
+ }
+ })
+ }
+}
+
+func TestWorldPickupConcurrentDuplicatesTransferOnce(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ errors := make(chan error, 2)
+ var workers sync.WaitGroup
+
+ for range 2 {
+ workers.Add(1)
+ go func() { defer workers.Done(); errors <- world.handleInventory(client, worldPickupRequest(1, 3)) }()
+ }
+ workers.Wait()
+ close(errors)
+ for err := range errors {
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if len(world.characters[1].inventory.Items) != 3 || len(world.worldItems) != 0 || len(output.packets) != 2 ||
+ !bytes.Equal(output.packets[0], inventoryWorldPickupReply(1, 3)) || binary.BigEndian.Uint32(output.packets[1][16:]) != 0x5e477770 {
+ t.Fatal("duplicate pickup transferred twice", output.packets)
+ }
+}
+
+func TestMissionRetirementDestroysOnlyUncollectedFloorItems(t *testing.T) {
+ for _, collected := range []bool{false, true} {
+ t.Run(map[bool]string{false: "floor", true: "collected"}[collected], func(t *testing.T) {
+ world, client, _ := enteredObjectiveWorld(t)
+ if collected {
+ if err := world.handleInventory(client, worldPickupRequest(1, 3)); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if err := world.handleMissionRemoval(client, missionRemovalPacket(1, 2)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+ _, exists := cold.items[3]
+
+ if exists != collected || len(world.worldItems) != 0 || len(cold.worldItems) != 0 || len(cold.characters[1].missions) != 0 ||
+ cold.characters[1].playfield != 3000 {
+ t.Fatal("retirement lost a collected item or retained a floor item", collected, cold.items)
+ }
+ })
+ }
+}
+
+func TestMissionObjectiveAllocationRollsBackBeforeEntry(t *testing.T) {
+ for _, scenario := range []struct{ name, sql string }{
+ {"item", "CREATE TRIGGER reject_objective BEFORE INSERT ON items WHEN NEW.id=3 BEGIN SELECT RAISE(ABORT,'objective'); END"},
+ {"placement", "CREATE TRIGGER reject_objective BEFORE INSERT ON item_locations WHEN NEW.item_id=3 BEGIN SELECT RAISE(IGNORE); END"},
+ {"binding", "CREATE TRIGGER reject_objective BEFORE UPDATE OF objective_id ON missions BEGIN SELECT RAISE(IGNORE); END"},
+ {"late rewrite", "CREATE TRIGGER reject_objective AFTER UPDATE OF last_item_id ON world BEGIN UPDATE missions SET objective_id=0; END"},
+ {"commit", "CREATE TABLE pending_objective (id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_objective AFTER UPDATE OF objective_id ON missions BEGIN INSERT INTO pending_objective VALUES(999999); END"},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ world, output := newMissionEntranceWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if _, err := world.db.Exec(scenario.sql); err != nil {
+ t.Fatal(err)
+ }
+
+ failure := world.handleMovement(client, playerMovementRequest(player, 1))
+ cold := reloadMissionEntranceWorld(t)
+
+ if failure == nil || len(output.packets) != 0 || len(world.worldItems) != 0 || len(cold.worldItems) != 0 ||
+ world.nextItem != 2 || cold.nextItem != 2 || len(cold.items) != 2 || player.playfield != 3000 ||
+ cold.characters[1].playfield != 3000 || player.missions[0].objective != 0 || cold.characters[1].missions[0].objective != 0 {
+ t.Fatal("failed allocation leaked item, binding or redirect", failure)
+ }
+
+ if _, err := world.db.Exec("DROP TRIGGER reject_objective"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMovement(client, playerMovementRequest(player, 1)); err != nil {
+ t.Fatal(err)
+ }
+
+ if world.nextItem != 3 || len(world.worldItems) != 1 || player.missions[0].objective != 3 || player.playfield != 65536 {
+ t.Fatal("allocation retry did not use the rolled-back identity", world.nextItem, player.missions)
+ }
+ })
+ }
+}
+
+func TestWorldPickupBetweenPlayersRemovesOnlyItsWorldCopy(t *testing.T) {
+ world, owner, output := enteredObjectiveWorld(t)
+ guest := world.characters[1].userData()
+ guest.ID, guest.Name = 2, "Guest"
+ world.characters[2] = guest.character()
+ if err := world.saveUser_locked(world.characters[2]); err != nil {
+ t.Fatal(err)
+ }
+ guestOutput, publicOutput := &combatTestConn{}, &combatTestConn{}
+ client := &worldClient{id: 2, target: true, ready: true, conn: guestOutput}
+ world.clients[2] = client
+ public := guest
+ public.ID, public.Name, public.Playfield = 3, "Observer", 3000
+ world.characters[3] = public.character()
+ world.clients[3] = &worldClient{id: 3, target: true, ready: true, conn: publicOutput}
+ if err := world.saveUser_locked(world.characters[3]); err != nil {
+ t.Fatal(err)
+ }
+ errors := make(chan error, 2)
+ var workers sync.WaitGroup
+
+ for _, participant := range []*worldClient{owner, client} {
+ workers.Add(1)
+ go func() {
+ defer workers.Done()
+ errors <- world.handleInventory(participant, worldPickupRequest(participant.id, 3))
+ }()
+ }
+ workers.Wait()
+ close(errors)
+ for err := range errors {
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ cold := reloadMissionEntranceWorld(t)
+ var holder uint32
+ if err := cold.db.QueryRow("SELECT player_id FROM item_locations WHERE item_id=3").Scan(&holder); err != nil {
+ t.Fatal(err)
+ }
+
+ if holder != 1 && holder != 2 || len(cold.worldItems) != 0 || len(output.packets)+len(guestOutput.packets) != 3 || len(publicOutput.packets) != 0 ||
+ len(cold.characters[1].inventory.Items)+len(cold.characters[2].inventory.Items) != 3 || len(cold.characters[holder].inventory.Items) == 0 {
+ t.Fatal("contested pickup duplicated ownership or crossed worlds", holder, output.packets, guestOutput.packets, publicOutput.packets)
+ }
+}
+
+func TestWorldPickupOutputFailureKeepsCommittedOwnership(t *testing.T) {
+ world, client, _ := enteredObjectiveWorld(t)
+ client.conn = &failingCombatConn{}
+
+ failure := world.handleInventory(client, worldPickupRequest(1, 3))
+ cold := reloadMissionEntranceWorld(t)
+
+ if failure == nil || len(world.worldItems) != 0 || len(cold.worldItems) != 0 || len(cold.characters[1].inventory.Items) != 3 ||
+ cold.characters[1].inventory.Items[2].ID != 3 || cold.characters[1].missions[0].objective != 3 {
+ t.Fatal("output failure reversed ownership or allowed objective respawn", failure)
+ }
+}