...

Package user

import "github.com/Diarkis/diarkis/user"
Overview
Index

Overview ▾

Index ▾

Constants
func CopyUser(user *User) map[string]interface{}
func DecodeUserCopy(b []byte) map[string]interface{}
func DecodeUserData(encoded string) (map[string]interface{}, error)
func DiscardUser(reliableClientAddr string, sid string)
func EncodeUserCopy(user *User) []byte
func EncodeUserData(user *User) (string, error)
func ExistsByID(sid string) bool
func GetAllUserIDs() []string
func GetCCU() int
func New(data map[string]interface{}, initTTL int64) (map[string]interface{}, error)
func OnClientAddressChange(callback func(userData *User))
func OnDiscard(callback func(sid string, userData *User))
func OnNew(callback func(userData *User))
func OnNewConnection(callback func(userData *User))
func OnSIDUpdate(callback func(previousSID string, newSID string, previousUserData *User, newUserData *User))
func RemoveOnNewConnection(callback func(userData *User))
func SetTCPState(sid string, state *tcp.State)
func SetUDPStateAndRUDPConn(sid string, state *udp.State)
func SetUserByID(sid string, user *User, ttl int64) bool
func Setup(ttl int64)
func SetupAsConnector(ttl int64)
func SetupAsTCPServer()
func SetupAsUDPServer()
func UpdateUserByID(sid string) bool
type User
    func CreateBlankUser(sid, uid string) *User
    func CreateNewUser(data map[string]interface{}, initTTL int64) (*User, int64, error)
    func GetUserByID(sid string) *User
    func GetUserBySID(sid string) *User
    func GetUserByUID(uid string) *User
    func (user *User) Delete(key string) bool
    func (user *User) Disconnect()
    func (user *User) Get(key string) interface{}
    func (u *User) GetAsBool(k string) (bool, bool)
    func (u *User) GetAsBoolArray(k string) ([]bool, bool)
    func (u *User) GetAsBytes(k string) ([]byte, bool)
    func (u *User) GetAsFloat32(k string) (float32, bool)
    func (u *User) GetAsFloat64(k string) (float64, bool)
    func (u *User) GetAsFloat64Array(k string) ([]float64, bool)
    func (u *User) GetAsInt(k string) (int, bool)
    func (u *User) GetAsInt16(k string) (int16, bool)
    func (u *User) GetAsInt16Array(k string) ([]int16, bool)
    func (u *User) GetAsInt32(k string) (int32, bool)
    func (u *User) GetAsInt32Array(k string) ([]int32, bool)
    func (u *User) GetAsInt64(k string) (int64, bool)
    func (u *User) GetAsInt64Array(k string) ([]int64, bool)
    func (u *User) GetAsInt8(k string) (int8, bool)
    func (u *User) GetAsInt8Array(k string) ([]int8, bool)
    func (u *User) GetAsIntArray(k string) ([]int, bool)
    func (u *User) GetAsString(k string) (string, bool)
    func (u *User) GetAsStringArray(k string) ([]string, bool)
    func (u *User) GetAsUint(k string) (uint, bool)
    func (u *User) GetAsUint16(k string) (uint16, bool)
    func (u *User) GetAsUint16Array(k string) ([]uint16, bool)
    func (u *User) GetAsUint32(k string) (uint32, bool)
    func (u *User) GetAsUint32Array(k string) ([]uint32, bool)
    func (u *User) GetAsUint64(k string) (uint64, bool)
    func (u *User) GetAsUint64Array(k string) ([]uint64, bool)
    func (u *User) GetAsUint8(k string) (uint8, bool)
    func (u *User) GetAsUint8Array(k string) ([]uint8, bool)
    func (user *User) GetClientAddr() string
    func (user *User) GetClientKey() string
    func (user *User) GetClientTransport() int
    func (user *User) GetLatency() int64
    func (user *User) IsTCP() bool
    func (user *User) IsUDP() bool
    func (user *User) OnClientAddressChange(callback func())
    func (user *User) OnNewConnection(callback func())
    func (user *User) Push(message []byte, reliable bool)
    func (user *User) RemoveOnNewConnection()
    func (user *User) Respond(message []byte, status uint8, reliable bool)
    func (user *User) Send(ver uint8, cmd uint16, message []byte, status uint8, reliable bool)
    func (user *User) ServerPush(ver uint8, cmd uint16, message []byte, reliable bool)
    func (user *User) ServerRespond(message []byte, ver uint8, cmd uint16, status uint8, reliable bool)
    func (user *User) Set(key string, value interface{})
    func (user *User) SetLatency(clientTime int64)
    func (user *User) Update(key string, op func(data interface{}) interface{})

