aorecomp

Anarchy Online classic in the browser

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


commit 1464218e2543fcd707dfb8b5b6f5477301ac5292
parent 7849adfc2db2dff2f8e351a67f55a0412ecc3bf0
Author: anon <anon@example.com>
Date:   Sat, 24 Oct 2026 03:35:51 +0000

Include seated posture in actor entry snapshots

Diffstat:
MTODO.md | 14++++++++------
Mdocs/combat-regeneration.md | 36++++++++++++++++++++++++++++++++++++
Mdocs/world-state.md | 7+++++--
Mserver/world.go | 4+++-
Aserver/world_posture_test.go | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 186 insertions(+), 9 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -853,12 +853,14 @@ and server restarts. Turn every reproduced bug into a focused regression test. - [ ] Audit disconnects, retries and failure handling across these features. Cover transport replacement, stale sessions, action replay, database failures and concurrent requests; success must follow the durable significant change. - Reconcile saved posture with native entry state: a patient sat in native - mode 8, then re-entered in mode 3 after a crash/restart while SQLite retained - `sitting=1`. Verify the original entry policy and synchronize the two states - before relying on seated-only item use and regeneration. Capture: - `local/consumable-outcome-research/after-server-restart.json` and - `after-server-start-database.json`. +- [x] Synchronize posture across world entry and late observers. Check: reconnect, + restart and replacement clear live resting posture before treatment eligibility; + posture checkpoints retain their normal cadence. A joining observer sees an + already seated actor in native mode 8, with its preferred walk/run mode retained + for standing. The earlier SQLite `sitting=1` versus native mode 3 observation + was an expected pending checkpoint, not a live eligibility mismatch. The actual + missing seated posture in observer spawn packets is now covered by regression + tests. See `server/world_posture_test.go` and [posture](docs/combat-regeneration.md). - [x] Coordinate background checkpoints with server shutdown. Check: shutdown commits current durable state and stops simulation/checkpoint writers before closing SQLite; normal restarts produce no late `database is closed` errors. diff --git a/docs/combat-regeneration.md b/docs/combat-regeneration.md @@ -120,6 +120,42 @@ anchored to its original phase, so small scheduling delays do not accumulate. The supported Leet's separate recovery rule and its server-policy limits are recorded in [NPC health recovery](npc-regeneration.md). +World entry clears the connecting actor's live sitting state before publishing +its snapshot or accepting item use. A saved `sitting=1` may remain in SQLite until +the next position/vitals checkpoint; it does not authorize seated-only treatment +after reconnect. Public connection regressions cover reconnect, process restart +and transport replacement, standing treatment rejection without a debit, the +normal posture checkpoint, and successful treatment after an acknowledged sit. +This establishes the reconstruction's current entry behavior; the original +Funcom server's login posture policy is not independently recovered. + +Other actors retain their posture when an observer enters. Their spawn vehicle +blob supplies sitting mode 8 and preserves the preferred ground mode 2/3 in its +trailing control state, so standing restores walking/running. The exact 14.9.1 +reader `kkr.dll!FUN_10049220` reads velocity before `FUN_10047160` calls +`FUN_100496b0` for ten control bytes and then reads the saved ground mode. +`FUN_100447c0` maps the sit movement command 28 to mode 8 and restores the saved +mode for stand command 31. REA evidence is retained in +`local/posture-research/native-evidence.json` (reader +`ev_afb34fc6c7a69b4461fb5a992dd641c1d68bcbbed3a366af495817d263c9a72b`, +controls `ev_09164768a836a3815c36e78e9a1a756f811dd853981e43a56ba70bba7fa1a05e`, +decode `ev_3972785e3b3aabc7bed848cb4fc292304d6701e8197dcb3c62808cef57620c9b`, +state machine `ev_cb87381e23709fde42ed0193fb4f535d6056a1db069f5ac16ec5203b5600769e`). +The evidence identifies client parsing and transitions, not a historical server +capture. Observer entry tests cover seated/standing actors with both ground +preferences, without changing the existing actor's live state. + +Two published WASM clients reproduced the missing observer posture before the +change: the owner and live server were sitting while the entering observer saw +mode 3. With the corrected snapshot both clients saw mode 8 after late join and +observer reload. Standing restored mode 3 when running and mode 2 when walking; +another observer reload preserved sitting with the walking preference too. +Reconnecting the seated owner reset both clients and live server to standing +mode 2. The original running preference was restored afterward, no items or +placements changed, and both test clients were closed. There were no page or +adapter errors. Captures and checked results are retained in +`local/posture-research/verification.json`. + Absolute health is sent only when neither the player nor an enemy targeting that player is attacking. StopFight flushes queued weapon outcomes before the correction can be sent. This prevents an absolute snapshot from pre-applying diff --git a/docs/world-state.md b/docs/world-state.md @@ -159,5 +159,8 @@ rejected by the native client without a server request or debit. No page or adapter errors occurred. Both profiles, their original item records/placements and receipts were restored, and the fixture items/team were removed. The full server suite and focused race checks pass. Evidence is retained in -`local/consumable-outcome-research/`. The saved/native posture mismatch observed -on entry remains a separate TODO. +`local/consumable-outcome-research/`. The apparent saved/native posture mismatch +on entry was a pending checkpoint: entry already resets live posture to standing. +Connection regressions now verify standing treatment rejection before that +checkpoint, and sitting is included in late observers' actor snapshots. See +[posture and recovery](combat-regeneration.md). diff --git a/server/world.go b/server/world.go @@ -110,10 +110,12 @@ func characterPacket(character *character) []byte { if character.running { vehicle[12] = 3 } - // Flight retains the ground speed mode used when its effect is removed. + // Sitting and flight retain the preferred walk/run mode for standing or landing. binary.BigEndian.PutUint32(vehicle[22:26], uint32(vehicle[12])) if character.flying() { vehicle[12] = 7 + } else if character.sitting { + vehicle[12] = 8 } body = binary.BigEndian.AppendUint32(body, uint32(len(vehicle))) body = append(body, vehicle...) diff --git a/server/world_posture_test.go b/server/world_posture_test.go @@ -0,0 +1,134 @@ +package main + +import ( + "bytes" + "encoding/binary" + "net" + "testing" + "time" +) + +func TestWorldEntryResetsSavedPostureBeforeTreatment(t *testing.T) { + for _, scenario := range []string{"reconnect", "restart", "replacement"} { + t.Run(scenario, func(t *testing.T) { + world, _, _ := newConsumableOutcomeWorld(t, 25812, false) + if scenario == "restart" { + world = newTestInventoryServer(t) + } else if scenario == "replacement" { + world.clients[1].conn = &combatInterestConn{} + } else { + delete(world.clients, 1) + } + world.characters[1].nextPositionSave = time.Now().Add(20 * time.Second) + selection := binary.BigEndian.AppendUint32(nil, 50000) + selection = binary.BigEndian.AppendUint32(selection, 1) + selection = binary.BigEndian.AppendUint32(selection, 0) + + client := connectZoningClient(t, world, true) + if _, err := client.Write(targetPacket(n3Packet(0x2252445f, 50000, 1, selection))); err != nil { + t.Fatal(err) + } + if _, err := client.Write(targetPacket(backpackUseRequest(1, 64, 1))); err != nil { + t.Fatal(err) + } + rejected, err := readPacket(client) + if err != nil { + t.Fatal(err) + } + + world.mutex.Lock() + player := *world.characters[1] + world.mutex.Unlock() + if player.sitting || player.health != 1 || player.inventory.Items[0].Count != 50 || !player.treatmentLockedUntil.IsZero() { + t.Fatalf("entry retained rest or consumed a standing patient's kit: %+v", player) + } + if binary.BigEndian.Uint32(rejected[16:20]) != 0x52526858 || binary.BigEndian.Uint32(rejected[29:33]) != 2 { + t.Fatalf("standing treatment was not rejected: %x", rejected) + } + var savedSitting bool + if err := world.db.QueryRow("SELECT sitting FROM characters WHERE id=1").Scan(&savedSitting); err != nil || !savedSitting { + t.Fatalf("entry eagerly rewrote checkpointed posture: sitting=%t error=%v", savedSitting, err) + } + if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil { + t.Fatal(err) + } + if err := world.db.QueryRow("SELECT sitting FROM characters WHERE id=1").Scan(&savedSitting); err != nil || savedSitting { + t.Fatalf("standing posture did not checkpoint: sitting=%t error=%v", savedSitting, err) + } + + // Sit through the same connection, then confirm the treatment can succeed. + posture := binary.BigEndian.AppendUint32(nil, 86) + posture = append(posture, make([]byte, 16)...) + if _, err := client.Write(targetPacket(n3Packet(0x5e477770, 50000, 1, posture))); err != nil { + t.Fatal(err) + } + if _, err := readPacket(client); err != nil { + t.Fatal(err) + } + if _, err := client.Write(targetPacket(backpackUseRequest(1, 64, 2))); err != nil { + t.Fatal(err) + } + accepted, err := readPacket(client) + if err != nil { + t.Fatal(err) + } + for range 3 { + if _, err := readPacket(client); err != nil { + t.Fatal(err) + } + } + world.mutex.Lock() + defer world.mutex.Unlock() + player = *world.characters[1] + if binary.BigEndian.Uint32(accepted[29:33]) != 1 || !player.sitting || player.health != 31 || player.inventory.Items[0].Count != 49 { + t.Fatalf("seated treatment did not heal and consume one charge: packet=%x player=%+v", accepted, player) + } + }) + } +} + +func TestWorldObserverEntryReceivesExistingPosture(t *testing.T) { + for _, sitting := range []bool{false, true} { + for _, running := range []bool{false, true} { + t.Run(map[bool]string{false: "standing", true: "sitting"}[sitting]+"/"+map[bool]string{false: "walk", true: "run"}[running], func(t *testing.T) { + world, _ := newCombatWorld() + delete(world.characters, 1000000) + world.characters[1].name, world.characters[1].sitting, world.characters[1].running = "Patient", sitting, running + world.characters[2] = &character{id: 2, name: "Observer", playfield: 950, health: 100} + cookie := systemPacket(0x1b, []byte{0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0}) + binary.BigEndian.PutUint16(cookie, 0xdfdf) + address, peer := net.Pipe() + defer address.Close() + defer peer.Close() + conn := &combatInterestConn{combatTestConn: combatTestConn{Conn: address}, input: bytes.NewReader(cookie)} + + if err := world.serveWorldClient(&worldClient{conn: conn, loading: true}); err != nil { + t.Fatal(err) + } + + var spawn []byte + for _, packet := range conn.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x271b3a6b && binary.BigEndian.Uint32(packet[24:28]) == 1 { + spawn = packet + } + } + start := bytes.Index(spawn, []byte("Patient\x00")) + len("Patient") + 40 + if len(spawn) < start+28 { + t.Fatalf("existing player's vehicle state missing: %x", spawn) + } + vehicle := spawn[start : start+28] + ground := byte(2) + if running { + ground = 3 + } + mode := ground + if sitting { + mode = 8 + } + if vehicle[12] != mode || binary.BigEndian.Uint32(vehicle[22:26]) != uint32(ground) || world.characters[1].sitting != sitting { + t.Fatalf("observer posture/ground preference changed: vehicle=%x sitting=%t", vehicle, world.characters[1].sitting) + } + }) + } + } +}