aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0/api0gameserver
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2023-03-06 00:16:04 -0500
committerpg9182 <96569817+pg9182@users.noreply.github.com>2023-03-07 20:04:20 -0500
commita3109ce30f0de2fec0f5f130761939233cbeee77 (patch)
treead3a3d794fa3429f2eb9a3bfedfb3113a0677e66 /pkg/api/api0/api0gameserver
parent18f4f61f0af62edd095da7b87533972e3f2b35fa (diff)
downloadAtlas-a3109ce30f0de2fec0f5f130761939233cbeee77.tar.gz
Atlas-a3109ce30f0de2fec0f5f130761939233cbeee77.zip
pkg/api/api0: Allow game servers to reject connections with a reason
This is backwards-compatible with old clients, since it implements it as a new error type.
Diffstat (limited to 'pkg/api/api0/api0gameserver')
-rw-r--r--pkg/api/api0/api0gameserver/nsserver.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/pkg/api/api0/api0gameserver/nsserver.go b/pkg/api/api0/api0gameserver/nsserver.go
index 5897a9c..38fa0ba 100644
--- a/pkg/api/api0/api0gameserver/nsserver.go
+++ b/pkg/api/api0/api0gameserver/nsserver.go
@@ -19,6 +19,22 @@ var (
ErrAuthFailed = errors.New("authentication failed")
)
+type ConnectionRejectedError string
+
+func (c ConnectionRejectedError) Reason() string {
+ if c == "" {
+ return "unknown"
+ }
+ return string(c)
+}
+
+func (c ConnectionRejectedError) Error() string {
+ if c == "" {
+ return "connection rejected"
+ }
+ return "connection rejected: " + string(c)
+}
+
// VerifyText is the expected server response for /verify.
const VerifyText = "I am a northstar server!"
@@ -72,11 +88,15 @@ func AuthenticateIncomingPlayer(ctx context.Context, auth netip.AddrPort, uid ui
defer resp.Body.Close()
var obj struct {
- Success bool `json:"success"`
+ Success bool `json:"success"`
+ Reject string `json:"reject"`
}
if err := json.NewDecoder(resp.Body).Decode(&obj); err != nil {
return ErrInvalidResponse
}
+ if obj.Reject != "" {
+ return ConnectionRejectedError(obj.Reject)
+ }
if !obj.Success {
return ErrAuthFailed
}