Constants

TCPClient Client transport type used with userData.GetClientTransport()

const TCPClient = 1

UDPClient Client transport type used with userData.GetClientTransport()

const UDPClient = 2

UnknownClient invalid network transport type that should never show up...

const UnknownClient = 4

WSClient Client transport type used with userData.GetClientTransport()

const WSClient = 3

func CopyUser

func CopyUser(user *User) map[string]interface{}

CopyUser Copies a user struct for transferring user client data to another server.

Parameters

userData - User to be copied as a map.

func DecodeUserCopy

func DecodeUserCopy(b []byte) map[string]interface{}

DecodeUserCopy decodes encoded user by EncodeUserCopy

func DecodeUserData

func DecodeUserData(encoded string) (map[string]interface{}, error)

DecodeUserData decodes encoded user property data to a map

func DiscardUser

func DiscardUser(reliableClientAddr string, sid string)

DiscardUser Deletes a user data. Either reliableClientAddr or SID to be used.

[NOTE] Uses mutex lock internally.

[NOTE] Newer version of the clients use SID instead of the client address.

Parameters

reliableClientAddr - Client address of the user to be discarded.
sid                - User SID of the user to be discarded.

func EncodeUserCopy

func EncodeUserCopy(user *User) []byte

EncodeUserCopy encodes the user into a byte array to be decoded by DecodeUserCopy.

func EncodeUserData

func EncodeUserData(user *User) (string, error)

EncodeUserData encodes the user property data to base64 string.

func ExistsByID

func ExistsByID(sid string) bool

ExistsByID returns true if the user by the given SID exists.

[NOTE] This does NOT update user TTL.

[NOTE] Uses mutex lock internally.

func GetAllUserIDs

func GetAllUserIDs() []string

GetAllUserIDs returns all user SIDs that are connected to the server process.

[IMPORTANT] This maybe extremely expensive to use as it loops all existing users on the server.
[IMPORTANT] Limiting the usage of this function for tests and debugging is recommended.

func GetCCU

func GetCCU() int

GetCCU returns the number of concurrent users of the server.

[NOTE] Uses mutex lock internally..

func New

func New(data map[string]interface{}, initTTL int64) (map[string]interface{}, error)

New [INTERNAL USE ONLY] handle mesh network command sent from HTTP

[NOTE] Uses mutex lock internally.

[IMPORTANT] The return value of map[string]interface{} is always nil with or without error returned.

If initTTL is greater than 0, it will be used as the initial TTL (in seconds)

If initTTL is 0 or less, config TTL will be used as the initial TTL (in seconds)

func OnClientAddressChange

func OnClientAddressChange(callback func(userData *User))

OnClientAddressChange assigns a callback on change client global address.

Public IP address is checked every time we receive TCP/UDP packets and if the address is changed, this callback will be triggered.

[IMPORTANT] All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a global IP address is changed on client side.
           func(userData *User)
           userData - User data of the user that made the new connection with the server.

func OnDiscard

func OnDiscard(callback func(sid string, userData *User))

OnDiscard Registers a callback on user data deletion.

[IMPORTANT] This function is not goroutine safe and it must not be used in runtime.
            assign callbacks on the start of your process only.
[IMPORTANT] The callbacks are invoked while a mutex lock is held,
            which means using mutex lock in the callbacks may result in unexpected blocking.

Parameters

