aorecomp

Anarchy Online classic in the browser

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


commit c112d8c013fd70642c03637a06d377918cdf675c
parent 39757bd836633810d6c41db45f66810e2f22a8c9
Author: anon <anon@example.com>
Date:   Sat, 28 Nov 2026 09:50:50 +0000

List saved players and retain ownership across dormant zone transfers

Diffstat:
Mserver/admin_pages.go | 55+++++++++++++++++++++++++++----------------------------
Mserver/world_admin_test.go | 19++++++++++++++++++-
Mserver/world_directory.go | 4+++-
Mserver/zone_population_test.go | 21+++++++++++++++++++++
4 files changed, 69 insertions(+), 30 deletions(-)

diff --git a/server/admin_pages.go b/server/admin_pages.go @@ -99,57 +99,56 @@ func (server *server) usersPage(w http.ResponseWriter, r *http.Request) { return } - // Fetch saved connection metadata together, including offline players. - rows, err := server.db.Query("SELECT id, last_ip, connected_seconds, last_connected_at FROM players") + // SQLite owns the player roster. A zone transfer can fall between live samples. + live := make(map[uint32]mapPlayer, len(players)) + for _, player := range players { + live[player.ID] = player + } + rows, err := server.db.Query(`SELECT id, name, title, playfield, last_ip, connected_seconds, last_connected_at + FROM characters JOIN players USING(id) ORDER BY id`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } defer rows.Close() - addresses := make(map[uint32]string) - connectedSeconds := make(map[uint32]int64) - lastConnected := make(map[uint32]time.Time) + var entries []adminTableRow for rows.Next() { - var id uint32 + var player mapPlayer var address string var seconds int64 - var connectedAt time.Time - if err := rows.Scan(&id, &address, &seconds, &connectedAt); err != nil { + var lastConnected time.Time + if err := rows.Scan(&player.ID, &player.Name, &player.Title, &player.Playfield, &address, &seconds, &lastConnected); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - addresses[id] = address - connectedSeconds[id] = seconds - lastConnected[id] = connectedAt - } - if err := rows.Err(); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - server.adminPageStart(w, "Players", "Players") - fmt.Fprint(w, "<h1>Players</h1>") - adminFilter(w, r) - var entries []adminTableRow - for _, player := range players { + if sample, ok := live[player.ID]; ok { + player = sample + } status := "Offline" - address := "-" - if addresses[player.ID] != "" { - address = addresses[player.ID] + if address == "" { + address = "-" } if player.Connected { status = "Connected" } zone := fmt.Sprintf("%s (%d)", gamedata.Playfields[player.Playfield].Name, player.Playfield) - connectedTime := (time.Duration(connectedSeconds[player.ID]) * time.Second).String() + connectedTime := (time.Duration(seconds) * time.Second).String() connectedAt := "-" - if !lastConnected[player.ID].IsZero() { - connectedAt = lastConnected[player.ID].UTC().Format("2006-01-02 15:04:05 MST") + if !lastConnected.IsZero() { + connectedAt = lastConnected.UTC().Format("2006-01-02 15:04:05 MST") } entries = append(entries, adminTableRow{ - values: []string{fmt.Sprint(player.ID), adminName(player.Name), player.Title, status, address, connectedAt, fmt.Sprint(connectedSeconds[player.ID]), zone}, + values: []string{fmt.Sprint(player.ID), adminName(player.Name), player.Title, status, address, connectedAt, fmt.Sprint(seconds), zone}, markup: fmt.Sprintf("<tr><td>%d</td><td><a href='admin/players/%d'>%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", player.ID, player.ID, html.EscapeString(adminName(player.Name)), html.EscapeString(player.Title), status, html.EscapeString(address), connectedAt, connectedTime, html.EscapeString(zone)), }) } + if err := rows.Err(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + server.adminPageStart(w, "Players", "Players") + fmt.Fprint(w, "<h1>Players</h1>") + adminFilter(w, r) adminTable(w, r, []string{"ID", "Name", "Title", "Status", "Last IP address", "Last connected", "Connected time", "Zone"}, entries) fmt.Fprint(w, "</main></body></html>") } diff --git a/server/world_admin_test.go b/server/world_admin_test.go @@ -20,7 +20,7 @@ func TestRoutedAdminPlayerViewsFollowZoneOwners(t *testing.T) { handler := adminTestHandler(fixture) page := adminRequest(handler, "GET", "/admin/players", "", nil) - if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), "<th>Title</th>") || !strings.Contains(page.Body.String(), "Member2</a></td><td>Visitor</td><td>Offline</td><td>192.0.2.9</td>") { + if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), "sort=Title'>Title</a>") || !strings.Contains(page.Body.String(), "Member2</a></td><td>Visitor</td><td>Offline</td><td>192.0.2.9</td>") { t.Fatal("remote player missing from list", page.Code, page.Body.String()) } online := adminRequest(handler, "GET", "/admin/map-players", "", nil) @@ -48,6 +48,23 @@ func TestRoutedAdminPlayerViewsFollowZoneOwners(t *testing.T) { } } +func TestAdminPlayersIncludesSavedPlayerBetweenZoneSamples(t *testing.T) { + world, _ := newTeamWorld(t) + world.world = newRoutedTestWorld(t, world) + defer world.world.stop() + + if _, err := world.db.Exec(`INSERT INTO characters (id,name,playfield) VALUES (18,'Betweenzones',716); + INSERT INTO players (id) VALUES (18)`); err != nil { + t.Fatal(err) + } + + page := adminRequest(adminTestHandler(world), "GET", "/admin/players", "", nil) + + if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), "admin/players/18'>Betweenzones</a>") { + t.Fatal("saved player missing from admin list", page.Code) + } +} + func TestRoutedAdminNPCMapReadsOnlyRequestedZone(t *testing.T) { fixture, _ := newTeamWorld(t) fixture.characters[2].playfield = 800 diff --git a/server/world_directory.go b/server/world_directory.go @@ -216,7 +216,9 @@ func (directory *worldDirectory) arrive(player *character, command zoneCommand) // A destination may be busy. Never wait for it on the routing goroutine. directory.arrivals++ go func() { - route.err = zone.call(command) + // Accept the already committed player before gameplay needs NPCs. A failed + // population load on the next join must leave ownership intact for retry. + route.err = zone.observe(command) close(route.ready) directory.arrived <- struct{}{} }() diff --git a/server/zone_population_test.go b/server/zone_population_test.go @@ -185,6 +185,12 @@ func TestDormantPopulationActivationFailureDoesNotBlockOtherZone(t *testing.T) { data.Playfields = append(data.Playfields, other) useNPCData(t, data) world := newDormantServerForTest(t) + traveler := world.newCharacter() + traveler.playfield = 800 + if err := world.saveUser(traveler); err != nil { + t.Fatal(err) + } + playerID := traveler.id startTestService(t, world) first, err := world.world.owner(1000000) if err != nil { @@ -207,6 +213,21 @@ func TestDormantPopulationActivationFailureDoesNotBlockOtherZone(t *testing.T) { if err := second.call(query); err != nil || query.npcs != 1 { t.Fatal("other zone could not activate", err, query) } + // Transfer into the failing playfield, then retry gameplay admission. + if err := second.call(zoneTeleport{playerID, 950}); err != nil { + t.Fatal(err) + } + owner, err := world.world.owner(playerID) + if err != nil || owner != first { + t.Fatal("zone activation stranded the traveler", err) + } + travel := &zoneTransferQuery{player: playerID} + if err := owner.observe(travel); err != nil || !travel.present { + t.Fatal("destination did not retain the traveler", err) + } + if err := owner.call(query); err == nil { + t.Fatal("gameplay should still report the population failure") + } var populations, npcs int if err := world.db.QueryRow("SELECT COUNT(*) FROM npc_populations").Scan(&populations); err != nil { t.Fatal(err)