aorecomp

Anarchy Online classic in the browser

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


commit 25998f1e55725fed0c80eac28332e66597ca4f14
parent cdab87c86bdcffb9f019d0d0b821bfa7169378a3
Author: anon <anon@example.com>
Date:   Sat,  7 Nov 2026 06:46:54 +0000

Run native protocol fixtures through production zone ownership

Diffstat:
MTODO.md | 7+++++--
Mserver/armor_test.go | 1+
Mserver/backpack_equipment_test.go | 1+
Mserver/backpacks_test.go | 1+
Mserver/interest_test.go | 5++++-
Mserver/inventory_test.go | 8++++++++
Mserver/logout_cancellation_test.go | 2++
Mserver/main_test.go | 11++++++++++-
Mserver/mission_doors_test.go | 1+
Mserver/player_altitude_test.go | 12++++++++----
Mserver/player_ip_test.go | 14++++----------
Mserver/stacks_test.go | 1+
Mserver/target_protocol_test.go | 21+++++++++++++++++----
Mserver/tradeskills_test.go | 1+
Mserver/world_runtime_test.go | 80+++++++++++++++++++++----------------------------------------------------------
15 files changed, 85 insertions(+), 81 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -49,8 +49,11 @@ research separately. More screenshots and test cases do not count as new gamepla replace server-wide password/database initialization locks with explicit service lifetimes. Password derivation now has a channel worker, and database construction is explicit before requests begin; both mutex fields are removed. - Simulation mutexes and their dependent harnesses remain. Audit shared caches - separately. Completion requires source + Routed fixtures now use production partitioning, and native connection, + inventory and restart tests are moving onto production service ownership. + The browser resource index publishes immutable results through completion + channels instead of a global mutex. Simulation mutexes and their dependent + harnesses remain; audit the shared geometry cache separately. Completion requires source inspection, race coverage of the migrated harnesses, and real-server protocol verification; the existing production isolation tests alone are insufficient. diff --git a/server/armor_test.go b/server/armor_test.go @@ -244,6 +244,7 @@ func TestArmorReconnectUsesInventoryWithoutRepeatingWear(t *testing.T) { world.advanceEquipment(world.clients[1].equipment.readyAt) } world = newTestInventoryServer(t) + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) diff --git a/server/backpack_equipment_test.go b/server/backpack_equipment_test.go @@ -17,6 +17,7 @@ func TestBackpackWornUseThroughNativeConnection(t *testing.T) { t.Fatal(err) } world := newTestInventoryServer(t) + startTestService(t, world) client, connection := net.Pipe() client.SetDeadline(time.Now().Add(5 * time.Second)) done := make(chan error, 1) diff --git a/server/backpacks_test.go b/server/backpacks_test.go @@ -70,6 +70,7 @@ func TestBackpackOpenCloseAndDistinctHandles(t *testing.T) { func TestBackpackNativeWireTransferAndRestart(t *testing.T) { newBackpackWorld(t) world := newTestInventoryServer(t) + startTestService(t, world) client, connection := net.Pipe() client.SetDeadline(time.Now().Add(5 * time.Second)) done := make(chan error, 1) diff --git a/server/interest_test.go b/server/interest_test.go @@ -17,6 +17,7 @@ func TestLoginIncludesNearbyNPCsButNotDistantPopulation(t *testing.T) { world := newTestServer(t) player := world.newCharacter() player.position = [3]float32{1000, 0, 1000} + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) @@ -46,7 +47,9 @@ func TestLoginIncludesNearbyNPCsButNotDistantPopulation(t *testing.T) { if len(seen) != 3 || !seen[1] || !seen[1000000] || !seen[1000001] { t.Fatalf("spawned identities: %v", seen) } - if len(world.characters) != 4 { + counts := &zoneAdminCounts{} + callTestZone(t, world, 1, counts) + if counts.players != 1 || counts.npcs != 3 { t.Fatal("distant NPC was removed from the world") } }) diff --git a/server/inventory_test.go b/server/inventory_test.go @@ -69,6 +69,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) { t.Fatalf("granted item: %+v", world.characters[1].inventory) } world = newTestInventoryServer(t) + shutdown := startTestService(t, world) connect := func() (net.Conn, chan error) { t.Helper() client, connection := net.Pipe() @@ -108,12 +109,16 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) { if err := <-done; err != nil { t.Fatal(err) } + if err := shutdown(); err != nil { + t.Fatal(err) + } world = newTestInventoryServer(t) expected.Slot = 93 if !reflect.DeepEqual(world.characters[1].inventory.Items, []ownedItem{expected}) || binary.BigEndian.Uint32(move[16:20]) != 0x47537a24 || binary.BigEndian.Uint32(move[45:49]) != 77 { t.Fatalf("move lost item identity or slot: %+v %x", world.characters[1].inventory, move) } + shutdown = startTestService(t, world) // The next connection must initialize using the saved slot. client, connection := net.Pipe() defer client.Close() @@ -151,6 +156,9 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) { if err := <-done; err != nil { t.Fatal(err) } + if err := shutdown(); err != nil { + t.Fatal(err) + } world = newTestInventoryServer(t) if len(world.characters[1].inventory.Items) != 0 || world.nextItem != 1 || diff --git a/server/logout_cancellation_test.go b/server/logout_cancellation_test.go @@ -33,8 +33,10 @@ func TestCampingCancellationClearsDeadlineAndNativeUI(t *testing.T) { name = "during countdown" } t.Run(name, func(t *testing.T) { + useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() serverConn := &logoutDeadlineConn{Conn: connection, deadlines: make(chan time.Time, 4)} if err := client.SetDeadline(time.Now().Add(5 * time.Second)); err != nil { diff --git a/server/main_test.go b/server/main_test.go @@ -104,9 +104,11 @@ func TestReadPacketConsumesPadding(t *testing.T) { } func TestTeleportReconnectsSameCharacterInDestination(t *testing.T) { + useNPCData(t, testNPCData()) world := newTestServer(t) world.worldPort = 7620 world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(30 * time.Second)) @@ -120,7 +122,7 @@ func TestTeleportReconnectsSameCharacterInDestination(t *testing.T) { t.Fatal(err) } mux := http.NewServeMux() - mux.HandleFunc("POST /admin/players/{character}/teleport", world.teleportPlayer) + mux.HandleFunc("POST /admin/players/{character}/teleport", world.playerHTTP((*server).teleportPlayer)) response := httptest.NewRecorder() done := make(chan struct{}) @@ -171,9 +173,11 @@ func TestTeleportReconnectsSameCharacterInDestination(t *testing.T) { } func TestTwoPlayersShareMovementAndDisconnect(t *testing.T) { + useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() world.newCharacter() + startTestService(t, world) first, firstServer := net.Pipe() second, secondServer := net.Pipe() defer first.Close() @@ -225,8 +229,10 @@ func TestTwoPlayersShareMovementAndDisconnect(t *testing.T) { } func TestSitAndStandAreAcknowledged(t *testing.T) { + useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) @@ -263,8 +269,10 @@ func TestSitAndStandAreAcknowledged(t *testing.T) { } func TestLogoutCompletesAfterCountdown(t *testing.T) { + useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() serverConn := &logoutDeadlineConn{Conn: connection, deadlines: make(chan time.Time, 1)} defer client.Close() @@ -352,6 +360,7 @@ func TestWorldCookieThenPing(t *testing.T) { client, server := net.Pipe() world := newTestServer(t) world.newCharacter() + startTestService(t, world) defer client.Close() done := make(chan error, 1) go func() { diff --git a/server/mission_doors_test.go b/server/mission_doors_test.go @@ -64,6 +64,7 @@ func TestMissionDoorsNativeSocketReplaysAfterPlayfieldAndBeforeReady(t *testing. t.Fatal(err) } cold := reloadMissionEntranceWorld(t) + startTestService(t, cold) connection, remote := net.Pipe() connection.SetDeadline(time.Now().Add(5 * time.Second)) done := make(chan error, 1) diff --git a/server/player_altitude_test.go b/server/player_altitude_test.go @@ -115,6 +115,7 @@ func TestPlayerAltitudeInitializationKeepsTheAuthoredSpawn(t *testing.T) { world := newCheckpointWorld(t) player := world.characters[1] player.playfield, player.position = 705, [3]float32{50, 900, 60} + startTestService(t, world) cookie := systemPacket(0x1b, []byte{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}) binary.BigEndian.PutUint16(cookie, 0xdfdf) connection, peer := net.Pipe() @@ -148,10 +149,13 @@ func TestPlayerAltitudeInitializationKeepsTheAuthoredSpawn(t *testing.T) { } } - world.updateMutex.Lock() - defer world.updateMutex.Unlock() - if snapshots != 1 || player.position[1] != 900 || player.movement.updatedAt.IsZero() { - t.Fatal("initial placement must be unchanged with the simulation clock running", snapshots, player.position, player.movement) + var prepared bool + callTestZone(t, world, 1, zoneTestCommand(func(state *server) error { + prepared = !state.characters[1].movement.updatedAt.IsZero() + return nil + })) + if snapshots != 1 || !prepared { + t.Fatal("initialization did not publish one authored spawn and prepare movement", snapshots, prepared) } } diff --git a/server/player_ip_test.go b/server/player_ip_test.go @@ -15,6 +15,7 @@ func TestPlayerLastIPSurvivesDisconnectAndDatabaseReopen(t *testing.T) { t.Fatal(err) } + shutdown := startTestService(t, world) for _, address := range []string{"192.0.2.10:4321", "[2001:db8::5]:8765"} { client, connection := net.Pipe() t.Cleanup(func() { client.Close(); connection.Close() }) @@ -55,19 +56,12 @@ func TestPlayerLastIPSurvivesDisconnectAndDatabaseReopen(t *testing.T) { } // Full snapshots must preserve connection metadata too. - if err := world.flushWorld(); err != nil { - t.Fatal(err) - } - if err := world.closeDatabase(); err != nil { - t.Fatal(err) - } - world.db = nil - db, err := world.openDatabase() - if err != nil { + if err := shutdown(); err != nil { t.Fatal(err) } + restored := newTestInventoryServer(t) var saved string - if err := db.QueryRow("SELECT last_ip FROM players WHERE id=1").Scan(&saved); err != nil || saved != "2001:db8::5" { + if err := restored.db.QueryRow("SELECT last_ip FROM players WHERE id=1").Scan(&saved); err != nil || saved != "2001:db8::5" { t.Fatal("last IP lost after reopening database", saved, err) } } diff --git a/server/stacks_test.go b/server/stacks_test.go @@ -77,6 +77,7 @@ func TestStackNativeWireDoesNotTranslateRetainedCountAsASlot(t *testing.T) { t.Fatal(err) } world := newTestInventoryServer(t) + startTestService(t, world) client, connection := net.Pipe() client.SetDeadline(time.Now().Add(5 * time.Second)) done := make(chan error, 1) diff --git a/server/target_protocol_test.go b/server/target_protocol_test.go @@ -81,6 +81,7 @@ func TestTargetWorldInitializationUsesRecoveredLayouts(t *testing.T) { useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) @@ -162,9 +163,11 @@ func TestTargetFullInventoryUsesAllThirtyNativeSlots(t *testing.T) { func TestTargetMovementIsPersistedAndRelayedToReleaseClient(t *testing.T) { useNPCData(t, testNPCData()) world := newTestServer(t) + world.newCharacter() + world.newCharacter() + shutdown := startTestService(t, world) var clients []net.Conn for id := uint32(1); id <= 2; id++ { - world.newCharacter() client, connection := net.Pipe() clients = append(clients, client) defer client.Close() @@ -218,7 +221,7 @@ func TestTargetMovementIsPersistedAndRelayedToReleaseClient(t *testing.T) { if err != nil { t.Fatal(err) } - if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil { + if err := shutdown(); err != nil { t.Fatal(err) } restarted := newServerForTest(t) @@ -248,6 +251,7 @@ func TestTargetInventoryBoundsAndLastSlotMovesSurviveRestart(t *testing.T) { if err := world.saveInventory_locked(player, player.inventory); err != nil { t.Fatal(err) } + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) @@ -307,6 +311,7 @@ func TestTargetTeleportIncludesFullPlayfieldProxy(t *testing.T) { useNPCData(t, testNPCData()) world := newTestServer(t) world.newCharacter() + startTestService(t, world) client, connection := net.Pipe() defer client.Close() client.SetDeadline(time.Now().Add(5 * time.Second)) @@ -332,7 +337,7 @@ func TestTargetTeleportIncludesFullPlayfieldProxy(t *testing.T) { request.SetPathValue("character", "1") done := make(chan struct{}) - go func() { world.teleportPlayer(httptest.NewRecorder(), request); close(done) }() + go func() { world.playerHTTP((*server).teleportPlayer)(httptest.NewRecorder(), request); close(done) }() teleport, err := readPacket(client) if err != nil { t.Fatal(err) @@ -346,7 +351,15 @@ func TestTargetTeleportIncludesFullPlayfieldProxy(t *testing.T) { if hex.EncodeToString(teleport[41:86]) != "610000c79c00000320000003200000000000009c5000000320000000000000000000009c500000032000000000" { t.Fatalf("target teleport proxy and identities: %x", teleport) } - if binary.BigEndian.Uint32(redirect[16:20]) != 0x3c || world.characters[1].playfield != 800 { + owner, err := world.world.owner(1) + if err != nil { + t.Fatal(err) + } + query := &zoneTransferQuery{player: 1} + if err := owner.call(query); err != nil { + t.Fatal(err) + } + if binary.BigEndian.Uint32(redirect[16:20]) != 0x3c || query.playfield != 800 { t.Fatalf("target teleport redirect: %x", redirect) } } diff --git a/server/tradeskills_test.go b/server/tradeskills_test.go @@ -220,6 +220,7 @@ func TestItemCombinationConcurrentReplayAndFullInventory(t *testing.T) { func TestItemCombinationUsesTheOriginalNativeInventorySlots(t *testing.T) { newCombinationWorld(t) world := newTestInventoryServer(t) + startTestService(t, world) client, connection := net.Pipe() client.SetDeadline(time.Now().Add(5 * time.Second)) done := make(chan error, 1) diff --git a/server/world_runtime_test.go b/server/world_runtime_test.go @@ -12,73 +12,35 @@ import ( // commands; the fixture retains only database infrastructure for assertions. func newRoutedTestWorld(t *testing.T, fixture *server) *worldRuntime { t.Helper() - states := make(map[uint32]*server) - for id, player := range fixture.characters { - state := states[player.playfield] - if state == nil { - state = fixture.emptyZone() - states[player.playfield] = state - } - state.characters[id] = player - if client := fixture.clients[id]; client != nil { - state.clients[id] = client - } - if player.npc { - if player.corpse != nil { - for _, item := range player.corpse.items { - state.items[item.ID], state.itemPlacements[item.ID] = fixture.items[item.ID], fixture.itemPlacements[item.ID] - for _, child := range fixture.items[item.ID].Slots { - if child != nil { - state.items[*child], state.itemPlacements[*child] = fixture.items[*child], fixture.itemPlacements[*child] - } - } - } - } - continue - } - for _, item := range player.inventory.allItems() { - state.items[item.ID], state.itemPlacements[item.ID] = fixture.items[item.ID], fixture.itemPlacements[item.ID] - } - } - for id, saved := range fixture.savedNPCs { - playfield := saved.State.Character.Position.Playfield - state := states[playfield] - if state == nil { - state = fixture.emptyZone() - states[playfield] = state - } - if state.savedNPCs == nil { - state.savedNPCs = make(map[uint32]savedNPC) - } - state.savedNPCs[id] = saved - } - clear(fixture.savedNPCs) - // Transfer physical mission objectives with their zone, not the owner journal. - for _, mission := range fixture.missionExpiry { - state := states[mission.world] - if state == nil { - state = fixture.emptyZone() - states[mission.world] = state - } - for id, item := range fixture.worldItems { - if item.mission == mission.id { - state.worldItems[id] = item - state.items[id], state.itemPlacements[id] = fixture.items[id], fixture.itemPlacements[id] - } - } + states, err := fixture.partitionWorld() + if err != nil { + t.Fatal(err) } - clear(fixture.worldItems) - clear(fixture.characters) - clear(fixture.clients) - clear(fixture.items) - clear(fixture.itemPlacements) world, err := newWorldRuntime(fixture, states) if err != nil { t.Fatal(err) } + fixture.relinquishWorld() return world } +// Commands execute on the owning goroutine. Return errors to the test goroutine +// rather than calling Fatal inside a command and terminating the owner. +type zoneTestCommand func(*server) error + +func (command zoneTestCommand) execute(state *server) error { return command(state) } + +func callTestZone(t *testing.T, fixture *server, player uint32, command zoneCommand) { + t.Helper() + owner, err := fixture.world.owner(player) + if err != nil { + t.Fatal(err) + } + if err := owner.call(command); err != nil { + t.Fatal(err) + } +} + type zoneTeleport struct { player, destination uint32 }