callback - Callback to be invoked when the target user is deleted.
           func(sid string, userData *User)
           sid      - SID of the discarded user.
           userData - User data of the discarded user.

func OnNew

func OnNew(callback func(userData *User))

OnNew Registers a callback on user.New()

[IMPORTANT] All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a new user is created.
           func(userData *User)
           userData - User data of new user.

func OnNewConnection

func OnNewConnection(callback func(userData *User))

OnNewConnection assigns a callback on new user connection.

New connection is made and the user client actually establishes a valid connection with the server.

[IMPORTANT] All callbacks are invoked synchronously and if a callback blocks, it will block the other operation.

Parameters

callback - Callback to be invoked when a new user is created.
           func(userData *User)
           userData - User data of the user that made the new connection with the server.

func OnSIDUpdate

func OnSIDUpdate(callback func(previousSID string, newSID string, previousUserData *User, newUserData *User))

OnSIDUpdate assigns a callback to be invoked when the user changes its SID.

[IMPORTANT] The callbacks are invoked while a mutex lock is held,
            which means using mutex lock in the callbacks may result in unexpected blocking.

[NOTE]      The callbacks are invoked when the user attempts to create a new user data with the existing user ID with different SID.
            If the user attempts to create a new user data without calling Disconnect and the user data is not expired yet,
            User module replaces the user data and SID.

func RemoveOnNewConnection

func RemoveOnNewConnection(callback func(userData *User))

RemoveOnNewConnection removes an assigned callback on new user connection.

func SetTCPState

func SetTCPState(sid string, state *tcp.State)

SetTCPState [INTERNAL USE ONLY] Sets TCP user state to the user data and updates TTL

[NOTE] Uses mutex lock internally.

Parameters

sid     - User SID of the target user to updated.
state   - TCP state to be assigned to the user.

func SetUDPStateAndRUDPConn

func SetUDPStateAndRUDPConn(sid string, state *udp.State)

SetUDPStateAndRUDPConn [INTERNAL USE ONLY] Sets UDP user state to the user data and updates TTL

[NOTE] Uses mutex lock internally.

Parameters

sid   - User SID of the target user to updated.
state - UDP state to be assigned to the user.

func SetUserByID

func SetUserByID(sid string, user *User, ttl int64) bool

SetUserByID Sets a user data by SID.

It returns false if it fails to set the user.

[NOTE] Uses mutex lock internally.

Parameters

sid      - User SID to store in the server memory.
userData - User to be stored.
ttl      - TTL of the stored user in seconds. This will be extended by using Extend etc.

func Setup

func Setup(ttl int64)

Setup sets up user package without network protocol association.

ttl int64 - TTL of the user data in seconds.

func SetupAsConnector

func SetupAsConnector(ttl int64)

SetupAsConnector Sets up as Connector server

ttl int64 - TTL of the health check in seconds.

func SetupAsTCPServer

func SetupAsTCPServer()

SetupAsTCPServer Sets up as TCP server.

[IMPORTANT] You must invoke this function before invoking diarkis.Start() to setup as TCP server.
[IMPORTANT] You may not setup both TCP and UDP.

func SetupAsUDPServer

func SetupAsUDPServer()

SetupAsUDPServer Sets up as UDP server

[IMPORTANT] You must invoke this function before invoking diarkis.Start() to setup as UDP server.
[IMPORTANT] You may not setup both TCP and UDP.

func UpdateUserByID

func UpdateUserByID(sid string) bool

UpdateUserByID Updates TTL of user data in the vault.

It returns false if the update fails.

[NOTE] Uses mutex lock internally.

Parameters

sid - User SID of the target user to updated.

type User

User represents user client and its property data, network connection.

type User struct {
    // unique ID to identify the user by
    ID       string
    SID      string
    SIDBytes []byte
    IsMoving bool
    // Key value storage: Do NOT use this map directly.
    // Use Get, Set, Update, and "GetAs..." instead.
    Data map[string]interface{}
    // Deprecated and no longer used
    Payload                []byte
    TCPState               *tcp.State
    UDPState               *udp.State
    RUDPConn               *udp.Connection
    UDPClientLocalAddrList []string
    // UDPState is always a new one..
    UDPClientKey string
    // encryption keys
    EncryptionKey    []byte
    EncryptionIV     []byte
    EncryptionMacKey []byte
    // reconnect flag
    Reconnect bool

    sync.RWMutex
    // contains filtered or unexported fields
}

