diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2022-10-13 12:06:01 -0400 |
---|---|---|
committer | pg9182 <96569817+pg9182@users.noreply.github.com> | 2022-10-13 12:06:01 -0400 |
commit | 6c160b6aa6a4127ba151f8ea2f4f314d9758d5db (patch) | |
tree | dcc196f32dd29eb9747a346095d33a000e234937 /pkg | |
parent | f2ca8dfe327f87672f0f82ac9318c5bf7d2243a0 (diff) | |
download | Atlas-6c160b6aa6a4127ba151f8ea2f4f314d9758d5db.tar.gz Atlas-6c160b6aa6a4127ba151f8ea2f4f314d9758d5db.zip |
pkg/api/api0: Add AccountStorage interface
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/api0/api.go | 3 | ||||
-rw-r--r-- | pkg/api/api0/storage.go | 47 |
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 |