aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/api0')
-rw-r--r--pkg/api/api0/api.go3
-rw-r--r--pkg/api/api0/storage.go47
2 files changed, 49 insertions, 1 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go
index 984c9a2..8273435 100644
--- a/pkg/api/api0/api.go
+++ b/pkg/api/api0/api.go
@@ -21,6 +21,9 @@ import (
// Handler serves requests for the original master server API.
type Handler struct {
+ // AccountStorage stores accounts. It must be non-nil.
+ AccountStorage AccountStorage
+
// PdataStorage stores player data. It must be non-nil.
PdataStorage PdataStorage
diff --git a/pkg/api/api0/storage.go b/pkg/api/api0/storage.go
index a17e8da..fdf411b 100644
--- a/pkg/api/api0/storage.go
+++ b/pkg/api/api0/storage.go
@@ -1,6 +1,51 @@
package api0
-import "crypto/sha256"
+import (
+ "crypto/sha256"
+ "net/netip"
+ "time"
+)
+
+// Account contains information about a registered account.
+type Account struct {
+ // UID is the player's Origin UID.
+ UID uint64 // required, unique
+
+ // Username is the player's last known in-game username (their EAID).
+ Username string // optional (but will usually be there)
+
+ // AuthIP is the IP used for the current auth session.
+ AuthIP netip.Addr
+
+ // AuthToken is the random token generated for the current auth session.
+ AuthToken string
+
+ // AuthTokenExpiry is the expiry date of the current auth token.
+ AuthTokenExpiry time.Time
+
+ // LastServerID is the ID of the last server the account connected to.
+ LastServerID string
+}
+
+func (a Account) IsOnOwnServer() bool {
+ return a.LastServerID == "self"
+}
+
+// AccountStorage stores information about registered users. It must be safe
+// for concurrent use.
+type AccountStorage interface {
+ // GetUIDsByUsername gets all known UIDs matching username. If none match, a
+ // nil/zero-length slice is returned. If another error occurs, err is
+ // non-nil.
+ GetUIDsByUsername(username string) ([]uint64, error)
+
+ // GetAccount gets the player matching uid. If none exists, nil is returned.
+ // If another error occurs, err is non-nil.
+ GetAccount(uid uint64) (*Account, error)
+
+ // SaveAccount creates or replaces an account by its uid.
+ SaveAccount(a *Account) error
+}
// PdataStorage stores player data for users. It should not make any assumptions
// on the contents of the stored blobs (including validity). It may compress the