func CreateBlankUser

func CreateBlankUser(sid, uid string) *User

CreateBlankUser creates an incomplete user to be used as a dummy.

Usage Example: Create a dummy user to create an empty room and/or group without actual client.

sid - Blank user SID.
uid - Blank user ID.

func CreateNewUser

func CreateNewUser(data map[string]interface{}, initTTL int64) (*User, int64, error)

CreateNewUser creates a new user data.

This function does NOT store the new user in the vault memory.

Input parameter data map[string]interface{} must contain the following properties:

Error Cases

+----------------------------+------------------------------------------------------------------+
| Error                      | Reason                                                           |
+----------------------------+------------------------------------------------------------------+
| Failed to generate UUID v4 | crypto/rand.Ready failed.                                        |
| User already exists        | User with the same SID or UID already exists on the same server. |
+----------------------------+------------------------------------------------------------------+

[IMPORTANT] Uniqueness of the user by its SID and UID is guaranteed only on the same server.

Parameters

sid    - SID of the new user to be created. The format is UUID v4.
key    - Encryption key of the user.
iv     - Encryption IV of the user.
macKey - Encryption mac key of the user.
uid    - User ID.
data   - Optional property: Encoded user property data.

func GetUserByID

func GetUserByID(sid string) *User

GetUserByID returns a user by its SID.

[IMPORTANT] It returns nil if the user is not found by the given SID.

[NOTE] This does NOT update user TTL.

[NOTE] Uses mutex lock internally.

Parameters

sid - User SID of the target user.

func GetUserBySID

func GetUserBySID(sid string) *User

GetUserBySID is an alias of GetUserByID and it returns a user by its SID.

[IMPORTANT] It returns nil if the user is not found by the given SID.

[NOTE] Uses mutex lock internally.

Parameters

sid - User SID of the target user.

func GetUserByUID

func GetUserByUID(uid string) *User

GetUserByUID returns a user by its user ID (UID).

[IMPORTANT] It returns nil if the user is not found by the given UID.

[NOTE] Uses mutex lock internally.

Parameters

uid - User ID of the target user.

func (*User) Delete

func (user *User) Delete(key string) bool

Delete removes the key and its value and returns true if the deletion was successful.

[NOTE] Uses mutex lock internally.
[NOTE] If the key does not exist, it will simple do nothing and returns false.

func (*User) Disconnect

func (user *User) Disconnect()

Disconnect disconnects the client from the server

func (*User) Get

func (user *User) Get(key string) interface{}

Get returns a value associated with the key (SID) given

[NOTE] Uses mutex lock internally.

User data must be handled by the user and nobody else, so no race condition...

[IMPORTANT] If you need to store a structured data, please use json label or convert to map instead.

[IMPORTANT] If the value is a map, the data type will become map[string]interface{} when the user moves to the other server.

[IMPORTANT] If the value is a slice, the data type will become []interface{} when the user moves to the other server.

[IMPORTANT] If the value is numeric, the data type will become float64 when the user moves to the other server.

Example:

numInterface := userData.GetAsInt("num") // this maybe float64, but we want to make sure it is read as an int

Parameters

key string - User property key of the value to retrieve.

func (*User) GetAsBool

func (u *User) GetAsBool(k string) (bool, bool)

GetAsBool returns user data by its key as a bool.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.

[NOTE] Uses mutex lock internally.

func (*User) GetAsBoolArray

func (u *User) GetAsBoolArray(k string) ([]bool, bool)

GetAsBoolArray returns user data by its key as an array of bool.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsBytes

func (u *User) GetAsBytes(k string) ([]byte, bool)

