Documentation
¶
Overview ¶
Package database contains helpers for customizing your database with the SQL features enabled. It mostly contains a bunch of mixed Gopher Server only functions and customizing methods. It would probably be easier to take a look at the database usage section on the Github page for the project before looking through here for more info.
Index ¶
- Constants
- Variables
- func AutoLoginClient(tag string, pass string, newPass string, dbID int) (string, helpers.GopherError)
- func ChangeAccountInfo(userName string, password string, customCols map[string]interface{}) helpers.GopherError
- func ChangePassword(userName string, password string, newPassword string, ...) helpers.GopherError
- func DeleteAccount(userName string, password string, customCols map[string]interface{}) helpers.GopherError
- func FriendRequest(userIndex int, friendIndex int) error
- func FriendRequestAccepted(userIndex int, friendIndex int) error
- func GetFriends(userIndex int) (map[string]*Friend, error)
- func GetUserDatabaseIndex(userName string) (int, error)
- func Init(userName string, password string, dbName string, protocol string, ip string, ...) error
- func LoginClient(userName string, password string, deviceTag string, remMe bool, ...) (string, int, string, helpers.GopherError)
- func NewAccountInfoColumn(name string, dataType int, maxSize int, precision int, notNull bool, ...) error
- func Pause()
- func RemoveAutoLog(userID int, deviceTag string)
- func RemoveFriend(userIndex int, friendIndex int) error
- func Resume()
- func SetCustomAccountInfoChangeRequirements(columnNames ...string) error
- func SetCustomDeleteAccountRequirements(columnNames ...string) error
- func SetCustomLoginRequirements(columnNames ...string) error
- func SetCustomPasswordChangeRequirements(columnNames ...string) error
- func SetCustomSignupRequirements(columnNames ...string) error
- func SetServerStarted(val bool)
- func SignUpClient(userName string, password string, customCols map[string]interface{}) helpers.GopherError
- type AccountInfoColumn
- type Friend
Constants ¶
const ( //NUMERIC TYPES DataTypeTinyInt = iota // TINYINT() DataTypeSmallInt // SMALLINT() DataTypeMediumInt // MEDIUMINT() DataTypeInt // INTEGER() DataTypeFloat // FLOAT()() DataTypeDouble // DOUBLE()() DataTypeDecimal // DECIMAL()() DataTypeBigInt // BIGINT() //CHARACTER TYPES DataTypeChar // CHAR() DataTypeVarChar // VARCHAR() DataTypeNationalVarChar // NVARCHAR() DataTypeJSON // JSON //TEXT TYPES DataTypeTinyText // TINYTEXT DataTypeMediumText // MEDIUMTEXT DataTypeText // TEXT() DataTypeLongText // LONGTEXT //DATE TYPES DataTypeDate // DATE DataTypeDateTime // DATETIME() DataTypeTime // TIME() DataTypeTimeStamp // TIMESTAMP() DataTypeYear // YEAR() //BINARY TYPES DataTypeTinyBlob // TINYBLOB DataTypeMediumBlob // MEDIUMBLOB DataTypeBlob // BLOB() DataTypeLongBlob // LONGBLOB DataTypeBinary // BINARY() DataTypeVarBinary // VARBINARY() //OTHER TYPES DataTypeBit // BIT() DataTypeENUM // ENUM() DataTypeSet // SET() )
MySQL database data types. Use one of these when making a new AccountInfoColumn or CustomTable's columns. The parentheses next to a type indicate it requires a maximum size when making a column of that type. Two pairs of parentheses means it requires a decimal precision number as well a max size.
const ( FriendStatusRequested = iota FriendStatusPending FriendStatusAccepted )
The three statuses a Friend could be: requested, pending, or accepted (0, 1, and 2). If a User has a Friend with the status FriendStatusRequested, they need to accept the request. If a User has a Friend with the status FriendStatusPending, that friend has not yet accepted their request. If a User has a Friend with the status FriendStatusAccepted, that friend is indeed a friend.
Variables ¶
var ( // SignUpCallback is only for internal Gopher Game Server mechanics. SignUpCallback func(string, map[string]interface{}) bool // LoginCallback is only for internal Gopher Game Server mechanics. LoginCallback func(string, int, map[string]interface{}, map[string]interface{}) bool // DeleteAccountCallback is only for internal Gopher Game Server mechanics. DeleteAccountCallback func(string, int, map[string]interface{}, map[string]interface{}) bool // AccountInfoChangeCallback is only for internal Gopher Game Server mechanics. AccountInfoChangeCallback func(string, int, map[string]interface{}, map[string]interface{}) bool // PasswordChangeCallback is only for internal Gopher Game Server mechanics. PasswordChangeCallback func(string, int, map[string]interface{}, map[string]interface{}) bool )
Functions ¶
func AutoLoginClient ¶
func AutoLoginClient(tag string, pass string, newPass string, dbID int) (string, helpers.GopherError)
AutoLoginClient logs in the client automatically with the client API when the SQL features and RememberMe enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to automatically log in a client when using the "Remember Me" SQL feature.
func ChangeAccountInfo ¶
func ChangeAccountInfo(userName string, password string, customCols map[string]interface{}) helpers.GopherError
ChangeAccountInfo changes a client's AccountInfoColumn with the SQL features enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to change a user's AccountInfoColumn when using the SQL features.
func ChangePassword ¶
func ChangePassword(userName string, password string, newPassword string, customCols map[string]interface{}) helpers.GopherError
ChangePassword changes a client's password with the SQL features enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to change a user's password when using the SQL features.
func DeleteAccount ¶
func DeleteAccount(userName string, password string, customCols map[string]interface{}) helpers.GopherError
DeleteAccount deletes a client's account with the SQL features enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to delete a user's account when using the SQL features.
func FriendRequest ¶
FriendRequest stores the data for a friend request onto the database.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to send a friend request when using the SQL features.
func FriendRequestAccepted ¶
FriendRequestAccepted stores the data for a friend accept onto the database.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to accept a friend request when using the SQL features.
func GetFriends ¶
GetFriends gets a User's frinds list from the database.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the *User.Friends() function instead to avoid errors when using the SQL features.
func GetUserDatabaseIndex ¶
GetUserDatabaseIndex gets the database index of a User by their name.
func Init ¶
func Init(userName string, password string, dbName string, protocol string, ip string, port int, encryptCost int, remMe bool, custLoginCol string) error
Init initializes the database connection and sets up the database according to your custom parameters.
WARNING: This is only meant for internal Gopher Game Server mechanics. If you want to enable SQL authorization and friending, use the EnableSqlFeatures and corresponding options in ServerSetting.
func LoginClient ¶
func LoginClient(userName string, password string, deviceTag string, remMe bool, customCols map[string]interface{}) (string, int, string, helpers.GopherError)
LoginClient logs in the client from the client API with the SQL features enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to log in a client when using the SQL features.
func NewAccountInfoColumn ¶
func NewAccountInfoColumn(name string, dataType int, maxSize int, precision int, notNull bool, unique bool, encrypt bool) error
NewAccountInfoColumn makes a new AccountInfoColumn. You can only make new AccountInfoColumns before starting the server.
func RemoveAutoLog ¶
RemoveAutoLog removes an auto-log entry when the client API logs out with the SQL features and RememberMe enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Auto-login entries in the database are automatically deleted when a User logs off, or are thought to be compromised by the server.
func RemoveFriend ¶
RemoveFriend removes the data for a friendship from database.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to remove a friend when using the SQL features.
func SetCustomAccountInfoChangeRequirements ¶
SetCustomAccountInfoChangeRequirements sets the required AccountInfoColumn names for processing an AccountInfoColumn change request from a client. If a client doesn't send the required info, an error will be sent back.
func SetCustomDeleteAccountRequirements ¶
SetCustomDeleteAccountRequirements sets the required AccountInfoColumn names for processing a delete account request from a client. If a client doesn't send the required info, an error will be sent back.
func SetCustomLoginRequirements ¶
SetCustomLoginRequirements sets the required AccountInfoColumn names for processing a login request from a client. If a client doesn't send the required info, an error will be sent back.
func SetCustomPasswordChangeRequirements ¶
SetCustomPasswordChangeRequirements sets the required AccountInfoColumn names for processing a password change request from a client. If a client doesn't send the required info, an error will be sent back.
func SetCustomSignupRequirements ¶
SetCustomSignupRequirements sets the required AccountInfoColumn names for processing a sign up request from a client. If a client doesn't send the required info, an error will be sent back.
func SetServerStarted ¶
func SetServerStarted(val bool)
SetServerStarted is for Gopher Game Server internal mechanics only.
func SignUpClient ¶
func SignUpClient(userName string, password string, customCols map[string]interface{}) helpers.GopherError
SignUpClient signs up the client from the client API with the SQL features enabled.
WARNING: This is only meant for internal Gopher Game Server mechanics. Use the client APIs to sign a client up when using the SQL features.
Types ¶
type AccountInfoColumn ¶
type AccountInfoColumn struct {
// contains filtered or unexported fields
}
AccountInfoColumn is the representation of an extra column on the users table that you can define. You can define as many as you want. These work with the ServerCallbacks and client APIs to provide you with information on data retrieved from the database when the corresponding callback is triggered.
You can make an AccountInfoColumn unique, which means when someone tries to update or insert into a unique column, the server will first check if any other row has that same value in that unique column. If a unique column cannot be updated because another row has the same value, an error will be sent back to the client. Keep in mind, this is an expensive task and should be used lightly, mainly for extra authentication.
type Friend ¶
type Friend struct {
// contains filtered or unexported fields
}
Friend represents a client's friend. A friend has a User name, a database index reference, and a status. Their status could be FriendStatusRequested, FriendStatusPending, or FriendStatusAccepted (0, 1, or 2). If a User has a Friend with the status FriendStatusRequested, they need to accept the request. If a User has a Friend with the status FriendStatusPending, that friend has not yet accepted their request. If a User has a Friend with the status FriendStatusAccepted, that friend is indeed a friend.
func NewFriend ¶
NewFriend makes a new Friend from given parameters. Used for Gopher Game Server inner mechanics only.
func (*Friend) DatabaseID ¶
DatabaseID gets the database index of the Friend.
func (*Friend) RequestStatus ¶
RequestStatus gets the request status of the Friend. Could be either friendStatusRequested or friendStatusAccepted (0 or 1).