commit 486871f1c3d6fd38a3dd4c687d7f5650d1f300cc
parent 107f3a9ddd4b851b0ab55e4d0ae78e8475c452cf
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 10:04:05 +0000
Handle native inventory combinations and NCU interface crafting
Diffstat:
6 files changed, 598 insertions(+), 4 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -982,6 +982,25 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
five-unit start check. Keep inferred policies explicit in the protocol ledger.
- [ ] Combine one tradeskill recipe. Check: valid ingredients and skills produce
the expected result QL; failure preserves the applicable inputs.
+ The original inventory combination request, slot translation and native
+ failure messages now work. NCU Hacker Interface crafting uses the period
+ Lock Pick/Nano Programming Interface pair and effective NP25/B&E60 gates,
+ with atomic consumption/result delivery, replay/rollback checks and usable
+ QL1 HUD equipment. Initial QL1 output and both-component consumption remain
+ explicit reconstruction policies; creation XP and any separate creation
+ profession requirement still need target-era evidence. Keep this milestone
+ open until those canonical recipe rules are established. See
+ [inventory combinations](docs/tradeskills.md).
+- [ ] Support the NCU Hacker Interface's original manual level upgrades.
+ Recover FINC/53130 behavior, level/QL selection, upgrade cash costs and
+ intermediate modifiers. Verify use while carried/worn, wrong profession,
+ maximum QL, repeated requests, SQL rollback and native reconnect without
+ losing the crafted item. Do not turn its flavor-text failure probability
+ into a destruction rule without behavioral evidence.
+ The fresh AddTemplate result emitted no Use request on the observed right
+ click; after cold reconnect its actual instance did send Use and received
+ the current unsupported-action rejection. Recover this input/delivery
+ difference before claiming the upgrade flow works for newly crafted items.
- [ ] Add one implant-building recipe. Check: the chosen cluster/implant pair
produces the evidenced requirements, bonuses and QL result.
diff --git a/docs/tradeskills.md b/docs/tradeskills.md
@@ -0,0 +1,94 @@
+# Original inventory combinations
+
+The server handles ordinary inventory combinations through the original
+14.9.1 CharacterAction81 request. Its first recipe combines a regular Lock Pick
+95577 with Nano Programming Interface161699, requiring effective Nano Programming
+25 and Breaking & Entering60. The current result is QL1 NCU Hacker Interface
+158416. Both ingredients commit as consumed in the same transaction that creates
+one new durable result. Failed requirements or persistence preserve the inputs.
+
+## Evidence and reconstruction limits
+
+The November2002 and February2003 Anarchy Arcanum guides establish the input pair,
+skill thresholds, shop categories and exclusion of Personal Lock Pick156639.
+Original14.9.1 records establish both inputs at QL1, result endpoints158416/158417
+at QL1/200, its NoDrop flag, HUD2 placement, six nano-skill modifiers and Fixer
+wear requirements. Retained source bytes, dates and hashes are in
+`local/tradeskill-research/sources/source-ledger.json` and
+`local/tradeskill-research/catalog/source-ledger.json`.
+
+Initial QL1 output is reconstruction policy inferred from the fixed QL1 inputs
+and level-one result endpoint. Both-component consumption has explicit later
+November2005 corroboration; it has not been directly established from a target-era
+server. Wearing requires Fixer, but the period guides do not establish a separate
+profession check on creation. The implemented combine checks the evidenced skill
+requirements without adding that unproven restriction.
+
+Creation XP is unimplemented because its amount, including whether it is zero,
+remains unproven. Manual leveling, intermediate-QL modifiers, cash costs and any
+other NCU upgrade behavior are separate unfinished work. Supporting this recipe
+does not establish generic tradeskill XP, variable QL/bumping, reusable tools,
+container/equipped combinations or the complete historical recipe set.
+
+## Native contract
+
+Original kkr.dll SHA-256:
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+The exported evidence bundle is `local/tradeskill-research/native-evidence.json`.
+
+Producer `n3EngineClientAnarchy_t::N3Msg_TradeskillCombine` at1002aa90 validates
+carried inputs and requires both references to use ordinary page104. It constructs
+CharacterActionIIR through1007d4b0 with action81, source identity and target
+identity. Stationary-object range checks exist in the producer, but it ultimately
+rejects nonordinary pages; their broader server behavior is not implemented.
+
+The five network-order DWORDs after the standard N3 header are
+`81,104,sourceSlot,104,targetSlot`. Native slots48..77 map to server slots64..93.
+Both references must be translated. The socket regression exercises this exact
+request through the public world connection and verifies the result after reload.
+
+The original CharacterAction receiver1007d640 dispatches into SimpleChar1006fa30.
+Action84 invokes100561d0, which formats combination feedback through the original
+stat-name lookup and native chat. Failure fields are:
+
+| Five DWORDs | Native feedback |
+| --- | --- |
+|84,2,0,0,0|It is not possible to assemble those two items. Maybe the order was wrong?|
+|84,32,0,stat,required|You need following skill to combine: followed by stat name and requirement|
+
+Bit0 selects a different preview wording; successful quality-grading variants
+also exist. Their historical server selection remains unproven and is not
+invented here. Creation delivers the resulting item without a guessed grade.
+
+After the atomic save, two original Delete112 messages remove the exact input
+template pairs. AddTemplate delivers one result into the first free ordinary
+slot. This sequence also works with a full inventory because consuming two
+inputs frees space. IDs are server-owned; the temporary native template proxy
+receives its persistent instance identity on reconnect.
+
+## Ownership and verification
+
+Every request checks the exact current client, readiness, life state, both
+ordinary slots, recipe order, input type/QL/count and effective skills. Pending
+equipment blocks combinations. An open player/shop basket cancels first and
+returns without acting on slots whose contents may have changed on restoration.
+
+Detached candidates remove both ingredients and allocate one result before one
+existing inventory transaction. SQLite failure publishes neither ownership nor
+deletion/result messages; retry creates once. A lost postcommit reply cannot
+reverse consumption or allocate the result again. The protocol has no operation
+nonce: an old request cannot be distinguished from a new request after both slots
+are deliberately reused with a fresh matching pair.
+
+Tests cover effective-skill boundaries, wrong order/Personal Lock Pick,
+missing/equipped/banked/contained/foreign references, stale sessions, loading,
+death, pending equipment, unsupported QL/type, full inventory, concurrent replay,
+ingredient/result/placement SQL failures, cancellation of both basket types,
+lost replies, native slot conversion and wearing/removing the crafted item.
+QL1 wear adds and removes the original six nano-skill bonuses through the shared
+equipment path. Native runtime evidence is retained in `local/tradeskill-smoke/`.
+Both clients verified those modifiers. After cold recovery the same persistent
+result and unrelated items remain; neither ingredient returns. An exploratory
+upgrade click on the fresh result emitted no Use request, while the cold-restored
+instance sent Use and received failure2. Upgrading remains unsupported, and the
+fresh/cold input difference needs separate investigation.
diff --git a/server/main.go b/server/main.go
@@ -562,6 +562,10 @@ func (server *server) serveWorldClient(client *worldClient) error {
if err := server.handleInventory(client, body); err != nil {
return err
}
+ case 81:
+ if err := server.handleItemCombination(client, body); err != nil {
+ return err
+ }
case 86, 87:
// Acknowledge sitting and standing so the client updates its posture.
if binary.BigEndian.Uint32(body[16:20]) == 87 {
diff --git a/server/target_protocol.go b/server/target_protocol.go
@@ -132,10 +132,10 @@ func targetPacket(packet []byte) []byte {
}
case 0x5e477770:
action := binary.BigEndian.Uint32(packet[36:40])
- if (action == 52 || action == 53 || action == 112 || action == 146) && binary.BigEndian.Uint32(packet[40:44]) == 104 {
+ if (action == 52 || action == 53 || action == 81 || action == 112 || action == 146) && binary.BigEndian.Uint32(packet[40:44]) == 104 {
binary.BigEndian.PutUint32(packet[44:48], binary.BigEndian.Uint32(packet[44:48])-16)
}
- if action == 53 && binary.BigEndian.Uint32(packet[48:52]) == 104 {
+ if (action == 53 || action == 81) && binary.BigEndian.Uint32(packet[48:52]) == 104 {
binary.BigEndian.PutUint32(packet[52:56], binary.BigEndian.Uint32(packet[52:56])-16)
}
case 0x54111123:
@@ -187,10 +187,10 @@ func decodeInventory1491(body []byte) {
}
case 0x5e477770:
action := binary.BigEndian.Uint32(body[16:20])
- if (action == 52 || action == 53 || action == 112) && binary.BigEndian.Uint32(body[20:24]) == 104 {
+ if (action == 52 || action == 53 || action == 81 || action == 112) && binary.BigEndian.Uint32(body[20:24]) == 104 {
binary.BigEndian.PutUint32(body[24:28], decodeInventorySlot1491(binary.BigEndian.Uint32(body[24:28])))
}
- if action == 53 && binary.BigEndian.Uint32(body[28:32]) == 104 {
+ if (action == 53 || action == 81) && binary.BigEndian.Uint32(body[28:32]) == 104 {
binary.BigEndian.PutUint32(body[32:36], decodeInventorySlot1491(binary.BigEndian.Uint32(body[32:36])))
}
}
diff --git a/server/tradeskills.go b/server/tradeskills.go
@@ -0,0 +1,96 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "fmt"
+ "slices"
+)
+
+var itemCombinations = map[[2]uint32]struct {
+ result uint32
+ skills [][2]uint32
+}{
+ {95577, 161699}: {158416, [][2]uint32{{160, 25}, {165, 60}}},
+}
+
+func (server *server) handleItemCombination(client *worldClient, body []byte) error {
+ if len(body) != 36 {
+ return fmt.Errorf("invalid item combination length")
+ }
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ defer server.mutex.Unlock()
+ player := server.characters[client.id]
+ if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || client.equipment != nil ||
+ binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
+ binary.BigEndian.Uint32(body[16:20]) != 81 || binary.BigEndian.Uint32(body[20:24]) != 104 || binary.BigEndian.Uint32(body[28:32]) != 104 {
+ return nil
+ }
+ // Cancelling an open basket can restore different items into these slots.
+ if client.trade != nil {
+ return server.abortPlayerTrade_locked(client)
+ }
+ if client.shop != nil {
+ return server.abortShop_locked(client)
+ }
+ sourceSlot, targetSlot := binary.BigEndian.Uint32(body[24:28]), binary.BigEndian.Uint32(body[32:36])
+ if sourceSlot < 64 || sourceSlot >= 94 || targetSlot < 64 || targetSlot >= 94 || sourceSlot == targetSlot {
+ return nil
+ }
+ source := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool { return item.Slot == sourceSlot })
+ target := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool { return item.Slot == targetSlot })
+ if source < 0 || target < 0 {
+ return nil
+ }
+ first, second := player.inventory.Items[source], player.inventory.Items[target]
+ recipe, exists := itemCombinations[[2]uint32{first.Template, second.Template}]
+ if !exists {
+ return client.send(characterActionPacket(client.id, [5]uint32{84, 2, 0, 0, 0}))
+ }
+ for _, item := range []ownedItem{first, second} {
+ definition := gamedata.ItemTemplates[item.Template]
+ if item.Type != definition.HeaderWords[0] || item.Quality != *definition.Quality || item.Count != 1 {
+ return nil
+ }
+ }
+ for _, requirement := range recipe.skills {
+ actual, known := player.effectiveStat(requirement[0])
+ if !known || actual < int32(requirement[1]) {
+ return client.send(characterActionPacket(client.id, [5]uint32{84, 32, 0, requirement[0], requirement[1]}))
+ }
+ }
+ if server.nextItem == ^uint32(0) {
+ return fmt.Errorf("item identities exhausted")
+ }
+
+ // Replace both ingredients with one result in a detached, atomic candidate.
+ inventory := player.inventory
+ inventory.Items = slices.DeleteFunc(slices.Clone(inventory.Items), func(item ownedItem) bool { return item.ID == first.ID || item.ID == second.ID })
+ definition := gamedata.ItemTemplates[recipe.result]
+ item := ownedItem{ID: server.nextItem + 1, Type: definition.HeaderWords[0], Template: recipe.result, Quality: *definition.Quality, Slot: 64, Count: 1}
+ for slices.ContainsFunc(inventory.Items, func(other ownedItem) bool { return other.Slot == item.Slot }) {
+ item.Slot++
+ }
+ inventory.LastID = item.ID
+ inventory.Items = append(inventory.Items, item)
+ if err := server.saveInventory_locked(player, inventory); err != nil {
+ return err
+ }
+ server.nextItem = max(server.nextItem, inventory.LastID)
+
+ // Native AddTemplate chooses first-free after both deletion acknowledgements.
+ for _, ingredient := range []ownedItem{first, second} {
+ low, high := ingredient.templateIDs()
+ if err := client.send(characterActionPacket(client.id, [5]uint32{112, 104, ingredient.Slot, low, high})); err != nil {
+ return err
+ }
+ }
+ low, high := item.templateIDs()
+ var result []byte
+ for _, value := range []uint32{low, high, item.Quality, 1} {
+ result = binary.BigEndian.AppendUint32(result, value)
+ }
+ return client.send(n3Packet(0x052e2f0c, 50000, client.id, result))
+}
diff --git a/server/tradeskills_test.go b/server/tradeskills_test.go
@@ -0,0 +1,381 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "net"
+ "reflect"
+ "sync"
+ "testing"
+ "time"
+)
+
+func newCombinationWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newEquipmentWorld(t)
+ player := world.characters[1]
+ player.profession = 4
+ // Ten in each ability contributes two points to both effective skills.
+ player.stats.TradeRepair.NanoProgramming = 23
+ player.stats.Spying.BreakingAndEntering = 58
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{95577, 161699} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatalf("ingredient: %v %v", granted, err)
+ }
+ }
+ conn.packets = nil
+ return world, conn
+}
+
+func combinationRequest(owner, source, target uint32) []byte {
+ return characterActionPacket(owner, [5]uint32{81, 104, source, 104, target})[20:]
+}
+
+func TestItemCombinationConsumesBothIngredientsAndPersistsOneResult(t *testing.T) {
+ world, conn := newCombinationWorld(t)
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+
+ if err := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+ restored := newTestInventoryServer(t)
+ if err := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 64, Count: 1},
+ {ID: 4, Type: 51022, Template: 158416, Quality: 1, Slot: 65, Count: 1}}
+ if !reflect.DeepEqual(world.characters[1].inventory.Items, expected) || !reflect.DeepEqual(restored.characters[1].inventory.Items, expected) ||
+ world.nextItem != 4 || len(world.items) != 2 || len(observer.packets) != 0 || len(conn.packets) != 3 {
+ t.Fatal("combination lost unrelated ownership, retained ingredients or repeated the result")
+ }
+ for index, slot := range []uint32{49, 50} {
+ if binary.BigEndian.Uint32(conn.packets[index][29:33]) != 112 || binary.BigEndian.Uint32(conn.packets[index][37:41]) != slot {
+ t.Fatal("ingredient deletion did not precede native first-free result delivery")
+ }
+ }
+ if binary.BigEndian.Uint32(conn.packets[2][16:20]) != 0x052e2f0c ||
+ !bytes.Equal(conn.packets[2][29:45], []byte{0, 2, 106, 208, 0, 2, 106, 208, 0, 0, 0, 1, 0, 0, 0, 1}) {
+ t.Fatalf("wrong result templates, QL or quantity: %x", conn.packets[2])
+ }
+}
+
+func TestItemCombinationRejectsInvalidSourcesAndInsufficientEffectiveSkills(t *testing.T) {
+ for _, scenario := range []string{"nano programming", "breaking and entering", "reverse", "personal lock pick", "missing", "same slot", "equipment", "bank", "container", "foreign", "replaced", "loading", "dead", "pending equip", "quality", "type"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newCombinationWorld(t)
+ player := world.characters[1]
+ client := world.clients[1]
+ request := combinationRequest(1, 65, 66)
+ feedback := uint32(0)
+ switch scenario {
+ case "nano programming":
+ player.stats.TradeRepair.NanoProgramming = 22
+ feedback = 160
+ case "breaking and entering":
+ player.stats.Spying.BreakingAndEntering = 57
+ feedback = 165
+ case "reverse":
+ request = combinationRequest(1, 66, 65)
+ feedback = 2
+ case "personal lock pick":
+ player.inventory.Items[1].Template = 156639
+ feedback = 2
+ case "missing":
+ request = combinationRequest(1, 65, 93)
+ case "same slot":
+ request = combinationRequest(1, 65, 65)
+ case "equipment":
+ request = combinationRequest(1, 6, 66)
+ case "bank":
+ binary.BigEndian.PutUint32(request[20:24], 105)
+ case "container":
+ binary.BigEndian.PutUint32(request[28:32], 107)
+ case "foreign":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "replaced":
+ world.clients[1] = &worldClient{id: 1}
+ case "loading":
+ world.clients[1].loading = true
+ case "dead":
+ player.health = 0
+ case "pending equip":
+ world.clients[1].equipment = &equipmentMove{}
+ case "quality":
+ player.inventory.Items[1].Quality = 2
+ case "type":
+ player.inventory.Items[1].Type = 51022
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ items := append([]ownedItem(nil), player.inventory.Items...)
+
+ err = world.handleItemCombination(client, request)
+ after, readErr := readTestItemStore(world)
+
+ if err != nil || readErr != nil || !bytes.Equal(before, after) || !reflect.DeepEqual(player.inventory.Items, items) || world.nextItem != 3 {
+ t.Fatal("rejected combination changed ownership or allocated an identity")
+ }
+ if feedback == 0 {
+ if len(conn.packets) != 0 {
+ t.Fatal("unauthenticated/invalid source received a combination response")
+ }
+ return
+ }
+ if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 84 {
+ t.Fatal("missing native combination feedback")
+ }
+ if feedback == 2 {
+ if binary.BigEndian.Uint32(conn.packets[0][33:37]) != 2 {
+ t.Fatal("wrong recipe/order feedback")
+ }
+ return
+ }
+ required := uint32(25)
+ if feedback == 165 {
+ required = 60
+ }
+ if binary.BigEndian.Uint32(conn.packets[0][33:37]) != 32 || binary.BigEndian.Uint32(conn.packets[0][41:45]) != feedback ||
+ binary.BigEndian.Uint32(conn.packets[0][45:49]) != required {
+ t.Fatal("wrong effective-skill failure or native threshold")
+ }
+ })
+ }
+}
+
+func TestItemCombinationFailureKeepsIngredientsAndAllowsRetry(t *testing.T) {
+ for _, trigger := range []string{
+ "CREATE TRIGGER fail_combination BEFORE DELETE ON items WHEN OLD.id=3 BEGIN SELECT RAISE(ABORT, 'ingredient'); END",
+ "CREATE TRIGGER fail_combination BEFORE INSERT ON items WHEN NEW.template=158416 BEGIN SELECT RAISE(ABORT, 'result'); END",
+ "CREATE TRIGGER fail_combination BEFORE INSERT ON item_locations WHEN NEW.item_id=4 BEGIN SELECT RAISE(ABORT, 'placement'); END",
+ } {
+ t.Run(trigger, func(t *testing.T) {
+ world, conn := newCombinationWorld(t)
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := world.db.Exec(trigger); err != nil {
+ t.Fatal(err)
+ }
+
+ failed := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66))
+ after, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if failed == nil || !bytes.Equal(before, after) || len(world.characters[1].inventory.Items) != 3 || world.nextItem != 3 || len(conn.packets) != 0 {
+ t.Fatal("failed combination published consumption, allocation or feedback")
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_combination"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+ if newTestInventoryServer(t).characters[1].inventory.Items[1].Template != 158416 {
+ t.Fatal("retry did not persist the result")
+ }
+ })
+ }
+}
+
+func TestItemCombinationConcurrentReplayAndFullInventory(t *testing.T) {
+ world, conn := newCombinationWorld(t)
+ for range 27 {
+ if granted, err := world.grantItem_locked(world.characters[1], 95577); err != nil || !granted {
+ t.Fatalf("fill: %v %v", granted, err)
+ }
+ }
+ conn.packets = nil
+
+ var requests sync.WaitGroup
+ for range 8 {
+ requests.Go(func() {
+ if err := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66)); err != nil {
+ t.Error(err)
+ }
+ })
+ }
+ requests.Wait()
+ restored := newTestInventoryServer(t)
+
+ if len(restored.characters[1].inventory.Items) != 29 || restored.characters[1].inventory.Items[28] !=
+ (ownedItem{ID: 31, Type: 51022, Template: 158416, Quality: 1, Slot: 65, Count: 1}) || world.nextItem != 31 {
+ t.Fatal("full-inventory combination lost value or repeated creation")
+ }
+ if len(conn.packets) != 3 {
+ t.Fatal("replayed completion emitted another result")
+ }
+}
+
+func TestItemCombinationUsesTheOriginalNativeInventorySlots(t *testing.T) {
+ newCombinationWorld(t)
+ world := newTestInventoryServer(t)
+ client, connection := net.Pipe()
+ client.SetDeadline(time.Now().Add(5 * time.Second))
+ done := make(chan error, 1)
+ go func() { defer connection.Close(); done <- world.serveWorldConnection(connection) }()
+ defer func() {
+ client.Close()
+ if err := <-done; err != nil {
+ t.Error(err)
+ }
+ }()
+ cookie := systemPacket(0x1b, []byte{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0})
+ binary.BigEndian.PutUint16(cookie[0:2], 0xdfdf)
+ client.Write(cookie)
+ for {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5f52412e {
+ break
+ }
+ }
+ client.Write(targetPacket(n3Packet(0x570c2039, 50000, 1, nil)))
+ if _, err := readPacket(client); err != nil {
+ t.Fatal(err)
+ }
+ request := targetPacket(characterActionPacket(1, [5]uint32{81, 104, 65, 104, 66}))
+
+ client.Write(request)
+ var replies [][]byte
+ for range 3 {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ replies = append(replies, packet)
+ }
+
+ if binary.BigEndian.Uint32(request[37:41]) != 49 || binary.BigEndian.Uint32(request[45:49]) != 50 ||
+ binary.BigEndian.Uint32(replies[0][37:41]) != 49 || binary.BigEndian.Uint32(replies[1][37:41]) != 50 ||
+ binary.BigEndian.Uint32(replies[2][16:20]) != 0x052e2f0c || newTestInventoryServer(t).characters[1].inventory.Items[1].Template != 158416 {
+ t.Fatal("native request/reply translated the wrong inventory slots")
+ }
+}
+
+func TestCraftedNCUHackerInterfaceCanBeWornAndRemoved(t *testing.T) {
+ world, _ := newCombinationWorld(t)
+ client, player := world.clients[1], world.characters[1]
+ if err := world.handleItemCombination(client, combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 15)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if client.equipment == nil {
+ t.Fatal("crafted HUD item could not be worn")
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ worn := newTestInventoryServer(t).characters[1]
+ if err := world.handleInventory(client, itemMovePacket(1, 15, 111)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+
+ if worn.inventory.Items[1] != (ownedItem{ID: 4, Type: 51022, Template: 158416, Quality: 1, Slot: 15, Count: 1}) ||
+ player.inventory.Items[1].ID != 4 || player.inventory.Items[1].Slot != 65 {
+ t.Fatal("wear/remove changed the crafted identity or placement")
+ }
+ for _, stat := range []uint32{122, 127, 128, 129, 130, 131} {
+ if worn.equipmentBonus(stat) != 1 || player.equipmentBonus(stat) != 0 {
+ t.Fatal("crafted item did not add/remove its six nano-skill bonuses")
+ }
+ }
+}
+
+func TestItemCombinationCancelsOpenBasketsWithoutConsumingRestoredItems(t *testing.T) {
+ for _, scenario := range []string{"shop", "player"} {
+ t.Run(scenario, func(t *testing.T) {
+ var world *server
+ source := uint32(65)
+ if scenario == "shop" {
+ world, _ = newShopWorld(t)
+ } else {
+ world, _ = newPlayerTradeWorld(t)
+ playerTradeRequest(t, world, 1, 0, [2]uint32{50000, 2}, [2]uint32{})
+ source = 66
+ }
+ for _, template := range []uint32{95577, 161699} {
+ if granted, err := world.grantItem_locked(world.characters[1], template); err != nil || !granted {
+ t.Fatalf("ingredient: %v %v", granted, err)
+ }
+ }
+ playerTradeRequest(t, world, 1, 4, [2]uint32{50000, 1}, [2]uint32{104, source})
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ lastID := world.nextItem
+
+ err = world.handleItemCombination(world.clients[1], combinationRequest(1, source, source+1))
+ after, readErr := readTestItemStore(world)
+
+ if err != nil || readErr != nil || !bytes.Equal(before, after) || world.nextItem != lastID ||
+ world.clients[1].trade != nil || world.clients[1].shop != nil {
+ t.Fatal("basket cancellation consumed a restored ingredient or allocated a result")
+ }
+ })
+ }
+}
+
+func TestItemCombinationLostReplyKeepsTheCommittedResult(t *testing.T) {
+ world, _ := newCombinationWorld(t)
+ world.clients[1].conn = &failingCombatConn{}
+
+ failed := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66))
+ if err := world.handleItemCombination(world.clients[1], combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+ restored := newTestInventoryServer(t)
+
+ if failed == nil || len(restored.characters[1].inventory.Items) != 2 || world.nextItem != 4 ||
+ restored.characters[1].inventory.Items[1] != (ownedItem{ID: 4, Type: 51022, Template: 158416, Quality: 1, Slot: 65, Count: 1}) {
+ t.Fatal("lost reply reversed consumption or repeated result creation")
+ }
+}
+
+func TestCraftedNCUHackerInterfaceRejectsWrongProfessionAndSlot(t *testing.T) {
+ for _, scenario := range []string{"profession", "slot"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newCombinationWorld(t)
+ client := world.clients[1]
+ if err := world.handleItemCombination(client, combinationRequest(1, 65, 66)); err != nil {
+ t.Fatal(err)
+ }
+ slot := uint32(15)
+ if scenario == "profession" {
+ world.characters[1].profession = 3
+ } else {
+ slot = 1
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ err = world.handleInventory(client, inventoryMovePacket(1, 65, slot)[20:])
+ after, readErr := readTestItemStore(world)
+
+ if err != nil || readErr != nil || !bytes.Equal(before, after) || client.equipment != nil ||
+ world.characters[1].inventory.Items[1].Slot != 65 || world.characters[1].equipmentBonus(122) != 0 ||
+ len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 ||
+ binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x47537a24 {
+ t.Fatal("crafted item's authored wear rejection changed ownership or effects")
+ }
+ })
+ }
+}