From f4fefa65ec1932056082d69d1bd827afbcb88174 Mon Sep 17 00:00:00 2001 From: pg9182 <96569817+pg9182@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:24:07 -0500 Subject: pkg/api/api0: Add region field to serverlist If empty, it is omitted from the server list JSON. --- pkg/api/api0/serverlist.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/api/api0/serverlist.go b/pkg/api/api0/serverlist.go index 710fbf9..170a684 100644 --- a/pkg/api/api0/serverlist.go +++ b/pkg/api/api0/serverlist.go @@ -80,6 +80,7 @@ type Server struct { LauncherVersion string // for metrics Name string + Region string Description string Password string // blank for none @@ -121,6 +122,7 @@ type ServerUpdate struct { Heartbeat bool Name *string + Region *string Description *string PlayerCount *int MaxPlayers *int @@ -278,7 +280,7 @@ func csJSON(ss []*Server, est int) ([]byte, int) { const ( estMin = 256 - estInit = 384 + estInit = 394 estMax = 512 ) switch { @@ -309,6 +311,10 @@ func csJSON(ss []*Server, est int) ([]byte, int) { b = append(b, srv.ID...) b = append(b, `","name":`...) b = appendJSONString(b, srv.Name) + if srv.Region != "" { + b = append(b, `,"region":`...) + b = appendJSONString(b, srv.Region) + } b = append(b, `,"description":`...) b = appendJSONString(b, srv.Description) b = append(b, `,"playerCount":`...) @@ -808,6 +814,9 @@ func (s *ServerList) ServerHybridUpdatePut(u *ServerUpdate, c *Server, l ServerL if u.Name != nil { esrv.Name, changed = *u.Name, true } + if u.Region != nil { + esrv.Region, changed = *u.Region, true + } if u.Description != nil { esrv.Description, changed = *u.Description, true } -- cgit v1.2.3