CmdBroadcastGroup The command ID of built-in broadcast group command
const CmdBroadcastGroup uint16 = 113
CmdBroadcastRoom The command ID of built-in broadcast to room command
const CmdBroadcastRoom uint16 = 103
CmdBuiltInUtilClientKey Command used for clientKey if required
const CmdBuiltInUtilClientKey uint16 = 4
CmdBuiltInUtilFin Command used for WebSocket server to close the server socket when received
const CmdBuiltInUtilFin uint16 = 0
CmdBuiltInUtilKeepAlive Command used for heartbeat of TCP and echo of RUDP
const CmdBuiltInUtilKeepAlive uint16 = 1
CmdBuiltInUtilPing Command used for ping of UDP
const CmdBuiltInUtilPing uint16 = 3
CmdBuiltInUtilReconn Command used for client reconnect
const CmdBuiltInUtilReconn uint16 = 2
CmdBuiltInUtilReconnWithType Command used for client reconnect with specific server type
const CmdBuiltInUtilReconnWithType uint16 = 5
CmdBuiltInUtilVer Command version strictly used by diarkis internal
const CmdBuiltInUtilVer uint8 = 0
CmdBuiltInVer All built-in commands' version
const CmdBuiltInVer uint8 = 1
CmdCancelReserveRoom The command ID of built-in message to room support command
const CmdCancelReserveRoom uint16 = 118
CmdCreateGroup The command ID of built-in create group command
const CmdCreateGroup uint16 = 110
CmdCreateRoom The command ID of built-in create room command
const CmdCreateRoom uint16 = 100
CmdFieldDisappear The command ID for built-in field push
const CmdFieldDisappear uint16 = 123
CmdFieldReconn The command ID for built-in field push
const CmdFieldReconn uint16 = 122
CmdFieldServerSync The command ID for built-in field push
const CmdFieldServerSync uint16 = 124
CmdFieldSync The command ID for build-in field command
const CmdFieldSync uint16 = 121
CmdFieldSyncInit The command ID of built-in field command
const CmdFieldSyncInit uint16 = 120
CmdFindRooms The command ID of built-in message to room support command
const CmdFindRooms uint16 = 116
CmdGetNumOfRoomMembers The command ID of built-in room member number
const CmdGetNumOfRoomMembers uint16 = 13
CmdGetRoomMemberIDs The command ID of built-in member user IDs sync
const CmdGetRoomMemberIDs uint16 = 11
CmdGetRoomOwnerID The command ID of built-in get command
const CmdGetRoomOwnerID uint16 = 109
CmdGetRoomProp The command ID of built-in property get command
const CmdGetRoomProp uint16 = 108
CmdIncrRoomProp The command ID of built-in increment room prop
const CmdIncrRoomProp uint16 = 10
CmdJoinGroup The command ID of built-in join group command
const CmdJoinGroup uint16 = 111
CmdJoinRoom The command ID of built-in join room command
const CmdJoinRoom uint16 = 101
CmdLeaveGroup The command ID of built-in leave group command
const CmdLeaveGroup uint16 = 112
CmdLeaveRoom The command ID of built-in leave room command
const CmdLeaveRoom uint16 = 102
CmdMMBackfill The command ID for built-in MatchMaker
const CmdMMBackfill uint16 = 211
CmdMMClaim The command ID for built-in MatchMaker
const CmdMMClaim uint16 = 205
CmdMMCommit The command ID for built-in MatchMaker
const CmdMMCommit uint16 = 215
CmdMMComplete The command ID for built-in MatchMaker
const CmdMMComplete uint16 = 206
CmdMMCompleteCommit The command ID for built-in MatchMaker
const CmdMMCompleteCommit uint16 = 216
CmdMMDisbandTeam The command ID for built-in MatchMaker
const CmdMMDisbandTeam uint16 = 212
CmdMMKick The command ID for built-in MatchMaker
const CmdMMKick uint16 = 217
CmdMMLeave The command ID for built-in MatchMaker
const CmdMMLeave uint16 = 203
CmdMMNewTeam The command ID for built-in MatchMaker
const CmdMMNewTeam uint16 = 209
CmdMMP2P The command ID for built-in MatchMaker
const CmdMMP2P uint16 = 208
CmdMMRemove The command ID for built-in MatchMaker
const CmdMMRemove uint16 = 202
CmdMMSearch The command ID for built-in MatchMaker
const CmdMMSearch uint16 = 201
CmdMMSearchList The command ID for built-in MatchMaker
const CmdMMSearchList uint16 = 207
CmdMMSync The command ID for built-in MatchMaker
const CmdMMSync uint16 = 204
CmdMMTeamComplete The command ID for built-in MatchMaker
const CmdMMTeamComplete uint16 = 213
CmdMMTeamSearch The command ID for built-in MatchMaker
const CmdMMTeamSearch uint16 = 214
CmdMMTeamSync The command ID for built-in MatchMaker
const CmdMMTeamSync uint16 = 210
CmdMMWait The command ID for built-in MatchMaker
const CmdMMWait uint16 = 200
CmdMessageRoom The command ID of built-in message to room command
const CmdMessageRoom uint16 = 104
CmdMigrateRoom The command ID of built-in room migration
const CmdMigrateRoom uint16 = 12
CmdRandCreateRoom The command ID of built-in create room command for random join
const CmdRandCreateRoom uint16 = 105
CmdRandJoinGroup The command ID of built-in message to room support command
const CmdRandJoinGroup uint16 = 114
CmdRandJoinRoom The command ID of built-in join room for random join
const CmdRandJoinRoom uint16 = 106
CmdRegisterRoom The command ID of built-in message to room support command
const CmdRegisterRoom uint16 = 115
CmdReserveRoom The command ID of built-in message to room support command
const CmdReserveRoom uint16 = 117
CmdUpdateRoomProp The command ID of built-in proerty update command
const CmdUpdateRoomProp uint16 = 107
ErrCodeCancelReserveRoom represents the failure of the cancelation of room reservation
const ErrCodeCancelReserveRoom uint32 = 2008
ErrCodeInvalidParams represents payload with invalid parameters
const ErrCodeInvalidParams uint32 = 1001
ErrCodeJoinGroup represents the failure of joining a group
const ErrCodeJoinGroup uint32 = 3001
ErrCodeJoinRoom represents the failure of joining a room
const ErrCodeJoinRoom uint32 = 2002
ErrCodeLeaveGroup represents the failure of leaving a group
const ErrCodeLeaveGroup uint32 = 3002
ErrCodeLeaveRoom represents the failure of leaving a room
const ErrCodeLeaveRoom uint32 = 2003
ErrCodeMM represents generic matchmaking operation failure
const ErrCodeMM uint32 = 4008
ErrCodeMMJoin represents failure of matchmaking join
const ErrCodeMMJoin uint32 = 4006
ErrCodeMMNotAllowed represents permission rejection of matchmaking command
const ErrCodeMMNotAllowed uint32 = 4005
ErrCodeMMNotFound represents failure of matchmaking not found
const ErrCodeMMNotFound uint32 = 4004
ErrCodeMMNotMatched represents matchmaking operation failure due to not matched
const ErrCodeMMNotMatched uint32 = 4007
ErrCodeMMReserve represents failure of matchmaking reservation
const ErrCodeMMReserve uint32 = 4003
ErrCodeMMSearch represents search command error
const ErrCodeMMSearch uint32 = 4000
ErrCodeMMSearchEmpty represents empty search resolts
const ErrCodeMMSearchEmpty uint32 = 4001
ErrCodeMMWait represents failure of matchmaking wait
const ErrCodeMMWait uint32 = 4002
ErrCodeMigrate error code for connection migration NOT room migration
const ErrCodeMigrate uint32 = 1003
ErrCodeMigrateRoom represents the failure of room migration
const ErrCodeMigrateRoom uint32 = 2010
ErrCodeMissingOwnerID represents missing ownner ID
const ErrCodeMissingOwnerID uint32 = 2005
ErrCodeMissingRoomID represents missing room ID
const ErrCodeMissingRoomID uint32 = 2004
ErrCodeNewGroup represents the failure of creating a new group
const ErrCodeNewGroup uint32 = 3000
ErrCodeNewRoom represents the failure of creating a new room
const ErrCodeNewRoom uint32 = 2000
ErrCodeNodeNotFound reprersents no server node found for mesh network communication
const ErrCodeNodeNotFound uint32 = 1002
ErrCodeNotInRoom represents the user that indicated is not in a room
const ErrCodeNotInRoom uint32 = 2001
ErrCodeNumberOfRoomMembers represents the failure of retrieving the number of room members
const ErrCodeNumberOfRoomMembers uint32 = 2012
ErrCodePayloadShort represents playload that is too short
const ErrCodePayloadShort uint32 = 1000
ErrCodeReserveRoom represents the failure of room reservation
const ErrCodeReserveRoom uint32 = 2007
ErrCodeRoom represents misc room operation error
const ErrCodeRoom uint32 = 2011
ErrCodeRoomNotFound represents room not found
const ErrCodeRoomNotFound uint32 = 2009
ErrCodeRoomPropIncr represents the failure of property update (increment)
const ErrCodeRoomPropIncr uint32 = 2006
MeshFieldNPCTransport Mesh network command ID
const MeshFieldNPCTransport uint16 = 51
MeshFieldNearbySync Mesh network command ID
const MeshFieldNearbySync uint16 = 52
MeshFieldReconn Mesh network command ID
const MeshFieldReconn uint16 = 50
MeshGetNumOfRoomMembers Mesh network command ID
const MeshGetNumOfRoomMembers uint16 = 16
MeshGroupBroadcastSync Mesh network command ID
const MeshGroupBroadcastSync uint16 = 22
MeshGroupJoin Mesh network command ID
const MeshGroupJoin uint16 = 21
MeshGroupSync Mesh network command ID
const MeshGroupSync uint16 = 23
MeshHealthCheck Mesh network command ID
const MeshHealthCheck uint16 = 1020
MeshMARSDel Mesh network command ID
const MeshMARSDel uint16 = 1001
MeshMARSSScan Mesh network command ID
const MeshMARSSScan uint16 = 1000
MeshMARSShow mesh command to show lists of nodes in the clusters
const MeshMARSShow uint16 = 1002
MeshMatchMakingAdd Mesh network command ID
const MeshMatchMakingAdd uint16 = 40
MeshMatchMakingSearch Mesh network command ID
const MeshMatchMakingSearch uint16 = 41
MeshMatchingMoveRoom Mesh network command ID
const MeshMatchingMoveRoom uint16 = 43
MeshMatchingRemove Mesh network command ID
const MeshMatchingRemove uint16 = 42
MeshMigrate Mesh network command ID
const MeshMigrate uint16 = 80
MeshRoomBackupDel Mesh network command ID
const MeshRoomBackupDel uint16 = 14
MeshRoomBackupExtend Mesh network command ID
const MeshRoomBackupExtend uint16 = 12
MeshRoomBackupNew Mesh network command ID
const MeshRoomBackupNew uint16 = 11
MeshRoomBackupUpdate Mesh network command ID
const MeshRoomBackupUpdate uint16 = 13
MeshRoomJoin Mesh network command ID
const MeshRoomJoin uint16 = 10
MeshRoomMigrate Mesh network command ID
const MeshRoomMigrate uint16 = 15
MeshSendPM Mesh network command ID
const MeshSendPM uint16 = 60
MeshSessionCreate Mesh network command ID for sending session data from HTTP to TCP/UDP
const MeshSessionCreate uint16 = 20
MeshStatusOffline Mesh network node status offline value
const MeshStatusOffline = 2
MeshStatusOnline Mesh network node status online value
const MeshStatusOnline = 1
MeshStatusTaken Mesh network node status taken value
const MeshStatusTaken = 3
MeshSubBJoin Mesh network command ID
const MeshSubBJoin uint16 = 70
func AddrToBytes(addr string) ([]byte, error)
AddrToBytes Converts address (address:port) string to byte array
func CreateBox(w int, text string, alignment int, isTop, connecting bool) string
CreateBox creates a box
func DeleteFromTmp(name string)
DeleteFromTmp removes a file under /tmp/ - The file must have a prefix of "DIARKIS_"
func ErrData(message string, code uint32) []byte
ErrData returns either a UTF8 string message as a byte array or structured error data as a byte array.
In order to use structured error data, use DIARKIS_USE_STRUCT_ERR env.
func ForEachParallel(list []interface{}, operation func(interface{}, func(error)), done func(error))
ForEachParallel executes the given operation function on each item in the list in parallel and calls done when finished
func GenShortID() (string, error)
GenShortID returns a randomly generated HEX encoded ID as a string (8 characters long). Does NOT guarantee uniqueness like UUID v4.
func GetEnv(name string) string
GetEnv returns a value of an environment variable w/ the given name all env name must have a prefix of "DIARKIS_"
func GetID(nodeAddrList []string) (string, error)
GetID Returns a unique ID with mesh node address encoded in it - Length of the returned ID is 52
func GetPublicEndPointAWS() (string, error)
GetPublicEndPointAWS returns the public endpoint hostname in Google Cloud Computing When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)
func GetPublicEndPointAlibaba() (string, error)
GetPublicEndPointAlibaba returns the public endpoint hostname in Alibaba Cloud When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)
func GetPublicEndPointGCP() (string, error)
GetPublicEndPointGCP returns the public endpoint hostname in Google Cloud Computing When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)
func GetPublicEndPointMS() (string, error)
GetPublicEndPointMS returns the public endpoint address in MS Azure Cloud When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)
func GetPublicEndPointMSLB() (string, error)
GetPublicEndPointMSLB returns the public endpoint address in MS Azure Cloud with Loadbalancer in front When diarkis process is ready (diarkis.OnReady(callback)), you set this value to server.SetPublicEndPoint(endpoint)
func IndexOf(array []string, me string) int
IndexOf Returns an index of a given element in the given array of strings
func IsNullBytes(buf []byte) bool
IsNullBytes returns true if the given byte array contains only x00
func LeadingZero(num int, digit int) string
LeadingZero Returns a string with leading 0
func NanoSecHex() string
NanoSecHex Converts the unix timestamp in nano seconds to a hex string - Length of the returned string is always 16
func NowMilliseconds() int64
NowMilliseconds Returns a Unix timestamp in milliseconds
func NowNanoseconds() int64
NowNanoseconds Returns a Unix timestamp in nanoseconds
func NowSeconds() int64
NowSeconds Returns a Unix timestamp in seconds
func Parallel(funcs []func(func(error)), done func(error))
Parallel executes multiple functions in parallel and calls done when all functions are finished
func ParseID(id string) (string, []string, error)
ParseID Returns unique ID and mesh node address list from an ID created by GetID()
func RandomInt(min int, max int) int
RandomInt Returns a random int between min and max
func ReadFromTmp(name string) string
ReadFromTmp reads from a file under /tmp/ - The file must have a prefix of "DIAKRIS_"
func ReverseBytes(bytes []byte) []byte
ReverseBytes Reverses byte array
func RmSpaces(str string) string
RmSpaces Removes all spaces in a string - performs a single allocation, but may grossly overallocate if the source string is mainly whitespace
func SetEnv(name string, val string)
SetEnv sets an environment variable w/ the given name all env name will have a prefix of "DIARKIS_"
func Setup()
Setup [INTERNAL USE ONLY] set up util package in diarkis
func StrConcat(strlist ...string) string
StrConcat Concatnates strings
func ToFixed(num float64, precision int) string
ToFixed Returns a fixed precision of decimal number as a string
func Waterfall(funcs []func(func(error)), done func(error))
Waterfall calls multiple functions in the order of the funcs array given and calls done func when finished.
func WriteToTmp(name string, val string)
WriteToTmp writes a string to a file under /tmp/ - The file with have a prefix of "DIARKIS_"
func ZuluTimeFormat(now time.Time) string
ZuluTimeFormat Retuns a string of time in UTC Zulu format: RFC 3339
Await represents asynchronous wait group
type Await struct { sync.WaitGroup }
func Async(taskNum int) *Await
Async returns await struct for asynchronous opertions:
Usage Example
await := util.Async(2) go func() { asynchronousOperation(func() { await.Done() }) } go func() { asynchronousOperation(func() { await.Done() }) } // this will block until all asynchronous operations are marked by await.Done() await.Wait() // all asynchronous operations are done now finish()