aorecomp

Anarchy Online classic in the browser

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


commit 284863f45df23e9e38d7fa21608047850259494a
parent 19b83259d14721c1fb39dea543704696738799d2
Author: anon <anon@example.com>
Date:   Sun,  8 Nov 2026 05:21:13 +0000

Show player titles in admin list and map

Diffstat:
Mserver/admin_pages.go | 4++--
Mserver/assets/map.js | 2+-
Mserver/maps.go | 3++-
Mserver/world_admin_test.go | 5+++--
4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/server/admin_pages.go b/server/admin_pages.go @@ -121,7 +121,7 @@ func (server *server) usersPage(w http.ResponseWriter, r *http.Request) { return } server.adminPageStart(w, "Players", "Players") - fmt.Fprint(w, "<h1>Players</h1><table><tr><th>ID</th><th>Name</th><th>Status</th><th>Last IP address</th><th>Zone</th></tr>") + fmt.Fprint(w, "<h1>Players</h1><table><tr><th>ID</th><th>Name</th><th>Title</th><th>Status</th><th>Last IP address</th><th>Zone</th></tr>") for _, player := range players { status := "Offline" address := "-" @@ -131,7 +131,7 @@ func (server *server) usersPage(w http.ResponseWriter, r *http.Request) { if player.Connected { status = "Connected" } - fmt.Fprintf(w, "<tr><td>%d</td><td><a href='admin/players/%d'>%s</a></td><td>%s</td><td>%s</td><td>%s (%d)</td></tr>", player.ID, player.ID, html.EscapeString(player.Name), status, html.EscapeString(address), html.EscapeString(gamedata.Playfields[player.Playfield].Name), player.Playfield) + fmt.Fprintf(w, "<tr><td>%d</td><td><a href='admin/players/%d'>%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s (%d)</td></tr>", player.ID, player.ID, html.EscapeString(player.Name), html.EscapeString(player.Title), status, html.EscapeString(address), html.EscapeString(gamedata.Playfields[player.Playfield].Name), player.Playfield) } fmt.Fprint(w, "</table></main></body></html>") } diff --git a/server/assets/map.js b/server/assets/map.js @@ -562,7 +562,7 @@ class AOMap { if (player.connected) ctx.fill(); ctx.stroke(); const atEntrance = player.entrance && this.view.value === "world" && !this.zones.get(player.playfield)?.origin; - const label = `${player.name}${player.connected ? "" : " (offline)"}${atEntrance ? ` [${player.zone} entrance]` : ""}`; + const label = `${player.title ? player.title + " " : ""}${player.name}${player.connected ? "" : " (offline)"}${atEntrance ? ` [${player.zone} entrance]` : ""}`; ctx.lineWidth = 3; ctx.strokeStyle = "#000"; ctx.strokeText(label, x + 10, y + 4); diff --git a/server/maps.go b/server/maps.go @@ -56,6 +56,7 @@ type mapEntrance struct { type mapPlayer struct { ID uint32 `json:"id"` Name string `json:"name"` + Title string `json:"title"` Playfield uint32 `json:"playfield"` Zone string `json:"zone"` Position [3]float32 `json:"position"` @@ -90,7 +91,7 @@ func (server *server) mapPlayerSnapshots() []mapPlayer { if user.npc { continue } - player := mapPlayer{ID: user.id, Name: user.name, Playfield: user.playfield, + player := mapPlayer{ID: user.id, Name: user.name, Title: user.title, Playfield: user.playfield, Zone: gamedata.Playfields[user.playfield].Name, Position: user.position, Rotation: user.rotation} if client := server.clients[user.id]; client != nil { player.Connected = client.ready diff --git a/server/world_admin_test.go b/server/world_admin_test.go @@ -10,6 +10,7 @@ import ( func TestRoutedAdminPlayerViewsFollowZoneOwners(t *testing.T) { fixture, _ := newTeamWorld(t) fixture.characters[2].playfield = 800 + fixture.characters[2].title = "Visitor" delete(fixture.clients, 2) if _, err := fixture.db.Exec("UPDATE players SET last_ip='192.0.2.9' WHERE id=2"); err != nil { t.Fatal(err) @@ -19,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(), "Member2</a></td><td>Offline</td><td>192.0.2.9</td>") { + 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>") { t.Fatal("remote player missing from list", page.Code, page.Body.String()) } online := adminRequest(handler, "GET", "/admin/map-players", "", nil) @@ -42,7 +43,7 @@ func TestRoutedAdminPlayerViewsFollowZoneOwners(t *testing.T) { if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil { t.Fatal(response.Code, err) } - if len(result.Players) != 8 || result.Players[1].ID != 2 || result.Players[1].Playfield != 705 || result.Players[1].Connected { + if len(result.Players) != 8 || result.Players[1].ID != 2 || result.Players[1].Title != "Visitor" || result.Players[1].Playfield != 705 || result.Players[1].Connected { t.Fatal("player snapshot lost its ordering, connection state or destination", result.Players) } }