aorecomp

Anarchy Online classic in the browser

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


commit 03ea0b6b435e7051cf8e7910ae9150c0da986617
parent 9905e9c88c4e2a963212ff135a7534a8f3630cf4
Author: anon <anon@example.com>
Date:   Tue, 27 Oct 2026 17:35:10 +0000

Serialize native doors with shared item placement and authored flags

Diffstat:
MTODO.md | 13++++++++-----
Mdocs/mission-doors.md | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/mission-interiors.md | 8+++++---
Aserver/doors.go | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/doors_test.go | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/shops.go | 26++------------------------
Aserver/world_items.go | 44++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 304 insertions(+), 32 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1524,11 +1524,14 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md). chamber and traversal both ways without a client patch. Validate authored portal choice in addition to reciprocal links and one unmatched exit. Original door data decodes3692 placements and53 templates; full style mapping is open. - Published-WASM fixtures verify open/close/reopen and deferred room disablement, - but both templates41565/41884 still allow a closed-door crossing with closed - flags/link. Recover the native collision/open-request contract and enforce - closed/locked/revoked-key admission authoritatively; test denial, auto-open, - concurrent use, reconnect and exit instead of relying on animation or visibility. + Server builders now serialize all53 original door templates, preserving absent + QL and authored flags; their SimpleItem body is shared with vending machines. + Published-WASM fixtures verify initial locking, sustained blocking from both + sides, unlock/open, relocking and return using actual builder output. The + earlier closed-door crossings used unlocked doors; no forced collision flag + or client patch is needed. Recover automatic-opening/access policy and enforce + locked/revoked-key admission authoritatively; test denial, auto-open, forged + movement, concurrent use, reconnect and exit instead of relying on native blocking. This is not usable entry, recovered style selection or a private-world boundary. See [mission interiors](docs/mission-interiors.md) and [doors](docs/mission-doors.md). - [ ] [P1] Complete mission-key destination metadata and duplication. Check: diff --git a/docs/mission-doors.md b/docs/mission-doors.md @@ -105,6 +105,57 @@ cross the closed door while its open flag/link stay clear. Recover collision and open-request semantics before implementing authoritative blocking; these owned client-side fixtures do not supply a private server's response. +## Server serializers and locked passage + +`server/doors.go` now emits the recovered full-update and status messages. +`server/world_items.go` shares the SimpleItem11 body with vending machines, +followed by each object's own subclass tail. Door full updates reject unknown +and non-door templates, preserve authored flags outside lock/open bits64/128, +and serialize all53 original door templates. Templates41553,41554 and41892 have +no authored QL; their updates omit stat701 rather than inventing a quality. +Status serialization keeps lock, open and the additional latch independent; +stat195 remains zero and the identity list empty in this supported subset. +The extra flag's producer policy and the additional full-update DWORD remain +unresolved. These are packet builders, with no production admission consumer. + +Original SimpleItem Apply `KKR:0x100b25c0` maps Flags bit0x200 to +`n3Dynel_t::SetTellCollinfo`. That does not establish it as a requirement for +door blocking. A controlled locked-door fixture286 removes only this bit and +still stops before the door plane. The serializer therefore preserves the +authored bit rather than forcing it. Original `0x1008e230` also contains a +dungeon-door deflection path; static analysis alone does not establish which +callback executed in these runs. + +The earlier crossing experiments281/282 used closed, unlocked doors. Their +result does not establish a defect in locked-door collision. Published-WASM +fixtures287/288 receive packets produced by the actual server builders, with +no forced0x200 bit. They stop under sustained forward and reverse movement at +a locked door, pass after unlock/open updates, and return across the same +portal. Full updates initialize lock state; subsequent status updates change +it without recreating the object. Templates41565 and41554 retain their original +animation durations, approximately0.6 and0.833333 seconds. The unqualified41554 +loads without stat701 and its native getter reports0. No client patch is needed. + +Captures and read-only snapshots are in +`local/mission-interior/runtime-final-server-door/` and +`runtime-final-unqualified-door/`. Packet producers and verification are retained +alongside them. Original evidence is in `kkr-door-collision-evidence.json`; +key records are `ev_9fab4fbc5cd930032d5fb4ae3d31570b6b63d3b3ebe70ba4a53a57fe762beeec` +(SimpleItem Apply) and +`ev_40500450c179a155dd837b6458934ac5cb3e63df336e2b7dd898ac147f9b615e` +(deflection code). Keep automatic opening, original access predicates, key +bindings and authoritative denial open. Native client blocking alone cannot +enforce private access against forged movement or prove instance isolation. + +Golden wire tests cover native placement/inheritance, all four initial lock/open +states, all eight status flag combinations, unknown/non-door rejection, all53 +templates and all three absent-QL cases. The final door/shop/mission-building +suite passes76 roots/257 results under the race detector; build and vet pass. +The existing shop packet checks cover the shared-body extraction. Native reports +are retained in `local/mission-interior/final-server-door-native-verification.json`; +the only browser errors are favicon404s. All owned clients and analysis sessions +are closed. The one shared HTTPS8443 preview and published client are unchanged. + Final timed captures are in `local/mission-interior/runtime-door-observe/`, with earlier exterior/interior template runs in `runtime-door/` and `runtime-door-interior/`. No page exceptions or adapter crashes occurred; diff --git a/docs/mission-interiors.md b/docs/mission-interiors.md @@ -135,9 +135,11 @@ also reaches the chamber's far wall; its return stops short of the doorway after collision shifts X sideways. Do not count that as a successful return walk. Both fixtures walk through the closed door while Flags bit128 and the room link -remain closed. This is a failed blocking scenario, not verified admission. Trace -the original collision/open-request contract and implement authoritative closed, -locked and revoked-key enforcement before private entry. The fixtures run on +remain closed. Those doors were unlocked: subsequent +[locked-door controls](mission-doors.md#server-serializers-and-locked-passage) +verify native blocking from both sides and unlock/open passage using real server +packet builders. This does not establish automatic-opening policy or authoritative +locked/revoked-key enforcement before private entry. The fixtures run on public-world visitors and cannot establish how a real private server responds. There are no page exceptions or adapter errors; browser404s are only favicon.ico. `local/mission-interior/entry-native-verification.json` records passing checks diff --git a/server/doors.go b/server/doors.go @@ -0,0 +1,55 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" +) + +type worldDoor struct { + id, template uint32 + position [3]float32 + rotation [4]float32 + locked, open bool +} + +func doorPacket(playfield uint32, door worldDoor) ([]byte, error) { + definition := gamedata.ItemTemplates[door.template] + if definition == nil || definition.HeaderWords[0] != 51016 { + return nil, fmt.Errorf("invalid door template %d", door.template) + } + + // Preserve authored flags; lock/open state occupies independent bits64/128. + flags := itemStat(definition, 0) &^ uint32(64|128) + if door.locked { + flags |= 64 + } + if door.open { + flags |= 128 + } + body := simpleItemBody(door.template, playfield, door.position, door.rotation, [][2]uint32{{0, flags}}) + // Lockable2 then Door2; the additional Door DWORD's meaning is unresolved. + for _, value := range []uint32{2, 0, 1009, 2, 0} { + body = binary.BigEndian.AppendUint32(body, value) + } + return n3Packet(0x365a5071, 51016, door.id, body), nil +} + +func doorStatusPacket(id uint32, locked, open, latch bool) []byte { + // KKR 14.9.1 0x100b0460: status2, lock/open, stat195, extra flag, identities. + body := binary.BigEndian.AppendUint32(nil, 2) + for _, value := range []bool{locked, open} { + body = append(body, 0) + if value { + body[len(body)-1] = 1 + } + } + body = binary.BigEndian.AppendUint32(body, 0) + // True latches Door+0x1c5; the original producer policy remains unverified. + body = append(body, 0) + if latch { + body[len(body)-1] = 1 + } + body = binary.BigEndian.AppendUint32(body, 1009) + return n3Packet(0x4c7d403b, 51016, id, body) +} diff --git a/server/doors_test.go b/server/doors_test.go @@ -0,0 +1,139 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "encoding/hex" + "fmt" + "testing" +) + +func TestDoorFullUpdateKeepsNativePlacementAndInheritance(t *testing.T) { + door := worldDoor{id: 8000001, template: 41565, position: [3]float32{15, 0, 29.999}, rotation: [4]float32{0, 1, 0, 0}} + + packet, err := doorPacket(9000001, door) + if err != nil { + t.Fatal(err) + } + packet = targetPacket(packet) + packet = packet[:binary.BigEndian.Uint16(packet[6:8])] + + if len(packet) != 135 || binary.BigEndian.Uint32(packet[16:20]) != 0x365a5071 || + binary.BigEndian.Uint32(packet[20:24]) != 51016 || binary.BigEndian.Uint32(packet[24:28]) != 8000001 { + t.Fatal("door identity or native message header changed") + } + if got := hex.EncodeToString(packet[29:]); got != "0000000b0000000000000000417000000000000041effdf4000000003f8000000000000000000000008954410000000000000000000000000fc4000000170000a25d000002bd000000010000000080081401000000000000000200000000000003f10000000200000000" { + t.Fatal("native door placement, state or subclass tail changed", got) + } +} + +func TestDoorFullUpdateKeepsIndependentLockAndOpenState(t *testing.T) { + for _, scenario := range []struct { + locked, open bool + flags uint32 + }{ + {false, false, 0x80081401}, + {true, false, 0x80081441}, + {false, true, 0x80081481}, + {true, true, 0x800814c1}, + } { + t.Run(fmt.Sprintf("locked=%t/open=%t", scenario.locked, scenario.open), func(t *testing.T) { + door := worldDoor{template: 41565, locked: scenario.locked, open: scenario.open} + + packet, err := doorPacket(9000001, door) + if err != nil { + t.Fatal(err) + } + packet = targetPacket(packet) + + if binary.BigEndian.Uint32(packet[107:111]) != scenario.flags { + t.Fatal("door state changed unrelated template flags") + } + }) + } +} + +func TestDoorFullUpdateAcceptsOriginalDoorCatalog(t *testing.T) { + count := 0 + for template, definition := range gamedata.ItemTemplates { + if definition.HeaderWords[0] != 51016 { + continue + } + + packet, err := doorPacket(9000001, worldDoor{template: template}) + + if err != nil || len(packet) == 0 { + t.Fatalf("original door %d was rejected: %v", template, err) + } + count++ + } + if count != 53 { + t.Fatalf("original door catalog changed: %d", count) + } +} + +func TestDoorFullUpdateRejectsUnknownAndNonDoorTemplates(t *testing.T) { + for _, template := range []uint32{0, 4294967295, 95577} { + t.Run(fmt.Sprint(template), func(t *testing.T) { + door := worldDoor{template: template} + + packet, err := doorPacket(9000001, door) + + if err == nil || packet != nil { + t.Fatal("invalid template produced a partial door update") + } + }) + } +} + +func TestDoorFullUpdatePreservesAbsentAuthoredQuality(t *testing.T) { + for _, template := range []uint32{41553, 41554, 41892} { + t.Run(fmt.Sprint(template), func(t *testing.T) { + door := worldDoor{template: template} + if gamedata.ItemTemplates[template].Quality != nil { + t.Fatal("original unqualified door changed") + } + + packet, err := doorPacket(9000001, door) + if err != nil { + t.Fatal(err) + } + packet = targetPacket(packet) + + if binary.BigEndian.Uint32(packet[83:87]) != 3027 || + binary.BigEndian.Uint32(packet[87:91]) != 23 || binary.BigEndian.Uint32(packet[91:95]) != template || + binary.BigEndian.Uint32(packet[95:99]) != 0 { + t.Fatal("unqualified door acquired an invented QL override") + } + }) + } +} + +func TestDoorStatusKeepsLockOpenAndLatchIndependent(t *testing.T) { + for _, scenario := range []struct { + locked, open, latch bool + body string + }{ + {false, false, false, "0000000200000000000000000003f1"}, + {true, false, false, "0000000201000000000000000003f1"}, + {false, true, false, "0000000200010000000000000003f1"}, + {true, true, false, "0000000201010000000000000003f1"}, + {false, false, true, "0000000200000000000001000003f1"}, + {true, false, true, "0000000201000000000001000003f1"}, + {false, true, true, "0000000200010000000001000003f1"}, + {true, true, true, "0000000201010000000001000003f1"}, + } { + t.Run(fmt.Sprintf("locked=%t/open=%t/latch=%t", scenario.locked, scenario.open, scenario.latch), func(t *testing.T) { + id := uint32(8000001) + + packet := targetPacket(doorStatusPacket(id, scenario.locked, scenario.open, scenario.latch)) + packet = packet[:binary.BigEndian.Uint16(packet[6:8])] + + if binary.BigEndian.Uint32(packet[16:20]) != 0x4c7d403b || + binary.BigEndian.Uint32(packet[20:24]) != 51016 || binary.BigEndian.Uint32(packet[24:28]) != 8000001 || + hex.EncodeToString(packet[29:]) != scenario.body { + t.Fatal("door status fields were merged, reordered or truncated", hex.EncodeToString(packet)) + } + }) + } +} diff --git a/server/shops.go b/server/shops.go @@ -6,7 +6,6 @@ import ( "encoding/binary" "fmt" "maps" - "math" "slices" "time" ) @@ -36,29 +35,8 @@ func (server *server) canUseShop_locked(client *worldClient, machine gamedata.Sh func shopMachinePacket(id uint32, machine gamedata.ShopMachine) []byte { // VendingMachineFullUpdate inherits SimpleItem 11, Lockable 2 and Chest 3. - var body []byte - for _, value := range []uint32{11, 0, 0} { - body = binary.BigEndian.AppendUint32(body, value) - } - for _, value := range machine.Position { - body = binary.BigEndian.AppendUint32(body, math.Float32bits(value)) - } - for _, value := range machine.Rotation { - body = binary.BigEndian.AppendUint32(body, math.Float32bits(value)) - } - for _, value := range []uint32{machine.Playfield, 0, 0} { - body = binary.BigEndian.AppendUint32(body, value) - } - body = append(body, 0, 0) - body = binary.BigEndian.AppendUint32(body, uint32(3+len(machine.Stats))*1009) - for _, value := range []uint32{23, machine.Template, 701, *gamedata.ItemTemplates[machine.Template].Quality} { - body = binary.BigEndian.AppendUint32(body, value) - } - for _, stat := range machine.Stats { - body = binary.BigEndian.AppendUint32(body, stat[0]) - body = binary.BigEndian.AppendUint32(body, stat[1]) - } - for _, value := range []uint32{0, 2, 0, 1009, 3} { + body := simpleItemBody(machine.Template, machine.Playfield, machine.Position, machine.Rotation, machine.Stats) + for _, value := range []uint32{2, 0, 1009, 3} { body = binary.BigEndian.AppendUint32(body, value) } return n3Packet(0x7f544905, 51035, id, body) diff --git a/server/world_items.go b/server/world_items.go @@ -0,0 +1,44 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "math" +) + +func simpleItemBody(template, playfield uint32, position [3]float32, rotation [4]float32, stats [][2]uint32) []byte { + // SimpleItem11: parentless world placement, owner and placement bytes. + var body []byte + for _, value := range []uint32{11, 0, 0} { + body = binary.BigEndian.AppendUint32(body, value) + } + for _, value := range position { + body = binary.BigEndian.AppendUint32(body, math.Float32bits(value)) + } + for _, value := range rotation { + body = binary.BigEndian.AppendUint32(body, math.Float32bits(value)) + } + for _, value := range []uint32{playfield, 0, 0} { + body = binary.BigEndian.AppendUint32(body, value) + } + body = append(body, 0, 0) + + // Preserve an absent authored QL, followed by placement overrides and payload. + count := 2 + len(stats) + if gamedata.ItemTemplates[template].Quality != nil { + count++ + } + body = binary.BigEndian.AppendUint32(body, uint32(count)*1009) + for _, value := range []uint32{23, template} { + body = binary.BigEndian.AppendUint32(body, value) + } + if gamedata.ItemTemplates[template].Quality != nil { + body = binary.BigEndian.AppendUint32(body, 701) + body = binary.BigEndian.AppendUint32(body, *gamedata.ItemTemplates[template].Quality) + } + for _, stat := range stats { + body = binary.BigEndian.AppendUint32(body, stat[0]) + body = binary.BigEndian.AppendUint32(body, stat[1]) + } + return binary.BigEndian.AppendUint32(body, 0) +}