user

package
v0.0.0-...-1af4f67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IController

type IController interface {
	Event(*MailBox, *Error)
}

IController contains methods for IUserManager callbacks

type IDbManager

type IDbManager interface {
	AddUser(name, email, hash, salt, promocode string) *Error
	GetUserByID(userID uint64) (*User, *Error)
	GetUserByName(name string) (*User, *Error)
	GetUserByNumber(number uint) (*User, *Error)
	GetAllAbilities() ([]byte, *Error)
	RegisterWin(ratingType byte, userID uint64, scoreDiff byte) *Error
	RegisterLoss(ratingType byte, userID uint64, scoreDiff byte) *Error
	RewardUser(userID uint64, gems, trustPoints uint32) *Error
	ConsumeTrustPoints(userID uint64, trustPoints uint32) *Error
	ChangeUser(userID uint64, email, hash string, character byte) *Error
	SetLastEnemy(userID, enemyID uint64) *Error
	SetAgentInfo(userID uint64, agentInfo string) *Error
	GetAbilities(userID uint64) ([]byte, []time.Time, *Error)
	BuyProduct(userID uint64, code, days byte) (cost uint32, error *Error)
	GetWins(userID uint64) (uint32, *Error) // not used since 1.3.8
	GetRating(userID uint64, ratingType, limit byte) ([]byte, *Error)
	GetBestUsers(ratingType, limit byte) (ids []uint64, error *Error)
	ClearRating(ratingType byte) *Error
	GetUserFriends(userID uint64) ([]byte, []string, *Error)
	AddFriend(userID uint64, name string) (character byte, err *Error)
	RemoveFriend(userID uint64, name string) *Error
	ActivatePromocode(userID, inviterID uint64) *Error
	DeactivatePromocode(userID, inviterID uint64) *Error
	PromocodeExists(userID uint64) (inviterID uint64, exists bool, err *Error)
	DeleteExpiredAbilities() (removedIds []uint64, error *Error)
	AddPayment(userID uint64, orderID, sku string, timestampMsec int64, data string, state uint8) *Error
	SetPaymentChecked(orderID string) *Error
	SetPaymentResult(orderID string, gems uint32) *Error
	Close() *Error
}

IDbManager is an interface to interact with a Database

type IPacker

type IPacker interface {
	PackUserInfo(info []byte) []byte
	PackPromocodeDone(inviter bool, name string, gems uint32) []byte
}

IPacker interface comprises of methods for converting some events into a bytearray

type IUserManager

type IUserManager interface {
	SetController(controller IController)
	SignUp(name, email, password, agentInfo, promocode string) (*User, *Error)
	SignIn(name, password, agentInfo string) (*User, *Error, Sid)
	SignOut(user *User)
	GetUserByName(name string) (*User, bool) // go has no overloaded functions
	GetUserByID(id uint64) (*User, bool)
	GetUserBySid(sid Sid) (*User, bool)
	GetUserInfo(user *User) ([]byte, *Error)
	GetUserFriends(user *User) ([]byte, []string, *Error)
	AddFriend(user *User, name string) (character byte, err *Error)
	RemoveFriend(user *User, name string) *Error
	Accept(user1, user2 *User) *Error
	GetUserAbilities(user *User) ([]byte, *Error)
	RewardUsers(winnerSid, loserSid Sid, score1, score2 byte, trust bool, box *MailBox) (reward uint32, err *Error)
	ChangeCharacter(user *User, character byte) *Error
	ChangePassword(user *User, oldPassword, newPassword string) *Error
	GetAllAbilities() ([]byte, *Error)
	BuyProduct(user *User, code, days byte) *Error
	GetWins(user *User) (uint32, *Error) // not used since 1.3.8
	GetRating(user *User, ratingType byte) ([]byte, *Error)
	IsPromocodeValid(promocode string) (inviter *User, ok bool, err *Error)
	GetUsersCount() uint
	GetUsersCountTotal() uint
	GetUserNumberN(n uint) (*User, *Error)
	GetSkuGems() map[string]uint32
	CheckPayment(user *User, jsonStr, signature string) (gems uint32, box *MailBox, err *Error)
	Close()
}

IUserManager is an interface for all user management operations

func NewUserManager

func NewUserManager(sidManager *TSidManager, checker *checker.SignatureChecker, dbManager IDbManager,
	packer IPacker, controller IController, localArg string, skuGems map[string]uint32,
	ratingRewards map[int]uint32, promoReward uint32) IUserManager

