1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package api0
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
// stored data. It must be safe for concurrent use.
type PdataStorage interface {
// GetPdataHash gets the current pdata hash for uid. If there is not any
// pdata for uid, exists is false. If another error occurs, err is non-nil.
GetPdataHash(uid uint64) (hash [sha256.Size]byte, exists bool, err error)
// GetPdataCached gets the pdata for uid. If there is not any pdata for uid,
// exists is false. If the provided hash is nonzero and the current pdata
// matches, buf is nil. If another error occurs, err is non-nil.
GetPdataCached(uid uint64, sha [sha256.Size]byte) (buf []byte, exists bool, err error)
// SetPdata sets the raw pdata for uid.
SetPdata(uid uint64, buf []byte) (err error)
}
|