aorecomp

Anarchy Online classic in the browser

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


commit 16ece231ba59e5df513264511b4ffbe981641882
parent 0599a90a67682150709d241812c86235785fd839
Author: anon <anon@example.com>
Date:   Sun, 25 Oct 2026 16:21:06 +0000

Keep world updates flowing after the actor snapshot during loading

Deliver ordered combat/effect and resource-maximum updates once the initial
snapshot has been queued. Preserve action/target guards and NPC interest;
loading observers must not lose health ticks, expiry or death messages.

Cover loading-observer periodic lifecycles, weapon timelines, idle healing
and trained maxima. The full run plus focused reruns cover 5,489 tests and
subtests. The full run found only the two old special-observer expectations;
update them to require ordered delivery and pass the special family rerun.
Loading/output and weapon-special tests pass three race repetitions; vet
and build pass.

Two RTX WASM clients agree on complete damage sequences and saved HP after
reload. Timed reloads verify final tick/expiry and lethal tick/removal/reset/
corpse delivery inside the loading interval. Remove owned fixtures, verify
unrelated database rows and restore the single shared HTTPS preview.

Diffstat:
MTODO.md | 14++++++++------
Mdocs/nano-periodic-damage.md | 41+++++++++++++++++++++++++++++++++--------
Mserver/combat.go | 5+++--
Mserver/npc_regeneration_test.go | 5++++-
Mserver/team_resources.go | 2+-
Mserver/weapon_special_animation_test.go | 4++--
Aserver/world_loading_test.go | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 157 insertions(+), 20 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -810,13 +810,15 @@ introduction and starting-item gameplay remain open below. verified refresh, separate strains, ticks, expiry and death, followed by a cold restart with a saved partial tick interval. See [periodic nano damage](docs/nano-periodic-damage.md). -- [ ] Reconcile NPC health after world loading. Check: damage or healing +- [x] Reconcile NPC health after world loading. Check: damage or healing between actor replay and character readiness cannot leave a late observer - with stale HP. A reloaded WASM observer received both active DoTs but missed - one 4-point hit during loading; its HP remained four points above the owner - and server (90 versus 86, later 43 versus 39). Cover ordinary combat and - resource changes as well as periodic damage, including expiry/death during - loading, with automated and native observer checks. + with stale HP. Once its snapshot is queued, an observer now receives ordered + combat, effect and resource maximum updates while its own actor finishes + loading. Action/target guards and NPC visibility remain enforced. Automated + checks cover weapon timelines, periodic expiry/death, healing, maxima and + excluded observers. Two WASM clients verified identical complete DoT damage + sequences and final HP, plus timed expiry and death/corpse delivery during + loading. See [periodic nano damage](docs/nano-periodic-damage.md). - [ ] Verify original-server periodic-nano timing and lifecycle. Check: first-tick phase, quantization, recast/replacement phase, overdue scheduling, caster death/disconnect, zoning and server downtime match a correlated diff --git a/docs/nano-periodic-damage.md b/docs/nano-periodic-damage.md @@ -94,9 +94,12 @@ contribution count to agree before commit. Catalog payload hashes, source records, native findings, test logs and current WASM checks are retained under `local/nano-dot-research/` and -`local/nano-dot-smoke/`. The final full suite passed 5,484 tests and subtests; -the periodic tests also passed three repetitions under the race detector. -`go vet` and the server build passed. +`local/nano-dot-smoke/`. The full server/data-export run plus focused reruns +cover 5,489 tests and subtests. The full run's only failures were the two +weapon-special expectations that excluded loading observers; both now require +ordered delivery and passed the focused rerun. Loading/output and weapon-special +checks passed three repetitions under the race detector. `go vet` and the +server build passed. Two headed WASM clients on the GPU exercised native crystal uploads, casting, one-time cost debits, refresh, independent strains, complete expiry @@ -115,10 +118,32 @@ client became ready. The warm lifecycle used the 59-program build; the final build additionally admits Hidden Killer through the same scheduler, covered by the final Go suite. No client adapter change was needed. -The late-observer check exposed an open health reconciliation defect: actor +The initial late-observer check exposed a health reconciliation defect: actor and effect replay succeeded, but a 4-point hit during loading was omitted from that observer's stream. Its native HP stayed four points above the owner -and server, including after effect expiry. The TODO retains this discrepancy -and requires a shared loading/resource reconciliation fix; the native checks -do not establish matching late-observer HP. Original-server timing and the -other policy limits above also remain open. +and server, including after effect expiry. + +The shared output paths now deliver combat/effect packets and resource maxima +as soon as the actor snapshot has been queued, including while the observer's +own actor is finishing native loading. The update lock and output queue retain +snapshot-before-update ordering. NPC interest checks still exclude unknown +actors; loading players remain unable to act or become combat targets. This +uses the ordinary event stream without a second snapshot or replay buffer. + +Regression tests cover a loading observer's weapon timeline, periodic expiry +and death, idle NPC healing and trained resource maxima with each observer's +modifier basis. Existing tests cover unready, wrong-zone and unseen observers, +loading-player action guards and ordered output. In the native replay, the +observer received a 4-point tick between spawn and its ready message. Both +clients received the same complete eight 3-point and ten 4-point sequences, +and both ended at the saved 39 HP after expiry. Active probes also matched +their committed HP; a further tick between captures accounts for their +different capture-time values. + +Separate timed native reloads put the final Prototype Biotoxin tick and +explicit expiry inside the loading interval, then did the same for a lethal +Repeated Cellular Trauma tick, effect removal, death/reset and corpse creation. +Both clients agreed with saved outcomes and reported no errors on the GPU. +Evidence is retained under `local/world-loading-smoke/` and +`local/world-loading-boundaries/`. Original-server timing and the other policy +limits above remain open. diff --git a/server/combat.go b/server/combat.go @@ -527,9 +527,10 @@ func (server *server) finishDamageEffects_locked(attacker, target *character, pr } func (server *server) queueCombat_locked(updates map[*worldClient][][]byte, character, target *character, packets ...[]byte) { - // Never announce an NPC before this observer has received its spawn. + // Ready means the actor snapshot is queued; keep later updates ordered behind it + // even while the observer's own character is still finishing native loading. for id, client := range server.clients { - if client.ready && !client.loading && server.characters[id].playfield == character.playfield && + if client.ready && server.characters[id].playfield == character.playfield && (!character.npc || client.npcs[character.id]) && (!target.npc || client.npcs[target.id]) { updates[client] = append(updates[client], packets...) } diff --git a/server/npc_regeneration_test.go b/server/npc_regeneration_test.go @@ -154,7 +154,10 @@ func TestNPCRegenerationSendsQuietHealthOnlyToReadyObserversWithInterest(t *test if len(first.packets) != 1 || len(observers[0].packets) != 1 || !bytes.Equal(first.packets[0][16:], observers[0].packets[0][16:]) || !bytes.Equal(first.packets[0][29:45], []byte{0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) || binary.BigEndian.Uint32(first.packets[0][24:28]) != 1000000 { t.Fatalf("quiet correction layout: %x", first.packets) } - for _, conn := range observers[1:] { + if len(observers[1].packets) != 1 || !bytes.Equal(first.packets[0][16:], observers[1].packets[0][16:]) { + t.Fatal("loading observer lost a correction after its actor snapshot") + } + for _, conn := range observers[2:] { if len(conn.packets) != 0 { t.Fatalf("correction leaked outside interest: %x", conn.packets) } diff --git a/server/team_resources.go b/server/team_resources.go @@ -70,7 +70,7 @@ func (server *server) queueTeamResources_locked(updates map[*worldClient][][]byt func (server *server) queueResourceMaximum_locked(updates map[*worldClient][][]byte, actor *character, stat, base uint32) { for id, client := range server.clients { - if !client.ready || client.loading || server.characters[id].playfield != actor.playfield || + if !client.ready || server.characters[id].playfield != actor.playfield || stat == 221 && id != actor.id && (actor.team == nil || actor.team != server.characters[id].team) { continue } diff --git a/server/weapon_special_animation_test.go b/server/weapon_special_animation_test.go @@ -43,7 +43,7 @@ func TestWeaponSpecialQueuesActionBeforeResultAndLockOnlyForVisibleClients(t *te } } - for _, output := range []*combatTestConn{owner, observers[0]} { + for _, output := range []*combatTestConn{owner, observers[0], observers[1]} { if len(output.packets) < 2 || !bytes.Equal(output.packets[0][16:], expected[16:]) || binary.BigEndian.Uint32(output.packets[1][16:20]) != 0x754f1115 { t.Fatalf("missing ordered special action and result: %x", output.packets) @@ -61,7 +61,7 @@ func TestWeaponSpecialQueuesActionBeforeResultAndLockOnlyForVisibleClients(t *te if binary.BigEndian.Uint32(owner.packets[2][29:33]) != 170 { t.Fatal("skill lock preceded the special action") } - for _, output := range observers[1:] { + for _, output := range observers[2:] { if len(output.packets) != 0 { t.Fatalf("special reached an unavailable observer: %x", output.packets) } diff --git a/server/world_loading_test.go b/server/world_loading_test.go @@ -0,0 +1,106 @@ +package main + +import ( + "bytes" + "encoding/binary" + "testing" + "time" +) + +func TestWorldLoadingObserverReceivesPeriodicLifecycleAfterActorSnapshot(t *testing.T) { + for _, lethal := range []bool{false, true} { + t.Run(map[bool]string{false: "expiry", true: "death"}[lethal], func(t *testing.T) { + world, owner := newPeriodicNanoWorld(t) + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true, loading: true, npcs: map[uint32]bool{1000000: true}} + if lethal { + world.characters[1000000].health = 7 + } + + at := castPeriodicNano(t, world, 43376) + world.advanceNanos(at.Add(time.Minute)) + + var expected [][]byte + for _, packet := range owner.packets { + if binary.BigEndian.Uint32(packet[24:28]) == 1000000 { + expected = append(expected, packet) + } + } + var actual [][]byte + for _, packet := range observer.packets { + if binary.BigEndian.Uint32(packet[24:28]) == 1000000 { + actual = append(actual, packet) + } + } + if len(expected) == 0 || len(actual) != len(expected) { + t.Fatalf("loading observer lost lifecycle packets: got %d want %d", len(actual), len(expected)) + } + for index, packet := range expected { + if !bytes.Equal(actual[index][16:], packet[16:]) { + t.Fatalf("loading observer changed packet %d", index) + } + } + if len(world.characters[1000000].activeNanos) != 0 || !world.clients[2].loading { + t.Fatal("expiry or observer loading state changed") + } + if lethal && world.characters[1000000].corpse == nil { + t.Fatal("lethal sequence did not produce a corpse") + } + }) + } +} + +func TestWorldLoadingObserverReceivesWeaponTimelineWithoutBecomingATarget(t *testing.T) { + world, owner := newCombatWorld() + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true, loading: true, npcs: map[uint32]bool{1000000: true}} + + if err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(world.characters[1].nextAttack) + if err := world.handleCombat(world.clients[2], attackPacket(2, 1000000)[20:]); err != nil { + t.Fatal(err) + } + + if len(owner.packets) != 3 || len(observer.packets) != 3 { + t.Fatalf("loading observer missed weapon timeline: %d/%d", len(owner.packets), len(observer.packets)) + } + for index, packet := range owner.packets { + if !bytes.Equal(observer.packets[index][16:], packet[16:]) { + t.Fatalf("weapon packet %d differs", index) + } + } + if world.characters[2].health != 100 || world.characters[2].fighting != 0 || world.characters[1000000].fighting != 1 { + t.Fatal("loading observer became a combat participant") + } +} + +func TestWorldLoadingObserverReceivesResourceMaximumChanges(t *testing.T) { + world, connections := newResourceBackpackTeam(t) + world.clients[2].loading = true + world.clients[3].loading = true + for _, conn := range connections { + conn.packets = nil + } + stats := world.characters[1].baseStats() + stats.Body.BodyDevelopment, stats.Body.NanoPool = 6, 6 + + if err := world.handleSkillTraining(world.clients[1], skillTrainingRequest(stats)[20:]); err != nil { + t.Fatal(err) + } + + for index, want := range [][2]uint32{{52, 46}, {142, 136}, {52, 0}} { + found := make(map[uint32]uint32) + for _, packet := range connections[index].packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[24:28]) == 1 { + found[binary.BigEndian.Uint32(packet[29:33])] = binary.BigEndian.Uint32(packet[33:37]) + } + } + if found[1] != want[0] || found[221] != want[1] { + t.Fatalf("observer %d maxima %v want %v", index+1, found, want) + } + } +}