NewUserManager creates a new instance of UsrManager and returns a reference to IUserManager interface. Please do not create a UsrManager directly. "sidManager" - reference to a TSidManager "checker" - reference to a SignatureChecker "dbManager" - reference to a IDbManager "packer" - reference to a IPacker "controller" - reference to a IController "localArg" - random host-specific string for generating password hashes "skuGems" - map [SKU -> price], e.g. "Map('gems_pack' -> 50)" means that gems_pack costs 50 gems "ratingRewards" - map [rating -> reward], e.g. "Map('rating.gold' -> 150)" means that a gold user will gain 150 gems "promoReward" - std reward for activating promo code (in gems)

type User

type User struct {
	sync.RWMutex
	Character   byte
	Sid         sid.Sid
	Gems        uint32
	TrustPoints uint32
	Name        string
	Email       string
	AuthType    string // ENUM: 'Local'
	AuthData    string
	Salt        string
	Promocode   string
	AgentInfo   string
	ID          uint64
	LastEnemy   uint64
	LastLogin   time.Time
	LastActive  time.Time
}

User is a struct for a 'user' DB row

type UsrManager

type UsrManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

UsrManager is an implementation of IUserManager. Both interface and implementation were placed in the same src intentionally! This component is independent.

func (*UsrManager) Accept

func (usrMgr *UsrManager) Accept(user1, user2 *User) *Error

Accept registers a new battle of given users. For this specific method the order of them doesn't matter. Note that this action affects DB as well.

func (*UsrManager) AddFriend

func (usrMgr *UsrManager) AddFriend(user *User, name string) (character byte, err *Error)

AddFriend adds a new friend for a given user. Note that this action affects DB as well.

func (*UsrManager) BuyProduct

func (usrMgr *UsrManager) BuyProduct(user *User, code, days byte) *Error

BuyProduct initiates purchasing a product (e.g. "Snorkel" for 3 days) for a given user "user" - user "code" - product code "days" - product duration (please note that it is not arbitrary value, the "days" must be present in DB)

func (*UsrManager) ChangeCharacter

func (usrMgr *UsrManager) ChangeCharacter(user *User, character byte) *Error

ChangeCharacter alters the "character" of a given user. Note that this action affects DB as well.

func (*UsrManager) ChangePassword

func (usrMgr *UsrManager) ChangePassword(user *User, oldPassword, newPassword string) *Error

ChangePassword replaces a user's old password with a new one. Note that this action affects DB as well. "user" - user "oldPassword" - old password (NOT hash) "newPassword" - new password (NOT hash)

func (*UsrManager) CheckPayment

func (usrMgr *UsrManager) CheckPayment(user *User, jsonStr, signature string) (gems uint32, box *MailBox, err *Error)

CheckPayment verifies payment of a given user, by checking the signature of "jsonStr". "user" - user "jsonStr" - JSON that contains details about the purchase order "signature" - String containing the signature of the purchase data that was signed with the private key of the developer. The data signature uses the RSASSA-PKCS1-v1_5 scheme

func (*UsrManager) Close

func (usrMgr *UsrManager) Close()

Close shuts IUserManager down and releases all seized resources

func (*UsrManager) GetAllAbilities

func (usrMgr *UsrManager) GetAllAbilities() ([]byte, *Error)

GetAllAbilities returns a full list of abilities, present in DB

func (*UsrManager) GetRating

func (usrMgr *UsrManager) GetRating(user *User, ratingType byte) ([]byte, *Error)

GetRating returns "Top N" ranking by "ratingType" for a given user. "ratingType" - rating type (ratingGeneral, ratingWeekly) The format of a single ranking row is the following (all numbers are big-endian): - name (null-terminated string) - wins (4 bytes) - losses (4 bytes) - score difference (4 bytes)

func (*UsrManager) GetSkuGems

func (usrMgr *UsrManager) GetSkuGems() map[string]uint32

GetSkuGems returns a map of all available SKUs -> price in gems, e.g. ("gems_pack" -> 50)

func (*UsrManager) GetUserAbilities

func (usrMgr *UsrManager) GetUserAbilities(user *User) ([]byte, *Error)

GetUserAbilities returns the abilities (list of IDs) of a given user.

func (*UsrManager) GetUserByID

func (usrMgr *UsrManager) GetUserByID(id uint64) (user *User, ok bool)

