database

package
v0.0.0-...-88cc3fa Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 7 Imported by: 2

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

View Source
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.

View Source
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

View Source
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

func FriendRequest(userIndex int, friendIndex int) error

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

func FriendRequestAccepted(userIndex int, friendIndex int) error

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

func GetFriends(userIndex int) (map[string]*Friend, error)

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

func GetUserDatabaseIndex(userName string) (int, error)

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 Pause

func Pause()

Pause is only for internal Gopher Game Server mechanics.

func RemoveAutoLog

func RemoveAutoLog(userID int, deviceTag string)

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

func RemoveFriend(userIndex int, friendIndex int) error

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 Resume

func Resume()

Resume is only for internal Gopher Game Server mechanics.

func SetCustomAccountInfoChangeRequirements

func SetCustomAccountInfoChangeRequirements(columnNames ...string) error

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

func SetCustomDeleteAccountRequirements(columnNames ...string) error

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

func SetCustomLoginRequirements(columnNames ...string) error

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

func SetCustomPasswordChangeRequirements(columnNames ...string) error

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

func SetCustomSignupRequirements(columnNames ...string) error

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

func NewFriend(name string, dbID int, status int) *Friend

NewFriend makes a new Friend from given parameters. Used for Gopher Game Server inner mechanics only.

func (*Friend) DatabaseID

func (f *Friend) DatabaseID() int

DatabaseID gets the database index of the Friend.

func (*Friend) Name

func (f *Friend) Name() string

Name gets the User name of the Friend.

func (*Friend) RequestStatus

func (f *Friend) RequestStatus() int

RequestStatus gets the request status of the Friend. Could be either friendStatusRequested or friendStatusAccepted (0 or 1).

func (*Friend) SetStatus

func (f *Friend) SetStatus(status int)

SetStatus sets the request status of a Friend.

WARNING: This is only meant for internal Gopher Game Server mechanics.

Jump to

Keyboard shortcuts

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