aorecomp

Anarchy Online classic in the browser

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


commit 3612c337549a6ee60bc49ce48d1e21070d7f7660
parent ad56d2b5f9255d9c9959b8dc8ac0f8cbe0a475f7
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 08:19:30 +0000

Refresh owner resources after stale worn equipment correction

Diffstat:
MTODO.md | 10++++++++++
Mdocs/inventory.md | 45+++++++++++++++++++++++++++++++++++++++++++++
Mserver/browser_stale_inventory_move_test.go | 23++++++++++++++++++++++-
Mserver/inventory.go | 31++++++++++++++++++++++++++++---
Mserver/regeneration.go | 8++++++--
Mserver/stale_armor_move_test.go | 4++--
Aserver/stale_equipment_resources_test.go | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/stale_implant_move_test.go | 4++--
Mserver/stale_non_hand_move_test.go | 4++--
Mtools/client/test_stale_inventory_move.mjs | 27++++++++++++++++++++++++---
10 files changed, 216 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4114,6 +4114,16 @@ 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] Refresh derived resources after correcting a stale worn source. + Reproduction: retain worn Pioneer152039 after an earlier controlled bank + transfer, then remove its stale source102:19. Its ability effects clear, but + the baseline retained native40/38/8 foundations and40/38 current points while + the server had committed37/35/7 and37/35. The correction now refreshes those + owner values once after unwear and row clearing. Same-page re-wear restores + maxima40/38 and rating8 without healing the clamped points; page replay and + cold ownership preserve both IDs. No correction-time writes, repeated unwear + or observer broadcasts occur. See + [stale resource foundations](docs/inventory.md#stale-worn-resource-foundations). - [x] [P0] Correct empty stale HUD/utility, belt and deck removal sources. Reproduction: retain a native page101:9 memory after a controlled earlier bank transfer empties its row, then remove it normally; the baseline sent no reply. diff --git a/docs/inventory.md b/docs/inventory.md @@ -299,6 +299,51 @@ checks pass; all five final native traces have no errors or dropped events. Exact packet ordering, unchanged durable ownership and the manually reviewed Stats-window image hashes are retained in `local/stale-armor-move/validation.json`. +### Stale worn resource foundations + +A controlled Pioneer152039/QL1 checkpoint with base abilities12 exposes a +second stale-source failure. Its worn ability effects produce maximum HP40, +maximum nano38 and attack rating8. An earlier unreported bank transfer commits +the corresponding unworn37/35/7 values and clamps current HP/nano to37/35. +The native drag sends source102:19 to first-free111. The previous correction +cancelled it, removed the exact effect and cleared the icon, but left the native +cached foundations and current points at40/38/8/40/38. + +The focused Go baseline receives only five packets for two repeated requests, +with no resource refresh. The native assertion reproduces the exact old vector +against the committed37/35/7/37/35 values. The captures are +`local/stale-inventory-move/20261104-001217/19/` and +`local/stale-worn-resources/baseline.log`. + +After consuming a known published unwear and clearing its row, the correction +now publishes the owner's current health/nano foundations and attack rating, +then its already committed HP and nano points. The raw health foundation +excludes effective equipment/nano bonuses already applied by the native owner; +this follows the existing owner initialization contract. The zero-change +HealthDamage snapshot shares the normal recovery packet builder. No ownership +or resource write occurs during correction, and these +owner-specific repairs are not broadcast to observers. A duplicate without a +remaining published effect still receives only cancellation and row clearing. + +`TestStaleWornSourceRefreshesDerivedResourcesOnce` verifies the exact three +foundations and two point updates once, duplicate handling, observer isolation, +unchanged durable ownership/allocation and cold committed points. Existing +armor, implant and non-hand stale checks now also account for that one refresh. +`TestBrowserStaleWornResources` uses real picking/placing to remove the stale +backpack, withdraw the exact banked ID and re-wear it on the same page. It +verifies native37/35/7/37/35 after correction and40/38/8/37/35 after re-wear and +page replay. Manual original Stats-window inspection confirms both maxima, +current points and attack ratings. Cold Go loading conserves backpack1 at19 and +part2 at65, zero cash and allocator2. + +The24.76-second verified capture is +`local/stale-inventory-move/20261104-001407/19/`; all five trace error/drop +counters are zero. Packet ordering, source/capture hashes and manual observations +are retained in `local/stale-worn-resources/validation.json`. This controlled +stale-view case leaves the broader disappearance audit open. +Related Go checks pass121 roots/685 results; the focused race check, vet and +driver syntax checks pass. + ## Native visual order The shipped `cd_image/text/help/The Inventory Window.txt` documents left-click diff --git a/server/browser_stale_inventory_move_test.go b/server/browser_stale_inventory_move_test.go @@ -37,6 +37,10 @@ func TestBrowserStaleMemoryMove(t *testing.T) { testBrowserStaleInventoryMove(t, 9) } +func TestBrowserStaleWornResources(t *testing.T) { + testBrowserStaleInventoryMove(t, 19) +} + func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { t.Helper() if os.Getenv("AO_GAME_TEST") != "1" { @@ -50,6 +54,9 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { player.playfield, player.position = 1183, [3]float32{193.79826, 5.01, 136.83983} player.rotation = [4]float32{0, .70710677, 0, .70710677} player.stats = testCharacterStats() + if sourceSlot == 19 { + player.stats.Abilities = characterAbilitiesStats{12, 12, 12, 12, 12, 12} + } if sourceSlot == 37 { player.stats.NanoAiding.Treatment = 20 player.implantChangesUntil = time.Now().Add(time.Minute) @@ -72,9 +79,18 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { inventory.LastID = 3 inventory.Items = append(inventory.Items, ownedItem{ID: 3, Type: 51022, Template: 36783, Quality: 1, Slot: 7, Count: 1}) } + if sourceSlot == 19 { + inventory.Items[0].Type, inventory.Items[0].Template = 51017, 152039 + } if err := world.saveInventory_locked(player, inventory); err != nil { t.Fatal(err) } + if sourceSlot == 19 { + player.health, player.nano = player.maximumHealth(), player.maximumNano() + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + } mux := http.NewServeMux() mux.Handle("/", world.httpHandler()) mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { @@ -88,7 +104,9 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { playerInventory Armor [8]int32 MaximumNCU uint32 - }{player.inventory, armor, player.maximumNCU()}) + Resources [5]uint32 + }{player.inventory, armor, player.maximumNCU(), [5]uint32{ + player.maximumHealth(), player.maximumNano(), uint32(player.attackRating()), player.health, player.nano}}) }) // Isolate an earlier bank transfer without refreshing its old source. mux.HandleFunc("POST /test-stale-view", func(w http.ResponseWriter, r *http.Request) { @@ -148,6 +166,9 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { expected[0].Type, expected[0].Template, expected[0].Slot = 51022, 36779, 9 expected = append(expected, ownedItem{ID: 3, Type: 51022, Template: 36783, Quality: 1, Slot: 7, Count: 1}) } + if sourceSlot == 19 { + expected[0].Type, expected[0].Template, expected[0].Slot = 51017, 152039, 19 + } for _, actual := range []playerInventory{player.inventory, cold.characters[1].inventory} { items := slices.Clone(actual.Items) slices.SortFunc(items, func(a, b ownedItem) int { return cmp.Compare(a.ID, b.ID) }) diff --git a/server/inventory.go b/server/inventory.go @@ -390,13 +390,38 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { if err := client.send(characterActionPacket(client.id, [5]uint32{146, sourceType, sourceSlot})); err != nil { return err } - if packet := client.wornRemoval[sourceSlot]; packet != nil { - if err := client.send(packet); err != nil { + removal := client.wornRemoval[sourceSlot] + if removal != nil { + if err := client.send(removal); err != nil { return err } client.wornRemoval[sourceSlot] = nil } - return client.send(characterActionPacket(client.id, [5]uint32{112, sourceType, sourceSlot})) + if err := client.send(characterActionPacket(client.id, [5]uint32{112, sourceType, sourceSlot})); err != nil { + return err + } + if removal == nil { + return nil + } + + // Inverse effects do not refresh the owner's cached derived foundations. + for _, stat := range [][2]uint32{ + {1, character.maximumHealth() - uint32(character.equipmentBonus(1)+character.nanoBonus(1))}, + {221, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))}, + {22, uint32(character.attackRating())}, + } { + body := binary.BigEndian.AppendUint32(nil, stat[0]) + body = binary.BigEndian.AppendUint32(body, stat[1]) + if err := client.send(n3Packet(0x2b333d6e, 50000, client.id, body)); err != nil { + return err + } + } + for _, packet := range [][]byte{healthSnapshotPacket(character), nanoPointsPacket(character)} { + if err := client.send(packet); err != nil { + return err + } + } + return nil } if index < 0 || (sourceSlot >= 64 && sourceType != 104) || (sourceSlot > 0 && sourceSlot < 16 && sourceType != 101) || diff --git a/server/regeneration.go b/server/regeneration.go @@ -101,13 +101,17 @@ func (server *server) queueQuietHealth_locked(updates map[*worldClient][][]byte, server.queueHealthSnapshot_locked(updates, actor) } -func (server *server) queueHealthSnapshot_locked(updates map[*worldClient][][]byte, actor *character) { +func healthSnapshotPacket(actor *character) []byte { // HealthDamage assigns absolute HP; a zero change suppresses feedback. var body []byte for _, value := range []uint32{actor.health, 0, 0, 0} { body = binary.BigEndian.AppendUint32(body, value) } - server.queueCombat_locked(updates, actor, actor, n3Packet(0x3710256c, 50000, actor.id, body)) + return n3Packet(0x3710256c, 50000, actor.id, body) +} + +func (server *server) queueHealthSnapshot_locked(updates map[*worldClient][][]byte, actor *character) { + server.queueCombat_locked(updates, actor, actor, healthSnapshotPacket(actor)) } func (server *server) characterInCombat_locked(actor *character) bool { diff --git a/server/stale_armor_move_test.go b/server/stale_armor_move_test.go @@ -82,10 +82,10 @@ func TestStaleArmorMoveUnwearsOnlyItsPublishedTemplateOnce(t *testing.T) { if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || - world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 5 || client.wornRemoval[18] != nil { + world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 10 || client.wornRemoval[18] != nil { t.Fatal("stale armor correction changed ownership, allocation or repeated its unwear", err, len(output.packets)) } - for index, action := range map[int]uint32{0: 146, 2: 112, 3: 146, 4: 112} { + for index, action := range map[int]uint32{0: 146, 2: 112, 8: 146, 9: 112} { packet := output.packets[index] if binary.BigEndian.Uint32(packet[16:20]) != 0x5e477770 || binary.BigEndian.Uint32(packet[29:33]) != action || binary.BigEndian.Uint32(packet[33:37]) != 102 || binary.BigEndian.Uint32(packet[37:41]) != 18 { diff --git a/server/stale_equipment_resources_test.go b/server/stale_equipment_resources_test.go @@ -0,0 +1,75 @@ +package main + +import ( + "bytes" + "encoding/binary" + "reflect" + "slices" + "testing" +) + +func TestStaleWornSourceRefreshesDerivedResourcesOnce(t *testing.T) { + world, output := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + player.stats.Abilities = characterAbilitiesStats{12, 12, 12, 12, 12, 12} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 152039); err != nil || !granted { + t.Fatal(granted, err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil { + t.Fatal("fixture Pioneer did not start wear", err) + } + world.advanceEquipment(client.equipment.readyAt) + if player.maximumHealth() != 40 || player.maximumNano() != 38 || player.attackRating() != 8 { + t.Fatal("fixture did not cross its native derived-stat boundaries") + } + player.health, player.nano = 40, 38 + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + item := inventory.Items[1] + item.Slot = 0 + inventory.Bank = []ownedItem{item} + inventory.Items = inventory.Items[:1] + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: player.playfield, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + auditCheckpointWrites(t, world) + output.packets = nil + + for range 2 { + if err := world.handleInventory(client, itemMovePacket(1, 19, 111)[20:]); err != nil { + t.Fatal(err) + } + } + after, err := readTestItemStore(world) + cold := newTestInventoryServer(t) + + if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || + !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || + player.health != 37 || player.nano != 35 || cold.characters[1].health != 37 || cold.characters[1].nano != 35 || + world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 10 || len(observer.packets) != 0 { + t.Fatal("stale source did not refresh its committed resource limits once", err, len(output.packets)) + } + for index, expected := range [][2]uint32{{1, 37}, {221, 35}, {22, 7}} { + packet := output.packets[index+3] + if binary.BigEndian.Uint32(packet[16:20]) != 0x2b333d6e || + binary.BigEndian.Uint32(packet[29:33]) != expected[0] || binary.BigEndian.Uint32(packet[33:37]) != expected[1] { + t.Fatalf("stale source retained a worn derived foundation: %x", packet) + } + } + if binary.BigEndian.Uint32(output.packets[6][16:20]) != 0x3710256c || + binary.BigEndian.Uint32(output.packets[6][29:33]) != 37 || + binary.BigEndian.Uint32(output.packets[6][33:37]) != 0 || + !bytes.Equal(output.packets[7], targetPacket(nanoPointsPacket(player))) { + t.Fatal("stale source did not publish its already committed current resources") + } +} diff --git a/server/stale_implant_move_test.go b/server/stale_implant_move_test.go @@ -57,10 +57,10 @@ func TestStaleImplantMoveUnwearsItsPublishedTemplateOnce(t *testing.T) { if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || - world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 5 || client.wornRemoval[37] != nil { + world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 10 || client.wornRemoval[37] != nil { t.Fatal("stale implant did not correct exactly once without changing ownership", err, len(output.packets)) } - for index, action := range map[int]uint32{0: 146, 2: 112, 3: 146, 4: 112} { + for index, action := range map[int]uint32{0: 146, 2: 112, 8: 146, 9: 112} { packet := output.packets[index] if binary.BigEndian.Uint32(packet[16:20]) != 0x5e477770 || binary.BigEndian.Uint32(packet[29:33]) != action || binary.BigEndian.Uint32(packet[33:37]) != 103 || binary.BigEndian.Uint32(packet[37:41]) != 37 { diff --git a/server/stale_non_hand_move_test.go b/server/stale_non_hand_move_test.go @@ -68,10 +68,10 @@ func TestStaleNonHandMoveUnwearsItsPublishedTemplateOnce(t *testing.T) { if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || - world.nextItem != inventory.LastID || cold.nextItem != inventory.LastID || len(output.packets) != 5 { + world.nextItem != inventory.LastID || cold.nextItem != inventory.LastID || len(output.packets) != 10 { t.Fatal("stale non-hand source did not correct once without changing ownership", err, len(output.packets)) } - for index, action := range map[int]uint32{0: 146, 2: 112, 3: 146, 4: 112} { + for index, action := range map[int]uint32{0: 146, 2: 112, 8: 146, 9: 112} { packet := output.packets[index] if binary.BigEndian.Uint32(packet[16:20]) != 0x5e477770 || binary.BigEndian.Uint32(packet[29:33]) != action || binary.BigEndian.Uint32(packet[33:37]) != 101 || binary.BigEndian.Uint32(packet[37:41]) != source { diff --git a/tools/client/test_stale_inventory_move.mjs b/tools/client/test_stale_inventory_move.mjs @@ -5,7 +5,7 @@ import {GameTest} from './game_test.mjs'; const {chromium} = createRequire(import.meta.url)('playwright'); const [url, output, sourceSlot] = process.argv.slice(2); -const sourcePage = sourceSlot === '6' || sourceSlot === '9' ? 101 : sourceSlot === '18' ? 102 : sourceSlot === '37' ? 103 : 104; +const sourcePage = sourceSlot === '6' || sourceSlot === '9' ? 101 : sourceSlot === '18' || sourceSlot === '19' ? 102 : sourceSlot === '37' ? 103 : 104; const nativeSlot = sourcePage === 104 ? 48 : Number(sourceSlot); const wornSlot = sourcePage === 104 ? 6 : Number(sourceSlot); const retained = sourceSlot === '9' ? [[2, 65], [3, 7]] : [[2, 65]]; @@ -51,6 +51,7 @@ try { } assert(sourcePresent() && cell(104, 49)); evidence.initial = await server(); + if (sourceSlot === '19') assert.deepEqual(evidence.initial.Resources, [40, 38, 8, 40, 38]); if (sourcePage === 102 || sourcePage === 103 || sourceSlot === '9') await saveStats('initial-armor'); assert((await page.request.post(url + '/test-stale-view')).ok()); evidence.transferred = await server(); @@ -58,7 +59,12 @@ try { assert.deepEqual(evidence.transferred.Bank.map(item => [item.ID, item.Slot]), [[1, 0]]); await game.save(output + '/stale'); const sequence = game.sequence; - if (sourcePage === 102) await game.click(927, 94, 'right'); + if (sourceSlot === '19') { + await game.click(989, 94); + await game.wait('worn backpack picked', state => state.dragged[0] === 102 && state.dragged[1] === 19); + await click(game.state.grids.find(grid => grid.totalCells === 30).cells.find(cell => cell.identity[0] === 0)); + } + else if (sourcePage === 102) await game.click(927, 94, 'right'); else if (sourcePage === 103) await game.click(927, 148, 'right'); else if (sourceSlot === '9') await game.click(867, 262, 'right'); else if (sourcePage === 101) await game.click(867, 206, 'right'); @@ -73,6 +79,10 @@ try { assert.deepEqual(await server(), evidence.transferred); if (sourcePage === 102 || sourcePage === 103 || sourceSlot === '9') await saveStats('refused'); else await game.save(output + '/refused'); + if (sourceSlot === '19') { + evidence.refusedNative = [1, 221, 22, 27, 214].map(stat => game.local().stats[stat]); + assert.deepEqual(evidence.refusedNative, evidence.transferred.Resources); + } // The correction must leave the actual banked instance available on this page. if (!game.state.camera.firstPerson) await game.key('F8'); @@ -83,7 +93,12 @@ try { await game.click(170, 8); if (!cell(104, 48)) await game.key('KeyI'); const retry = game.sequence; - await click(cell(104, 48), 'right'); + if (sourceSlot === '19') { + await click(cell(104, 48)); + await game.wait('retained backpack picked for wear', state => state.dragged[0] === 104 && state.dragged[1] === 48); + await game.click(989, 94); + } + else await click(cell(104, 48), 'right'); await game.wait('valid same-page wear completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === wornSlot) && game.events.some(event => event.sequence > retry && event.direction === 'framereceived' && event.opcode === '47537a24'), 15000); evidence.after = await server(); @@ -94,6 +109,11 @@ try { if (sourceSlot === '9') assert.deepEqual([evidence.initial.MaximumNCU, evidence.transferred.MaximumNCU, evidence.after.MaximumNCU], [10, 8, 10]); if (sourcePage === 102 || sourcePage === 103 || sourceSlot === '9') await saveStats('moved'); else await game.save(output + '/moved'); + if (sourceSlot === '19') { + await game.wait('native re-wear resources agree', state => [1, 221, 22, 27, 214].every((stat, index) => + game.local(state).stats[stat] === evidence.after.Resources[index])); + evidence.afterNative = [1, 221, 22, 27, 214].map(stat => game.local().stats[stat]); + } await page.reload(); await game.ready(); await page.waitForFunction(() => touchRegion(500, 400)?.world === true); @@ -101,6 +121,7 @@ try { assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]).sort((a, b) => a[0] - b[0]), expected.map(([id, slot]) => [id, slot >= 64 ? slot - 16 : slot])); assert.deepEqual(await server(), evidence.after); + if (sourceSlot === '19') assert.deepEqual([1, 221, 22, 27, 214].map(stat => game.local().stats[stat]), evidence.after.Resources); assert.deepEqual(game.errors, []); console.log('PASS: stale inventory source cleared, exact banked item withdrawn/moved and both instances retained through page/cold recovery'); } finally {