GetAsBytes returns user data by its key as a string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the value held is a base64 encoded string, it will be returned as a byte array as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsFloat32

func (u *User) GetAsFloat32(k string) (float32, bool)

GetAsFloat32 returns user data by its key as a float32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsFloat64

func (u *User) GetAsFloat64(k string) (float64, bool)

GetAsFloat64 returns user data by its key as a float64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsFloat64Array

func (u *User) GetAsFloat64Array(k string) ([]float64, bool)

GetAsFloat64Array returns user data by its key as an array of float64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsInt

func (u *User) GetAsInt(k string) (int, bool)

GetAsInt returns user data by its key as a int.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsInt16

func (u *User) GetAsInt16(k string) (int16, bool)

GetAsInt16 returns user data by its key as a int16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsInt16Array

func (u *User) GetAsInt16Array(k string) ([]int16, bool)

GetAsInt16Array returns user data by its key as an array of int16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsInt32

func (u *User) GetAsInt32(k string) (int32, bool)

GetAsInt32 returns user data by its key as a int32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsInt32Array

func (u *User) GetAsInt32Array(k string) ([]int32, bool)

GetAsInt32Array returns user data by its key as an array of int32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsInt64

func (u *User) GetAsInt64(k string) (int64, bool)

GetAsInt64 returns user data by its key as a int64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsInt64Array

func (u *User) GetAsInt64Array(k string) ([]int64, bool)

GetAsInt64Array returns user data by its key as an array of int64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsInt8

func (u *User) GetAsInt8(k string) (int8, bool)

GetAsInt8 returns user data by its key as a int8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsInt8Array

func (u *User) GetAsInt8Array(k string) ([]int8, bool)

GetAsInt8Array returns user data by its key as an array of int8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsIntArray

func (u *User) GetAsIntArray(k string) ([]int, bool)

GetAsIntArray returns user data by its key as an array of int.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsString

func (u *User) GetAsString(k string) (string, bool)

GetAsString returns user data by its key as a string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.

[NOTE] Uses mutex lock internally.

func (*User) GetAsStringArray

func (u *User) GetAsStringArray(k string) ([]string, bool)

GetAsStringArray returns user data by its key as an array of string.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsUint

func (u *User) GetAsUint(k string) (uint, bool)

GetAsUint returns user data by its key as a uint.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsUint16

func (u *User) GetAsUint16(k string) (uint16, bool)

GetAsUint16 returns user data by its key as a uint16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsUint16Array

func (u *User) GetAsUint16Array(k string) ([]uint16, bool)

GetAsUint16Array returns user data by its key as an array of uint16.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsUint32

func (u *User) GetAsUint32(k string) (uint32, bool)

GetAsUint32 returns user data by its key as a uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsUint32Array

func (u *User) GetAsUint32Array(k string) ([]uint32, bool)

GetAsUint32Array returns user data by its key as an array of uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsUint64

func (u *User) GetAsUint64(k string) (uint64, bool)

GetAsUint64 returns user data by its key as a uint32.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsUint64Array

func (u *User) GetAsUint64Array(k string) ([]uint64, bool)

GetAsUint64Array returns user data by its key as an array of uint64.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetAsUint8

func (u *User) GetAsUint8(k string) (uint8, bool)

GetAsUint8 returns user data by its key as a uint8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be true, if the value is invalid or missing.
[IMPORTANT] If the held value is float64, it will be converted to the correct type and returned as a valid value.

[NOTE] Uses mutex lock internally.

func (*User) GetAsUint8Array

func (u *User) GetAsUint8Array(k string) ([]uint8, bool)

GetAsUint8Array returns user data by its key as an array of uint8.

[IMPORTANT] The second returned value indicates if the value exists or not.
            The second value will be false, if the value data type is not invalid or missing.
            Valid means that the value is of the correct data type.
[IMPORTANT] If one or more elements in the array are not the specified data type,
            the second return value will be false.
[IMPORTANT] If one or more elements in the array are to be float64,
            it is an exception that will be auto-converted to the specified numerical data type
            and the second return value will be true.

