aorecomp

Anarchy Online classic in the browser

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


commit 2e20e2860492e817907f4b41a84b9e0657d73a42
parent 55221305f42639a8369c32b25295a780d266f707
Author: anon <anon@example.com>
Date:   Fri, 23 Oct 2026 13:56:28 +0000

Support complete Metaplast sets and restore rejected equipment drags

Diffstat:
MTODO.md | 50++++++++++++++++++++++++++++++++++++++++++++++++--
Mdocs/armor.md | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mdocs/inventory.md | 24+++++++++++++++++++++++-
Mdocs/ranged-weapons.md | 13+++++++------
Mserver/equipment.go | 54+++++++++++++++++++++++++++++++++++++++---------------
Mserver/equipment_test.go | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mserver/flying_vehicle_test.go | 4++--
Mserver/inventory.go | 2+-
Aserver/metaplast_test.go | 218+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/vehicle_test.go | 4++--
10 files changed, 484 insertions(+), 50 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -55,6 +55,11 @@ 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 + 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. Essence of Pure Jealousy now supports persistent native splitting and merging. The historical merge cap remains unresolved, so the merge item stays open; @@ -78,6 +83,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). exactly once and unequipping restores the baseline. - [x] Combine two equipment bonuses to the same stat. Check: removing either item leaves precisely the other item's contribution. +- [x] Equip the complete Metaplast set at both shipped QL endpoints. Check: + helmet, body, two sleeves, gloves, pants and boots use their authored slots, + requirements, effects and delays; each instance survives removal, reconnect + and restart, and unsupported equipment is explicitly rejected. +- [ ] Interpolate one armor family's intermediate qualities. Check: native + template endpoints, requirements, AC and visuals agree at representative + qualities and rounding boundaries, including after equip/remove and restart. - [x] Equip one implant. Check: its slot, treatment/ability requirements and bonuses work independently of armor and weapon slots. - [x] Equip one belt. Check: the corresponding deck slots become available and @@ -283,6 +295,11 @@ checks are recorded in [treatment kits](docs/treatment-kit.md). ## Shops +- [ ] Support shop vending machines. Check: using a shipped terminal opens + its native shop window with the correct stock and prices; purchases preserve + credits and item identity atomically, and insufficient credits or inventory + space leaves both unchanged. Cover vending-machine types and access rules + separately from NPC vendors, including reconnect and restart. - [ ] Browse one vendor's fixed stock. Check: the native shop window displays the expected items, QLs and prices without transferring ownership. - [ ] Buy one item. Check: credits and inventory change together; insufficient @@ -484,6 +501,16 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah ## Complete coverage beyond first examples +- [ ] Show readable item tables below the control panel's character YAML editor. + Check: inventory and equipment rows show slot, item name and a link to the + exact item instance; empty slots are clear, and the YAML remains editable. + Include backpack contents with links to their container and item instances, + so every assigned item can be found without looking up numeric IDs manually. +- [ ] Clarify inventory, equipment and backpack structure in the control panel. + Check: the character YAML has top-level equipment separate from the ordinary + inventory slots. Backpack instances expose their own contents on their item + pages, with clear navigation from the owning character and the readable tables. + Update validation and editor round-trip tests; no legacy YAML reader is needed. - [ ] Audit the complete 14.9.1 server-facing action set. Check: native requests, catalog action/effect types and player-facing systems have an evidence-based coverage record; each missing handler, silent no-op or provisional rule has @@ -555,8 +582,16 @@ and server restarts. Turn every reproduced bug into a focused regression test. - [ ] Reproduce and resolve disappearing equipment. Check: create and assign items, then equip/unequip them through the native client; every instance is accounted for in inventory, equipment or an explicit rejection, including - after reconnect and restart. The earlier player report is unconfirmed on the - current build and must not be dismissed solely because Go tests pass. + after reconnect and restart. The rejected-drag defect below is reproduced and + fixed; continue auditing other paths rather than treating that one fix or + passing Go tests as proof that the entire earlier report is resolved. +- [x] Restore the inventory icon after a rejected equipment drag. Check: native + pickup/place and auto-equip of unsupported armor leave its icon usable and + its instance/slot unchanged. Repeated rejection preserves the worn suit's AC; + correction packets conserve every instance even with a full inventory. + The same-slot acknowledgement skipped a native GUI notification; see + [inventory correction](docs/inventory.md#native-messages). Other equipment + acceptance/rejection scenarios remain part of the open audits. - [ ] Audit equipment acceptance and rejection. Cover every supported item and slot, unsuitable slots, unsupported catalog equipment, insufficient skills, locked slots, occupied destinations, swaps, repeated actions, interruptions, @@ -601,6 +636,11 @@ and server restarts. Turn every reproduced bug into a focused regression test. - [ ] Audit disconnects, retries and failure handling across these features. Cover transport replacement, stale sessions, action replay, database failures and concurrent requests; success must follow the durable significant change. +- [ ] Coordinate background checkpoints with server shutdown. Check: shutdown + commits current durable state and stops simulation/checkpoint writers before + closing SQLite; normal restarts produce no late `database is closed` errors. + Repeated preview-server shutdowns currently log this error from the periodic + world saver, despite the final flush completing. - [ ] Run a repeatable two-client WASM regression scenario through the complete supported gameplay loop. Record visible item accounting, combat feedback, page errors, adapter failures and cleanup, alongside automated test results. @@ -608,6 +648,12 @@ and server restarts. Turn every reproduced bug into a focused regression test. Cover leaving/returning to the tab, opening/closing options or chat, held keys/modifiers, repeats, reconnect and slow frames. Compare the first input after each transition and the final selected target in the UI and server. +- [ ] Prevent browser wheel camera gestures from activating native GUI items. + Check: wheel/trackpad input over inventory cannot equip or use the hovered + item; world-camera gestures still work. A WASM armor test reproduced a wheel + gesture equipping hovered gloves through the synthetic right-button action. + Verify inventory, containers, toolbar and other native windows, including + focus loss during a gesture, and add a focused regression for the fix. ## Checks that apply to each milestone diff --git a/docs/armor.md b/docs/armor.md @@ -1,21 +1,28 @@ # Metaplast armor in 14.9.1 -The supported armor pieces are exact catalog endpoints. Their native -identity type is 51022. Acquisition remains fixture-controlled, like the first -weapon and corpse items. - -| Item | Template | Native slot | Catalog | -| --- | --- | --- | --- | -| Worn Metaplast Body Armor | 85686 | 21, chest | `server/gamedata/items/items_005.yaml` | -| Worn Metaplast Armor Boots | 85638 | 30, feet | `server/gamedata/items/items_004.yaml` | -| High-Quality Metaplast Body Armor, QL 200 | 85685 | 21, chest | `server/gamedata/items/items_005.yaml` | - -The QL 1 Wear actions require Strength 16 and Agility 17 strictly greater than -7. The QL 200 chest requires Strength greater than 460 and Agility greater -than 510. All three have EquipDelay 211 equal to 10 centiseconds, processed on -the existing 250 ms equipment tick. Their default armor positions are 5 and 14, -within the armor range starting at 16. The native inventory remains 48..77; armor slots -are not shifted by the ordinary-inventory conversion. +All six Metaplast armor families support their exact QL 1 and QL 200 catalog +endpoints. Their native identity type is 51022. Acquisition remains +fixture-controlled, like the first weapon and corpse items. Intermediate +qualities still require interpolation. + +| Piece | Worn, QL 1 | High-Quality, QL 200 | Native slots | Catalog shard | +| --- | --- | --- | --- | --- | +| Helmet | 85557 | 85556 | 18, head | `items_004.yaml` | +| Body | 85686 | 85685 | 21, chest | `items_005.yaml` | +| Sleeves | 85742 | 85741 | 23 and 25, arms | `items_005.yaml` | +| Gloves | 85596 | 85595 | 24, hands | `items_004.yaml` | +| Pants | 85512 | 85511 | 27, legs | `items_004.yaml` | +| Boots | 85638 | 85637 | 30, feet | `items_004.yaml` | + +These shards are under `server/gamedata/items/`. Every QL 1 Wear action requires +Strength 16 and Agility 17 strictly greater than 7. Every QL 200 endpoint requires +Strength greater than 460 and Agility greater than 510. All twelve records have +EquipDelay 211 equal to 10 centiseconds, processed on the existing 250 ms +equipment tick. Stat 298 supplies the permitted armor-slot mask, starting at +16; stat 88 supplies the default position within that range. Sleeves permit +both bits 7 and 9, so two separate instances can be worn together. The native +inventory remains 48..77; armor slots are not shifted by the ordinary-inventory +conversion. Other armor families remain explicitly unsupported. The chest's OnWear section (type 2, subtype 14) adds 5 to AC stats 90..93 and 1 to 94..97. The boots add 1 to all eight. These are authored Modify 53045 @@ -38,7 +45,20 @@ The native labels map these totals as follows: The QL 200 chest contributes 1000 Projectile, 875 Melee, 1000 Energy, 750 Chemical and 150 each Radiation, Cold, Disease and Fire AC. Its texture -is the same 8736/1 pair. Intermediate qualities are not supported. +is the same 8736/1 pair. + +All twelve records have unconditional positive AC Modify effects. A full suit +contains seven instances, including two sleeves. In stat order 90..97, its QL 1 +totals are `15,15,15,15,7,7,7,7`; QL 200 totals are +`3500,3059,3500,2622,522,522,522,522`. Removing either QL 200 sleeve leaves +`3250,2841,3250,2435,485,485,485,485`. Each equipped instance contributes once. + +The native TemplateAction also handles the authored visual effects. Gloves, +pants and sleeves use texture/category pairs 9422/0, 9425/4 and 9423/3. +Helmets use Mesh 53035 functions with breed/sex conditions and mesh resources +19994, 20016, 20033, 20050, 20061, 20078 and 20095. These conditions are not AC +requirements: the server sums only the unconditional Modify effects, while +the client evaluates the visual functions through the native wear/removal path. ## Authoritative armor reduction @@ -75,7 +95,7 @@ supported weapons retain their catalog endpoints. ## Native move and effect messages Native left-click pickup/place sends ContainerAddItem `0x47537a24` from -ordinary page 104 to slot 21 or 30. Removal uses page 102 and destination 111, +ordinary page 104 to the applicable armor slot. Removal uses page 102 and destination 111, which the server resolves to the first free ordinary slot while preserving 111 in the acknowledgement. Wrong pages, foreign owners, unsupported templates or qualities, occupied slots and insufficient abilities cannot change ownership. @@ -182,3 +202,50 @@ were closed before the regression builds. The full `go test ./server/...` suite passes. Focused race checks for armor, combat, equipment, inventory and reclaim also pass. + +## Complete Metaplast endpoint checks + +`server/metaplast_test.go` covers fourteen endpoint/slot combinations, including +both arms for each sleeve endpoint, 108 rejection/interruption cases and a full +QL 200 suit with independent sleeve removal. Cases check the exact strength +and agility boundaries, wrong slots, identity/quality mismatch, occupied slots, +foreign ownership, changed requirements, failed writes, native page validation, +owner/observer messages and durable identity/AC across restart. +`server/equipment_test.go` also checks rejected wear with all 30 ordinary slots +occupied, including the first two slots and the final native slot. Its two +correction swaps leave every instance in its original location and publish no +equipment effects to the observer. + +The normal HTTPS preview and owned WASM characters were used for the complete +sets; no second fixture server was started. Artifacts are in +`local/metaplast-smoke/`. All twelve extracted catalog payload hashes, qualities, +slot masks, equip delays, requirements and unconditional AC effects were checked +against the original resource database by `tmp_original.py`. + +Native pickup/place equipped all seven QL 1 pieces, then removed every piece +back to inventory with zero AC. The native Protection window showed 15 for +Projectile/Melee/Energy/Chemical and 7 for the remaining types. QL 200 armor +was rejected at abilities 8/8, with the native requirements reporting minimum +Strength 461 and Agility 511. After the fixture met those requirements, the +complete QL 200 set matched all eight totals above. Both outfits replicated +appearance to an independent observer, and the complete QL 200 set restored +without doubled AC after a normal-server restart. + +The unsupported Basic Flowers Tech Armor Helmet 85535 exposed an additional +explicit-drag failure: a same-slot corrective acknowledgement preserved the item +in SQLite and the native inventory model but left its icon hidden. Two ordinary +native swaps now restore the icon immediately. See +[inventory correction](inventory.md#native-messages) for the original native +guard and the recovery policy. This is a concrete reproduction of apparent +equipment disappearance; the broader equipment audit remains open. + +The same run also reproduced wheel camera gestures auto-equipping a hovered +inventory item. That separate input bug has a specific unchecked TODO; the +remaining armor checks used the native scrollbar. + +The fixed native run also checked repeated drag rejection and auto-equip +rejection, followed by independent sleeve removal/re-equip. All fifteen client +inventory-model entries matched SQLite exactly in identity, type, quality, +template endpoints, count and slot. No page, adapter or socket errors occurred. +The full Go server suite passed, as did the focused race run covering Metaplast, +equipment, armor, inventory and ground/flying vehicles. diff --git a/docs/inventory.md b/docs/inventory.md @@ -52,7 +52,7 @@ merge cap remains unresolved. [Small Backpack](backpacks.md) now provides its native 21-slot inventory 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. Exact QL 1/200 Metaplast chest armor and QL 1 boots use the +is described below. All six Metaplast families at exact QL 1/200 use the [native armor path](armor.md). Other equipment remains unsupported. ## Native messages @@ -93,6 +93,28 @@ layout is corroborated by the local AOtomation `ContainerAddItemMessage` and CellAO `ContainerAddItemMessageHandler` reference sources; it is not the message used by the native same-window visual rearrangement described below. +Rejected inventory-to-equipment drags require an actual native inventory +notification to restore the source icon. Original `kkr.dll` `FUN_100614e0` +skips same-slot ContainerAddItem replies. The item can therefore remain in the +native inventory model and SQLite while disappearing from the inventory window. +Auto-equip alone does not reproduce that explicit pickup/place path. + +The server corrects these rejected drags with two ordinary-slot swaps, returning +both entries to their original positions. This works with an empty or occupied +second slot, including a full inventory. It neither changes authoritative item +state nor sends TemplateAction, so worn effects are not applied again. The native +path is `FUN_1005dd60`, which notifies the GUI through +`ClientInterface_t::CMsg_ItemChangedID` or the occupied-slot swap notification; +`FUN_1002d380` swaps the two inventory pointers. This is a reconstructed recovery +policy using native messages, not evidence of the original server's rejection +sequence. Other rejected equipment transitions remain part of the broader audit. + +Original binary evidence is retained in +`local/metaplast-smoke/kkr-rejection.snapshot.json`: same-slot guard +`ev_73e692bf124b00f1a8b2cc878c5ef7ce39702af627aa6a6fbe1dbc90e18d1ee0`, +move/GUI dispatch `ev_ca3b544e617f693a15193dbb11303ccaae381dc0a5c322c52dc0dd2f5a9af6ff`, +and pointer swap `ev_85f3ecb1753e0364c277ff18a656a781f86d4b3b92040ee1ddcb33bcfaa7f5d5`. + `kkr.dll` `sub_3605C400` constructs the character's inventory with 78 slots through `sub_3602D080`. Ordinary inventory begins at 48 in `sub_3605E1A0` and `sub_3605FB40`; next-free searches stop at the container size through diff --git a/docs/ranged-weapons.md b/docs/ranged-weapons.md @@ -123,9 +123,10 @@ with native stat 26 still zero and no replacement ammunition stack. The earlier disappearing-equipment report is still an open regression audit. The missing reply for unsupported slots is reproduced by a server test, but has not established the cause of that historical player report. -The final WASM rejection check created Worn Metaplast Armor Helmet 85557, -assigned it to ordinary inventory and used native auto-equip. The client sent -destination 18 (head), which this server does not support. The corrective reply -kept the helmet visibly in inventory, left the head empty and preserved the -same instance in SQLite. The focused regression uses that exact template and -native destination. +Metaplast helmets are now supported at both catalog endpoints. The unsupported +wear regression uses Basic Flowers Tech Armor Helmet 85535 and native head +destination 18. Explicit pickup/place needs a stronger correction than the +auto-equip check: the original client skips a same-slot acknowledgement and can +hide the dragged icon. The [inventory correction](inventory.md#native-messages) +and complete [Metaplast checks](armor.md#complete-metaplast-endpoint-checks) +document its reproduction and repair. diff --git a/server/equipment.go b/server/equipment.go @@ -20,6 +20,15 @@ func (item ownedItem) isKineticAxe() bool { return item.Type == 51018 && item.Template == 209283 && item.Quality == 1 } +func (item ownedItem) isMetaplast() bool { + // Only the shipped endpoints are supported; intermediate qualities need interpolation. + switch item.Template { + case 85511, 85512, 85556, 85557, 85595, 85596, 85637, 85638, 85685, 85686, 85741, 85742: + return item.Type == 51022 && item.Quality == *gamedata.ItemTemplates[item.Template].Quality + } + return false +} + func (item ownedItem) fitsEquipmentSlot(slot uint32) bool { if item.isKodaik() || item.isYalmaha() { return slot == 1 @@ -27,15 +36,11 @@ func (item ownedItem) fitsEquipmentSlot(slot uint32) bool { if item.isKineticAxe() || item.isFlechettePistol() { return slot == 6 } - if item.Type == 51022 && item.Template == 85685 && item.Quality == 200 { - return slot == 21 + if item.isMetaplast() { + return slot >= 16 && slot < 32 && itemStat(gamedata.ItemTemplates[item.Template], 298)&(1<<(slot-16)) != 0 } if item.Type == 51022 && item.Quality == 1 { switch item.Template { - case 85686: - return slot == 21 - case 85638: - return slot == 30 case 101173: return slot == 37 case 36783: @@ -74,10 +79,10 @@ func (character *character) canEquip(item ownedItem) bool { return stats.effectiveSkill(stats.Ranged.Pistol, [6]uint32{0, 60, 0, 0, 40, 0}) > 5 && stats.effectiveSkill(stats.Ranged.FlingShot, [6]uint32{0, 100, 0, 0, 0, 0}) > 5 } - if item.Template == 85685 { + if item.isMetaplast() && item.Quality == 200 { return character.baseStats().Abilities.Strength > 460 && character.baseStats().Abilities.Agility > 510 } - // Both QL 1 Metaplast pieces require Strength and Agility greater than 7. + // All QL 1 Metaplast pieces require Strength and Agility greater than 7. return character.baseStats().Abilities.Strength > 7 && character.baseStats().Abilities.Agility > 7 } @@ -154,7 +159,7 @@ func itemMovePacket(owner, source, destination uint32) []byte { page := uint32(104) if source == 1 || source == 6 || source == 7 || source >= 9 && source <= 14 { page = 101 - } else if source == 21 || source == 30 { + } else if source >= 16 && source < 32 { page = 102 } else if source == 37 { page = 103 @@ -166,6 +171,20 @@ func itemMovePacket(owner, source, destination uint32) []byte { return n3Packet(0x47537a24, 50000, owner, body) } +func equipmentCorrectionPackets(owner, source uint32) [][]byte { + if source < 64 { + return [][]byte{itemMovePacket(owner, source, source)} + } + // kkr.dll FUN_100614e0 skips GUI notifications for same-slot replies. + // Swap ordinary entries twice to restore their icons and final placement, + // including when the inventory is full, without replaying worn effects. + other := uint32(64) + if source == other { + other = 65 + } + return [][]byte{itemMovePacket(owner, source, other), itemMovePacket(owner, other, source)} +} + func (server *server) equipmentBlocked_locked(character *character, now time.Time) bool { // Combat swaps are a separate milestone; do not replace an active attack phase. if now.Before(character.rechargeUntil) { @@ -193,7 +212,12 @@ func (server *server) beginEquipment_locked(client *worldClient, index int, dest if destination == item.Slot || destination >= 94 || !character.canMoveEquipment(item, destination, time.Now()) || slices.ContainsFunc(character.inventory.Items, func(other ownedItem) bool { return other.Slot == destination }) || server.equipmentBlocked_locked(character, time.Now()) { - return client.send(itemMovePacket(client.id, item.Slot, item.Slot)) + for _, packet := range equipmentCorrectionPackets(client.id, item.Slot) { + if err := client.send(packet); err != nil { + return err + } + } + return nil } // Leave the owned item at its source until the catalog's equip delay expires. @@ -228,7 +252,7 @@ func (server *server) advanceEquipment(now time.Time) { if server.equipmentBlocked_locked(character, now) || !character.canMoveEquipment(character.inventory.Items[index], move.destination, now) || slices.ContainsFunc(character.inventory.Items, func(item ownedItem) bool { return item.Slot == move.destination }) { - updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source)) + updates[client] = append(updates[client], equipmentCorrectionPackets(client.id, move.source)...) continue } @@ -243,7 +267,7 @@ func (server *server) advanceEquipment(now time.Time) { inventory.Items[index].Slot = move.destination if err := server.saveInventory_locked(character, inventory); err != nil { log.Printf("Equipment: %v", err) - updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source)) + updates[client] = append(updates[client], equipmentCorrectionPackets(client.id, move.source)...) continue } if move.source == 1 || move.destination == 1 { @@ -251,7 +275,7 @@ func (server *server) advanceEquipment(now time.Time) { character.position = position client.movementStarted = now } - if move.source == 1 || move.source == 7 || move.source >= 9 && move.source <= 14 || move.source == 21 || move.source == 30 || move.source == 37 { + if move.source == 1 || move.source == 7 || move.source >= 9 && move.source <= 14 || move.source >= 16 && move.source < 32 || move.source == 37 { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, item, 7)) } if move.source == 6 { @@ -263,7 +287,7 @@ func (server *server) advanceEquipment(now time.Time) { } } updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.requestedSlot)) - if move.destination == 1 || move.destination == 7 || move.destination >= 9 && move.destination <= 14 || move.destination == 21 || move.destination == 30 || move.destination == 37 { + if move.destination == 1 || move.destination == 7 || move.destination >= 9 && move.destination <= 14 || move.destination >= 16 && move.destination < 32 || move.destination == 37 { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, character.inventory.Items[index], 6)) } if move.source == 6 || move.destination == 6 { @@ -329,7 +353,7 @@ func equipmentActionPacket(owner uint32, item ownedItem, action uint32) []byte { func equippedItemPackets(character *character) [][]byte { packets := equippedWeaponPackets(character) for _, item := range character.inventory.Items { - if item.Slot == 1 || item.Slot == 7 || item.Slot >= 9 && item.Slot <= 14 || item.Slot == 21 || item.Slot == 30 || item.Slot == 37 { + if item.Slot == 1 || item.Slot == 7 || item.Slot >= 9 && item.Slot <= 14 || item.Slot >= 16 && item.Slot < 32 || item.Slot == 37 { packets = append(packets, equipmentActionPacket(character.id, item, 6)) } } diff --git a/server/equipment_test.go b/server/equipment_test.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" + "fmt" "reflect" "testing" "time" @@ -118,7 +119,7 @@ func TestEquipmentRequiresEachEffectiveSkillAtFive(t *testing.T) { func TestEquipmentUnsupportedWearSlotRestoresInventoryItem(t *testing.T) { world, conn := newEquipmentWorld(t) inventory := world.characters[1].inventory - inventory.Items[0].Type, inventory.Items[0].Template = 51022, 85557 + inventory.Items[0].Type, inventory.Items[0].Template = 51022, 85535 if err := world.saveInventory_locked(world.characters[1], inventory); err != nil { t.Fatal(err) } @@ -137,12 +138,67 @@ func TestEquipmentUnsupportedWearSlotRestoresInventoryItem(t *testing.T) { !reflect.DeepEqual(world.characters[1].inventory.Items, restarted.characters[1].inventory.Items) { t.Fatal("rejected equipment move changed the item", err, readErr) } - if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 || - binary.BigEndian.Uint32(conn.packets[0][33:37]) != 48 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != 48 { + if len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 || + binary.BigEndian.Uint32(conn.packets[0][33:37]) != 48 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != 49 || + binary.BigEndian.Uint32(conn.packets[1][33:37]) != 49 || binary.BigEndian.Uint32(conn.packets[1][45:49]) != 48 { t.Fatalf("rejected wear slot left the native move pending: %x", conn.packets) } } +func TestEquipmentRejectedWearRestoresFullNativeInventory(t *testing.T) { + for _, source := range []uint32{64, 65, 93} { + t.Run(fmt.Sprint(source), func(t *testing.T) { + world, conn := newEquipmentWorld(t) + player := world.characters[1] + player.inventory.Items[0].Type, player.inventory.Items[0].Template = 51022, 85535 + player.inventory.Items[0].Slot = source + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + for range 29 { + if granted, err := world.grantItem_locked(player, 121567); err != nil || !granted { + t.Fatal("fill inventory", granted, err) + } + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + original := append([]ownedItem(nil), player.inventory.Items...) + placements, expected := make(map[uint32]uint32), make(map[uint32]uint32) + for _, item := range original { + placements[item.Slot], expected[item.Slot] = item.ID, item.ID + } + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + + request := inventoryMovePacket(1, source-16, 18)[20:] + decodeInventory1491(request) + if err := world.handleInventory(world.clients[1], request); err != nil { + t.Fatal(err) + } + after, err := readTestItemStore(world) + + if err != nil || !bytes.Equal(before, after) || !reflect.DeepEqual(original, player.inventory.Items) || + len(conn.packets) != 2 || len(observer.packets) != 0 { + t.Fatal("correction changed durable items or announced equipment", err) + } + for _, packet := range conn.packets { + from, to := binary.BigEndian.Uint32(packet[33:37])+16, binary.BigEndian.Uint32(packet[45:49])+16 + if binary.BigEndian.Uint32(packet[16:20]) != 0x47537a24 || binary.BigEndian.Uint32(packet[29:33]) != 104 || + from < 64 || from >= 94 || to < 64 || to >= 94 || from == to { + t.Fatalf("invalid native correction: %x", packet) + } + placements[from], placements[to] = placements[to], placements[from] + } + if !reflect.DeepEqual(placements, expected) { + t.Fatal("native correction left an item in the wrong slot") + } + }) + } +} + func TestEquipmentCompletionRechecksStateAndPreservesFailedSave(t *testing.T) { for _, scenario := range []string{"requirements", "own combat", "incoming combat", "recharge", "loading", "dead", "replaced session", "failed save"} { t.Run(scenario, func(t *testing.T) { diff --git a/server/flying_vehicle_test.go b/server/flying_vehicle_test.go @@ -107,7 +107,7 @@ func TestFlyingVehicleRejectsIneligibleEquipment(t *testing.T) { t.Fatal(err) } - if client.equipment != nil || player.inventory.Items[0].Slot != 64 || len(conn.packets) > 1 { + if client.equipment != nil || player.inventory.Items[0].Slot != 64 || len(conn.packets) > 2 { t.Fatal("ineligible Yalmaha changed equipment or published effects") } }) @@ -135,7 +135,7 @@ func TestFlyingVehicleRechecksRequirementsAfterDelay(t *testing.T) { world.advanceEquipment(finish) - if player.inventory.Items[0].Slot != 64 || player.flying() || len(conn.packets) != 1 { + if player.inventory.Items[0].Slot != 64 || player.flying() || len(conn.packets) != 2 { t.Fatal("Yalmaha used stale eligibility from the start of its equip delay") } }) diff --git a/server/inventory.go b/server/inventory.go @@ -190,7 +190,7 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { if index < 0 || (sourceSlot >= 64 && sourceType != 104) || ((sourceSlot == 1 || sourceSlot == 6 || sourceSlot == 7 || sourceSlot >= 9 && sourceSlot <= 14) && sourceType != 101) || (sourceSlot == 37 && sourceType != 103) || - ((sourceSlot == 21 || sourceSlot == 30) && sourceType != 102) { + (sourceSlot >= 16 && sourceSlot < 32 && sourceType != 102) { return nil } destination := binary.BigEndian.Uint32(body[32:36]) diff --git a/server/metaplast_test.go b/server/metaplast_test.go @@ -0,0 +1,218 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "reflect" + "testing" +) + +func TestMetaplastNativeWearRemoveAndRestart(t *testing.T) { + for _, piece := range []struct { + template uint32 + slot uint32 + armor [8]uint32 + }{ + {85512, 27, [8]uint32{3, 3, 3, 3, 1, 1, 1, 1}}, + {85557, 18, [8]uint32{3, 3, 3, 3, 1, 1, 1, 1}}, + {85596, 24, [8]uint32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85638, 30, [8]uint32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85686, 21, [8]uint32{5, 5, 5, 5, 1, 1, 1, 1}}, + {85742, 23, [8]uint32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85742, 25, [8]uint32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85511, 27, [8]uint32{625, 546, 625, 468, 93, 93, 93, 93}}, + {85556, 18, [8]uint32{750, 656, 750, 562, 112, 112, 112, 112}}, + {85595, 24, [8]uint32{250, 218, 250, 187, 37, 37, 37, 37}}, + {85637, 30, [8]uint32{375, 328, 375, 281, 56, 56, 56, 56}}, + {85685, 21, [8]uint32{1000, 875, 1000, 750, 150, 150, 150, 150}}, + {85741, 23, [8]uint32{250, 218, 250, 187, 37, 37, 37, 37}}, + {85741, 25, [8]uint32{250, 218, 250, 187, 37, 37, 37, 37}}, + } { + t.Run(fmt.Sprintf("%s/slot%d", gamedata.ItemTemplates[piece.template].Name, piece.slot), func(t *testing.T) { + world, conn := newEquipmentWorld(t) + player := world.characters[1] + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 8, 8 + if *gamedata.ItemTemplates[piece.template].Quality == 200 { + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 461, 511 + } + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, piece.template); err != nil || !granted { + t.Fatal("grant armor", granted, err) + } + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + original := player.inventory.Items[1] + + request := inventoryMovePacket(1, 49, piece.slot)[20:] + decodeInventory1491(request) + if err := world.handleInventory(world.clients[1], request); err != nil { + t.Fatal(err) + } + if world.clients[1].equipment == nil { + t.Fatal("catalog armor was rejected") + } + world.advanceEquipment(world.clients[1].equipment.readyAt) + worn := newTestInventoryServer(t).characters[1] + + expected := original + expected.Slot = piece.slot + if !reflect.DeepEqual(worn.inventory.Items, []ownedItem{player.inventory.Items[0], expected}) || + len(conn.packets) != 2 || len(observer.packets) != 1 || + !bytes.Equal(conn.packets[1][16:], observer.packets[0][16:]) { + t.Fatalf("wear changed identity or failed to replicate: %+v", worn.inventory.Items) + } + initial := equippedItemPackets(worn) + if len(initial) != 1 || !bytes.Equal(targetPacket(initial[0])[16:], conn.packets[1][16:]) { + t.Fatal("observer reconnect did not restore exactly one wear action") + } + for index, armor := range piece.armor { + if got := worn.inventory.equipmentBonus(90 + uint32(index)); got != armor { + t.Fatalf("AC %d = %d, want %d", 90+index, got, armor) + } + } + forged := itemMovePacket(1, piece.slot, 111)[20:] + binary.BigEndian.PutUint32(forged[16:20], 104) + world.handleInventory(world.clients[1], forged) + if world.clients[1].equipment != nil || len(conn.packets) != 2 { + t.Fatal("forged inventory page accepted an armor removal") + } + + // Remove through the native armor page, including a repeated stale request. + conn.packets, observer.packets = nil, nil + remove := itemMovePacket(1, piece.slot, 111)[20:] + if binary.BigEndian.Uint32(remove[16:20]) != 102 { + t.Fatal("armor removal used the wrong native page") + } + world.handleInventory(world.clients[1], remove) + if world.clients[1].equipment == nil { + t.Fatal("armor removal was rejected") + } + world.advanceEquipment(world.clients[1].equipment.readyAt) + world.handleInventory(world.clients[1], remove) + removed := newTestInventoryServer(t).characters[1] + if !reflect.DeepEqual(removed.inventory.Items, []ownedItem{player.inventory.Items[0], original}) || + len(conn.packets) != 2 || len(observer.packets) != 1 || + binary.BigEndian.Uint32(conn.packets[0][45:49]) != 7 || + binary.BigEndian.Uint32(conn.packets[0][53:57]) != piece.slot || + len(equippedItemPackets(removed)) != 0 { + t.Fatal("removal lost the armor or repeated its effects") + } + for stat := uint32(90); stat <= 97; stat++ { + if removed.inventory.equipmentBonus(stat) != 0 { + t.Fatal("removed armor retained AC") + } + } + }) + } +} + +func TestMetaplastRejectedWearPreservesOwnedItem(t *testing.T) { + for _, template := range []uint32{85511, 85512, 85556, 85557, 85595, 85596, 85637, 85638, 85685, 85686, 85741, 85742} { + for _, scenario := range []string{"strength", "agility", "quality", "identity", "wrong slot", "foreign owner", "occupied", "changed requirement", "failed save"} { + t.Run(gamedata.ItemTemplates[template].Name+"/"+scenario, func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 8, 8 + strength, agility := uint16(7), uint16(7) + if *gamedata.ItemTemplates[template].Quality == 200 { + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 461, 511 + strength, agility = 460, 510 + } + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal("grant armor", granted, err) + } + destination := 16 + itemStat(gamedata.ItemTemplates[template], 88) + owner := uint32(1) + switch scenario { + case "strength": + player.stats.Abilities.Strength = strength + case "agility": + player.stats.Abilities.Agility = agility + case "quality": + player.inventory.Items[1].Quality++ + case "identity": + player.inventory.Items[1].Type = 51018 + case "wrong slot": + destination = 31 + case "foreign owner": + owner = 2 + case "occupied": + occupied := player.inventory.Items[1] + occupied.ID, occupied.Slot = 3, destination + player.inventory.LastID = 3 + player.inventory.Items = append(player.inventory.Items, occupied) + } + before := append([]ownedItem(nil), player.inventory.Items...) + stored, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + + if err := world.handleInventory(world.clients[1], inventoryMovePacket(owner, 65, destination)[20:]); err != nil { + t.Fatal(err) + } + if scenario == "changed requirement" || scenario == "failed save" { + if world.clients[1].equipment == nil { + t.Fatal("qualifying armor was rejected before interruption") + } + if scenario == "changed requirement" { + player.stats.Abilities.Agility = agility + } else { + failDatabaseWrites(t, world) + } + world.advanceEquipment(world.clients[1].equipment.readyAt) + } + after, err := readTestItemStore(world) + + if err != nil || !bytes.Equal(stored, after) || world.clients[1].equipment != nil || !reflect.DeepEqual(before, player.inventory.Items) { + t.Fatal("rejected wear changed an owned item", err) + } + }) + } + } +} + +func TestMetaplastFullSuitKeepsSeparateSleeveContributions(t *testing.T) { + world, _ := newEquipmentWorld(t) + player := world.characters[1] + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 461, 511 + for _, piece := range [][2]uint32{{85556, 18}, {85685, 21}, {85741, 23}, {85741, 25}, {85595, 24}, {85511, 27}, {85637, 30}} { + if granted, err := world.grantItem_locked(player, piece[0]); err != nil || !granted { + t.Fatal("grant armor", granted, err) + } + if err := world.handleInventory(world.clients[1], inventoryMovePacket(1, 65, piece[1])[20:]); err != nil { + t.Fatal(err) + } + if world.clients[1].equipment == nil { + t.Fatal("suit piece rejected") + } + world.advanceEquipment(world.clients[1].equipment.readyAt) + } + var before [8]uint32 + for index := range before { + before[index] = player.inventory.equipmentBonus(90 + uint32(index)) + } + + world.handleInventory(world.clients[1], itemMovePacket(1, 23, 111)[20:]) + world.advanceEquipment(world.clients[1].equipment.readyAt) + restarted := newTestInventoryServer(t).characters[1] + var after [8]uint32 + for index := range after { + after[index] = restarted.inventory.equipmentBonus(90 + uint32(index)) + } + + if before != [8]uint32{3500, 3059, 3500, 2622, 522, 522, 522, 522} || + after != [8]uint32{3250, 2841, 3250, 2435, 485, 485, 485, 485} { + t.Fatalf("sleeve removal changed other contributions: before=%v after=%v", before, after) + } + if len(restarted.inventory.Items) != 8 || len(equippedItemPackets(restarted)) != 6 || + restarted.inventory.Items[3].ID != 4 || restarted.inventory.Items[3].Slot != 65 || + restarted.inventory.Items[4].ID != 5 || restarted.inventory.Items[4].Slot != 25 { + t.Fatalf("sleeve instances were lost or interchanged: %+v", restarted.inventory.Items) + } +} diff --git a/server/vehicle_test.go b/server/vehicle_test.go @@ -109,7 +109,7 @@ func TestGroundVehicleRejectsIneligibleEquipment(t *testing.T) { t.Fatal(err) } - if client.equipment != nil || player.inventory.Items[0].Slot != 64 || len(conn.packets) > 1 { + if client.equipment != nil || player.inventory.Items[0].Slot != 64 || len(conn.packets) > 2 { t.Fatal("ineligible vehicle move changed equipment or published effects") } }) @@ -137,7 +137,7 @@ func TestGroundVehicleRechecksRequirementsAfterDelay(t *testing.T) { world.advanceEquipment(finish) - if player.inventory.Items[0].Slot != 64 || player.inventory.equipmentBonus(156) != 0 || len(conn.packets) != 1 { + if player.inventory.Items[0].Slot != 64 || player.inventory.equipmentBonus(156) != 0 || len(conn.packets) != 2 { t.Fatal("vehicle used stale eligibility from the start of its equip delay") } })