aboutsummaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/api0/api.go7
-rw-r--r--pkg/api/api0/client.go129
-rw-r--r--pkg/api/api0/metrics.go16
3 files changed, 7 insertions, 145 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go
index 355deef..2fc1347 100644
--- a/pkg/api/api0/api.go
+++ b/pkg/api/api0/api.go
@@ -27,7 +27,6 @@ import (
"github.com/klauspost/compress/gzip"
"github.com/pg9182/ip2x"
- "github.com/r2northstar/atlas/pkg/eax"
"github.com/r2northstar/atlas/pkg/metricsx"
"github.com/r2northstar/atlas/pkg/nspkt"
"github.com/rs/zerolog/hlog"
@@ -48,12 +47,6 @@ type Handler struct {
// NSPkt handles connectionless packets. It must be non-nil.
NSPkt *nspkt.Listener
- // UsernameSource configures the source to use for usernames.
- UsernameSource UsernameSource
-
- // EAXClient makes requests to the EAX API.
- EAXClient *eax.Client
-
// CleanBadWords is used to filter bad words from server names and
// descriptions. If not provided, words will not be filtered.
CleanBadWords func(s string) string
diff --git a/pkg/api/api0/client.go b/pkg/api/api0/client.go
index b718e17..1cb5cf3 100644
--- a/pkg/api/api0/client.go
+++ b/pkg/api/api0/client.go
@@ -12,34 +12,11 @@ import (
"time"
"github.com/r2northstar/atlas/pkg/api/api0/api0gameserver"
- "github.com/r2northstar/atlas/pkg/eax"
"github.com/r2northstar/atlas/pkg/pdata"
"github.com/r2northstar/atlas/pkg/stryder"
"github.com/rs/zerolog/hlog"
)
-// UsernameSource determines where to get player in-game usernames from.
-type UsernameSource string
-
-const (
- // Don't get usernames.
- UsernameSourceNone UsernameSource = ""
-
- // Get the username from EAX.
- UsernameSourceEAX UsernameSource = "eax"
-
- // Get the username from Stryder (available since October 2, 2023). Note
- // that this source only returns usernames for valid tokens.
- UsernameSourceStryder UsernameSource = "stryder"
-
- // Get the username from Stryder, but fall back to EAX on missing/failure.
- UsernameSourceStryderEAX UsernameSource = "stryder-eax"
-
- // Get the username from Stryder, but also check EAX and warn if it's
- // different.
- UsernameSourceStryderEAXDebug UsernameSource = "stryder-eax-debug"
-)
-
type MainMenuPromos struct {
NewInfo MainMenuPromosNew `json:"newInfo"`
LargeButton MainMenuPromosButtonLarge `json:"largeButton"`
@@ -214,14 +191,7 @@ func (h *Handler) handleClientOriginAuth(w http.ResponseWriter, r *http.Request)
}
}
}
-
- select {
- case <-r.Context().Done(): // check if the request was canceled to avoid making unnecessary requests
- return
- default:
- }
-
- username := h.lookupUsername(r, uid, stryderRes)
+ username, _ := h.lookupUsername(r, uid, stryderRes)
select {
case <-r.Context().Done(): // check if the request was canceled to avoid making unnecessary requests
@@ -298,99 +268,10 @@ func (h *Handler) handleClientOriginAuth(w http.ResponseWriter, r *http.Request)
})
}
-// lookupUsername gets the username for uid according to the configured
-// UsernameSource, returning an empty string if not found or on error.
-func (h *Handler) lookupUsername(r *http.Request, uid uint64, stryderRes []byte) (username string) {
- switch h.UsernameSource {
- case UsernameSourceNone:
- break
- case UsernameSourceEAX:
- username, _ = h.lookupUsernameEAX(r, uid)
- case UsernameSourceStryder:
- username, _ = h.lookupUsernameStryder(r, uid, stryderRes)
- case UsernameSourceStryderEAX:
- username, _ = h.lookupUsernameStryder(r, uid, stryderRes)
- if username == "" {
- if eaxUsername, ok := h.lookupUsernameEAX(r, uid); ok {
- username = eaxUsername
- hlog.FromRequest(r).Warn().
- Uint64("uid", uid).
- Str("eax_username", eaxUsername).
- Msgf("failed to get username from stryder, but got it from eax")
- }
- }
- case UsernameSourceStryderEAXDebug:
- username, _ = h.lookupUsernameStryder(r, uid, stryderRes)
- if eaxUsername, ok := h.lookupUsernameEAX(r, uid); ok {
- if eaxUsername != username {
- hlog.FromRequest(r).Warn().
- Uint64("uid", uid).
- Str("stryder_username", username).
- Str("eax_username", eaxUsername).
- Msgf("got username from stryder and eax, but they don't match; using the stryder one")
- }
- } else {
- hlog.FromRequest(r).Warn().
- Uint64("uid", uid).
- Str("stryder_username", username).
- Msgf("got username from stryder, but failed to get username from eax")
- }
- default:
- hlog.FromRequest(r).Error().
- Msgf("unknown username source %q", h.UsernameSource)
- }
- return
-}
-
-// lookupUsernameEAX gets the username for uid from the EAX API, returning an
-// empty string if a username does not exist for the uid, and false on error.
-func (h *Handler) lookupUsernameEAX(r *http.Request, uid uint64) (username string, ok bool) {
- select {
- case <-r.Context().Done(): // check if the request was canceled to avoid polluting the metrics
- return
- default:
- }
- if h.EAXClient == nil {
- hlog.FromRequest(r).Error().
- Str("username_source", "eax").
- Msgf("no eax client available for username lookup")
- return
- }
- eaxStart := time.Now()
- if p, err := h.EAXClient.PlayerIDByPD(r.Context(), uid); err == nil {
- if p != nil {
- username = p.DisplayName
- h.m().client_originauth_eax_username_lookup_calls_total.success.Inc()
- } else {
- hlog.FromRequest(r).Warn().
- Err(err).
- Uint64("uid", uid).
- Str("username_source", "eax").
- Msgf("no eax username found for uid")
- h.m().client_originauth_eax_username_lookup_calls_total.notfound.Inc()
- }
- ok = true
- } else if errors.Is(err, eax.ErrVersionRequired) || errors.Is(err, eax.ErrAutoUpdateBackoff) {
- hlog.FromRequest(r).Error().
- Err(err).
- Str("username_source", "eax").
- Msgf("eax update check failure")
- h.m().client_originauth_eax_username_lookup_calls_total.fail_update_check.Inc()
- } else if !errors.Is(err, context.Canceled) {
- hlog.FromRequest(r).Error().
- Err(err).
- Str("username_source", "eax").
- Msgf("failed to get eax player info")
- h.m().client_originauth_eax_username_lookup_calls_total.fail_other_error.Inc()
- }
- h.m().client_originauth_eax_username_lookup_duration_seconds.UpdateDuration(eaxStart)
- return
-}
-
-// lookupUsernameStryder gets the username for uid from the Stryder response,
-// returning an empty string if the username is empty, or false if the
-// username is not present in the response or the response is invalid.
-func (h *Handler) lookupUsernameStryder(r *http.Request, uid uint64, res []byte) (username string, ok bool) {
+// lookupUsername gets the username for uid from the Stryder response, returning
+// an empty string if the username is empty, or false if the username is not
+// present in the response or the response is invalid.
+func (h *Handler) lookupUsername(r *http.Request, uid uint64, res []byte) (username string, ok bool) {
select {
case <-r.Context().Done(): // check if the request was canceled to avoid polluting the metrics
return
diff --git a/pkg/api/api0/metrics.go b/pkg/api/api0/metrics.go
index 5c8c462..161c1da 100644
--- a/pkg/api/api0/metrics.go
+++ b/pkg/api/api0/metrics.go
@@ -70,15 +70,8 @@ type apiMetrics struct {
fail_other_error *metrics.Counter
http_method_not_allowed *metrics.Counter
}
- client_originauth_requests_map *metricsx.GeoCounter2
- client_originauth_stryder_auth_duration_seconds *metrics.Histogram
- client_originauth_eax_username_lookup_duration_seconds *metrics.Histogram
- client_originauth_eax_username_lookup_calls_total struct {
- success *metrics.Counter
- notfound *metrics.Counter
- fail_update_check *metrics.Counter
- fail_other_error *metrics.Counter
- }
+ client_originauth_requests_map *metricsx.GeoCounter2
+ client_originauth_stryder_auth_duration_seconds *metrics.Histogram
client_originauth_stryder_username_lookup_calls_total struct {
success *metrics.Counter
notfound *metrics.Counter
@@ -263,11 +256,6 @@ func (h *Handler) m() *apiMetrics {
mo.client_originauth_requests_total.http_method_not_allowed = mo.set.NewCounter(`atlas_api0_client_originauth_requests_total{result="http_method_not_allowed"}`)
mo.client_originauth_requests_map = metricsx.NewGeoCounter2(`atlas_api0_client_originauth_requests_map`)
mo.client_originauth_stryder_auth_duration_seconds = mo.set.NewHistogram(`atlas_api0_client_originauth_stryder_auth_duration_seconds`)
- mo.client_originauth_eax_username_lookup_duration_seconds = mo.set.NewHistogram(`atlas_api0_client_originauth_eax_username_lookup_duration_seconds`)
- mo.client_originauth_eax_username_lookup_calls_total.success = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="success"}`)
- mo.client_originauth_eax_username_lookup_calls_total.notfound = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="notfound"}`)
- mo.client_originauth_eax_username_lookup_calls_total.fail_update_check = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="fail_update_check"}`)
- mo.client_originauth_eax_username_lookup_calls_total.fail_other_error = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="fail_other_error"}`)
mo.client_originauth_stryder_username_lookup_calls_total.success = mo.set.NewCounter(`atlas_api0_client_originauth_stryder_username_lookup_calls_total{result="success"}`)
mo.client_originauth_stryder_username_lookup_calls_total.notfound = mo.set.NewCounter(`atlas_api0_client_originauth_stryder_username_lookup_calls_total{result="notfound"}`)
mo.client_originauth_stryder_username_lookup_calls_total.fail_other_error = mo.set.NewCounter(`atlas_api0_client_originauth_stryder_username_lookup_calls_total{result="fail_other_error"}`)