aorecomp

Anarchy Online classic in the browser

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


commit 3eabb0825cad0b281e8df6eaa8fc194eecef4a37
parent 8ba67415c509e683f7925144dd924a5047ccc068
Author: anon <anon@example.com>
Date:   Sun, 25 Oct 2026 13:26:46 +0000

Test shop drafts across live control edits

Cover mixed-basket inventory edits through public HTTP and native world reconnections. Verify retired-session Accept rejection, fresh purchases, and preservation of the original draft after a failed SQL save.

Record actual WASM edit, range and purchase checks. Keep the unreproduced historical range failure and unwind freeze open, and flag typed static-shop aliases for further audit.

Diffstat:
MTODO.md | 16++++++++++++++++
Adocs/shop-control-edits.md | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/shops.md | 4++++
Aserver/shop_control_edit_test.go | 169+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 311 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -605,6 +605,12 @@ introduction and starting-item gameplay remain open below. Original terminal bindings keep the opaque OTIM code from leaking Tools entries into Computers. Native purchases preserve each row's template, price, Unique rules and durable identity. +- [ ] Audit static type-51005 shop Use aliases against full typed identities, + templates and positions. Equal numeric IDs can belong to distinct objects: + the live-edit scene's 51005:3221226655 is template 43553 at a different + position from vending 51035:3221226655. Recover when static scene picking + legitimately refers to a vending placement before changing the alias path. + See `docs/shop-control-edits.md` and `local/shop-edit-smoke/verification.json`. - [ ] Recover complete historical shop stock, including the starter QETS category's actual membership. Original descriptors identify 153 categories but do not establish their stock. Research online for shop @@ -1371,6 +1377,16 @@ current SQLite storage when applying these findings. reopening the window; establish the cause before changing the protocol. Evidence: `local/player-trade-smoke/check-vendor-pick-state.json` and `fixed-fresh-vendor.png`. This is separate from the freeze below. + A bounded follow-up audit found native actor/helper replacement, draft + closure and successful reopening after empty, sale-only and mixed-basket + inventory edits. The old probe also compared a Tools hit with a hardcoded + Medical object. This does not establish a fix or explain the old failure. + See `docs/shop-control-edits.md` and `local/shop-edit-smoke/verification.json`. +- [x] Add HTTP-to-world regressions for edits during a mixed shop basket: + assign another item, move/unassign the offered item, reject stale Accept + before/after native reconnect, reopen an empty basket and buy again. + Inject a failed SQL edit and verify unchanged ownership/cash/session plus + acceptance of the original draft. See `server/shop_control_edit_test.go`. - [ ] Reproduce and fix a WASM freeze during live control-panel player edits that reload the playfield. Check: capture the full stack for the observed `ErrorEvent: unwind`, verify that native frames and world traffic resume, diff --git a/docs/shop-control-edits.md b/docs/shop-control-edits.md @@ -0,0 +1,122 @@ +# Shop drafts during control-panel edits + +Live inventory edits retire the current world session and send a playfield +teleport followed by a redirect. A shop draft owns no items: offered rows +remain in the durable inventory until Accept commits the transaction. The +replacement session starts without a shop, and old-session requests fail the +current-client check. A failed control-panel save leaves both the session and +its draft intact. + +This regression audit did not reproduce the earlier nearby-terminal range +failure or the separate WASM `unwind` freeze. Both remain open in TODO.md. +There is no production protocol change in this milestone. + +## Original client lifecycle and range check + +The retained 14.9.1 evidence separates three operations: + +- KKR actor destruction disposes the trade helper at actor `+0x160`, invokes + cancellation, and frees the separate action validator at `+0x180`. +- Trade cancellation clears actor flag 8 and emits `CMsg_TradeCompleted`. + DDR closes the trade window and clears its active byte at `+0x4c`. + Cached partner identities and old quote fields can remain while inactive. +- DDR shutdown destroys the trade view singleton. A normal trade cancellation + does not require that module shutdown. + +Original KKR `100774a0` only cancels while actor flag 8 is set. Constructor +`10077320` clears that flag. Sending a late abort after actor replacement can +therefore be ignored. DDR `100485b0` also ignores trade startup while its view +is already active. These are useful diagnostic boundaries, not evidence that +the reported failed edit actually took either path. + +Use validation is independent of the trade view's cached partner. KKR +`1004d350` freshly resolves the command's target and compares exact global +positions against the action helper's owner. An unparented target fails at +Euclidean distance greater than five metres. The helper's first DWORD stores +its actor; actor getter `10071dd0` supplies that helper. LLR `10017f50` delegates +global position to QQR `10011200`, selecting vehicle `+0x54` or `+0xe8` +according to vehicle `+0x28`. Unconditional relative-position probes are +insufficient for parented vehicles. + +Native validation can reject a command before it reaches the wire. A separate +server feedback entry has similar range-error wording, so chat text alone +does not identify which layer rejected the interaction. Capture the clicked +identity, exact positions, helper owner and outgoing Use together. + +The old smoke capture's active partner and ray hit identify Tools, while its +separate hardcoded shop probe identifies Medical. That mismatch does not prove +a stale object or incorrect native target. The old failure cannot be diagnosed +from that probe alone. + +The new scene probe also finds static `51005:3221226655`, template 43553, at +`[176.325,5.00036,129]`, separately from Medical `51035:3221226655` at +`[192,5,139.5]`. These are distinct full identities despite equal numeric IDs. +The existing static Use alias needs an audit of actual picks and placements; +this observation alone does not establish the correct mapping or justify +removing an interaction path used by earlier native checks. + +The source ledger is `local/shop-edit-research/native/README.md`, with 14 +complete retained original REA records, 11 checked citations and supporting +maintained-source ranges. Original KKR SHA-256 is +`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. +Principal cancellation evidence is +`ev_3b068fe016d29c9c6d60176e86341dcd106df72df90b32492a9c956186bf61c7`; +range validation is +`ev_6483e6cd8d2790a26b1aca8299d6837e26f7efbde18efd5fa8babcb9a5c4abc1`. +No fresh binary analysis session was opened. The original scene teardown's +complete same-playfield destruction ordering remains unproven statically. + +## Automated regressions + +`server/shop_control_edit_test.go` stages both a purchase and a sale before +each public HTTP edit. Cases assign another item, move the offered item, and +unassign the offered item without deleting its instance. They verify exact +live/restored ownership, unchanged cash, the teleport/redirect sequence, and +old Accept requests before and after a native world reconnection. + +The replacement connection also sends an unsolicited Accept, reopens Tools +over the native wire, verifies an empty draft, and completes a fresh purchase. +A separate injected SQL failure verifies rollback of profile, cash and item +placement, preservation of the active session/draft, and successful acceptance +of that original basket afterward. The Tools fixture pays 734 for the axe and +charges 228 for the lock pick; 1000 starting cash becomes exactly 1506. +Three race-detector repetitions passed in 98.723 seconds. Vet passed. +The full Go suite passed 4875 tests and subtests: server 805.656 seconds and +game data 7.621 seconds. + +## Actual WASM checks + +Two owned clients used the published build and GPU renderer. Native +mouse input opened Tools in playfield 1183. Public control routes performed +the edits; native heaps, world WebSockets and SQLite were read for comparison. + +An empty draft, a sale-only draft and a mixed draft all closed on inventory +assignment. The verified mixed quote was 230 purchase / 13 sale. Each edit +replaced the actor and action helper, restored the staged sale, retained +20000 cash and reopened an empty catalog within two metres of Tools. Cached +partner IDs and quote values remaining in the inactive view were inert. + +An open backpack and an item held on the cursor also survived edits with +advancing native ticks and all item IDs accounted for. The range check was +tested by moving beyond five metres and returning nearby without reloading +the page. At 5.125 metres the corrected repeat captured the native range +feedback and no outgoing Use; at 1.990 metres it reopened normally. A new +230-credit purchase then completed, leaving 19770 cash and six durable items. +Page reload recovered all six real item identities and the same cash. +Verification details and bounded limitations are recorded in +`local/shop-edit-smoke/verification.json`. + +The first mixed-basket input attempt added and then removed its purchase; +it is retained as a sale-only case. A later snapshot explicitly verifies +both quote fields before the mixed edit. The initial harness also stopped on +a missing chat-probe file after its completed checks; its cleanup closed the +owned clients. Another browser launch reset the camera, so its missed clicks +were excluded from range conclusions. The corrected repeat explicitly selected +first person and checked the hit identity. Those harness errors are not client +failures. Page and worker error listeners captured no client errors; the +observed `unwind` freeze still needs a reproduction and full stack. + +Both owned clients were closed. Cleanup removed only players 55/56 and their +six items; unrelated-row hashes, foreign keys and SQLite integrity passed, +retaining players 8/24. The single normal preview was restarted on its default +HTTPS and game ports. No WASM rebuild or production catalog change was needed. diff --git a/docs/shops.md b/docs/shops.md @@ -58,6 +58,10 @@ native client, rather than a recovered historical server implementation. Native scene picking can send Use for static identity type 51005 with the same instance ID. That request resolves to the supported placement and receives the same validation. Trade messages identify the machine as type 51035. +The alias is a reconstruction that needs a complete typed-identity audit: +the live-edit regression scene also contains a type-51005 object whose numeric +ID matches a different vending placement. Numeric equality alone does not +establish that two objects are aliases. See [control-edit checks](shop-control-edits.md). `local/shop-research/catalog.json` retains parsed templates, raw placement bytes and hashes. The Omni training-ground placement record SHA-256 is diff --git a/server/shop_control_edit_test.go b/server/shop_control_edit_test.go @@ -0,0 +1,169 @@ +package main + +import ( + "encoding/binary" + "net/http" + "net/url" + "reflect" + "testing" +) + +func TestShopControlEditRetiresDraftBeforeReconnection(t *testing.T) { + for _, scenario := range []struct { + name string + document string + items []ownedItem + nextItem uint32 + }{ + {"assign another item", "", []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 64, Count: 1}, {ID: 2, Type: 51005, Template: 95577, Quality: 1, Slot: 65, Count: 1}}, 2}, + {"move offered item", "inventory:\n slots: {inventory_slot_1: null, inventory_slot_2: 1}\n", []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 65, Count: 1}}, 1}, + {"unassign offered item", "inventory:\n slots: {inventory_slot_1: null}\n", nil, 1}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, conn := newPurchaseWorld(t) + world.baseURL = "/" + client := world.clients[1] + for _, body := range [][]byte{ + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:], + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221488799}, [2]uint32{111, 0})[20:], + } { + if err := world.handleTrade(client, body); err != nil { + t.Fatal(err) + } + } + if len(client.shop.items) != 1 || client.shop.purchases[0] != 1 { + t.Fatal("mixed basket was not staged") + } + if scenario.document == "" { + created := postControlForm(world, "/control/items", url.Values{"template": {"95577"}}) + if created.Code != http.StatusSeeOther || created.Header().Get("Location") != "/control/items/2" { + t.Fatalf("create item: %d %s", created.Code, created.Body.String()) + } + } + conn.packets = nil + + path, fields := "/control/users/1", url.Values{"data": {scenario.document}} + if scenario.document == "" { + path, fields = "/control/items/2", url.Values{"action": {"assign"}, "owner": {"1"}, "destination": {"0:65"}} + } + response := postControlForm(world, path, fields) + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{}) + if err := world.handleTrade(client, accept[20:]); err != nil { + t.Fatal(err) + } + restored := newTestInventoryServer(t) + + if response.Code != http.StatusSeeOther || world.clients[1] != nil || client.ready || + len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x43197d22 || binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x3c { + t.Fatalf("edit did not retire the old session: %d %s packets=%x", response.Code, response.Body.String(), conn.packets) + } + for _, state := range []*server{world, restored} { + if state.characters[1].inventory.Credits != 1000 || !reflect.DeepEqual(state.characters[1].inventory.Items, scenario.items) || + state.nextItem != scenario.nextItem || state.items[1].Template != 209283 { + t.Fatalf("stale acceptance changed edited ownership: %+v", state.characters[1].inventory) + } + } + + // Reconnect on the native wire; an old Accept must not create a new basket. + connection := connectZoningClient(t, world, true) + if err := world.handleTrade(client, accept[20:]); err != nil { + t.Fatal(err) + } + if _, err := connection.Write(targetPacket(accept)); err != nil { + t.Fatal(err) + } + ping := systemPacket(1, nil) + binary.BigEndian.PutUint16(ping[2:4], 11) + if _, err := connection.Write(ping); err != nil { + t.Fatal(err) + } + packet, err := readPacket(connection) + world.mutex.Lock() + active := world.clients[1] + unchanged := active != client && active.shop == nil && world.characters[1].inventory.Credits == 1000 + world.mutex.Unlock() + if err != nil || len(packet) != 20 || !unchanged { + t.Fatalf("old acceptance survived reconnect: %v %x", err, packet) + } + + // Reopening delivers a fresh empty catalog and accepts a new purchase. + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221488799) + if _, err := connection.Write(targetPacket(n3Packet(0x52526858, 50000, 1, request[16:]))); err != nil { + t.Fatal(err) + } + for range 5 { + if _, err := readPacket(connection); err != nil { + t.Fatal(err) + } + } + world.mutex.Lock() + empty := active.shop != nil && len(active.shop.items) == 0 && len(active.shop.purchases) == 0 + world.mutex.Unlock() + if !empty { + t.Fatal("reopened shop retained an old offer") + } + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221488799}, [2]uint32{111, 0}) + if _, err := connection.Write(targetPacket(add)); err != nil { + t.Fatal(err) + } + if _, err := readPacket(connection); err != nil { + t.Fatal(err) + } + if _, err := connection.Write(targetPacket(shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{}))); err != nil { + t.Fatal(err) + } + for range 3 { + if _, err := readPacket(connection); err != nil { + t.Fatal(err) + } + } + purchased := newTestInventoryServer(t) + if purchased.characters[1].inventory.Credits != 772 || purchased.nextItem != scenario.nextItem+1 || len(purchased.characters[1].inventory.Items) != len(scenario.items)+1 { + t.Fatalf("fresh purchase failed after edit: %+v", purchased.characters[1].inventory) + } + }) + } +} + +func TestShopRejectedControlSavePreservesAcceptableDraft(t *testing.T) { + world, conn := newPurchaseWorld(t) + world.baseURL = "/" + client := world.clients[1] + for _, body := range [][]byte{ + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:], + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221488799}, [2]uint32{111, 0})[20:], + } { + if err := world.handleTrade(client, body); err != nil { + t.Fatal(err) + } + } + if _, err := world.db.Exec("CREATE TRIGGER reject_editor BEFORE UPDATE OF name ON characters WHEN NEW.id=1 BEGIN SELECT RAISE(ABORT, 'write failed'); END"); err != nil { + t.Fatal(err) + } + conn.packets = nil + + response := postControlForm(world, "/control/users/1", url.Values{"data": {"name: Changed\ninventory:\n credits: 17\n slots: {inventory_slot_1: null, inventory_slot_2: 1}\n"}}) + restored := newTestInventoryServer(t) + + if response.Code != http.StatusInternalServerError || world.clients[1] != client || !client.ready || client.shop == nil || + len(client.shop.items) != 1 || client.shop.purchases[0] != 1 || len(conn.packets) != 0 { + t.Fatalf("failed save changed the live draft/session: %d %s", response.Code, response.Body.String()) + } + for _, state := range []*server{world, restored} { + if state.characters[1].name != "Axe Owner" || state.characters[1].inventory.Credits != 1000 || len(state.characters[1].inventory.Items) != 1 || state.characters[1].inventory.Items[0].Slot != 64 { + t.Fatal("failed save changed the profile or offered item") + } + } + if _, err := world.db.Exec("DROP TRIGGER reject_editor"); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil { + t.Fatal(err) + } + purchased := newTestInventoryServer(t).characters[1].inventory + // Tools pays 734 for the axe and charges 228 for the lock pick. + if purchased.Credits != 1506 || !reflect.DeepEqual(purchased.Items, []ownedItem{{ID: 2, Type: 51005, Template: 95577, Quality: 1, Slot: 64, Count: 1}}) { + t.Fatalf("failed edit prevented the original basket from completing: %+v", purchased) + } +}