[NOTE]      Uses mutex lock internally.

func (*User) GetClientAddr

func (user *User) GetClientAddr() string

GetClientAddr returns the user client address.

[IMPORTANT] If the UDP server has a configuration enableP2P: false,
            The returned value will be "0.0.0.0:0".

func (*User) GetClientKey

func (user *User) GetClientKey() string

GetClientKey returns clientKey.

Returns an empty string if client key is not set by environment variable DIARKIS_CLIENT_KEY.

func (*User) GetClientTransport

func (user *User) GetClientTransport() int

GetClientTransport returns enum to indicate which network transport the user client is using:

Possible values:

TCPClient int = 1
UDPClient int = 2
WSClient  int = 3
UnknownClient int = 4 // this should never happen...

func (*User) GetLatency

func (user *User) GetLatency() int64

GetLatency returns server-to-client latency in milliseconds of the user client.

func (*User) IsTCP

func (user *User) IsTCP() bool

IsTCP returns true if the user client is TCP

func (*User) IsUDP

func (user *User) IsUDP() bool

IsUDP returns true if the user client is UDP

func (*User) OnClientAddressChange

func (user *User) OnClientAddressChange(callback func())

OnClientAddressChange [INTERNAL USE ONLY]

callback - Callback to be invoked when a public IP address for the client is changed

func (*User) OnNewConnection

func (user *User) OnNewConnection(callback func())

OnNewConnection [INTERNAL USE ONLY]

callback - Callback to be invoked when a new user connection is established with the client.

func (*User) Push

func (user *User) Push(message []byte, reliable bool)

Push use ServerPush instead

Deprecated

func (*User) RemoveOnNewConnection

func (user *User) RemoveOnNewConnection()

RemoveOnNewConnection [INTERNAL USE ONLY]

func (*User) Respond

func (user *User) Respond(message []byte, status uint8, reliable bool)

Respond use ServerRespond instead

Deprecated

func (*User) Send

func (user *User) Send(ver uint8, cmd uint16, message []byte, status uint8, reliable bool)

Send Sends a packet from the server to the target user client with a response status

Deprecated

func (*User) ServerPush

func (user *User) ServerPush(ver uint8, cmd uint16, message []byte, reliable bool)

ServerPush Sends a push packet from the server to the target user client.

ver       - Server push message command version.
cmd       - Server push message command ID.
message   - Message byte array to be sent as a push.
reliable  - If true, UDP will become RUDP.

func (*User) ServerRespond

func (user *User) ServerRespond(message []byte, ver uint8, cmd uint16, status uint8, reliable bool)

ServerRespond sends a packet as a response w/ ver and cmd of your choice

message  - Message byte array to be sent as a response.
ver      - Server response command version.
cmd      - Server response command ID.
status   - Server response status. Status consts are available in server package.
           server.Ok (success), server.Bad (error caused by the user), server.Err (error caused by the server).
reliable - If true, UDP will become RUDP.

func (*User) Set

func (user *User) Set(key string, value interface{})

Set stores a value along with the key (SID): the value will remain stored until user object is discarded

[NOTE] Uses mutex lock internally.

User data must be handled by the user and nobody else, so no race condition....

[IMPORTANT] value does NOT support struct. If you need to store a structured data, please use map instead.

[IMPORTANT] If you store complex data types such as maps etc all value type will be stored as interface{}.

key   string      - Key of the user property to be set.
value interface{} - Value of the user property to be set.

func (*User) SetLatency

func (user *User) SetLatency(clientTime int64)

SetLatency [INTERNAL USE ONLY]

func (*User) Update

func (user *User) Update(key string, op func(data interface{}) interface{})

Update allows a custom operation function to "update" user data by its key

[NOTE] Uses mutex lock internally.

[IMPORTANT] value does NOT support struct. If you need to store a structured data, please use map instead.

[IMPORTANT] If you store complex data types such as maps etc all value type will be stored as interface{}.

Parameters

key string                                - Key of the user property to be updated.
op  func(targetPropertyValue interface{}) - Operation function to handle the property update.