diff options
-rw-r--r-- | pkg/api/api0/api.go | 19 | ||||
-rw-r--r-- | pkg/api/api0/server.go | 4 | ||||
-rw-r--r-- | pkg/api/api0/serverlist.go | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go index 10729e1..51d3c18 100644 --- a/pkg/api/api0/api.go +++ b/pkg/api/api0/api.go @@ -148,6 +148,25 @@ func (h *Handler) checkLauncherVersion(r *http.Request) bool { return semver.Compare(rver, mver) >= 0 } +// extractLauncherVersion extracts the launcher version from r, returning an +// empty string if it's missing or invalid. +func (h *Handler) extractLauncherVersion(r *http.Request) string { + rver, _, _ := strings.Cut(r.Header.Get("User-Agent"), " ") + if x := strings.TrimPrefix(rver, "R2Northstar/"); rver != x { + if len(x) > 0 && x[0] != 'v' { + rver = "v" + x + } else { + rver = x + } + } else { + rver = "" + } + if rver != "" && semver.IsValid(rver) { + return rver[1:] + } + return "" +} + // respFail writes a {success:false,error:ErrorObj} response with the provided // response status. func respFail(w http.ResponseWriter, r *http.Request, status int, obj ErrorObj) { diff --git a/pkg/api/api0/server.go b/pkg/api/api0/server.go index 756c48b..68c94c9 100644 --- a/pkg/api/api0/server.go +++ b/pkg/api/api0/server.go @@ -85,7 +85,9 @@ func (h *Handler) handleServerUpsert(w http.ResponseWriter, r *http.Request) { var s *Server if canCreate { - s = &Server{} + s = &Server{ + LauncherVersion: h.extractLauncherVersion(r), + } } var u *ServerUpdate diff --git a/pkg/api/api0/serverlist.go b/pkg/api/api0/serverlist.go index 04ee79b..35be9f6 100644 --- a/pkg/api/api0/serverlist.go +++ b/pkg/api/api0/serverlist.go @@ -53,6 +53,8 @@ type Server struct { Addr netip.AddrPort // unique, must not be modified after creation AuthPort uint16 // unique with Addr.Addr(), must not be modified after creation + LauncherVersion string // for metrics + Name string Description string Password string // blank for none |