Bad Send status for server response.
const Bad = 4
Err Send status for server response.
const Err = 5
Ok Send status for server response.
const Ok = 1
TCPType a type of TCP server used by mesh module
const TCPType = tcp.Type
UDPType a type of UDP server used by mesh module
const UDPType = udp.Type
WSType a type of WebSocket server used by mesh module
const WSType = ws.Type
func Command(ver uint8, cmd uint16, handler func(*user.User, func(error)))
Command [WebSocket ONLY] use HandleCommand instead for other servers.
ver uint8 - Command version of the handler. cmd uint16 - Command ID of the handler. handler func(userData *user.User, next func(error))
Returns an error if it fails to assign a handler.
NOTE: If you assign multiple handles with the same ver and cmd, all handlers will be executed in the order of assignment.
func GetEndPoint() string
GetEndPoint returns the end point address the server is bound with
func GetServerType() string
GetServerType returns server type as a string
func HandleCommand(ver uint8, cmd uint16, handler func(uint8, uint16, []byte, *user.User, func(error))) error
HandleCommand registers a command handler function for TCP and UDP/RUDP server.
ver uint8 - Command version of the handler. cmd uint16 - Command ID of the handler. handler func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)) - Handler function to be executed when the server receives the command.
Returns an error if it fails to assign a handler.
NOTE: If you assign multiple handles with the same ver and cmd, all handlers will be executed in the order of assignment.
func HandleWSCommand(ver float64, cmd float64, handler func(float64, float64, map[string]interface{}, *user.User, func(error))) error
HandleWSCommand registers WebSocket command function.
ver float64 - Command version of the handler. cmd float64 - Command ID of the handler. handler func(ver float64, cmd float64, data map[string]interfae{}, userData *user.User, next func(error)) - Handler function to be executed when the server receives the command.
Returns an error if it fails to assign a handler.
NOTE: If you assign multiple handles with the same ver and cmd, all handlers will be executed in the order of assignment.
func HookAllCommands(handler func(*user.User, func(error)))
HookAllCommands Registers a packet handler as a hook to all commands
handler func(userData *user.User, next func(error)) - Function to be invoked on command hook.
NOTE: The second argument next func(error) must be called at the end of handler to move the operation to next.
func IsCommandDuplicate(ver uint8, commandID uint16) bool
IsCommandDuplicate returns true if ver and commandID are used elsewhere when this function is invoked
ver uint8 - Command version to be checked for duplication. cmd uint16 - Command ID to be checked for duplication.
func IsTCP() bool
IsTCP Returns true if the server is setup as TCP server
func IsUDP() bool
IsUDP Returns true if the server is setup as UDP server
func IsWebSocket() bool
IsWebSocket Returns true if the server is setup as WebSocket server
func Offline()
Offline Set server status to offline
func OnDisconnect(callback func(string, *user.User))
OnDisconnect Registers a callback on connection termination for TCP/UDP
func OnKeepAlive(handler func(*user.User, func(error)))
OnKeepAlive Registers a handler on TCP heartbeat or UDP echo
handler func(userData *user.User, next func(error)) - Function to be invoked on keep alive message from the clients.
NOTE: next func(error) must be called at the end of handler's operation.
func Online()
Online Set server status to online
func SendPM(nodeAddr string, sid string, ver uint8, cmd uint16, message []byte)
SendPM sends a direct message to another user - The sent private message is a reliable delivery
nodeAddr string - This is the node (server) internal address of the target user. sid string - This is the sid (session ID) of the target user. ver uint8 - This is the command version to be used with the message sent. cmd uint16 - This is the command version to be used with the message sent. message []byte - This is the message data byte array.
func SetPublicEndPoint(addr string)
SetPublicEndPoint sets public end point to be sent to the client to be used to connect
addr string - This is the public endpoint for the server to be registered and used by the clients.
This is usually used internally.
func SetupAsConnector(path string)
SetupAsConnector Initialize the server as a Connector server for an external real-time server. This is meant to be used with an external real-time server such as Unreal Engine Dedicated server etc. Diarkis itself will not communicate wit the clients, but focuses on autoscaling and horizontal scaling on K8s.
path string - This is the absolute path of the configuration file to read.
func SetupAsTCPServer(path string)
SetupAsTCPServer Initialize as a TCP server. Load configurations from the file path given. Pass an empty string, if there is no need for configurations.
path string - This is the absolute path of the configuration file to read.
func SetupAsUDPServer(path string)
SetupAsUDPServer Initialize as a UDP server. Load configurations from the file path given. Pass an empty string, if there is no need for configurations.
path string - This is the absolute path of the configuration file to read.
func SetupAsWebSocketServer(path string)
SetupAsWebSocketServer Initialize as a WebSocket server. Load configurations from the file path given. The config name is "WS". Pass an empty string, if there is no need for configurations.
path string - This is the absolute path of the configuration file to read.
func SetupServerForAWS() error
SetupServerForAWS sets public endpoint in AWS environement Must be called in diarkis.OnReady() as a callback
func SetupServerForAzure() error
SetupServerForAzure sets public endpoint in Microsoft Azure environement Must be called in diarkis.OnReady() as a callback
func SetupServerForGCP() error
SetupServerForGCP sets public endpoint in GCP environement Must be called in diarkis.OnReady() as a callback