GetUserByID returns a user by ID (DB primary key)

func (*UsrManager) GetUserByName

func (usrMgr *UsrManager) GetUserByName(name string) (user *User, ok bool)

GetUserByName returns a user by name

func (*UsrManager) GetUserBySid

func (usrMgr *UsrManager) GetUserBySid(sid Sid) (user *User, ok bool)

GetUserBySid returns a user by Session ID

func (*UsrManager) GetUserFriends

func (usrMgr *UsrManager) GetUserFriends(user *User) ([]byte, []string, *Error)

GetUserFriends returns the friend list (list of characters and list of names) of a given user. It is guaranteed that sizes of returned lists are equal

func (*UsrManager) GetUserInfo

func (usrMgr *UsrManager) GetUserInfo(user *User) ([]byte, *Error)

GetUserInfo returns info about a given user, expressed as a bytearray. The format is the following (all numbers are big-endian): - name (null-terminated string) - promo code (null-terminated string) - character (1 byte) - gems count (4 bytes) - abilities count (1 byte) - list of abilities, 3 bytes each (1 byte for ID and 2 bytes for time left for ability)

func (*UsrManager) GetUserNumberN

func (usrMgr *UsrManager) GetUserNumberN(n uint) (*User, *Error)

GetUserNumberN returns a user by a given sequence number in DB

func (*UsrManager) GetUsersCount

func (usrMgr *UsrManager) GetUsersCount() uint

GetUsersCount returns current count of users, stored in an internal collection

func (*UsrManager) GetUsersCountTotal

func (usrMgr *UsrManager) GetUsersCountTotal() uint

GetUsersCountTotal returns total count of users for the whole Server lifetime

func (*UsrManager) GetWins

func (usrMgr *UsrManager) GetWins(user *User) (uint32, *Error)

GetWins returns total count of wins for a given user from DB @deprecated: not used since 1.3.8

func (*UsrManager) IsPromocodeValid

func (usrMgr *UsrManager) IsPromocodeValid(promocode string) (inviter *User, ok bool, err *Error)

IsPromocodeValid checks if a given "promocode" is valid. Aside from boolean value (valid/invalid), also returns the inviter User

func (*UsrManager) RemoveFriend

func (usrMgr *UsrManager) RemoveFriend(user *User, name string) *Error

RemoveFriend removes a friend (by a given name) for a given user. Note that this action affects DB as well.

func (*UsrManager) RewardUsers

func (usrMgr *UsrManager) RewardUsers(winnerSid, loserSid Sid, score1, score2 byte, trust bool,
	box *MailBox) (reward uint32, err *Error)

RewardUsers registers the end of the battle in DB, rewards the winner with some gems, adds trust points if necessary, rolls forward promo code bonuses if necessary, etc. Note that this action affects DB. "winnerSid" - Session ID of the winner "loserSid" - Session ID of the loser "score1" - score of user 1 (doesn't matter winner or loser) "score2" - score of user 2 (doesn't matter winner or loser) "trust" - trusted battle (by default Quick Battle is considered as 'trusted', and AI-mode is not) "box" - mail box nolint: gocyclo

func (*UsrManager) SetController

func (usrMgr *UsrManager) SetController(controller IController)

SetController assigns a non-NULL IController for this IUserManager

func (*UsrManager) SignIn

func (usrMgr *UsrManager) SignIn(name, password, agentInfo string) (user *User, err *Error, oldSid Sid)

SignIn is a method to log in an existing user. "name" - user name "password" - user's password (NOT hash!) "agentInfo" - agent info (language, client version, OS, Android version, etc.)

func (*UsrManager) SignOut

func (usrMgr *UsrManager) SignOut(user *User)

SignOut is a method to log out a given user. This method is preferred, because it removes the user from internal collections and releases memory. Anyway if a client just silently disconnects without sighing out, then a user will be forcefully kicked out in several minutes by external mechanisms.

func (*UsrManager) SignUp

func (usrMgr *UsrManager) SignUp(name, email, password, agentInfo, promocode string) (user *User, err *Error)

SignUp is a method to sign up a new user. important: all string lengths (name, email, etc.) are controlled by DBMS, so we don't need to check them manually early on, there were the following limits: name - 32 chars, other fields - 64 chars. "name" - user name "email" - user's e-mail "password" - user's password (NOT hash!) "agentInfo" - agent info (language, client version, OS, Android version, etc.) "promocode" - user's promo code

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL