diff options
Diffstat (limited to 'pkg/api/api0/storage.go')
-rw-r--r-- | pkg/api/api0/storage.go | 47 |
1 files changed, 46 insertions, 1 deletions
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 |