commit 0f6b2f5e8f5764bbca6568c3d04bb07685de9f5c
parent 5412f5092c78db35968830972e446aedcdbcb31b
Author: anon <anon@example.com>
Date: Fri, 23 Oct 2026 16:01:48 +0000
Support every portable container and preserve filled corpse loot
Diffstat:
20 files changed, 594 insertions(+), 50 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -55,11 +55,16 @@ recorded in [inventory behavior](docs/inventory.md).
backpack contents survive reconnect and restart, with no duplicate item.
- [x] Enforce container placement rules. Check: full bags and prohibited nesting
are rejected without losing items; permitted moves match recovered rules.
-- [ ] Support every 14.9.1 backpack size and type. Check: catalog-backed
+- [x] Support every 14.9.1 backpack size and type. Check: catalog-backed
capacities and placement rules replace the Small Backpack-only restriction;
each size opens correctly in the native client, accepts its full capacity,
rejects overflow without loss, and preserves contents across transfers,
reconnect and restart. Cover the control panel, looting, deletion and reclaim.
+- [ ] Equip portable bags with their authored requirements and effects. Check:
+ back-slot bags and the Pre-Universe Storage Device use the correct slots;
+ ability/skill/level boundaries, signed bonuses, health and XP effects, use while
+ worn, and supported QL interpolation match recovered behavior. Storage support
+ alone must not enable unsupported equipment effects.
Essence of Pure Jealousy now supports persistent native splitting and merging.
The historical merge cap remains unresolved, so the merge item stays open;
@@ -67,8 +72,8 @@ The historical merge cap remains unresolved, so the merge item stays open;
rejected-split recovery and verification are in
[inventory stacks](docs/inventory-stacks.md).
-Small Backpack 99228 uses its recovered 21-slot native inventory and persistent
-contents. Protocol evidence, ownership/placement checks, native tests and the
+All 37 portable Chest templates use the recovered 21-slot native inventory
+and persistent contents. Protocol evidence, ownership/placement checks, native tests and the
unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
## Equipment, one kind at a time
diff --git a/docs/backpacks.md b/docs/backpacks.md
@@ -1,12 +1,37 @@
# Backpacks in 14.9.1
-The supported container is Small Backpack, template 99228, exact QL 1,
-identity type 51017. Its shipped record is in
-`server/gamedata/items/items_010.yaml`: Can 13, Flags 4097, and stat 24 = 10000.
-Its description says ten kilograms; that value is not a slot count.
-[Auno's historical 14.8 record](https://auno.org/ao/db.php?id=99228&patch=14080000)
-corroborates these fields. The Adventuring requirement belongs to equipping
-the bag; this milestone uses it as an ordinary inventory container.
+Storage supports all 37 portable Chest templates in the shipped 14.9.1
+catalog. A portable container has identity type 51017 and both Carry and Use
+capabilities (stat 30 bits 1 and 8). The other 23 Chest records are fixed world
+objects and are not owned inventory containers. Template type is checked as well
+as the instance type; an item cannot acquire container storage by spoofing its type.
+
+| Containers | Templates | Authored QL |
+| --- | --- | --- |
+| Small, Medium, Large Backpack | 99228, 99241, 143832 | 1 |
+| Fourteen named Large Backpack variants | 157682..157695 | 1 |
+| Pioneer and Modified Pioneer | 152039, 156831 | 1 |
+| Robust Backpack | 158790 | 1 |
+| Notum Threaded Backpack | 164564 | 140 |
+| Beeping Backpack, Pre-Universe Storage Device, Dust Collector | 165201, 168658, 200461 | 200 |
+| Backpack of Survival endpoints | 206730, 206731 | 50, 150 |
+| Personal Backpack | 207254 | 1 |
+| Portable trunks, boxes, barrels, jar, Bag | 23143, 23147, 23149, 23151, 23153, 23155, 23157, 23159, 23161 | 1 |
+| Book of Knowledge | 99302 | 1 |
+
+Every portable Chest has 21 native slots. Small, Medium and Large describe
+10, 50 and 100 kilograms respectively (stat 24); those values do not set slot
+capacity. The storage path forwards each instance's template and QL unchanged.
+The Adventuring and other wear requirements do not gate opening an ordinary
+inventory container. Equipping bags and applying their effects remain separate
+work, including signed bonuses and the unusual Pre-Universe equipment slots.
+
+The full shipped catalog audit is retained in
+`local/backpack-sizes-research/catalog.json` (60 records, including source files),
+with a compact rendering in `catalog.txt`. The matching 94-record REA bundle is
+`local/backpack-sizes-research/native.snapshot.json`; it includes the earlier
+backpack evidence and the generic Chest construction path. Historical Auno pages
+were inaccessible during this expansion; no additional web claim is inferred.
## Native object and contents
@@ -31,7 +56,7 @@ success acknowledgement and supplies a live Chest plus its contents:
| ChestFullUpdate `465a5d73`, outer `(51017,bagID)` | SimpleItem version 11; parent `(50000,owner)`; playfield; auxiliary `(0,0)`; page/slot bytes; encoded stat pairs; extra-data length 0; Lockable version 2; lock field 0; empty identity list 1009; Chest version 3 |
| InventoryUpdate `4e536976`, outer `(50000,owner)` | Encoded 32-byte item rows; `(51017,bagID)`; container handle; open flag 1 |
-The explicit Chest stats are `23=99228,701=1,702=99228,703=99228`.
+The explicit Chest stats are `23=template,701=QL,702=template,703=template`.
SimpleItem has no XYZ/quaternion when it has a parent. ChestFullUpdate has no
corpse tail or animation list. Reader evidence:
`ev_275528c4a10136c1a2de368bd4bdbb1c2bf5c0b29f946a68808e609e47d9218d`.
@@ -73,7 +98,7 @@ Ordinary items without separate live objects use FullCharacter entry flag 1.
Flag 2 selects identity-object lookup; a visible icon alone does not instantiate
that object. Keeping an ordinary pistol at flag 2 made the server accept a put
while the client left its source row untouched. The native template branch moves
-the complete entry instead. The equipped Kinetic Axe and Small Backpack retain
+the complete entry instead. The equipped Kinetic Axe and portable Chests retain
flag 2, with separate WeaponItemFullUpdate/ChestFullUpdate object creation.
Template equipment such as armor and vehicles uses flag 1 even when worn.
Evidence for the flag test and both transfer branches:
@@ -91,7 +116,7 @@ Evidence:
## Persistence and boundaries
-The world database stores each backpack's contents as item locations. Its YAML
+The world database stores each portable container's contents as item locations. Its YAML
editor shows 21 named slots containing item IDs or null. Each item occurs in
exactly one location. Startup rejects orphan contents,
duplicate IDs/slots, nested bags, zero quantities and positions outside 0..20.
@@ -109,12 +134,22 @@ deletion and reclaim policy remains unverified; the persistence behavior here
must not be cited as historical proof.
The native slot bound and placement checks are established. Enforcement of the
-description's ten-kilogram limit was not recovered, so no new mass cap is
+catalog's kilogram limits was not recovered, so no new mass cap is
invented. Equipment moves currently pass through ordinary inventory first.
-Bag equipping, custom names, trades and other container templates
-remain separate features. As with other slot-addressed messages, the wire has
+Bag equipping, signed equipment effects, QL interpolation, custom names and
+trades remain separate features. As with other slot-addressed messages, the wire has
no operation token to identify every replay after later slot reuse.
+Filled containers on corpses keep their contents through periodic checkpoints.
+Pickup transfers the parent and every child in one transaction, preserving the
+global ID counter even when a child ID exceeds its parent's. A failed save leaves
+both ownership locations unchanged. Expiring an unlooted corpse destroys its
+container and children; expiry never removes a container already taken by a player.
+NoDrop containers remain on the player at death. Other containers retain their
+children in reclaim. These are current server persistence policies; the original
+server's filled-container death and deletion policies are not established by the
+native client code.
+
## Verification
`server/backpacks_test.go` exercises the actual world connection for opening and
@@ -147,3 +182,48 @@ The complete maintained suite, `go test ./server/... -count=1`, passed with
`ao/server` completing in 85.561 seconds.
The focused race run over backpacks, stacks, inventory, equipment, armor, attack
rating, overequipping, character stats, reclaim and combat passed in 137.165 seconds.
+
+## Portable container expansion verification
+
+`server/portable_containers_test.go` checks every one of the 37 authored portable
+records through the world handlers: opening metadata, FullCharacter identity
+flags, all 21 positions, overflow without success or loss, taking the last slot,
+transfers through a different container type, deletion, restart, death and reclaim.
+The NoDrop fixtures remain on the character. Fixed world Chests, unknown
+templates and spoofed instance/template types are rejected.
+
+`server/control_containers_test.go` creates and assigns every template through
+HTTP, fills its last slot, rejects nesting, follows the contained-item parent
+link and reloads the database. Container labels cover portable boxes as well as
+bags. `server/portable_container_loot_test.go` covers all 37 corpse pickups and
+filled-container checkpoint, failed transaction, expiry and post-pickup expiry
+cases. The red tests reproduced detached corpse contents and contents lost during
+pickup before the persistence fix.
+
+The complete `go test ./server/... -count=1` suite passed (`ao/server` 345.550s).
+The race detector passed the backpack, loot, filled-container and concurrent
+control ownership suites in 362.093s. The focused container lifecycle run passed
+in 62.552s, all-template control tests in 55.219s, and the final control wording
+checks in 7.778s.
+
+Two owned browser visitors exercised the published WASM client on the single
+normal HTTPS preview. All 37 templates opened native windows; read-only heap
+snapshots confirmed their separate identities and 21-slot inventories. Small,
+Medium and Large each loaded 21 pistols, and their final slots were taken without
+changing identity or quantity. A normal server restart preserved a pistol left
+in ordinary inventory. The restarted client put it into a Small Trunk and moved
+it directly into the Medium Backpack's final free slot. Small, Medium and Large each produced the native full-container rejection;
+retained source items and contents were checked in native memory. The final
+Small Backpack check used adjacent inventory positions and restored its
+temporary editor change in `finally` (`small-final-overflow-native.json`,
+`small-final.log` and an empty `small-final-errors.json`).
+
+`local/container-catalog-smoke/tmp_verify.py` compares the retained native
+snapshots with the exact fixture identities and locations, including all 63
+contained pistols. Fourteen checks passed. All 148 persisted item records and
+locations matched before and after the native round trip; the intermediate
+restart snapshots matched as well. Both owned browser sessions closed in
+`finally`, with no client exceptions or unimplemented adapter calls. Browser
+screenshots, JSON snapshots and verification results are retained in
+`local/container-catalog-smoke/`. The preview remained on HTTPS 8443 and the
+ordinary server ports throughout; no extra gameplay server was started.
diff --git a/docs/inventory-stacks.md b/docs/inventory-stacks.md
@@ -51,7 +51,7 @@ and `ev_d87a842dd8417af8e91dcb61a97596d71ff6fce8b6bca2b6110cdabd783afcc6`.
Stack mutations require inventory entry flag `0x1`. Essence and other template
items use flag 1, including worn template equipment. The equipped Kinetic Axe
-and Small Backpack use flag 2 for their separate live identities. Local split clones use
+and portable Chests use flag 2 for their separate live identities. Local split clones use
`0x21` and a zero instance identity. The row stores a ushort quantity at offset
6 and its QL/low/high triple at offsets 16/20/24. Persistent server IDs remain
owned state, while stack requests address page/slot and carry no new instance
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -48,8 +48,8 @@ Profile edits and zoning preserve inventory independently of profile fields.
Items use exact catalog qualities with identical template endpoints. Essence
of Pure Jealousy now supports persistent [native stacks](inventory-stacks.md),
including merge, split and rejected-split correction. Its historical server
-merge cap remains unresolved. [Small Backpack](backpacks.md) now provides its
-native 21-slot inventory and persistent contents. Arbitrary-quality interpolation
+merge cap remains unresolved. [All 37 portable containers](backpacks.md) now provide their
+native 21-slot inventories and persistent contents. Arbitrary-quality interpolation
and starter loadouts remain separate milestones. Native corpse pickup is
described in [the corpse and loot protocol](corpse-loot.md). QL 1 Kinetic Axe equipment
is described below. All six Metaplast families at exact QL 1/200 use the
@@ -78,7 +78,7 @@ two shorts, identity and template information. `sub_360011B0` in
The 14.9.1 conversion inserts its seventh list after the variable-length
inventory, rather than at an offset valid only for an empty list. Template
items use flag 1 even when worn, so native transfers and subsequent use do not
-require a separate live object. The equipped Kinetic Axe and Small Backpack
+require a separate live object. The equipped Kinetic Axe and portable Chests
use flag 2; their native object updates are sent separately. The
[backpack protocol](backpacks.md) explains this distinction.
diff --git a/docs/vehicles.md b/docs/vehicles.md
@@ -195,7 +195,7 @@ conversion and clothing flags passed in 96.323 seconds.
FullCharacter uses entry flag 1 for template equipment, including worn vehicles,
armor, implants, belts and NCU. Flag 2 denotes a separate live item identity;
-it is retained for the equipped Kinetic Axe and Small Backpack, whose object
+it is retained for the equipped Kinetic Axe and portable Chests, whose object
updates are sent separately. Worn template effects still initialize once.
Native `kkr.dll` possession helper `100619d0`, reached by UseItem `1002acd0`,
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -12,8 +12,11 @@ type backpackHandle struct {
open bool
}
-func (item ownedItem) isSmallBackpack() bool {
- return item.Type == 51017 && item.Template == 99228 && item.Quality == 1
+func (item ownedItem) isPortableContainer() bool {
+ definition := gamedata.ItemTemplates[item.Template]
+ // Owned Chest templates must support both Carry and Use; world chests do not.
+ return item.Type == 51017 && definition != nil && definition.HeaderWords[0] == 51017 &&
+ itemStat(definition, 30)&9 == 9
}
func backpackPacket(owner, playfield uint32, item ownedItem) []byte {
@@ -92,7 +95,7 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error
return nil
}
item := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool {
- return item.isSmallBackpack() && (page == 104 && item.Slot == slot || page == 51017 && item.ID == slot)
+ return item.isPortableContainer() && (page == 104 && item.Slot == slot || page == 51017 && item.ID == slot)
})
reply := append([]byte(nil), body[16:]...)
if item < 0 {
@@ -140,7 +143,7 @@ func (server *server) moveBackpackItem_locked(client *worldClient, body []byte)
items := inventory.Items
if sourcePage == 107 {
sourceBag = client.backpacks[sourceSlot>>16].id
- if sourceBag == 0 || !client.backpacks[sourceSlot>>16].open || !slices.ContainsFunc(inventory.Items, func(item ownedItem) bool { return item.ID == sourceBag && item.isSmallBackpack() }) {
+ if sourceBag == 0 || !client.backpacks[sourceSlot>>16].open || !slices.ContainsFunc(inventory.Items, func(item ownedItem) bool { return item.ID == sourceBag && item.isPortableContainer() }) {
return nil
}
sourceSlot &= 65535
@@ -160,7 +163,7 @@ func (server *server) moveBackpackItem_locked(client *worldClient, body []byte)
targetItems := inventory.Items
first, end := uint32(64), uint32(94)
if targetType == 51017 {
- if targetID == sourceBag || !slices.ContainsFunc(inventory.Items, func(item ownedItem) bool { return item.ID == targetID && item.isSmallBackpack() }) {
+ if targetID == sourceBag || !slices.ContainsFunc(inventory.Items, func(item ownedItem) bool { return item.ID == targetID && item.isPortableContainer() }) {
return nil
}
known := false
@@ -226,7 +229,7 @@ func (server *server) handleBackpackAction_locked(client *worldClient, body []by
position := binary.BigEndian.Uint32(body[24:28])
handle := client.backpacks[position>>16]
player := server.characters[client.id]
- if !client.target || !handle.open || !slices.ContainsFunc(player.inventory.Items, func(item ownedItem) bool { return item.ID == handle.id && item.isSmallBackpack() }) {
+ if !client.target || !handle.open || !slices.ContainsFunc(player.inventory.Items, func(item ownedItem) bool { return item.ID == handle.id && item.isPortableContainer() }) {
return nil
}
action := binary.BigEndian.Uint32(body[16:20])
diff --git a/server/control.go b/server/control.go
@@ -75,7 +75,7 @@ func (server *server) userPage(w http.ResponseWriter, r *http.Request) {
controlMap(w, data.ID)
fmt.Fprint(w, "<h2>Character data</h2><p>This YAML document edits the character in the world database. Slots contain item IDs or null. Saving reconnects an online character. ID is fixed; position is XYZ and rotation is XYZW.</p>")
fmt.Fprintf(w, "<form method='post' action='control/users/%d'><p><label>Character:<br><textarea name='data' rows='40' cols='100' required>%s</textarea></label></p><button>Save character</button></form>", data.ID, html.EscapeString(string(contents)))
- fmt.Fprint(w, "<p>Inventory uses inventory_slot_1 through inventory_slot_30; equipment uses named weapons, clothes and implants positions. Slots contain item IDs or null. Clearing a slot unassigns its item. <a href='control/items'>Browse and create item instances</a>. Backpack slots are edited on the backpack's item page. improvement_points is the available IP balance; native IP spending is not implemented.</p>")
+ fmt.Fprint(w, "<p>Inventory uses inventory_slot_1 through inventory_slot_30; equipment uses named weapons, clothes and implants positions. Slots contain item IDs or null. Clearing a slot unassigns its item. <a href='control/items'>Browse and create item instances</a>. Container slots are edited on the container's item page. improvement_points is the available IP balance; native IP spending is not implemented.</p>")
fmt.Fprint(w, itemTables.String())
fmt.Fprint(w, "</body></html>")
}
diff --git a/server/control_containers_test.go b/server/control_containers_test.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "strconv"
+ "strings"
+ "testing"
+)
+
+func TestControlPortableContainerCatalog(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ useNPCData(t, testNPCData())
+ world := newTestServer(t)
+ postControlForm(world, "/control/users", url.Values{"name": {"Explorer"}})
+ for _, template := range []uint32{container.template, 121567, 99241} {
+ response := postControlForm(world, "/control/items", url.Values{"template": {strconv.FormatUint(uint64(template), 10)}})
+ if response.Code != http.StatusSeeOther {
+ t.Fatal(response.Body.String())
+ }
+ }
+
+ assigned := postControlForm(world, "/control/items/1", url.Values{"action": {"assign"}, "owner": {"1"}, "destination": {"0:64"}})
+ filled := postControlForm(world, "/control/items/2", url.Values{"action": {"assign"}, "owner": {"1"}, "destination": {"1:20"}})
+ nested := postControlForm(world, "/control/items/3", url.Values{"action": {"assign"}, "owner": {"1"}, "destination": {"1:0"}})
+ page, child := httptest.NewRecorder(), httptest.NewRecorder()
+ world.httpHandler().ServeHTTP(page, httptest.NewRequest("GET", "/control/users/1", nil))
+ world.httpHandler().ServeHTTP(child, httptest.NewRequest("GET", "/control/items/2", nil))
+ restarted := newTestInventoryServer(t)
+
+ if assigned.Code != http.StatusSeeOther || filled.Code != http.StatusSeeOther || nested.Code != http.StatusBadRequest {
+ t.Fatal("container placement, final slot or nesting check failed", assigned.Code, filled.Code, nested.Code)
+ }
+ if !strings.Contains(page.Body.String(), fmt.Sprintf("<h2>Container <a href='control/items/1'>%s (ID 1)</a></h2>", container.name)) ||
+ !strings.Contains(page.Body.String(), "<tr><td>slot_21</td><td><a href='control/items/2'>Solar-Powered Pistol (ID 2)</a></td></tr>") ||
+ !strings.Contains(child.Body.String(), "<a href='control/items/1'>Container 1, slot_21</a>") {
+ t.Fatal("container table or contained item parent link missing")
+ }
+ contents := restarted.characters[1].inventory.Containers[1]
+ if len(contents) != 1 || contents[0].ID != 2 || contents[0].Slot != 20 || len(restarted.items[1].Slots) != 21 || restarted.items[3].Template != 99241 {
+ t.Fatal("control placement or rejected nesting lost items on restart")
+ }
+ })
+ }
+}
diff --git a/server/control_data_test.go b/server/control_data_test.go
@@ -106,7 +106,7 @@ func TestControlItemsShareOneRegistryAndShowOwnersAndBackpackContents(t *testing
t.Fatalf("slot references lost their items: %+v", inventory)
}
if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), "Solar-Powered Pistol") || !strings.Contains(page.Body.String(), "Explorer (1)") ||
- !strings.Contains(page.Body.String(), "Backpack 2, slot_1") || !strings.Contains(page.Body.String(), "href='control/items/3'") {
+ !strings.Contains(page.Body.String(), "Container 2, slot_1") || !strings.Contains(page.Body.String(), "href='control/items/3'") {
t.Fatalf("item list: %d %s", page.Code, page.Body.String())
}
if details.Code != http.StatusOK || !strings.Contains(details.Body.String(), "Instance properties") || !strings.Contains(details.Body.String(), "Catalog properties") {
diff --git a/server/control_inventory.go b/server/control_inventory.go
@@ -54,12 +54,12 @@ func (server *server) inventoryTables_locked(w io.Writer, inventory playerInvent
fmt.Fprint(w, "</table>")
}
- // Include every owned backpack, including bags waiting in reclaim.
+ // Include every owned container, including those waiting in reclaim.
for _, item := range inventory.allItems() {
if len(server.items[item.ID].Slots) == 0 {
continue
}
- fmt.Fprintf(w, "<h2>Backpack <a href='control/items/%d'>%s (ID %d)</a></h2>", item.ID,
+ fmt.Fprintf(w, "<h2>Container <a href='control/items/%d'>%s (ID %d)</a></h2>", item.ID,
html.EscapeString(gamedata.ItemTemplates[item.Template].Name), item.ID)
server.backpackTable_locked(w, server.items[item.ID])
}
diff --git a/server/control_inventory_test.go b/server/control_inventory_test.go
@@ -76,7 +76,7 @@ func TestControlInventoryTablesShowInstancesContainersAndEmptySlots(t *testing.T
"<base href='/share/test/'>", "<textarea name='data'", "<h2>Inventory</h2>", "<h2>Equipment</h2>",
"<tr><td>inventory_slot_1</td><td><a href='control/items/1'>Solar-Powered Pistol (ID 1)</a></td></tr>",
"<tr><td>clothes_head</td><td><a href='control/items/2'>Worn Metaplast Armor Helmet (ID 2)</a></td></tr>",
- "<h2>Backpack <a href='control/items/3'>Small Backpack (ID 3)</a></h2>",
+ "<h2>Container <a href='control/items/3'>Small Backpack (ID 3)</a></h2>",
"<tr><td>slot_1</td><td><a href='control/items/4'>Solar-Powered Pistol (ID 4)</a></td></tr>",
"<tr><td>slot_21</td><td>Empty</td></tr>",
} {
@@ -102,7 +102,7 @@ func TestControlBackpackPagesLinkContentsAndParentContainer(t *testing.T) {
!strings.Contains(bag.Body.String(), "<a href='control/users/1'>Explorer (1)</a>") {
t.Fatal("backpack page lost its owner or readable contents")
}
- if !strings.Contains(child.Body.String(), "<a href='control/items/3'>Backpack 3, slot_1</a>") {
+ if !strings.Contains(child.Body.String(), "<a href='control/items/3'>Container 3, slot_1</a>") {
t.Fatal("contained item has no link to its parent backpack")
}
}
@@ -187,7 +187,7 @@ func TestControlInventoryTablesIncludeReclaimAndItsBackpackContents(t *testing.T
if !strings.Contains(page.Body.String(), "<h2>Reclaim</h2>") ||
!strings.Contains(page.Body.String(), "<tr><td>inventory_slot_2</td><td><a href='control/items/3'>Small Backpack (ID 3)</a></td></tr>") ||
- !strings.Contains(page.Body.String(), "<h2>Backpack <a href='control/items/3'>Small Backpack (ID 3)</a></h2>") ||
+ !strings.Contains(page.Body.String(), "<h2>Container <a href='control/items/3'>Small Backpack (ID 3)</a></h2>") ||
!strings.Contains(page.Body.String(), "<tr><td>slot_1</td><td><a href='control/items/4'>Solar-Powered Pistol (ID 4)</a></td></tr>") {
t.Fatal("reclaim hides an assigned item or its backpack contents")
}
diff --git a/server/control_items.go b/server/control_items.go
@@ -19,7 +19,7 @@ func controlItemSlots(inventory playerInventory, item ownedItem) []controlItemSl
}
if item.Type != 51017 {
for _, bag := range inventory.Items {
- if !bag.isSmallBackpack() {
+ if !bag.isPortableContainer() {
continue
}
for slot := uint32(0); slot < 21; slot++ {
diff --git a/server/inventory.go b/server/inventory.go
@@ -57,7 +57,7 @@ func (inventory playerInventory) validate() error {
return fmt.Errorf("invalid inventory item identity or slot")
}
ids[item.ID], slots[item.Slot] = true, true
- if item.isSmallBackpack() {
+ if item.isPortableContainer() {
bags[item.ID] = true
}
}
@@ -73,7 +73,7 @@ func (inventory playerInventory) validate() error {
return fmt.Errorf("invalid reclaim item identity or slot")
}
ids[entry.Item.ID] = true
- if entry.Item.isSmallBackpack() {
+ if entry.Item.isPortableContainer() {
bags[entry.Item.ID] = true
}
}
@@ -221,7 +221,7 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
return nil
}
inventory.Items = slices.Delete(inventory.Items, index, index+1)
- if character.inventory.Items[index].isSmallBackpack() {
+ if character.inventory.Items[index].isPortableContainer() {
inventory.Containers = maps.Clone(inventory.Containers)
delete(inventory.Containers, character.inventory.Items[index].ID)
if len(inventory.Containers) == 0 {
diff --git a/server/item_database.go b/server/item_database.go
@@ -180,7 +180,7 @@ func (server *server) readItems() (itemStore, error) {
rows.Close()
return store, err
}
- if (ownedItem{Type: record.Type, Template: record.Template, Quality: record.Quality}).isSmallBackpack() {
+ if (ownedItem{Type: record.Type, Template: record.Template, Quality: record.Quality}).isPortableContainer() {
record.Slots = emptyItemSlots(21)
}
store.Items[id] = record
diff --git a/server/item_pages.go b/server/item_pages.go
@@ -64,7 +64,7 @@ func (server *server) itemLocations_locked() map[uint32]itemLocation {
for id, record := range server.items {
for slot, contained := range record.Slots {
if contained != nil {
- locations[*contained] = itemLocation{locations[id].owner, id, fmt.Sprintf("Backpack %d, %s", id, slot)}
+ locations[*contained] = itemLocation{locations[id].owner, id, fmt.Sprintf("Container %d, %s", id, slot)}
}
}
}
@@ -249,7 +249,7 @@ func (server *server) itemPage(w http.ResponseWriter, r *http.Request) {
for _, destination := range controlItemSlots(selectedInventory, item) {
label := equipmentSlots[destination.slot]
if destination.bag != 0 {
- label = fmt.Sprintf("Backpack %d, slot_%d", destination.bag, destination.slot+1)
+ label = fmt.Sprintf("Container %d, slot_%d", destination.bag, destination.slot+1)
} else if destination.slot >= 64 {
label = fmt.Sprintf("inventory_slot_%d", destination.slot-63)
}
@@ -258,7 +258,7 @@ func (server *server) itemPage(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "</select></label> <button>Assign item</button></form>")
}
}
- fmt.Fprintf(w, "<h2>Instance properties</h2><p>ID %d is fixed. Slots contain instance IDs or null; backpacks have 21 slots. Saving reconnects the owner.</p><form method='post' action='control/items/%d'><textarea name='data' rows='25' cols='80' required>%s</textarea><p><button>Save item</button></p></form>", id, id, html.EscapeString(string(contents)))
+ fmt.Fprintf(w, "<h2>Instance properties</h2><p>ID %d is fixed. Slots contain instance IDs or null; containers have 21 slots. Saving reconnects the owner.</p><form method='post' action='control/items/%d'><textarea name='data' rows='25' cols='80' required>%s</textarea><p><button>Save item</button></p></form>", id, id, html.EscapeString(string(contents)))
if contentsTable.Len() != 0 {
fmt.Fprint(w, "<h2>Contents</h2>", contentsTable.String())
}
diff --git a/server/item_store.go b/server/item_store.go
@@ -75,7 +75,7 @@ func (inventory playerInventory) references() characterItemReferences {
func recordItem(item ownedItem, contents []ownedItem) itemRecord {
record := itemRecord{Type: item.Type, Template: item.Template, Quality: item.Quality, Count: item.Count, Ammo: item.Ammo}
- if item.isSmallBackpack() {
+ if item.isPortableContainer() {
record.Slots = emptyItemSlots(21)
for _, contained := range contents {
record.Slots[fmt.Sprintf("slot_%d", contained.Slot+1)] = &contained.ID
@@ -146,7 +146,7 @@ func (references characterItemReferences) inventory(records map[uint32]itemRecor
inventory.Reclaim = append(inventory.Reclaim, reclaimItem{ownedItem{ID: entry.ID, Type: record.Type, Template: record.Template, Quality: record.Quality, Slot: slot, Count: record.Count, Ammo: record.Ammo}, entry.AvailableAt})
}
for _, item := range append(slices.Clone(inventory.Items), reclaimItems(inventory.Reclaim)...) {
- if !item.isSmallBackpack() {
+ if !item.isPortableContainer() {
continue
}
contents, err := referencedItems(records[item.ID].Slots, 0, 21, records)
@@ -185,7 +185,11 @@ func (server *server) itemStore_locked(character *character, inventory playerInv
if player.npc && player.corpse != nil {
store.Corpses[id] = player.corpse.items
for _, item := range player.corpse.items {
- store.Items[item.ID] = recordItem(item, nil)
+ record := recordItem(item, nil)
+ if item.isPortableContainer() {
+ record.Slots = maps.Clone(server.items[item.ID].Slots)
+ }
+ store.Items[item.ID] = record
store.LastID = max(store.LastID, item.ID)
}
}
@@ -211,6 +215,11 @@ func (server *server) itemStore_locked(character *character, inventory playerInv
for id, placement := range server.itemPlacements {
if placement.Corpse != 0 {
if _, present := store.Corpses[placement.Corpse]; !present && !claimed[id] {
+ for _, contained := range store.Items[id].Slots {
+ if contained != nil {
+ delete(store.Items, *contained)
+ }
+ }
delete(store.Items, id)
}
}
@@ -222,9 +231,9 @@ func (server *server) writeItemStore_locked(store itemStore) error {
if err := store.validate(); err != nil {
return err
}
- // Materialize every backpack slot even when an editor submitted only occupied ones.
+ // Materialize every container slot even when an editor submitted only occupied ones.
for id, record := range store.Items {
- if (ownedItem{Type: record.Type, Template: record.Template, Quality: record.Quality}).isSmallBackpack() {
+ if (ownedItem{Type: record.Type, Template: record.Template, Quality: record.Quality}).isPortableContainer() {
slots := emptyItemSlots(21)
maps.Copy(slots, record.Slots)
record.Slots = slots
@@ -301,7 +310,7 @@ func (store itemStore) validate() error {
if id == 0 || id > store.LastID || item.Count == 0 || !item.validAmmo() || item.Count != 1 && !item.isStackable() {
return fmt.Errorf("invalid item instance %d", id)
}
- if len(record.Slots) != 0 && !item.isSmallBackpack() {
+ if len(record.Slots) != 0 && !item.isPortableContainer() {
return fmt.Errorf("item %d cannot contain slots", id)
}
contents, err := referencedItems(record.Slots, 0, 21, store.Items)
diff --git a/server/loot.go b/server/loot.go
@@ -3,6 +3,7 @@ package main
import (
"ao/server/gamedata"
"encoding/binary"
+ "maps"
"math"
"slices"
"time"
@@ -197,8 +198,21 @@ func (server *server) takeLoot_locked(client *worldClient, body []byte) error {
item := corpse.corpse.items[index]
item.Slot = slot
inventory := player.inventory
- inventory.LastID = max(player.inventory.LastID, item.ID)
+ inventory.LastID = max(player.inventory.LastID, server.nextItem, item.ID)
inventory.Items = append(slices.Clone(player.inventory.Items), item)
+ if item.isPortableContainer() {
+ contents, err := referencedItems(server.items[item.ID].Slots, 0, 21, server.items)
+ if err != nil {
+ return err
+ }
+ if len(contents) != 0 {
+ inventory.Containers = maps.Clone(player.inventory.Containers)
+ if inventory.Containers == nil {
+ inventory.Containers = make(map[uint32][]ownedItem)
+ }
+ inventory.Containers[item.ID] = contents
+ }
+ }
previous := corpse.corpse.items
corpse.corpse.items = slices.Delete(slices.Clone(previous), index, index+1)
if err := server.saveInventory_locked(player, inventory); err != nil {
diff --git a/server/portable_container_loot_test.go b/server/portable_container_loot_test.go
@@ -0,0 +1,122 @@
+package main
+
+import (
+ "bytes"
+ "reflect"
+ "testing"
+ "time"
+
+ "ao/server/gamedata"
+)
+
+func newFilledLootContainerWorld(t *testing.T, template uint32) *server {
+ t.Helper()
+ world, _ := newLootWorld(t)
+ bag := ownedItem{ID: 17, Type: 51017, Template: template, Quality: *gamedata.ItemTemplates[template].Quality, Count: 1}
+ contained := ownedItem{ID: 18, Type: 51005, Template: 152030, Quality: 42, Count: 3}
+ world.characters[1000000].corpse.items = []ownedItem{bag}
+ store := itemStore{
+ LastID: 18,
+ Items: map[uint32]itemRecord{17: recordItem(bag, []ownedItem{contained}), 18: recordItem(contained, nil)},
+ Players: map[uint32]characterItemReferences{1: world.characters[1].inventory.references()},
+ Corpses: map[uint32][]ownedItem{1000000: {bag}},
+ }
+ if err := world.writeItemStore_locked(store); err != nil {
+ t.Fatal(err)
+ }
+ return world
+}
+
+func TestFilledLootContainerContentsSurviveCheckpoint(t *testing.T) {
+ world := newFilledLootContainerWorld(t, 99241)
+
+ err := world.checkpointWorld(time.Now())
+ restarted := newTestInventoryServer(t)
+ var bag, slot uint32
+ locationErr := restarted.db.QueryRow("SELECT backpack_id, slot FROM item_locations WHERE item_id=18").Scan(&bag, &slot)
+
+ if err != nil || locationErr != nil || bag != 17 || slot != 0 || len(restarted.items) != 2 || restarted.items[18].Count != 3 {
+ t.Fatalf("checkpoint detached corpse-container contents: bag %d, slot %d, %v, %v", bag, slot, err, locationErr)
+ }
+}
+
+func TestPortableContainerLootRetainsContentsAndCounter(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world := newFilledLootContainerWorld(t, container.template)
+ client := world.clients[1]
+
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ err := world.handleInventory(client, lootTakeRequest())
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || len(restarted.items) != 2 || restarted.nextItem != 18 || len(world.characters[1000000].corpse.items) != 0 {
+ t.Fatalf("container pickup lost identities or source ownership: %v", err)
+ }
+ inventory := restarted.characters[1].inventory
+ if !reflect.DeepEqual(inventory.Items, []ownedItem{{ID: 17, Type: 51017, Template: container.template, Quality: container.quality, Slot: 64, Count: 1}}) ||
+ !reflect.DeepEqual(inventory.Containers[17], []ownedItem{{ID: 18, Type: 51005, Template: 152030, Quality: 42, Slot: 0, Count: 3}}) {
+ t.Fatalf("container pickup lost contents: %+v", inventory)
+ }
+ })
+ }
+}
+
+func TestFilledLootContainerPickupFailurePreservesBothLocations(t *testing.T) {
+ world := newFilledLootContainerWorld(t, 143832)
+ client := world.clients[1]
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER reject_container_loot BEFORE UPDATE ON world BEGIN SELECT RAISE(ABORT, 'write failed'); END"); err != nil {
+ t.Fatal(err)
+ }
+
+ err = world.handleInventory(client, lootTakeRequest())
+ after, readErr := readTestItemStore(world)
+
+ if err == nil || readErr != nil || !bytes.Equal(before, after) || len(world.characters[1].inventory.Items) != 0 ||
+ len(world.characters[1000000].corpse.items) != 1 || world.items[17].Slots["slot_1"] == nil || *world.items[17].Slots["slot_1"] != 18 {
+ t.Fatal("failed pickup moved the bag or its contents", err, readErr)
+ }
+}
+
+func TestFilledLootContainerExpiryRemovesContents(t *testing.T) {
+ world := newFilledLootContainerWorld(t, 143832)
+ corpse := world.characters[1000000]
+ world.corpseExpiry = []*character{corpse}
+ expires := corpse.corpse.expiresAt
+
+ world.advanceCorpseExpiry(expires)
+ err := world.checkpointWorld(expires)
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || len(restarted.items) != 0 || restarted.nextItem != 18 {
+ t.Fatal("expired container left recoverable orphan contents or reused IDs", err)
+ }
+}
+
+func TestLootedContainerContentsSurviveOldCorpseExpiry(t *testing.T) {
+ world := newFilledLootContainerWorld(t, 143832)
+ corpse := world.characters[1000000]
+ world.corpseExpiry = []*character{corpse}
+ expires := corpse.corpse.expiresAt
+ world.handleLootUse(world.clients[1], lootUseRequest(1))
+ if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+
+ world.advanceCorpseExpiry(expires)
+ err := world.checkpointWorld(expires)
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || len(restarted.items) != 2 || len(restarted.characters[1].inventory.Containers[17]) != 1 || restarted.items[18].Count != 3 {
+ t.Fatal("old corpse expiry removed a looted bag or its contents", err)
+ }
+}
diff --git a/server/portable_containers_test.go b/server/portable_containers_test.go
@@ -0,0 +1,263 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "reflect"
+ "slices"
+ "testing"
+ "time"
+)
+
+// Portable Chest records in the shipped 14.9.1 catalog.
+var portableContainerCatalog = []struct {
+ template uint32
+ quality uint32
+ name string
+}{
+ {23143, 1, "Small Trunk"},
+ {23147, 1, "Cardboard Box"},
+ {23149, 1, "Light Plasteel Barrel"},
+ {23151, 1, "Worn Crate"},
+ {23153, 1, "Bag"},
+ {23155, 1, "Old Barrel"},
+ {23157, 1, "Small Box"},
+ {23159, 1, "Large Metal Box"},
+ {23161, 1, "Small Jar"},
+ {99228, 1, "Small Backpack"},
+ {99241, 1, "Medium Backpack"},
+ {99302, 1, "Book of Knowledge"},
+ {143832, 1, "Large Backpack"},
+ {152039, 1, "The Pioneer Backpack"},
+ {156831, 1, "The Pioneer Backpack (Modified Version)"},
+ {157682, 1, "Large Backpack - Sharp Star"},
+ {157683, 1, "Large Backpack - Mountain Top"},
+ {157684, 1, "Large Backpack - Black Button"},
+ {157685, 1, "Large Backpack - Sniper"},
+ {157686, 1, "Large Backpack - Cold Front"},
+ {157687, 1, "Large Backpack - Swimmer"},
+ {157688, 1, "Large Backpack - Speeder"},
+ {157689, 1, "Large Backpack - Clothing"},
+ {157690, 1, "Large Backpack - Weapons"},
+ {157691, 1, "Large Backpack - Implants"},
+ {157692, 1, "Large Backpack - Medical"},
+ {157693, 1, "Large Backpack - Nano Crystals"},
+ {157694, 1, "Large Backpack - Trash"},
+ {157695, 1, "Large Backpack - Vehicles"},
+ {158790, 1, "Robust Backpack"},
+ {164564, 140, "Notum Threaded Backpack"},
+ {165201, 200, "Beeping Backpack"},
+ {168658, 200, "Pre-Universe Storage Device"},
+ {200461, 200, "Dust Collector"},
+ {206730, 50, "Backpack of Survival"},
+ {206731, 150, "Backpack of Survival"},
+ {207254, 1, "Personal Backpack"},
+}
+
+func newPortableContainerWorld(t *testing.T, template uint32) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newStackWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ for _, id := range []uint32{template, 121567} {
+ if granted, err := world.grantItem_locked(world.characters[1], id); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ return world, conn
+}
+
+func TestPortableContainerCatalogOpensWithAuthoredMetadata(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world, conn := newPortableContainerWorld(t, container.template)
+
+ err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 66, 1)[20:])
+ restarted := newTestInventoryServer(t)
+ packet := targetPacket(fullCharacterPacket(restarted.characters[1]))
+
+ if err != nil || len(conn.packets) != 3 || world.clients[1].backpacks[1] != (backpackHandle{3, true}) {
+ t.Fatalf("container did not open: %v, %d packets", err, len(conn.packets))
+ }
+ if binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x465a5d73 ||
+ !bytes.Contains(conn.packets[1], binary.BigEndian.AppendUint32(binary.BigEndian.AppendUint32(nil, 701), container.quality)) ||
+ !bytes.Contains(conn.packets[1], binary.BigEndian.AppendUint32(binary.BigEndian.AppendUint32(nil, 702), container.template)) {
+ t.Fatal("Chest update lost its authored template or quality")
+ }
+ if len(restarted.items[3].Slots) != 21 || restarted.items[3].Template != container.template || restarted.items[3].Quality != container.quality ||
+ binary.BigEndian.Uint16(packet[105:107]) != 2 {
+ t.Fatal("container lost its slots, live identity or metadata on reload")
+ }
+ })
+ }
+}
+
+func TestPortableContainerCapacityOverflowAndLastSlot(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world, conn := newPortableContainerWorld(t, container.template)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ for range 21 {
+ if err := world.handleInventory(client, backpackMoveRequest(104, 67, 51017, 3, 111)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 121567); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ packets := len(conn.packets)
+
+ err = world.handleInventory(client, backpackMoveRequest(104, 67, 51017, 3, 111)[20:])
+ after, readErr := readTestItemStore(world)
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || readErr != nil || !bytes.Equal(before, after) || len(conn.packets) != packets {
+ t.Fatal("overflow changed item accounting or sent success", err, readErr)
+ }
+ contents := restarted.characters[1].inventory.Containers[3]
+ if len(contents) != 21 || contents[20] != (ownedItem{ID: 24, Type: 51018, Template: 121567, Quality: 1, Slot: 20, Count: 1}) ||
+ len(restarted.characters[1].inventory.Items) != 4 {
+ t.Fatalf("full capacity did not persist: %+v", contents)
+ }
+ if err := world.handleInventory(client, backpackMoveRequest(107, 1<<16|20, 50000, 1, 111)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if len(player.inventory.Containers[3]) != 20 || !slices.Contains(player.inventory.Items, ownedItem{ID: 24, Type: 51018, Template: 121567, Quality: 1, Slot: 68, Count: 1}) {
+ t.Fatal("last contents slot could not be taken without loss")
+ }
+ })
+ }
+}
+
+func TestPortableContainerTransfersBetweenDifferentTypes(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world, _ := newPortableContainerWorld(t, container.template)
+ client := world.clients[1]
+ if granted, err := world.grantItem_locked(world.characters[1], 99241); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 68, 2)[20:])
+
+ for _, request := range [][]byte{
+ backpackMoveRequest(104, 67, 51017, 3, 111),
+ backpackMoveRequest(107, 1<<16, 51017, 5, 111),
+ backpackMoveRequest(107, 2<<16, 50000, 1, 111),
+ } {
+ if err := world.handleInventory(client, request[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ restarted := newTestInventoryServer(t)
+
+ inventory := restarted.characters[1].inventory
+ if len(inventory.Containers) != 0 || len(inventory.Items) != 5 ||
+ !slices.Contains(inventory.Items, ownedItem{ID: 4, Type: 51018, Template: 121567, Quality: 1, Slot: 67, Count: 1}) ||
+ restarted.items[3].Template != container.template || restarted.items[5].Template != 99241 {
+ t.Fatal("cross-container transfers changed instances or lost contents")
+ }
+ })
+ }
+}
+
+func TestPortableContainerDeletionIncludesContents(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world, _ := newPortableContainerWorld(t, container.template)
+ client := world.clients[1]
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleInventory(client, backpackMoveRequest(104, 67, 51017, 3, 111)[20:])
+ request := inventoryDeletePacket(1, 66)[20:]
+ binary.BigEndian.PutUint32(request[28:32], container.template)
+ binary.BigEndian.PutUint32(request[32:36], container.template)
+
+ err := world.handleInventory(client, request)
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || len(restarted.items) != 2 || len(restarted.characters[1].inventory.Items) != 2 ||
+ len(restarted.characters[1].inventory.Containers) != 0 || len(client.backpacks) != 0 || restarted.nextItem != 4 {
+ t.Fatal("container deletion left contents, a handle or reused identities", err)
+ }
+ })
+ }
+}
+
+func TestPortableContainerContentsFollowDeathAndReclaim(t *testing.T) {
+ for _, container := range portableContainerCatalog {
+ t.Run(container.name, func(t *testing.T) {
+ world, _ := newPortableContainerWorld(t, container.template)
+ player, client := world.characters[1], world.clients[1]
+ player.level = 10
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleInventory(client, backpackMoveRequest(104, 67, 51017, 3, 111)[20:])
+
+ defeatReclaimPlayer(t, world)
+ restarted := newTestInventoryServer(t)
+ noDrop := slices.Contains([]uint32{165201, 168658, 200461, 207254}, container.template)
+
+ if !reflect.DeepEqual(restarted.characters[1].inventory.Containers[3], []ownedItem{{ID: 4, Type: 51018, Template: 121567, Quality: 1, Slot: 0, Count: 1}}) {
+ t.Fatal("death lost the container's contents")
+ }
+ kept := slices.ContainsFunc(restarted.characters[1].inventory.Items, func(item ownedItem) bool { return item.ID == 3 })
+ if kept != noDrop {
+ t.Fatal("container did not follow its authored NoDrop flag")
+ }
+ if noDrop {
+ return
+ }
+ player.health = player.maximumHealth()
+ player.playfield, player.position = 705, [3]float32{918, 20.7, 578}
+ for index := range player.inventory.Reclaim {
+ player.inventory.Reclaim[index].AvailableAt = time.Now().Add(-time.Second)
+ }
+ world.handleReclaim(client, reclaimRequest(109))
+ slot := slices.Index(client.reclaimItems, uint32(3))
+ if slot < 0 {
+ t.Fatal("container did not enter reclaim")
+ }
+ if err := world.handleInventory(client, reclaimTakeRequest(uint32(slot))); err != nil {
+ t.Fatal(err)
+ }
+ if len(player.inventory.Containers[3]) != 1 || !slices.Contains(player.inventory.Items,
+ ownedItem{ID: 3, Type: 51017, Template: container.template, Quality: container.quality, Slot: 64, Count: 1}) {
+ t.Fatal("reclaim lost the container or its contents")
+ }
+ })
+ }
+}
+
+func TestPortableContainerRejectsWorldChestsAndSpoofedTypes(t *testing.T) {
+ for _, scenario := range []struct {
+ template uint32
+ itemType uint32
+ }{
+ {23163, 51017}, // Fixed world Barrel has Use without Carry.
+ {212906, 51017}, // Fixed world Box.
+ {121567, 51017}, // Weapon template with a forged Chest identity.
+ {99241, 51022}, // Container template with a forged armor identity.
+ {999999, 51017},
+ } {
+ t.Run(fmt.Sprint(scenario.template), func(t *testing.T) {
+ world, conn := newPortableContainerWorld(t, 99228)
+ world.characters[1].inventory.Items[2].Template = scenario.template
+ world.characters[1].inventory.Items[2].Type = scenario.itemType
+
+ err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 66, 1)[20:])
+
+ if err != nil || len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 || len(world.clients[1].backpacks) != 0 {
+ t.Fatal("invalid container opened or did not reject cleanly", err)
+ }
+ })
+ }
+}
diff --git a/server/world.go b/server/world.go
@@ -175,7 +175,7 @@ func fullCharacterPacket(character *character) []byte {
body = binary.BigEndian.AppendUint32(body, uint32(len(character.inventory.Items)+1)*1009)
for _, item := range character.inventory.Items {
flags := uint32(1)
- if item.isSmallBackpack() || (item.isKineticAxe() || item.isFlechettePistol()) && item.Slot == 6 {
+ if item.isPortableContainer() || (item.isKineticAxe() || item.isFlechettePistol()) && item.Slot == 6 {
flags = 2
}
for _, value := range []uint32{item.Slot, flags<<16 | uint32(item.Count), item.Type, item.ID, item.Template, item.Template, item.Quality, 0} {