aorecomp

Anarchy Online classic in the browser

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


commit 0370ad1516d7220e853f0889d89d2ce31048d4db
parent 757732b221ea6843b3aa4427840a036d4c8de230
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 00:50:54 +0000

Resynchronize kept stacks after a consumed source is joined again

Diffstat:
MTODO.md | 14+++++++-------
Mdocs/inventory-stacks.md | 36+++++++++++++++++++++++-------------
Mserver/browser_stale_stack_join_test.go | 12++++++++++++
Mserver/stack_family_test.go | 12++++++++++--
Mserver/stacks.go | 9+++++++++
Mserver/stacks_test.go | 8+++++++-
Mserver/stale_stack_join_test.go | 6++++--
Mtools/client/test_stale_stack_join.mjs | 10++++++----
8 files changed, 78 insertions(+), 29 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4041,13 +4041,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. both directions during wear/removal without writes or deadline changes. No product defect reproduced on this path; see [backpack joins](docs/backpacks.md#stack-join-during-pending-equipment). -- [x] [P0] Restore a still-owned ordinary stack after joining onto a stale empty - target. A controlled earlier merge without native refresh leaves a seven-charge - source hidden after its real join receives no reply, although storage retains - all fifteen charges. Source restoration and authoritative selected-QL rows now - pass without writes or false join success. A17.74-second WASM check verifies a - same-window valid retry, page and cold recovery of the final identity and all - charges; invalid/unowned sources remain ignored. See +- [x] [P0] Restore ordinary stacks after stale joins. A missing target hides the + still-owned source; an already-consumed source leaves the kept count stale. + Controlled missed-refresh checkpoints reproduce both real requests without + replies. Source restoration and authoritative selected-QL rows now pass without + writes or false join success. Two short WASM checks verify a same-window valid + retry, page and cold recovery of the final identity and all fifteen charges. + Foreign/out-of-range requests and joins without a known owned stack stay ignored. See [stale stack joins](docs/inventory-stacks.md#stale-ordinary-join-targets). - [x] Explicitly refuse owned-item Use during pending equipment. Reproduction: real backpack Use after the local equip animation receives no response while diff --git a/docs/inventory-stacks.md b/docs/inventory-stacks.md @@ -248,29 +248,39 @@ onto it sends action53 and empties the cursor, but the missing target previously caused a silent return. The seven-charge source stayed dummy/hidden; both surviving instances and all fifteen charges remained in storage. -The handler now validates the removed source as an owned ordinary stack, restores -its GUI entry through the existing two ContainerAddItem swaps, then uses the -ordinary-stack rebuild described above. This removes the stale target and sends +The complementary case drags the consumed ID1 onto the still-owned ID2. Its +missing removed source also previously caused a silent return. The cursor clears +and the ghost becomes hidden, while the visible kept stack still reports5 charges +instead of8. No second ownership change is needed to repair this state. + +The handler validates the surviving removed or kept entry as an owned ordinary +stack, restores its GUI entry through the existing two ContainerAddItem swaps, +then uses the ordinary-stack rebuild described above. This removes ghosts and sends the authoritative selected endpoints, QL and counts. It writes no inventory or -allocation state and sends no successful join acknowledgement. Unknown, -individual-item, foreign-page and out-of-range sources remain ignored. Pending +allocation state and sends no successful join acknowledgement. Requests without +a known owned stack, with an individual item instead, or with foreign pages or +out-of-range slots remain ignored. Pending equipment retains its separate refusal path. This uses recovered native operations, without establishing the original server's refusal sequence. `TestStaleStackJoinRestoresOwnedSourceWithoutWrites` checks repeated requests, -source validation, ordered restoration, exact selected endpoints, no writes and +source validation, both missing-entry directions, ordered restoration, exact selected endpoints, no writes and cold ownership. `TestBrowserStaleStackJoin` uses real inventory gestures to reproduce the missing source, restore usable8/7-charge rows and immediately retry against the correct target. Only that retry receives a successful action53; ID2 then retains15 charges through page replay and cold Go loading, with allocation still3. The earlier merge is controlled fixture state, not earned progression. -The native check passed in17.74s with five clean traces. Baseline and corrected -captures are in `local/stale-stack-join/20261103-163358/` and -`local/stale-stack-join/20261103-163641/`. -Related checks pass16 Go roots/164 results in50.918s; the focused race run passes -3 roots/15 results in98.219s, including individual-source rejection. Vet and Node -syntax checks pass. Independent request/reply, selected-contract and source-hash -checks are retained in `local/stale-stack-join/validation.json`. +The maintained fixture now runs both directions separately, with five clean +traces each. They pass in17.64s/17.80s; captures are in +`local/stale-stack-join/20261103-164641/` and `20261103-164659/`. +The missing-source negative capture is `local/stale-stack-join/20261103-164449/`; +the earlier missing-target baseline remains at `20261103-163358/`. +Related checks pass16 Go roots/168 results in69.151s. Repeated and concurrent +joins retain one successful acknowledgement; ordinary repeats additionally +resynchronize current rows. Bank/backpack reply behavior is unchanged. +The focused race run passes3 roots/16 results in98.372s; vet and Node syntax +checks pass. Independent request/reply, selected-contract, trace-completeness +and source-hash checks are retained in `local/stale-stack-source/validation.json`. ## Verification diff --git a/server/browser_stale_stack_join_test.go b/server/browser_stale_stack_join_test.go @@ -20,7 +20,13 @@ func TestBrowserStaleStackJoin(t *testing.T) { if os.Getenv("AO_GAME_TEST") != "1" { t.Skip("set AO_GAME_TEST=1 for stale ordinary stack joins") } + for _, missing := range []string{"target", "source"} { + t.Run(missing, func(t *testing.T) { testBrowserStaleStackJoin(t, missing) }) + } +} +func testBrowserStaleStackJoin(t *testing.T, missing string) { + t.Helper() _, source, _, _ := runtime.Caller(0) root := filepath.Dir(filepath.Dir(source)) output := filepath.Join(root, "local/stale-stack-join", time.Now().Format("20060102-150405")) @@ -61,7 +67,13 @@ func TestBrowserStaleStackJoin(t *testing.T) { if err := world.saveInventory_locked(player, inventory); err != nil { t.Error(err) http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + gesture := map[string]uint32{"removed": 50, "kept": 48} + if missing == "source" { + gesture = map[string]uint32{"removed": 48, "kept": 49} } + json.NewEncoder(w).Encode(gesture) }) host := httptest.NewServer(mux) t.Cleanup(host.Close) diff --git a/server/stack_family_test.go b/server/stack_family_test.go @@ -67,8 +67,16 @@ func TestStackJoinUsesReviewedSelectedEndpoints(t *testing.T) { t.Fatal("joined source retained a duplicate physical instance") } } - if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x5e477770 || - binary.BigEndian.Uint32(conn.packets[0][29:33]) != 53 { + acknowledgements, rebuilds := 0, 0 + for _, packet := range conn.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 53 { + acknowledgements++ + } + if binary.BigEndian.Uint32(packet[16:20]) == 0x052e2f0c { + rebuilds++ + } + } + if acknowledgements != 1 || (rebuilds == 1) != (location == "carried") || rebuilds > 1 { t.Fatal("reviewed-anchor join lost its single native acknowledgement") } }) diff --git a/server/stacks.go b/server/stacks.go @@ -66,6 +66,15 @@ func (server *server) changeStack_locked(client *worldClient, index int, body [] otherSlot &= 65535 } other := slices.IndexFunc(items, func(item ownedItem) bool { return item.Slot == otherSlot }) + if other < 0 && page == 104 && otherSlot >= 64 && otherSlot < 94 && binary.BigEndian.Uint32(body[28:32]) == 104 { + // A previously consumed source still needs the kept stack's current count. + for _, packet := range equipmentCorrectionPackets(client.id, items[index].Slot) { + if err := client.send(packet); err != nil { + return err + } + } + return server.syncStacks_locked(client) + } if binary.BigEndian.Uint32(body[28:32]) != binary.BigEndian.Uint32(body[20:24]) || other < 0 || other == index || items[other].Type != items[index].Type || items[other].Quality != items[index].Quality { return nil diff --git a/server/stacks_test.go b/server/stacks_test.go @@ -271,7 +271,13 @@ func TestStackConcurrentRepeatDoesNotDuplicateQuantity(t *testing.T) { t.Fatal(err) } } - if !reflect.DeepEqual(world.characters[1].inventory.Items, scenario.expected) || len(conn.packets) != 1 { + acknowledgements := 0 + for _, packet := range conn.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == scenario.action { + acknowledgements++ + } + } + if !reflect.DeepEqual(world.characters[1].inventory.Items, scenario.expected) || acknowledgements != 1 { t.Fatalf("repeated stack request duplicated quantity: %+v packets%d", world.characters[1].inventory, len(conn.packets)) } }) { diff --git a/server/stale_stack_join_test.go b/server/stale_stack_join_test.go @@ -9,7 +9,7 @@ import ( ) func TestStaleStackJoinRestoresOwnedSourceWithoutWrites(t *testing.T) { - for _, scenario := range []string{"owned source", "individual source", "unknown source", "foreign source page", "target outside inventory", "source outside inventory"} { + for _, scenario := range []string{"owned source", "consumed source", "individual source", "unknown source", "foreign source page", "target outside inventory", "source outside inventory"} { t.Run(scenario, func(t *testing.T) { world, conn := newStackWorld(t) player, client := world.characters[1], world.clients[1] @@ -26,6 +26,8 @@ func TestStaleStackJoinRestoresOwnedSourceWithoutWrites(t *testing.T) { } request := stackActionPacket(1, 53, 64, 65)[20:] switch scenario { + case "consumed source": + request = stackActionPacket(1, 53, 65, 64)[20:] case "individual source": player.inventory.Items[0] = ownedItem{ID: 2, Type: 51018, Template: 209283, Quality: 1, Slot: 65, Count: 1} if err := world.saveInventory_locked(player, player.inventory); err != nil { @@ -64,7 +66,7 @@ func TestStaleStackJoinRestoresOwnedSourceWithoutWrites(t *testing.T) { world.nextItem != 2 || cold.nextItem != 2 { t.Fatal("stale join refusal wrote inventory, changed allocation or lost charges", err) } - if scenario != "owned source" { + if scenario != "owned source" && scenario != "consumed source" { if len(conn.packets) != 0 { t.Fatal("invalid source or target created correction traffic") } diff --git a/tools/client/test_stale_stack_join.mjs b/tools/client/test_stale_stack_join.mjs @@ -31,14 +31,16 @@ try { await game.key('i'); await game.wait('three ordinary stacks', () => cell(48) && cell(49) && cell(50)); evidence.initial = await server(); - assert((await page.request.post(url + '/test-stale-view')).ok()); + const checkpoint = await page.request.post(url + '/test-stale-view'); + assert(checkpoint.ok()); + evidence.gesture = await checkpoint.json(); evidence.stale = await server(); await game.save(output + '/stale'); - // A real join targets the removed stack while hiding its still-owned source. + // Real input exercises either a missing target or an already-consumed source. const start = game.sequence; - await click(50); - await click(48); + await click(evidence.gesture.removed); + await click(evidence.gesture.kept); await game.wait('actual stale ordinary join', () => game.events.some(event => event.sequence > start && event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53));