aorecomp

Anarchy Online classic in the browser

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


commit a22151736837f0ebf9b192ac3665c08ed550a902
parent 21758db1dea2d349447e9536b41786e254963603
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 04:43:18 +0000

Protect original pet owner-list and command protocol

Diffstat:
MTODO.md | 4++++
Adocs/pet-owner-protocol.md | 44++++++++++++++++++++++++++++++++++++++++++++
Aserver/browser_pet_owner_protocol_test.go | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_pet_owner_protocol.mjs | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 215 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3125,6 +3125,10 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah - [ ] [P1] Summon one pet. Check: one owned entity appears to its owner and an observer; repeated requests follow the applicable pet-count limit. + A controlled two-client regression now establishes original AddPet/RemovePet, + duplicate identity handling, the separate packed counter and native report + request. It does not implement summoning or prove an ownership field in NPC + full updates. See [owner-list protocol](docs/pet-owner-protocol.md). - [ ] [P1] Make the pet follow. Check: it follows its owner across a simple route without changing another player's pet. - [ ] [P1] Make the pet wait. Check: it stays at the commanded position while its diff --git a/docs/pet-owner-protocol.md b/docs/pet-owner-protocol.md @@ -0,0 +1,44 @@ +# Original pet owner-list protocol + +This is a protocol prerequisite for summoning, not an implemented pet system. +The server still rejects the unsupported summon effect and does not create, +persist, command or expire an owned pet. + +## Original client evidence + +Original `kkr.dll` SHA256 is +`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. +The retained native analysis is in `local/pet-research/` and +`local/pet-owner-protocol/native/kkr-evidence.json`. + +AddPet `194e4f76` and RemovePet `58742a0f` use the owner's character identity +as their envelope and one eight-byte pet identity as their body. Activation +updates the owner's identity set and stat458 NPCNumPets. Duplicate additions +do not increase its size. These messages do not update stat251 PetCounter, +whose packed nibbles are independently consulted by summon requirements. + +PetCommand `6b333303` reads a command, argument, encoded identity list, boolean +and bounded string. Native `/pet report` with no name filter emits body words +`14, 0, 1009, 0, 0`: the owner set is implicit, and no explicit pet identity is +present. This establishes the request, not a server report response. + +The NPC full-update reader at `10082da0` reads four compact fields after its +flags. Activation at `100821d0` publishes these as stats455,466,512,388. +The first three are byte/short fields, not a 32-bit owner identity. A later +emulator's ownership aliases do not establish an original wire field. Exact +summon template/profile, type and lifecycle contracts remain unresolved. + +## Focused native regression + +`TestBrowserPetOwnerProtocol` creates two controlled players and an ordinary +NPC rendered with candidate body96195. Test-only endpoints deliver original +AddPet/RemovePet and a separate stat251 update. No server ownership state is +created; this is not evidence of a working summon or earned progression. + +Both WASM clients observe owner stat458 become1, stay1 after a duplicate, then +become0 after removal. The observer's own list is unchanged. Stat251 remains0 +until the explicit counter update and remains1 after removal. Real keyboard +input emits the exact report request. The clients report no runtime errors, +and the server retains empty physical inventories without allocating items. +The passing run and screenshots are retained in +`local/pet-owner-protocol/20261103-204010/`. diff --git a/server/browser_pet_owner_protocol_test.go b/server/browser_pet_owner_protocol_test.go @@ -0,0 +1,101 @@ +package main + +import ( + "ao/server/assets" + "context" + "crypto/sha256" + "encoding/binary" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserPetOwnerProtocol(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the original pet owner-list protocol") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/pet-owner-protocol", time.Now().Format("20060102-150405")) + data := testNPCData() + data.Playfields[0].ID = 705 + group := &data.Playfields[0].Districts[0].Groups[0] + group.Name, group.MonsterData, group.AppearanceStatus = "Anger Manifestation", 96195, "inferred_species" + group.Levels, group.Positions = [2]uint16{1, 1}, [][3]float32{{960, 16.5, 514}} + useNPCData(t, data) + useResources(t, assets.Files) + world := newTestServer(t) + for index := range 2 { + player := world.newCharacter() + player.name = fmt.Sprint("Petowner", index) + player.profession = 12 + player.stats = testCharacterStats() + player.stats.NanoAiding.MatterCreation, player.stats.NanoAiding.TimeAndSpace = 6, 6 + player.playfield, player.position = 705, [3]float32{960 + float32(index*2), 16.5, 511} + player.rotation = [4]float32{0, 0, 0, 1} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("pet-owner-", index)))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + for _, action := range []struct { + path string + code uint32 + }{{"link", 0x194e4f76}, {"unlink", 0x58742a0f}} { + mux.HandleFunc("POST /test-"+action.path, func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + defer world.updateMutex.Unlock() + world.mutex.Lock() + defer world.mutex.Unlock() + body := binary.BigEndian.AppendUint32(nil, 50000) + body = binary.BigEndian.AppendUint32(body, 1000000) + for _, client := range world.clients { + if err := client.send(n3Packet(action.code, 50000, 1, body)); err != nil { + t.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + }) + } + mux.HandleFunc("POST /test-counter", func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + defer world.updateMutex.Unlock() + world.mutex.Lock() + defer world.mutex.Unlock() + body := binary.BigEndian.AppendUint32(nil, 251) + body = binary.BigEndian.AppendUint32(body, 1) + for _, client := range world.clients { + if err := client.send(n3Packet(0x2b333d6e, 50000, 1, body)); err != nil { + t.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + }) + 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_pet_owner_protocol.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) + } + if world.nextItem != 0 || len(world.characters[1].inventory.Items) != 0 || len(world.characters[2].inventory.Items) != 0 { + t.Fatal("protocol fixture changed physical inventory") + } +} diff --git a/tools/client/test_pet_owner_protocol.mjs b/tools/client/test_pet_owner_protocol.mjs @@ -0,0 +1,66 @@ +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']}); +const games = [], evidence = {}; +const actor = (game, id) => game.state.actors.find(actor => actor.type === 50000 && actor.id === id); +const counts = () => games.map(game => ({ownerCount: actor(game, 1).stats[458], + ownerPacked: actor(game, 1).stats[251], localCount: game.local().stats[458], petType: actor(game, 1000000).stats[512]})); +try { + for (let index = 0; index < 2; index++) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'pet-owner-' + index, url}]); + const page = await context.newPage(), game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + } + const [owner] = games; + await Promise.all(games.map(game => game.wait('owner, peer and controlled manifestation visible', () => + actor(game, 1) && actor(game, 2) && actor(game, 1000000)))); + evidence.before = counts(); + assert((await owner.page.request.post(url + '/test-link')).ok()); + await Promise.all(games.map(game => game.wait('native owner list receives pet', () => actor(game, 1).stats[458] === 1))); + evidence.linked = counts(); + assert.equal(evidence.linked[1].localCount, evidence.before[1].localCount); + evidence.linked.forEach((value, index) => assert.equal(value.ownerPacked, evidence.before[index].ownerPacked)); + assert((await owner.page.request.post(url + '/test-link')).ok()); + await Promise.all(games.map(game => game.wait('duplicate native AddPet received', () => game.events.filter(event => + event.direction === 'framereceived' && event.opcode === '194e4f76').length === 2))); + assert(counts().every(value => value.ownerCount === 1)); + await Promise.all(games.map((game, index) => game.save(output + '/linked-' + index))); + + // The original report command addresses the owner's set without explicit pet IDs. + const sequence = owner.sequence; + await owner.key('Enter'); + await owner.page.keyboard.type('/pet report'); + await owner.key('Enter'); + await owner.wait('native report command for the owner pet set', () => owner.events.some(event => + event.sequence > sequence && event.direction === 'framesent' && event.opcode === '6b333303')); + evidence.report = owner.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '6b333303'); + const packet = Buffer.from(evidence.report.hex, 'hex'); + assert.deepEqual([29, 33, 37, 41, 45].map(offset => packet.readUInt32BE(offset)), [14, 0, 1009, 0, 0]); + assert((await owner.page.request.post(url + '/test-counter')).ok()); + await Promise.all(games.map(game => game.wait('packed count is independent from owner list size', () => actor(game, 1).stats[251] === 1))); + evidence.counter = counts(); + assert((await owner.page.request.post(url + '/test-unlink')).ok()); + await Promise.all(games.map(game => game.wait('native owner list removes pet', () => actor(game, 1).stats[458] === 0))); + evidence.unlinked = counts(); + assert(evidence.unlinked.every(value => value.ownerPacked === 1)); + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: original Add/RemovePet owner list, duplicate identity, native report request and independent packed counter'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); + } finally { await browser.close(); } +}