commit 107f3a9ddd4b851b0ab55e4d0ae78e8475c452cf
parent 5365d90a9ee4a2db323d165e4a12fb02ba1206b1
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 09:30:01 +0000
Explain rejected player trades through original feedback messages
Diffstat:
4 files changed, 163 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -971,9 +971,12 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
- [x] Include credits in a trade. Both balances and item ownership commit in one
transaction. Tests cover native Cash6-on-Accept, bounds, overflow, failed
persistence, concurrent/replayed acceptance and lost completion replies.
-- [ ] Recover native feedback for rejected player trades, including a full
- recipient inventory and duplicate Unique items. Current rejection safely
- closes the trade; show an evidenced reason through the original client.
+- [x] Recover native feedback for rejected player trades. Full recipients and
+ their partners receive original FeedbackIIR IDs 24/21; duplicate Unique
+ recipients and partners receive 48/47. Send feedback after durable restoration,
+ with failure/retry and both directions covered. Two hardware WASM clients
+ verified each message, unchanged items/cash, and a subsequent valid gift.
+ See [player-trade feedback](docs/player-trading.md).
- [ ] Establish remaining historical trade policies: Unique counting across
bank/reclaim, acceptance edits and server-side eligibility beyond the native
five-unit start check. Keep inferred policies explicit in the protocol ledger.
diff --git a/docs/player-trading.md b/docs/player-trading.md
@@ -86,6 +86,16 @@ validator 0x10060510 rejects any NoDrop or Unique child through 0x1008bdd0.
Original server-error strings also describe recipient capacity and Unique
duplicates; they do not establish exact server counting rules.
+Rejected completion now uses the original FeedbackIIR key `0x50544d19`, whose
+body is one catalog-ID DWORD. Full recipients receive 24 and their partners 21;
+duplicate Unique recipients receive 48 and their partners 47. The original
+client supplies the text. Both inventories restore durably before Abort and
+feedback; failed restoration leaves the draft retryable and sends neither.
+The IDs, reader and native chat delivery are recovered client behavior. Selecting
+the participant according to the text's perspective is reconstruction policy;
+historical server routing and multi-error priority remain unproven. Research:
+`local/player-trade-research/native/feedback.md`.
+
Peer Add7 reaches 0x10061b40 then row constructor 0x1002d870, which explicitly
creates flags 0x22 and count one. QL and templates come from actual item
stats 701/702/703. Neither Energy26 nor MultipleCount412 populates the row
diff --git a/server/player_trade_feedback_test.go b/server/player_trade_feedback_test.go
@@ -0,0 +1,127 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "testing"
+)
+
+func TestPlayerTradeRejectionExplainsEachParticipantsFailure(t *testing.T) {
+ for _, reason := range []string{"full inventory", "duplicate unique"} {
+ for _, recipient := range []uint32{1, 2} {
+ t.Run(fmt.Sprintf("%s/recipient%d", reason, recipient), func(t *testing.T) {
+ world, conns := newPlayerTradeWorld(t)
+ donor := 3 - recipient
+ source := uint32(64)
+ if donor == 1 {
+ source = 65
+ }
+ if reason == "full inventory" {
+ for len(world.characters[recipient].inventory.Items) < 30 {
+ if granted, err := world.grantItem_locked(world.characters[recipient], 95577); err != nil || !granted {
+ t.Fatalf("fill: %v %v", granted, err)
+ }
+ }
+ } else {
+ for _, id := range []uint32{1, 2} {
+ if granted, err := world.grantItem_locked(world.characters[id], 161699); err != nil || !granted {
+ t.Fatalf("unique: %v %v", granted, err)
+ }
+ }
+ source++
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ playerTradeRequest(t, world, 1, 0, [2]uint32{50000, 2}, [2]uint32{})
+ playerTradeRequest(t, world, donor, 4, [2]uint32{50000, donor}, [2]uint32{104, source})
+ playerTradeRequest(t, world, donor, 1, [2]uint32{}, [2]uint32{})
+ conns[0].packets, conns[1].packets = nil, nil
+
+ playerTradeRequest(t, world, recipient, 1, [2]uint32{}, [2]uint32{})
+ playerTradeRequest(t, world, recipient, 1, [2]uint32{}, [2]uint32{})
+ after, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if !bytes.Equal(before, after) || world.clients[1].trade != nil || world.clients[2].trade != nil {
+ t.Fatal("rejection changed ownership/cash or retained the draft")
+ }
+ for side, conn := range conns {
+ code := uint32(21)
+ if uint32(side+1) == recipient {
+ code = 24
+ }
+ if reason == "duplicate unique" {
+ code = 47
+ if uint32(side+1) == recipient {
+ code = 48
+ }
+ }
+ feedback := 0
+ for _, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x50544d19 {
+ feedback++
+ if binary.BigEndian.Uint32(packet[24:28]) != uint32(side+1) || binary.BigEndian.Uint32(packet[29:33]) != code {
+ t.Fatalf("wrong feedback perspective: %x", packet)
+ }
+ }
+ }
+ if feedback != 1 || binary.BigEndian.Uint32(conn.packets[0][33:37]) != 2 ||
+ binary.BigEndian.Uint32(conn.packets[len(conn.packets)-1][16:20]) != 0x50544d19 {
+ t.Fatal("feedback was repeated, missing or sent before cancellation")
+ }
+ }
+ })
+ }
+ }
+}
+
+func TestPlayerTradeRejectionWaitsForDurableRestoration(t *testing.T) {
+ world, conns := newPlayerTradeWorld(t)
+ for _, id := range []uint32{1, 2} {
+ if granted, err := world.grantItem_locked(world.characters[id], 161699); err != nil || !granted {
+ t.Fatalf("unique: %v %v", granted, err)
+ }
+ }
+ inventory := world.characters[1].inventory
+ inventory.Items[2].Slot = 70
+ if err := world.saveInventory_locked(world.characters[1], inventory); err != nil {
+ t.Fatal(err)
+ }
+ playerTradeRequest(t, world, 1, 0, [2]uint32{50000, 2}, [2]uint32{})
+ playerTradeRequest(t, world, 1, 4, [2]uint32{50000, 1}, [2]uint32{104, 70})
+ playerTradeRequest(t, world, 1, 1, [2]uint32{}, [2]uint32{})
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER fail_restore BEFORE INSERT ON item_locations WHEN NEW.item_id=4 BEGIN SELECT RAISE(ABORT, 'restoration'); END"); err != nil {
+ t.Fatal(err)
+ }
+ conns[0].packets, conns[1].packets = nil, nil
+ request := shopTradePacket([2]uint32{50000, 2}, 1, [2]uint32{}, [2]uint32{})[20:]
+
+ failed := world.handleTrade(world.clients[2], request)
+ after, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if failed == nil || !bytes.Equal(before, after) || world.clients[1].trade == nil || world.clients[2].trade == nil ||
+ len(conns[0].packets) != 0 || len(conns[1].packets) != 0 {
+ t.Fatal("failed restoration published rejection or changed ownership")
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_restore"); err != nil {
+ t.Fatal(err)
+ }
+ playerTradeRequest(t, world, 2, 1, [2]uint32{}, [2]uint32{})
+ if world.clients[1].trade != nil || world.clients[2].trade != nil ||
+ binary.BigEndian.Uint32(conns[0].packets[len(conns[0].packets)-1][29:33]) != 47 ||
+ binary.BigEndian.Uint32(conns[1].packets[len(conns[1].packets)-1][29:33]) != 48 {
+ t.Fatal("successful retry did not cancel with the Unique explanation")
+ }
+}
diff --git a/server/player_trading.go b/server/player_trading.go
@@ -122,6 +122,20 @@ func (server *server) cancelPlayerTrade_locked(client *worldClient) {
}
}
+func (server *server) rejectPlayerTrade_locked(client *worldClient, feedback [2]uint32) error {
+ trade := client.trade
+ if err := server.abortPlayerTrade_locked(client); err != nil {
+ return err
+ }
+ for side, participant := range trade.clients {
+ body := binary.BigEndian.AppendUint32(nil, feedback[side])
+ if err := participant.send(n3Packet(0x50544d19, 50000, participant.id, body)); err != nil {
+ participant.disconnect(participant.conn)
+ }
+ }
+ return nil
+}
+
func tradeableItem(inventory playerInventory, item ownedItem) bool {
if itemStat(item.templateDefinition(), 0)&0x04000000 != 0 {
return false
@@ -305,14 +319,18 @@ func (server *server) completePlayerTrade_locked(client *worldClient) error {
for _, slot := range tradeSlots(trade.items[1-side]) {
item := trade.items[1-side][slot]
if itemStat(item.templateDefinition(), 0)&0x08000000 != 0 && inventories[side].carriesUnique(item) {
- return server.abortPlayerTrade_locked(client)
+ feedback := [2]uint32{47, 47}
+ feedback[side] = 48
+ return server.rejectPlayerTrade_locked(client, feedback)
}
item.Slot = 64
for slices.ContainsFunc(inventories[side].Items, func(other ownedItem) bool { return other.Slot == item.Slot }) {
item.Slot++
}
if item.Slot >= 94 {
- return server.abortPlayerTrade_locked(client)
+ feedback := [2]uint32{21, 21}
+ feedback[side] = 24
+ return server.rejectPlayerTrade_locked(client, feedback)
}
inventories[side].Items = append(inventories[side].Items, item)
contents := server.characters[trade.clients[1-side].id].inventory.Containers[item.ID]