aorecomp

Anarchy Online classic in the browser

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


commit f231abe1a62f7993ddfba28b6af10ef6dbace806
parent a4c7dff575d15f22ffb3edb9705b3b4470ffa9e2
Author: anon <anon@example.com>
Date:   Mon,  2 Nov 2026 18:12:07 +0000

Explain insurance refusals while reclaim items remain

Diffstat:
MTODO.md | 12++++++------
Mdocs/reclaim.md | 28++++++++++++++++++++++++----
Aserver/browser_scanner_refusal_test.go | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/insurance.go | 7++++++-
Mserver/insurance_test.go | 1+
Mserver/reclaim_test.go | 66+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Atools/client/test_scanner_refusal.mjs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 226 insertions(+), 16 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1146,12 +1146,12 @@ Historical outdoor give-up timing and obstacle navigation remain open. [street insurance](docs/insurance.md#street-level-omni-pair) and [Clan/ICC coverage](docs/insurance.md#clan-and-icc-scanners). Unsaved training return must not imply that training contains a reclaim booth. -- [ ] [P1] Explain scanner refusal while reclaim items remain. Recover the - original feedback route for the shipped reclaim-before-save message and show - it only for that restriction. The earned level-ten native check receives a - failure acknowledgement without an explanation; inventory/progress remain - safe. Verify pending/available reclaim, successful saving after collection, - repeated requests and unrelated faction/range failures. See +- [x] [P1] Explain scanner refusal while reclaim items remain. Native FeedbackIIR + code 64 now follows the failure acknowledgement only for otherwise valid + scanner uses blocked by reclaim. Go tests cover pending/available items, + stale replays, unchanged durable ownership, collection and unrelated failures. + A focused controlled WASM check displays the shipped explanation on repeated + uses and collects the exact instance before successfully saving. See [reclaim rules](docs/reclaim.md#shipped-rules-and-placement). - [x] Admit selected original Clan/ICC scanners and reclaim through shared rules. Tir117650 uses its authored Clan-only SaveChar requirement; Newland117651 diff --git a/docs/reclaim.md b/docs/reclaim.md @@ -41,10 +41,13 @@ Original addresses use base `0x10000000`; generated C uses `0x36000000`. 75 seconds when it is below one. Shipped string `0x101c0020` instead says items remain with the corpse for one minute before collection. This conflict leaves the original server timing unresolved. -- String `0x101c00f0` says reclaim must be emptied before saving. The supported - scanner now rejects insurance while any reclaim items remain, including - items still awaiting collection. Whether the historical save restriction also - covered items awaiting corpse collection remains unresolved. +- String `0x101c00f0`, `You must empty your reclaim before you can save!`, is + catalog entry 64 in initializer `0x10040b00`. FeedbackIIR `0x50544d19` reads + one DWORD at `0x1007e1e0`; activation `0x1007e210` passes it to lookup + `0x100418d0`, which delivers the shipped text to native chat. The scanner + sends this code after a failed Use only when reclaim blocks an otherwise + eligible save. Pending and available items both block saving; the historical + restriction for items awaiting corpse collection remains unresolved. - Shipped `cd_image/text/help/Death and insurance.txt` describes a short delay and retrieval at any reclaim terminal. It does not require the terminal beside the saved scanner. This implementation enables four known booths; @@ -132,6 +135,23 @@ mutex. ## Verification +`TestReclaimPreventsInsuranceUntilEmptied` now checks pending/available reclaim, +new and stale Use sequences, failure-then-Feedback64 ordering and unchanged +live/cold ownership. `TestReclaimCollectionPermitsInsurance` collects the same +instance through the normal handler and verifies durable saving afterward. +Invalid-session, faction, range and identity checks with reclaim present receive +no reclaim explanation. The refusal regression failed before the server fix. + +`TestBrowserScannerReclaimRefusal` is a focused controlled fixture beside the +street-level Omni pair. Two native right-click attempts for each of pending and +available reclaim display the shipped message. Native collection recovers the +same item, and the next scanner use saves cumulative XP 38650. The 30-second +run had no client errors; screenshots and traces are retained under +`local/scanner-refusal/20261102-100943/`. These fixtures do not establish earned +progression or original server timing. The original catalog/lookup evidence is +in `local/scanner-refusal/`; the exact activation bytes and wire registration +are retained in `local/player-trade-research/native/feedback.md`. + `server/reclaim_test.go` covers the level 9/10 boundary, equipment/NoDrop retention, persisted delay, failed death saves, native private contents and pickup packets, restart, invalid sessions/identities/range, full inventory, diff --git a/server/browser_scanner_refusal_test.go b/server/browser_scanner_refusal_test.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserScannerReclaimRefusal(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused scanner refusal check") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/scanner-refusal", time.Now().Format("20060102-150405")) + world := newTestServer(t) + for _, availability := range []time.Duration{time.Hour, -time.Hour} { + player := world.newCharacter() + player.name, player.level, player.appearance = "Reclaim scanner", 10, 0x515 + player.playfield, player.position = 705, [3]float32{598, 16.9, 329} + player.rotation = [4]float32{0, 0.70710677, 0, 0.70710677} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("scanner-", player.id)))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 42640); !granted || err != nil { + t.Fatal(granted, err) + } + inventory := player.inventory + inventory.Reclaim = []reclaimItem{{inventory.Items[0], time.Now().Add(availability).UTC()}} + inventory.Items = nil + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + player := world.browserCharacter_locked(r) + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, + "insurance": player.resurrectionTerminal, "insuredExperience": player.insuredExperience}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_scanner_refusal.mjs"), host.URL, output) + command.Dir = root + command.Stdout, command.Stderr = os.Stdout, os.Stderr + err := command.Run() + + if err != nil { + t.Fatal(err) + } + t.Logf("Browser artifacts: %s", output) +} diff --git a/server/insurance.go b/server/insurance.go @@ -59,6 +59,7 @@ func (server *server) handleTerminalUse(client *worldClient, body []byte) error reclaim := binary.BigEndian.Uint32(body[40:44]) == 51059 grid := binary.BigEndian.Uint32(body[40:44]) == 51005 && binary.BigEndian.Uint32(body[44:48]) == 0xc0040320 var destination userData + reclaimBlocked := false if grid { // Borealis statel 0xc0040320 requires Computer Literacy > 90 and no combat. x, y, z := position[0]-636.4026, position[1]-66.81002, position[2]-728.8094 @@ -80,7 +81,8 @@ func (server *server) handleTerminalUse(client *worldClient, body []byte) error x, y, z := position[0]-terminal.Position[0], position[1]-terminal.Position[1], position[2]-terminal.Position[2] accepted = client.target && known && player.playfield == terminal.Playfield && x*x+y*y+z*z <= 25 } else { - accepted = accepted && len(player.inventory.Reclaim) == 0 + reclaimBlocked = accepted && len(player.inventory.Reclaim) != 0 + accepted = accepted && !reclaimBlocked } if accepted && !reclaim && !grid { // Persist the scanner before acknowledging use or changing live state. @@ -106,6 +108,9 @@ func (server *server) handleTerminalUse(client *worldClient, body []byte) error if err := client.send(n3Packet(0x52526858, 50000, client.id, reply)); err != nil { return err } + if reclaimBlocked { + return client.send(n3Packet(0x50544d19, 50000, client.id, binary.BigEndian.AppendUint32(nil, 64))) + } if accepted && grid { return server.updateUser_locked(destination) } diff --git a/server/insurance_test.go b/server/insurance_test.go @@ -79,6 +79,7 @@ func TestInsuranceRejectsInvalidUseWithoutSaving(t *testing.T) { player.playfield = 705 player.position = [3]float32{918, 20.7, 578} player.appearance = 0x515 + player.inventory.Reclaim = []reclaimItem{{Item: ownedItem{ID: 4, Type: 51005, Template: 42640, Quality: 1, Slot: 65, Count: 1}}} body := insuranceUseRequest(1)[20:] switch scenario { case "Clan": diff --git a/server/reclaim_test.go b/server/reclaim_test.go @@ -334,14 +334,70 @@ func TestReclaimLargePoolRemainsAvailableAcrossWindows(t *testing.T) { } func TestReclaimPreventsInsuranceUntilEmptied(t *testing.T) { + for _, availability := range []time.Duration{-time.Hour, time.Hour} { + t.Run(availability.String(), func(t *testing.T) { + world, conn := newReclaimWorld(t) + player, client := world.characters[1], world.clients[1] + player.inventory.Reclaim = []reclaimItem{{player.inventory.Items[2], time.Now().Add(availability).UTC()}} + player.inventory.Items = player.inventory.Items[:2] + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + before := player.inventory + + for _, sequence := range []uint32{1, 1, 2} { + if err := world.handleTerminalUse(client, insuranceUseRequest(sequence)[20:]); err != nil { + t.Fatal(err) + } + } + restored := newTestInventoryServer(t).characters[1] + + if player.resurrectionTerminal != 0 || player.insuredExperience != 0 || restored.resurrectionTerminal != 0 || + !reflect.DeepEqual(player.inventory, before) || !reflect.DeepEqual(restored.inventory, before) { + t.Fatal("refused scanner changed insurance or item ownership") + } + if len(conn.packets) != 4 { + t.Fatalf("expected two refusal/feedback pairs, got %d packets", len(conn.packets)) + } + for i := 0; i < 4; i += 2 { + if binary.BigEndian.Uint32(conn.packets[i][16:20]) != 0x52526858 || binary.BigEndian.Uint32(conn.packets[i][29:33]) != 2 || + binary.BigEndian.Uint32(conn.packets[i+1][16:20]) != 0x50544d19 || binary.BigEndian.Uint32(conn.packets[i+1][29:33]) != 64 { + t.Fatalf("missing native reclaim-before-save feedback: %x", conn.packets) + } + } + }) + } +} + +func TestReclaimCollectionPermitsInsurance(t *testing.T) { world, conn := newReclaimWorld(t) - player := world.characters[1] - player.inventory.Reclaim = []reclaimItem{{ownedItem{ID: 4, Type: 51005, Template: 42640, Quality: 1, Slot: 65, Count: 1}, time.Now().Add(-time.Second)}} + player, client := world.characters[1], world.clients[1] + player.inventory.Reclaim = []reclaimItem{{player.inventory.Items[2], time.Now().Add(-time.Hour).UTC()}} + player.inventory.Items = player.inventory.Items[:2] + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } - err := world.handleTerminalUse(world.clients[1], insuranceUseRequest(1)[20:]) + if err := world.handleReclaim(client, reclaimRequest(109)); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, reclaimTakeRequest(0)); err != nil { + t.Fatal(err) + } + conn.packets = nil + if err := world.handleTerminalUse(client, insuranceUseRequest(1)[20:]); err != nil { + t.Fatal(err) + } + restored := newTestInventoryServer(t).characters[1] - if err != nil || player.resurrectionTerminal != 0 || len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 { - t.Fatal("scanner accepted insurance with unclaimed items") + if len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 1 || + binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x5e477770 || binary.BigEndian.Uint32(conn.packets[1][29:33]) != 79 { + t.Fatal("collection did not permit normal scanner confirmation", conn.packets) + } + if len(player.inventory.Reclaim) != 0 || len(player.inventory.Items) != 3 || player.inventory.Items[2].ID != 3 || + player.resurrectionTerminal != 0xc00202c1 || restored.resurrectionTerminal != 0xc00202c1 || + !reflect.DeepEqual(player.inventory, restored.inventory) { + t.Fatal("collection or insurance lost durable ownership/save") } } diff --git a/tools/client/test_scanner_refusal.mjs b/tools/client/test_scanner_refusal.mjs @@ -0,0 +1,58 @@ +import assert from 'node:assert/strict'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', headless: false, + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']}); +const games = []; +try { + for (const id of [1, 2]) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'scanner-' + id, url}]); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + const server = async () => (await page.request.get(url + '/test-state')).json(); + const before = await server(); + assert.equal(before.inventory.Reclaim[0].Item.ID, id); + for (let attempt = 0; attempt < 2; ++attempt) { + const sequence = game.sequence; + const [x, y] = await game.pick(51005, 0xc00802c1); + await game.click(x, y, 'right'); + await game.wait('native reclaim-before-save feedback', () => game.events.some(event => + event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '50544d19' && + Buffer.from(event.hex, 'hex').readUInt32BE(29) === 64)); + assert.deepEqual(await server(), before); + await game.save(output + '/' + id + '-refused-' + attempt); + } + if (id === 2) { + const [x, y] = await game.pick(51059, 0xc00a02c1); + await game.click(x, y, 'right'); + await game.wait('native reclaim window', state => state.regions.some(region => + region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); + await game.click(30, 45); + await game.wait('same item collected into native inventory', state => + game.local(state).inventory.some(item => item.id === 2)); + await game.click(170, 8); + const [saveX, saveY] = await game.pick(51005, 0xc00802c1); + await game.click(saveX, saveY, 'right'); + await game.wait('insurance after collection', state => game.local(state).stats[236] === 38650); + const after = await server(); + assert.equal(after.insurance, 0xc00802c1); + assert.equal(after.insuredExperience, 38650); + assert.equal(after.inventory.Reclaim, null); + assert.deepEqual(after.inventory.Items, [{...before.inventory.Reclaim[0].Item, Slot: 64}]); + await game.save(output + '/collected-and-saved'); + } + assert.deepEqual(game.errors, []); + await context.close(); + } + console.log('PASS: pending/available reclaim explains repeated native refusals; exact collection permits saving'); +} finally { + try { for (const [index, game] of games.entries()) if (!game.page.isClosed()) await game.save(output + '/final-' + index); } + finally { await browser.close(); } +}