aorecomp

Anarchy Online classic in the browser

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


commit b0ddc6be3086f993276911b2796733ef4d769056
parent d5375d5fbb769cd811b6c014bb2265d083fff55b
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 19:44:43 +0000

Keep vending Use distinct from colliding static item identities

Diffstat:
MTODO.md | 22+++++++++++++---------
Mdocs/shop-control-edits.md | 9+++++----
Adocs/shop-typed-identities.md | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/shops.md | 13++++++-------
Aserver/browser_shop_typed_identity_test.go | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/insurance.go | 3---
Aserver/shop_typed_identity_test.go | 41+++++++++++++++++++++++++++++++++++++++++
Mserver/shops.go | 2+-
Mserver/shops_test.go | 5+++--
Atools/client/test_shop_typed_identity.mjs | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 261 insertions(+), 26 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1887,15 +1887,15 @@ introduction and starting-item gameplay remain open below. independent sleeve removal and using purchased gloves to qualify for a laboratory. Controlled funds isolate these rules; the P0 earned-income purchase above remains open. See [medical clothing stock](docs/shop-med-suit.md). -- [ ] [P2] 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. - The training scene also separates About the Guard 51005:3221226422 (template - 100280) from Startup Shop 51035:3221226422 (template 100035). Fresh, returning - and earlier successful native shop captures all use the vending identity. - See `docs/shop-control-edits.md` and `local/shop-edit-smoke/verification.json`. +- [x] [P0] Keep static-item Use distinct from vending machines with equal numeric + IDs. A real About the Guard click incorrectly opened the Startup Shop. All + 795 maintained original vending placements have type 51035; 77 share a numeric + ID with a distinct type 51005 template, with no matching-template aliases. + Remove the numeric alias and require the full vending type. Failing handler + cases cover both known collisions; native information and vending clicks, + normal cancellation, page replay and cold inventory retention pass. Static + information/clinic script execution remains in the world-item Use task. + See [typed shop identities](docs/shop-typed-identities.md). - [ ] [P2] 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 @@ -2473,6 +2473,10 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md). player state. Both page reconnects, separate R/Pick Up, exact-book hand-in and cold recovery conserve all 37 final owned items, with 803 credits and unchanged XP/IP/vitals/supplies. Other world-item effects remain unsupported. + Include original static information objects and Stationary Automated Surgery + Clinic 43553, resolving their own placements and complete effect contracts; + they are separate from numerically equal vending identities. See + [typed shop identities](docs/shop-typed-identities.md). See [world-item Use](docs/mission-objectives.md#pickup-protocol). - [x] Populate the fixed mission through shared admitted NPC profiles. Acceptance commits five concrete level-1 Leets with the assignment and key; reconnect, diff --git a/docs/shop-control-edits.md b/docs/shop-control-edits.md @@ -49,11 +49,12 @@ 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 +`[176.325,5.00036,129]`, separately from armor vending `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 subsequent [typed-identity audit](shop-typed-identities.md) reproduces a +wrong shop from an actual tutorial-object click and removes that numeric alias. +The original scene census and distinct native vending clicks resolve this +routing issue; the control-edit lifecycle limitations above remain separate. The source ledger is `local/shop-edit-research/native/README.md`, with 14 complete retained original REA records, 11 checked citations and supporting diff --git a/docs/shop-typed-identities.md b/docs/shop-typed-identities.md @@ -0,0 +1,63 @@ +# Typed vending identities + +Clicking About the Guard in the original Omni training ground sent Use for +`51005:3221226422`. The server matched only its numeric ID to the Startup Shop, +acknowledged success and opened that unrelated vending transaction. The actual +shop uses `51035:3221226422`. Both are reachable from the controlled fixture at +`[60,14.75,53]`, so the vending range check did not prevent the mistake. + +Vending Use now requires type 51035. The terminal dispatcher no longer forwards +type-51005 requests by numeric shop membership. Static information and clinic +objects retain their independent terminal/world-item path. Their full script +execution remains open; refusing an unsupported static Use does not establish +the original script's server behavior. + +## Original placements + +Fresh parsing of the shipped 14.9.1 statels, record type 1000026, matches all +795 maintained vending placements' IDs, templates, playfields and transforms. +Every vending row has type 51035. There are 77 same-playfield type-51005 rows +with equal numeric IDs; none has the corresponding vending template. + +| Playfield | Full identity | Template | Original position | +| --- | --- | --- | --- | +| 950 | 51005:3221226422 | 100280, About the Guard | [59.26055,15.99995,55.73878] | +| 950 | 51035:3221226422 | 100035, Startup Shop | [60,14,50] | +| 950 | 51016:3221226422 | 95258, door | [52.59733,15.87024,55.13618] | +| 1183 | 51005:3221226655 | 43553, Stationary Automated Surgery Clinic | [176.32516,5.00036,129] | +| 1183 | 51035:3221226655 | 99383, armor vending | [192,5,139.5] | +| 1183 | 51016:3221226655 | 41888, door | [187.00072,5,116.00997] | + +The original index SHA256 is +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. +Original placement bytes, ordinals and per-record/resource hashes are retained +in `local/shop-typed-identity/census.json` and `placements.json`. About the Guard's +complete item payload SHA256 is +`f318569c8007a499cb7e33da8ce841de1a680e0285948de791b54b12c211f6d0`; +its OnUse function 53044 supplies an information hint, without a vending contract. +The clinic's payload is +`e72d6f5caa15be8609c9cd95bb6ca58dca182b6ac12bfd283c7e804145a003be`. + +## Verification + +`TestStaticItemUseDoesNotAliasCollidingShop` failed on both original collision +IDs before the fix. It now checks rejection without a shop or inventory change, +followed by successful Use of each actual vending identity. The existing native +socket sale test uses the original type 51035; the forged-Use cases explicitly +reject type 51005 at the vending handler. Related terminal regressions cover +insurance, bank, Grid and mission-floor Use dispatch. + +`TestBrowserShopTypedIdentity` uses real native picking and input. Its baseline +received success 1 for About the Guard instead of rejection 2. The fixed run +receives 2 without a shop, turns through ordinary input, receives success 1 for +the Startup Shop, opens its normal window and cancels it. Page replay and a +fresh inventory reader retain zero owned items and zero cash. This controlled +fixture verifies routing; it is not earned-progression evidence. + +The native check takes 16.53 seconds and retains three clean traces, including +both clicked full identities and replies, under +`local/shop-typed-identity/20261103-114138/`. Baseline failures and source audits +are retained in the parent directory. The related Go checks pass 12 roots and +102 results in 14.064 seconds; vet and Node syntax checks pass. The independent +`verification-summary.json` checks the census, both baseline failures, complete +native traces and exact request/reply pairs. No client source or bundle changed. diff --git a/docs/shops.md b/docs/shops.md @@ -56,13 +56,12 @@ server policy; the native player-trade distance does not establish historical vending range. These are reconstructed server admission rules grounded in the 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). +Vending Use and trade messages identify the machine as type 51035. Static +type-51005 objects with equal numeric IDs have their own templates and positions. +The numeric Use alias incorrectly opened the Startup Shop when clicking +About the Guard and has been removed. All 795 maintained original vending +placements retain their authored type. See [typed identities](shop-typed-identities.md) +for the source census, failing baseline and native verification. `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/browser_shop_typed_identity_test.go b/server/browser_shop_typed_identity_test.go @@ -0,0 +1,61 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserShopTypedIdentity(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for typed vending identities") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/shop-typed-identity", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.position, player.rotation = [3]float32{60, 14.75, 53}, [4]float32{0, 0, 0, 1} + player.appearance = 0x515 + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("shop-typed-identity"))) + 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) { + world.mutex.Lock() + defer world.mutex.Unlock() + machine := uint32(0) + if client := world.clients[1]; client != nil && client.shop != nil { + machine = client.shop.machine + } + json.NewEncoder(w).Encode(map[string]any{"machine": machine, "inventory": player.inventory}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_shop_typed_identity.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + t.Logf("Browser artifacts: %s", output) + if err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + if len(player.inventory.Items) != 0 || len(cold.characters[1].inventory.Items) != 0 || + player.inventory.Credits != 0 || cold.characters[1].inventory.Credits != 0 || world.nextItem != 0 { + t.Fatal("typed shop interaction changed inventory or cash") + } +} diff --git a/server/insurance.go b/server/insurance.go @@ -10,9 +10,6 @@ func (server *server) handleTerminalUse(client *worldClient, body []byte) error if _, bank := gamedata.BankTerminals[binary.BigEndian.Uint32(body[44:48])]; bank && binary.BigEndian.Uint32(body[40:44]) == 51005 { return server.handleBankUse(client, body) } - if _, shop := gamedata.ShopMachines[binary.BigEndian.Uint32(body[44:48])]; shop && binary.BigEndian.Uint32(body[40:44]) == 51005 { - return server.handleShopUse(client, body) - } server.updateMutex.Lock() defer server.updateMutex.Unlock() server.mutex.Lock() diff --git a/server/shop_typed_identity_test.go b/server/shop_typed_identity_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "reflect" + "testing" +) + +func TestStaticItemUseDoesNotAliasCollidingShop(t *testing.T) { + for _, machineID := range []uint32{3221226422, 3221226655} { + t.Run(fmt.Sprint(machineID), func(t *testing.T) { + world, output := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + machine := gamedata.ShopMachines[machineID] + player.playfield, player.position, player.appearance = machine.Playfield, machine.Position, 0x515 + request := shopUseRequest(1) + binary.BigEndian.PutUint32(request[40:44], 51005) + binary.BigEndian.PutUint32(request[44:48], machineID) + before := player.inventory + output.packets = nil + + err := world.handleTerminalUse(client, request) + + if err != nil || client.shop != nil || !reflect.DeepEqual(player.inventory, before) || len(output.packets) != 1 || + binary.BigEndian.Uint32(output.packets[0][16:20]) != 0x52526858 || + binary.BigEndian.Uint32(output.packets[0][29:33]) != 2 { + t.Fatal("static item initialized an unrelated vending transaction", err) + } + + binary.BigEndian.PutUint32(request[20:24], 2) + binary.BigEndian.PutUint32(request[40:44], 51035) + err = world.handleShopUse(client, request) + + if err != nil || client.shop == nil || client.shop.machine != machineID || !reflect.DeepEqual(player.inventory, before) { + t.Fatal("the original vending identity no longer opens its own shop", err) + } + }) + } +} diff --git a/server/shops.go b/server/shops.go @@ -62,7 +62,7 @@ func (server *server) handleShopUse(client *worldClient, body []byte) error { binary.BigEndian.Uint32(body[16:20]) != 0 || binary.BigEndian.Uint32(body[24:28]) != 3 || binary.BigEndian.Uint32(body[28:32]) != 1 || binary.BigEndian.Uint32(body[32:36]) != 50000 || binary.BigEndian.Uint32(body[36:40]) != client.id || - (binary.BigEndian.Uint32(body[40:44]) != 51035 && binary.BigEndian.Uint32(body[40:44]) != 51005) || + binary.BigEndian.Uint32(body[40:44]) != 51035 || !client.target || server.clients[client.id] != client || !client.ready || client.loading { return nil } diff --git a/server/shops_test.go b/server/shops_test.go @@ -96,7 +96,6 @@ func TestShopNativeSocketUseAndSale(t *testing.T) { defer connection.Close() request := shopUseRequest(1) - binary.BigEndian.PutUint32(request[40:44], 51005) connection.Write(targetPacket(n3Packet(0x52526858, 50000, 1, request[16:]))) for index, key := range []uint32{0x52526858, 0x7f544905, 0x36284f6e, 0x36284f6e} { packet, err := readPacket(connection) @@ -423,7 +422,7 @@ func TestShopCommitFailureRollsBackCashAndOwnership(t *testing.T) { } func TestShopUseRejectsIneligibleAndForgedRequests(t *testing.T) { - for _, scenario := range []string{"Clan", "Neutral", "wrong zone", "too far", "dead", "loading", "unready", "replaced", "wrong owner", "wrong caller", "wrong machine", "wrong type", "reply", "wrong action", "11.0", "replay"} { + for _, scenario := range []string{"Clan", "Neutral", "wrong zone", "too far", "dead", "loading", "unready", "replaced", "wrong owner", "wrong caller", "wrong machine", "wrong type", "static item type", "reply", "wrong action", "11.0", "replay"} { t.Run(scenario, func(t *testing.T) { world, conn := newCombatWorld(t) client, player := world.clients[1], world.characters[1] @@ -454,6 +453,8 @@ func TestShopUseRejectsIneligibleAndForgedRequests(t *testing.T) { binary.BigEndian.PutUint32(body[44:48], 0xc00003b8) case "wrong type": binary.BigEndian.PutUint32(body[40:44], 51059) + case "static item type": + binary.BigEndian.PutUint32(body[40:44], 51005) case "reply": binary.BigEndian.PutUint32(body[16:20], 1) case "wrong action": diff --git a/tools/client/test_shop_typed_identity.mjs b/tools/client/test_shop_typed_identity.mjs @@ -0,0 +1,68 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +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', args: [ + '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +let game; +const evidence = {}; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'shop-typed-identity', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + if (!game.state.camera.firstPerson) await game.key('F8'); + const server = async () => (await page.request.get(url + '/test-state')).json(); + const use = async (type, result) => { + const sequence = game.sequence; + await game.click(...await game.pick(type, 3221226422), 'right'); + await game.wait('exact native Use request and reply', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framereceived' && event.opcode === '52526858')); + const request = game.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '52526858'); + assert(request, 'real native Use request is retained'); + const reply = game.events.find(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '52526858'); + assert.deepEqual([Buffer.from(request.hex, 'hex').readUInt32BE(53), Buffer.from(request.hex, 'hex').readUInt32BE(57)], [type, 3221226422]); + assert.equal(Buffer.from(reply.hex, 'hex').readUInt32BE(29), result); + return server(); + }; + evidence.information = await use(51005, 2); + assert.equal(evidence.information.machine, 0); + assert(!game.state.regions.some(([left, top, right, bottom]) => + left === 832 && top === 0 && right === 1024 && bottom === 494)); + await game.save(output + '/information'); + + // Turn with ordinary input to use the separately typed vending object. + await game.hold('KeyD', 'face the Startup Shop', state => { + const actor = game.local(state); + return Math.cos(2 * Math.atan2(actor.rotation[1], actor.rotation[3])) < -0.98; + }); + evidence.vending = await use(51035, 1); + assert.equal(evidence.vending.machine, 3221226422); + await game.wait('Startup Shop opens normally', state => state.regions.some(([left, top, right, bottom]) => + left === 832 && top === 0 && right === 1024 && bottom === 494)); + assert.deepEqual(evidence.vending.inventory, evidence.information.inventory); + await game.save(output + '/vending'); + await game.click(945, 475); + await game.wait('normal shop cancellation closes the window', state => !state.regions.some(([left, top, right, bottom]) => + left === 832 && top === 0 && right === 1024 && bottom === 494)); + await page.reload(); + await game.ready(); + evidence.reloaded = await server(); + assert.equal(evidence.reloaded.machine, 0); + assert.deepEqual(evidence.reloaded.inventory, evidence.information.inventory); + assert.deepEqual(game.errors, []); + console.log('PASS: distinct information/vending identities retain independent native Use and shop behavior'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}