commit add6c477acd0094cf8def01d9e7b3f1b41c90c57
parent db54974f453aece70fba04c938b1ef2d217213ad
Author: anon <anon@example.com>
Date: Sat, 7 Nov 2026 07:16:56 +0000
Run native zoning and lifecycle fixtures through zone owners
Diffstat:
9 files changed, 107 insertions(+), 98 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -50,6 +50,8 @@ research separately. More screenshots and test cases do not count as new gamepla
simpler and efficient; zero mutexes is not the goal. Password derivation has a
channel worker, database construction is explicit before requests begin, and
native connection, inventory and restart fixtures use production partitioning.
+ Native zoning, resurrection/insurance and mission fixtures also use production
+ owners and timers; observations return detached values.
Shared geometry now decodes immutable assets once per resource outside map
synchronization; a short mission-registry mutex protects only registration
access. Navigation jobs retain their scene across retirement. Connection-local
diff --git a/server/insurance_test.go b/server/insurance_test.go
@@ -26,6 +26,7 @@ func TestInsuranceNativeUseSurvivesRestartAndReturnsAfterDeath(t *testing.T) {
if err := world.saveUser_locked(player); err != nil {
t.Fatal(err)
}
+ shutdown := startTestService(t, world)
connection := connectZoningClient(t, world, true)
connection.Write(targetPacket(insuranceUseRequest(1)))
@@ -41,6 +42,9 @@ func TestInsuranceNativeUseSurvivesRestartAndReturnsAfterDeath(t *testing.T) {
}
}
connection.Close()
+ if err := shutdown(); err != nil {
+ t.Fatal(err)
+ }
world = newServerForTest(t)
player = world.characters[1]
destination := player.userData()
@@ -49,26 +53,25 @@ func TestInsuranceNativeUseSurvivesRestartAndReturnsAfterDeath(t *testing.T) {
if err := world.updateUser(destination); err != nil {
t.Fatal(err)
}
+ shutdown = startTestService(t, world)
connection = connectZoningClient(t, world, true)
- world.mutex.Lock()
- player.health = 0
- world.mutex.Unlock()
+ callTestZone(t, world, 1, zoneTestCommand(func(state *server) error {
+ state.characters[1].health = 0
+ return nil
+ }))
connection.Write(targetPacket(resurrectionRequest(1)))
for range 3 {
if _, err := readPacket(connection); err != nil {
t.Fatal(err)
}
}
- restarted := newServerForTest(t)
-
- world.mutex.Lock()
- defer world.mutex.Unlock()
+ if err := shutdown(); err != nil {
+ t.Fatal(err)
+ }
+ player = newTestInventoryServer(t).characters[1]
if player.resurrectionTerminal != 0xc00202c1 || player.playfield != 705 || player.position != [3]float32{918, 20.7, 578} || player.health != 1 || player.nano != 1 {
t.Fatalf("death did not return to the scanner saved before restart: %+v", player)
}
- if restarted.characters[1].resurrectionTerminal != 0xc00202c1 || restarted.characters[1].position != [3]float32{918, 20.7, 578} {
- t.Fatal("resurrection erased the saved scanner or durable arrival")
- }
}
func TestInsuranceRejectsInvalidUseWithoutSaving(t *testing.T) {
diff --git a/server/mission_booths_test.go b/server/mission_booths_test.go
@@ -25,10 +25,10 @@ func TestMissionBoothNativeSocketOpensWithoutAwarding(t *testing.T) {
t.Fatal(err)
}
world = newTestInventoryServer(t)
- player = world.characters[1]
+ startTestService(t, world)
connection := connectZoningClient(t, world, true)
defer connection.Close()
- before := player.userData()
+ before := testPlayerData(t, world, 1)
request := missionBoothUseRequest(3221228472, 1)
if _, err := connection.Write(targetPacket(n3Packet(0x52526858, 50000, 1, request[16:]))); err != nil {
@@ -40,9 +40,7 @@ func TestMissionBoothNativeSocketOpensWithoutAwarding(t *testing.T) {
binary.BigEndian.Uint32(packet[29:33]) != 1 || !bytes.Equal(packet[33:], request[20:]) {
t.Fatalf("native booth callback missing or changed: %x %v", packet, err)
}
- world.mutex.Lock()
- defer world.mutex.Unlock()
- if !reflect.DeepEqual(before, player.userData()) {
+ if !reflect.DeepEqual(before, testPlayerData(t, world, 1)) {
t.Fatal("opening the terminal changed the character or inventory")
}
}
diff --git a/server/missions_test.go b/server/missions_test.go
@@ -25,6 +25,7 @@ func missionAcceptanceRequest(offer missionOffer) []byte {
func TestMissionAcceptanceNativeDispatchCommitsKeyAndJournal(t *testing.T) {
newMissionOfferWorld(t)
world := reloadMissionEntranceWorld(t)
+ startTestService(t, world)
connection := connectZoningClient(t, world, true)
defer connection.Close()
request := missionOffersRequest()
diff --git a/server/player_follow_test.go b/server/player_follow_test.go
@@ -13,13 +13,15 @@ import (
func TestPlayerFollowNativeWorldRequestReachesOwnerAndObserver(t *testing.T) {
world := newCheckpointWorld(t)
+ world.newCharacter().playfield = 950
+ startTestService(t, world)
client := connectZoningClient(t, world, true)
observer := &combatTestConn{}
observerClient := &worldClient{id: 2, target: true, ready: true, conn: observer}
- world.mutex.Lock()
- world.newCharacter_locked().playfield = 950
- world.clients[2] = observerClient
- world.mutex.Unlock()
+ callTestZone(t, world, 1, zoneTestCommand(func(state *server) error {
+ state.clients[2] = observerClient
+ return nil
+ }))
// Captured /follow: owned subject, selected target, distance2.5, no correction/path.
captured, _ := hex.DecodeString("dfdf000a0001003a0000000100000002260f36710000c35000000001010000c350000000024020000000000000000000000000000000000000000000")
ping := systemPacket(1, nil)
diff --git a/server/resurrection_test.go b/server/resurrection_test.go
@@ -28,12 +28,14 @@ func TestResurrectionNativeRequestRedirectsAndPersistsBeforeReconnect(t *testing
if err := world.saveInventory_locked(player, playerInventory{LastID: 17, Items: []ownedItem{item}}); err != nil {
t.Fatal(err)
}
+ startTestService(t, world)
connection := connectZoningClient(t, world, true)
- world.mutex.Lock()
- player.health = 0
- player.nano = 0
- player.returnDoor = &doorOrigin{705, 1}
- world.mutex.Unlock()
+ callTestZone(t, world, 1, zoneTestCommand(func(state *server) error {
+ state.characters[1].health = 0
+ state.characters[1].nano = 0
+ state.characters[1].returnDoor = &doorOrigin{705, 1}
+ return nil
+ }))
if _, err := connection.Write(targetPacket(resurrectionRequest(1))); err != nil {
t.Fatal(err)
@@ -50,14 +52,12 @@ func TestResurrectionNativeRequestRedirectsAndPersistsBeforeReconnect(t *testing
t.Fatalf("wrong native resurrection resources: %x", packet)
}
}
- restarted := newServerForTest(t)
+ restarted := newTestInventoryServer(t)
connection.Close()
connection = connectZoningClient(t, world, true)
- world.mutex.Lock()
- movement := *player
- world.mutex.Unlock()
+ movement := testPlayerData(t, world, 1).character()
movement.position[0]++
- connection.Write(targetPacket(npcMovementPacket(&movement, 2)))
+ connection.Write(targetPacket(npcMovementPacket(movement, 2)))
ping := systemPacket(1, nil)
binary.BigEndian.PutUint16(ping[2:4], 11)
connection.Write(ping)
@@ -69,10 +69,14 @@ func TestResurrectionNativeRequestRedirectsAndPersistsBeforeReconnect(t *testing
if arrived.playfield != 952 || arrived.position != [3]float32{42.737694, 14.75, 70.091897} || arrived.returnDoor == nil || *arrived.returnDoor != (doorOrigin{3100, 3876588572}) || !slices.Equal(arrived.inventory.Items, []ownedItem{item}) {
t.Fatalf("resurrection arrival or belongings did not persist: %+v", arrived)
}
- world.mutex.Lock()
- defer world.mutex.Unlock()
- if player.health != 1 || player.nano != 1 || player.position != [3]float32{43.625, 14.75, 70} || !world.clients[1].ready || world.clients[1].loading {
- t.Fatalf("resurrected character cannot play: %+v", player)
+ var playable bool
+ callTestZone(t, world, 1, zoneTestCommand(func(state *server) error {
+ player, client := state.characters[1], state.clients[1]
+ playable = player.health == 1 && player.nano == 1 && player.position == [3]float32{43.625, 14.75, 70} && client.ready && !client.loading
+ return nil
+ }))
+ if !playable {
+ t.Fatal("resurrected character cannot play")
}
}
diff --git a/server/social_actions_test.go b/server/social_actions_test.go
@@ -18,13 +18,16 @@ func socialActionRequest(action uint32) []byte {
func TestSocialActionNativeDispatchDoesNotReplayGesturesToLateObservers(t *testing.T) {
world := newCheckpointWorld(t)
+ world.newCharacter().playfield = 950
+ world.newCharacter().playfield = 950
+ startTestService(t, world)
client := connectZoningClient(t, world, true)
observer := &combatTestConn{}
observerClient := &worldClient{id: 2, target: true, ready: true, conn: observer}
- world.mutex.Lock()
- world.newCharacter_locked().playfield = 950
- world.clients[2] = observerClient
- world.mutex.Unlock()
+ callTestZone(t, world, 1, zoneTestCommand(func(state *server) error {
+ state.clients[2] = observerClient
+ return nil
+ }))
captured, _ := hex.DecodeString("dfdf000a0001002900000001000000023b2907710000c350000000010100000000000000010000003d000000")
ping := systemPacket(1, nil)
binary.BigEndian.PutUint16(ping[2:4], 11)
@@ -41,9 +44,6 @@ func TestSocialActionNativeDispatchDoesNotReplayGesturesToLateObservers(t *testi
if err != nil {
t.Fatal(err)
}
- world.mutex.Lock()
- world.newCharacter_locked().playfield = 950
- world.mutex.Unlock()
late, peer := net.Pipe()
defer late.Close()
late.SetDeadline(time.Now().Add(5 * time.Second))
diff --git a/server/world_runtime_test.go b/server/world_runtime_test.go
@@ -41,6 +41,21 @@ func callTestZone(t *testing.T, fixture *server, player uint32, command zoneComm
}
}
+// Return detached values rather than leaking an actor owned by a live zone.
+func testPlayerData(t *testing.T, fixture *server, player uint32) userData {
+ t.Helper()
+ var data userData
+ callTestZone(t, fixture, player, zoneTestCommand(func(state *server) error {
+ data = state.characters[player].userData()
+ if data.ReturnDoor != nil {
+ door := *data.ReturnDoor
+ data.ReturnDoor = &door
+ }
+ return nil
+ }))
+ return data
+}
+
type zoneTeleport struct {
player, destination uint32
}
diff --git a/server/zoning_test.go b/server/zoning_test.go
@@ -60,9 +60,9 @@ func TestShopDoorReturnsToItsOriginalEntrance(t *testing.T) {
player := world.newCharacter()
player.playfield = 705
player.position = [3]float32{765.0848, 19.1349, 516.5}
- client := connectZoningClient(t, world, target)
-
movement := npcMovementPacket(player, 1)
+ shutdown := startTestService(t, world)
+ client := connectZoningClient(t, world, target)
if target {
movement = targetPacket(movement)
}
@@ -75,10 +75,7 @@ func TestShopDoorReturnsToItsOriginalEntrance(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil {
- t.Fatal(err)
- }
- restarted := newServerForTest(t)
+ restarted := newTestInventoryServer(t)
arrived := restarted.characters[1].userData()
offset := 20
@@ -94,21 +91,19 @@ func TestShopDoorReturnsToItsOriginalEntrance(t *testing.T) {
client.Close()
client = connectZoningClient(t, world, target)
- world.mutex.Lock()
- movementPlayer := *player
- world.mutex.Unlock()
+ movementPlayer := testPlayerData(t, world, 1).character()
movementPlayer.position = [3]float32{187.0007, 5, 116.01}
- movement = npcMovementPacket(&movementPlayer, 1)
+ movement = npcMovementPacket(movementPlayer, 1)
if target {
movement = targetPacket(movement)
}
client.Write(movement)
readPacket(client)
readPacket(client)
- if err := world.flushPositions(time.Now().Add(40 * time.Second)); err != nil {
+ if err := shutdown(); err != nil {
t.Fatal(err)
}
- restarted = newServerForTest(t)
+ restarted = newTestInventoryServer(t)
returned := restarted.characters[1].userData()
if returned.Playfield != 705 || returned.ReturnDoor != nil || math.Abs(float64(returned.Position[2]-514.007)) > 0.001 {
@@ -125,46 +120,35 @@ func TestHeldWalkingCrossesDoorWithoutAnotherMovementPacket(t *testing.T) {
player.playfield = 705
player.position = [3]float32{765.0848, 19.1349, 511.5}
player.rotation = [4]float32{0, 0, 0, 1}
+ movement := targetPacket(npcMovementPacket(player, 1))
+ startTestService(t, world)
client := connectZoningClient(t, world, true)
- client.Write(targetPacket(npcMovementPacket(player, 1)))
+ client.Write(movement)
ping := systemPacket(1, nil)
binary.BigEndian.PutUint16(ping[2:4], 11)
client.Write(ping)
if _, err := readPacket(client); err != nil {
t.Fatal(err)
}
- world.mutex.Lock()
- started := world.characters[1].movement.updatedAt
- world.mutex.Unlock()
-
- done := make(chan struct{})
- go func() {
- defer close(done)
- for frame := 1; frame <= 180; frame++ {
- now := started.Add(time.Duration(frame) * time.Second / 60)
- world.advancePlayerMovement(now)
- world.advanceZoneCrossings(now)
- }
- }()
opening, err := readPacket(client)
if err != nil || !bytes.Equal(opening[16:], targetPacket(doorStatusPacket(0xc01102c1, false, true, true))[16:]) {
t.Fatal("approach did not open the authored shop door before zoning", err)
}
- teleport, err := readPacket(client)
- if err != nil {
- world.mutex.Lock()
- snapshot := world.characters[1].predictedMovement(started.Add(3 * time.Second))
- world.mutex.Unlock()
- t.Fatal(err, "predicted door pose", snapshot.position, snapshot.movement)
- }
- redirect, err := readPacket(client)
- if err != nil {
- t.Fatal(err)
+ // Observe the transition among ordinary simulation updates while walking.
+ var transition []uint32
+ for len(transition) < 2 {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err, "door pose", testPlayerData(t, world, 1).Position, "transition", transition)
+ }
+ key := binary.BigEndian.Uint32(packet[16:])
+ if key == 0x43197d22 || key == 0x3c {
+ transition = append(transition, key)
+ }
}
- <-done
-
- if binary.BigEndian.Uint32(teleport[16:]) != 0x43197d22 || binary.BigEndian.Uint32(redirect[16:]) != 0x3c || world.characters[1].playfield != 1183 {
- t.Fatal("held forward movement did not enter the mapped shop")
+ arrived := testPlayerData(t, world, 1)
+ if transition[0] != 0x43197d22 || transition[1] != 0x3c || arrived.Playfield != 1183 {
+ t.Fatal("held forward movement did not enter the mapped shop", transition, arrived)
}
}
@@ -174,16 +158,19 @@ func TestOmniCityPortalMapsToItsBoundaryExit(t *testing.T) {
player := world.newCharacter()
player.playfield = 705
player.position = [3]float32{1025, 16.4, 509}
+ movement := targetPacket(npcMovementPacket(player, 20))
+ startTestService(t, world)
client := connectZoningClient(t, world, true)
- client.Write(targetPacket(npcMovementPacket(player, 20)))
+ client.Write(movement)
teleport, err := readPacket(client)
if err != nil {
t.Fatal(err)
}
readPacket(client)
- if binary.BigEndian.Uint32(teleport[16:]) != 0x43197d22 || world.characters[1].playfield != 716 || world.characters[1].position[0] == gamedata.Playfields[716].Spawn[0] {
+ arrived := testPlayerData(t, world, 1)
+ if binary.BigEndian.Uint32(teleport[16:]) != 0x43197d22 || arrived.Playfield != 716 || arrived.Position[0] == gamedata.Playfields[716].Spawn[0] {
t.Fatal("city portal did not use the paired boundary destination")
}
}
@@ -205,8 +192,9 @@ func TestOmniBoundaryArrivalClearsTheGround(t *testing.T) {
world.characters = make(map[uint32]*character)
player := world.newCharacter()
player.playfield, player.position = crossing.playfield, crossing.position
- client := connectZoningClient(t, world, target)
movement := npcMovementPacket(player, 20)
+ startTestService(t, world)
+ client := connectZoningClient(t, world, target)
if target {
movement = targetPacket(movement)
}
@@ -218,9 +206,7 @@ func TestOmniBoundaryArrivalClearsTheGround(t *testing.T) {
if _, err := readPacket(client); err != nil {
t.Fatal(err)
}
- world.mutex.Lock()
- arrived := player.userData()
- world.mutex.Unlock()
+ arrived := testPlayerData(t, world, 1)
if arrived.Playfield != crossing.destination || math.Abs(float64(arrived.Position[1]-crossing.height)) > 0.001 {
t.Fatalf("boundary arrival intersects terrain: playfield %d position %v", arrived.Playfield, arrived.Position)
@@ -236,6 +222,7 @@ func TestLookingAtDoorAndUnassignedMissionDoNotZone(t *testing.T) {
player := world.newCharacter()
player.playfield = 705
player.position = [3]float32{765.0848, 19.1349, 516.5}
+ startTestService(t, world)
client := connectZoningClient(t, world, true)
look := binary.BigEndian.AppendUint32(nil, 51016)
look = binary.BigEndian.AppendUint32(look, 0xc01102c1)
@@ -250,27 +237,25 @@ func TestLookingAtDoorAndUnassignedMissionDoNotZone(t *testing.T) {
t.Fatal(err)
}
- if binary.BigEndian.Uint16(reply[2:]) != 11 || player.playfield != 705 {
+ if binary.BigEndian.Uint16(reply[2:]) != 11 || testPlayerData(t, world, 1).Playfield != 705 {
t.Fatal("selecting a door incorrectly triggered zoning")
}
- world.mutex.Lock()
- movementPlayer := *player
- world.mutex.Unlock()
+ movementPlayer := testPlayerData(t, world, 1).character()
for _, door := range world.zoneLinks["target"][705].Doors {
if door.ID == 0xc00402c1 {
movementPlayer.position = door.Position
}
}
- client.Write(targetPacket(npcMovementPacket(&movementPlayer, 2)))
+ client.Write(targetPacket(npcMovementPacket(movementPlayer, 2)))
client.Write(ping)
reply, err = readPacket(client)
if err != nil {
t.Fatal(err)
}
- if binary.BigEndian.Uint16(reply[2:]) != 11 || player.playfield != 705 {
+ if binary.BigEndian.Uint16(reply[2:]) != 11 || testPlayerData(t, world, 1).Playfield != 705 {
t.Fatal("unassigned mission entrance incorrectly triggered zoning")
}
}
@@ -281,13 +266,14 @@ func TestMovementBeforeCharacterReadyPreservesZoneArrival(t *testing.T) {
player := world.newCharacter()
player.playfield = 716
player.position = [3]float32{726, 9.8, 2304}
+ stale := *player
+ shutdown := startTestService(t, world)
client, connection := net.Pipe()
t.Cleanup(func() { client.Close() })
client.SetDeadline(time.Now().Add(5 * time.Second))
go func() { defer connection.Close(); world.serveWorldConnection(connection) }()
client.Write(systemPacket(0x1b, []byte{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}))
readWorldUpdates(t, client)
- stale := *player
stale.position = [3]float32{1025, 16.4, 509}
ping := systemPacket(1, nil)
binary.BigEndian.PutUint16(ping[2:4], 11)
@@ -296,9 +282,7 @@ func TestMovementBeforeCharacterReadyPreservesZoneArrival(t *testing.T) {
client.Write(ping)
readPacket(client)
- world.mutex.Lock()
- arrival := player.position
- world.mutex.Unlock()
+ arrival := testPlayerData(t, world, 1).Position
if arrival != [3]float32{726, 9.8, 2304} {
t.Fatalf("loading movement overwrote arrival: %v", arrival)
}
@@ -311,10 +295,10 @@ func TestMovementBeforeCharacterReadyPreservesZoneArrival(t *testing.T) {
client.Write(npcMovementPacket(&stale, 2))
client.Write(ping)
readPacket(client)
- if err := world.flushPositions(time.Now().Add(20 * time.Second)); err != nil {
+ if err := shutdown(); err != nil {
t.Fatal(err)
}
- restarted := newServerForTest(t)
+ restarted := newTestInventoryServer(t)
if restarted.characters[1].position != [3]float32{727, 9.8, 2304} {
t.Fatal("movement after CharacterReady was not persisted")