package diarkisexec

import "github.com/Diarkis/diarkis/diarkisexec"

Package diarkisexec ▷

Diarkis Server DiarkisExec

This package helps you to setup Diarkis server with ease.

Setting Up Redundant MARS

You may configure your Diarkis cluster with MARS auto-redundancy when deploying it in environments where server nodes are more prone to failure and restarting them is challenging, such as non-cloud or unstable infrastructures.

In order to setup redundant MARS, you must add the following setup on the HTTP servers and add the configuration for Mesh module. If your Diarkis cluster is running in a cloud environment, you most likely won’t need this setup. Redundancy failover is triggered after 10 seconds of inactivity. If MARS recovers within that window, normal operation resumes without initiating failover.

diarkisexec.SetupDiarkis(logConfigPath, meshConfigPath, &diarkisexec.Modules{
	... // Modules configurations here
	MARS: &diarkisexec.Options{ ConfigPath: "path/to/config/file/mars.json" },
})

Mesh Module Configuration for Redundant MARS

In order for redundant MARS to work properly, you must add the host name of the HTTP endpoint of your Diarkis cluster. this host name is the one that is used to call /endpoint/type/$(server_type)/user/$(user_id) and metrics endpoints.

Important

The hostname MUST NOT include either "http://" or "https://".
If "secureHttpHost" is configured to true, it will internally use https:// for the API call.
Otherwise, default behavior is to use http:// for the API call.

Setting Up Diarkis Server (HTTP, UDP, or TCP) With Environment Variable

DiarkisExec allows you to setup Diarkis server with a specific network protocol by giving an environment variable instead of calling SetupDiarkisHTTPServer, SetupDiarkisUDPServer, or SetupDiarkisTCPServer.

Important

If you use either DIARKIS_HTTP_SERVER_CONFIG_PATH, DIARKIS_UDP_SERVER_CONFIG_PATH, or DIARKIS_TCP_SERVER_CONFIG_PATH,
you do NOT need to call SetupDiarkisHTTPServer, SetupDiarkisUDPServer, or SetupDiarkisTCPServer.

Example:

# Start the server as Diarkis HTTP server
DIARKIS_HTTP_SERVER_CONFIG_PATH=configs/http/main.json ./remote_bin/http

Valid Environment Variables For the Server

DIARKIS_HTTP_SERVER_CONFIG_PATHSetup the server as Diarkis HTTP server.
DIARKIS_UDP_SERVER_CONFIG_PATHSetup the server as Diarkis UDP server.
DIARKIS_TCP_SERVER_CONFIG_PATHSetup the server as Diarkis TCP server.

Custom configuration root directory

If the environment variable DIARKIS_CONFIG_ROOT_PATH is set, the process will resolve the configuration path using it instead of using the current working directory.

Example:

# Start the http server from anywhere while the project code is located at /home/user/diarkis
DIARKIS_CONFIG_ROOT_PATH=/home/user/diarkis /home/user/diarkis/remote_bin/http

Index

Constants

const CommandResponseBad uint8 = server.Bad

CommandResponseBad represents the server response status code for UDP/TCP server command.

The status indicates the command execution failed due to the client operation: invalid parameters etc..

const CommandResponseErr uint8 = server.Err

CommandResponseErr represents the server response status code for UDP/TCP server command.

The status indicates the command execution failed due to the server internal error.

const CommandResponseOK uint8 = server.Ok

CommandResponseOK represents the server response status code for UDP/TCP server command.

The status indicates the command execution was successful.

Functions

func CreateReturnBytes

func CreateReturnBytes(data map[string]interface{}) ([]byte, error)

CreateReturnBytes converts the given map[string]interface{} into a byte error for MeshCommandHandler return value.

func GetMeshAddress

func GetMeshAddress() string

GetMeshAddress returns the server's internal mesh address.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

func GetMeshAddressByPublicEndpoint

func GetMeshAddressByPublicEndpoint(publicEndpoint string) string

GetMeshAddressByPublicEndpoint returns the remote/local server's internal mesh address by its public endpoint.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

This function is available for UDP and TCP servers only.

func GetMeshAddressByServerRole

func GetMeshAddressByServerRole(serverRole string) string

GetMeshAddressByServerRole returns a randomly selected internal mesh address of the given server role.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Important

The function returns an empty string if the given serverRole does not exist.

Note

Uses mutex lock internally.

Note

Server roles are automatically determined by server's network protocol.
The valid server roles are: HTTP, UDP, and TCP.

func GetMeshAddressByServerType

func GetMeshAddressByServerType(serverType string) string

GetMeshAddressByServerType returns a randomly selected internal mesh address of the given server type.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Important

The function returns an empty string if the given serverType does not exist.

Note

Uses mutex lock internally.

Note

The default server types: HTTP, UDP, and TCP.

Note

Server type can be customized by using DIARKIS_SERVER_TYPE=$(server_type) env.

func GetMeshAddressesByServerRole

func GetMeshAddressesByServerRole(serverRole string) []string

GetMeshAddressesByServerRole returns an array of internal mesh addresses of the given server role.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

Server roles are automatically determined by server's network protocol.
The valid server roles are: HTTP, UDP, and TCP.

func GetMeshAddressesByServerType

func GetMeshAddressesByServerType(serverType string) []string

GetMeshAddressesByServerType returns an array of internal mesh addresses of the given server type.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

The default server types: HTTP, UDP, and TCP.

Note

Server type can be customized by using DIARKIS_SERVER_TYPE=$(server_type) env.

func GetPublicEndpoint

func GetPublicEndpoint() string

GetPublicEndpoint returns the server's public endpoint.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

This function is available for UDP and TCP servers only.

func GetPublicEndpointByMeshAddress

func GetPublicEndpointByMeshAddress(meshAddress string) string

GetPublicEndpointByMeshAddress returns the remote/local server's public endpoint by its internal mesh address.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

This function is available for UDP and TCP servers only.

func GetServerRole

func GetServerRole() string

GetServerRole returns the server role of itself.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

Server roles are automatically determined by server's network protocol.
The valid server roles are: HTTP, UDP, and TCP.

func GetServerRoleByMeshAddress

func GetServerRoleByMeshAddress(meshAddress string) string

GetServerRoleByMeshAddress returns the server role of a remote server by its internal mesh address.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

Server roles are automatically determined by server's network protocol.
The valid server roles are: HTTP, UDP, and TCP.

func GetServerType

func GetServerType() string

GetServerType returns the server type of itself.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

The default server types: HTTP, UDP, and TCP.

Note

Server type can be customized by using DIARKIS_SERVER_TYPE=$(server_type) env.

func GetServerTypeByMeshAddress

func GetServerTypeByMeshAddress(meshAddress string) string

GetServerTypeByMeshAddress returns the server type of a remote server by its internal mesh address.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

Note

The default server types: HTTP, UDP, and TCP.

Note

Server type can be customized by using DIARKIS_SERVER_TYPE=$(server_type) env.

func GetSharedData

func GetSharedData(key string) (int16, bool)

GetSharedData returns synchronized shared data by its key.

func IsOffline

func IsOffline() bool

IsOffline returns true if the server is marked to be shutdown.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

func IsOfflineByMeshAddress

func IsOfflineByMeshAddress(meshAddress string) bool

IsOfflineByMeshAddress returns true if the remote server of the given mesh address is marked to be shutdown.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

func IsServerRoleHTTP

func IsServerRoleHTTP() bool

IsServerRoleHTTP returns true if the server role is HTTP.

Important

This function does not work correctly before Diarkis server is ready.

Note

Server role is decided according to the network protocol the server uses and it does not change unlike server type.

func IsServerRoleTCP

func IsServerRoleTCP() bool

IsServerRoleTCP returns true if the server role is UDP.

Important

This function does not work correctly before Diarkis server is ready.

Note

Server role is decided according to the network protocol the server uses and it does not change unlike server type.

func IsServerRoleUDP

func IsServerRoleUDP() bool

IsServerRoleUDP returns true if the server role is UDP.

Important

This function does not work correctly before Diarkis server is ready.

Note

Server role is decided according to the network protocol the server uses and it does not change unlike server type.

func IsTaken

func IsTaken() bool

IsTaken returns true if the server is in taken state.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

func IsTakenByMeshAddress

func IsTakenByMeshAddress(meshAddress string) bool

IsTakenByMeshAddress returns true if the remote server of the given mesh address is in taken state.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Note

Uses mutex lock internally.

func MarkServerAsOffline

func MarkServerAsOffline()

MarkServerAsOffline flags the server as "OFFLINE".

Note

"OFFLINE" server does not allow the following operations on the server:
- Accept new user creation and connection.
- Diarkis Room's new room creation.
- Diarkis Group's new group creation.
- Diarkis Session's new session creation.

Note

"OFFLINE" server still functions as normal except for the prohibited operations listed above.

func MarkServerAsOnline

func MarkServerAsOnline()

MarkServerAsOnline flags the server as "ONLINE".

Note

"ONLINE" is the default state of the server.

func MarkServerAsTaken

func MarkServerAsTaken()

MarkServerAsTaken flags the server as "TAKEN".

Note

"TAKEN" server does not allow the following operation on the server:
- Accept new user creation and connection.

Note

"TAKEN" server still functions as normal except for the prohibited operations listed above.

func MarkServerAsTakenIf

func MarkServerAsTakenIf(callback func() bool)

MarkServerAsTakenIf flags the server as "TAKEN" if the callback returns true. The callback is invoked every 2 second and if the callback returns true, the server will be marked as "ONLINE".

Important

If the server is marked as "OFFLINE", this function will be ignored.

Note

This function is executed every 2 seconds so there will be race condition and it is not precise.

TAKEN - When the server is marked as "TAKEN", the server will NOT accept new user connections.

func NewLogger

func NewLogger(name string) *log.Logger

NewLogger creates a new instance of log.Logger.

Important

This function must be invoked BEFORE calling diarkisexec.StartDiarkis()

func OnKeepAlive

func OnKeepAlive(handler func(userData *user.User, next func(error)))

OnKeepAlive assigns a callback to be invoked on every echo (UDP) or heartbeat (TCP).

Important

Every callback must call next func(error) at the end of the operation
to allow Diarkis to move on to the next on keep alive operations.

func RemoveOnSharedDataRemove

func RemoveOnSharedDataRemove(cb func(key string, updated int64))

RemoveOnSharedDataRemove removes the given callback that has been assigned by SetOnSharedDataRemove.

Important

This function uses mutex lock internally.

func RemoveOnSharedDataUpdate

func RemoveOnSharedDataUpdate(cb func(key string, value int16, updated int64))

RemoveOnSharedDataUpdate removes the given callback that has been assigned by SetOnSharedDataUpdate.

Important

This function uses mutex lock internally.

func RemoveSharedData

func RemoveSharedData(key string) bool

RemoveSharedData removes the given shared key and propagates the removal to all server nodes in the cluster.

The propagation of the shared data may take some time.

Important

Updated value may suffer from race condition.
If multiple server nodes attempt to update the same key,
The value of the key maybe overwritten.

func ResponseStatusBad

func ResponseStatusBad() uint8

ResponseStatusBad returns UDP or TCP server response status code for invalid command invocation.

func ResponseStatusErr

func ResponseStatusErr() uint8

ResponseStatusErr returns UDP or TCP server response status code for server error while handling command.

func ResponseStatusOK

func ResponseStatusOK() uint8

ResponseStatusOK returns UDP or TCP server response status code for successfully handled command.

func SendMeshCommand

func SendMeshCommand(cmd uint16, addresses []string, data interface{}, reliable bool) error

SendMeshCommand sends a mesh command of the given cmd to the given internal mesh address.

The server of the given address will invoke the command handler of the given cmd.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Important

The command handler must be defined using diarkisexec.SetMeshCommandHandler(cmd uint16, handler MeshCommandHandler).

Parameters

cmd       - Mesh command ID.
addresses - Internal mesh address of the server to send the command to.
data      - Data to be sent to the handler.
            The valid data type of data must be the following two types only:
            1. map[string]interface{}
            2. struct
reliable  - If true, UDP will be RUDP.

The diagram below show how command is sent to multiple servers when you give multiple addresses:

                                                           ┌──────────┐
                                                     ┌────▶︎│ Server D │
                                                     │     └──────────┘
                               ┌──────────┐ <2> Send │
                           ┌──▶︎│ Server B │──────────┤     ┌──────────┐
                           │   └──────────┘          └────▶︎│ Server E │
┌──────────┐ <1> Send      │                               └──────────┘
│ Server A │ ──────────────┤                               ┌──────────┐
└──────────┘               │   ┌──────────┐          ┌────▶︎│ Server F │
                           └──▶︎│ Server C │──────────┤     └──────────┘
                               └──────────┘          │
                                                     │     ┌──────────┐
                                                     └────▶︎│ Server G │
                                                           └──────────┘

func SendMeshRPC

func SendMeshRPC(cmd uint16, address string, data []byte) (response []byte, err error)

SendMeshRPC sends a mesh RPC of the given cmd to the given internal mesh address and expects a response back from the server.

The server of the given address will invoke the command handler of the given cmd and sends back a response.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Important

The command handler must be defined using diarkisexec.SetMeshRPCHandler(cmd uint16, handler MeshRPCHandler).

Error Cases:

┌───────────────┬─────────────────────────────────────────────────────────────────────────┐
│ Error         │ Reason                                                                  │
╞═══════════════╪═════════════════════════════════════════════════════════════════════════╡
│ Handler error │ Handler function of the request returned an error.                      │
├───────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Network error │ Mesh network error. Failed to send or receive server-to-server message. │
└───────────────┴─────────────────────────────────────────────────────────────────────────┘

The diagram below show how SendMeshRequest works:

┌──────────┐ <1> Send request  ┌──────────┐
│ Server A │ ─────────────────▶︎│ Server B │
│          │ ◀︎──────────────── │          │
└──────────┘ <2> Send Response └──────────┘

Parameters

cmd       - Mesh command ID.
address   - Internal mesh address of the server to send the command to.
data      - Data to be sent to the handler.
            You may use td.DefineTransportData to create a data structure for RPC.

Returned Values

response  - The RPC handler on a remote server's response to the RPC sent.
err       - If the RPC operation fails, an error is sent.

func SendMeshRequest

func SendMeshRequest(cmd uint16, address string, data interface{}, callback func(err error, response map[string]interface{}))

SendMeshRequest sends a mesh command of the given cmd to the given internal mesh address and expects a response back from the server.

The server of the given address will invoke the command handler of the given cmd and sends back a response.

Important

This function must be used AFTER invoking diarkisexec.StartDiarkis()

Important

The command handler must be defined using diarkisexec.SetMeshCommandHandler(cmd uint16, handler MeshCommandHandler).

Error Cases:

┌───────────────────┬─────────────────────────────────────────────────────────────────────────┐
│ Error             │ Reason                                                                  │
╞═══════════════════╪═════════════════════════════════════════════════════════════════════════╡
│ Invalid data type │ Input data type must be either a struct or map[string]interface{}.      │
├───────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Handler error     │ Handler function of the request returned an error.                      │
├───────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Network error     │ Mesh network error. Failed to send or receive server-to-server message. │
└───────────────────┴─────────────────────────────────────────────────────────────────────────┘

The diagram below show how SendMeshRequest works:

┌──────────┐ <1> Send request  ┌──────────┐
│ Server A │ ─────────────────▶︎│ Server B │
│          │ ◀︎──────────────── │          │
└──────────┘ <2> Send Response └──────────┘

Parameters

cmd       - Mesh command ID.
address   - Internal mesh address of the server to send the command to.
data      - Data to be sent to the handler.
            The valid data type of data must be the following two types only:
            1. map[string]interface{}
            2. struct
callback  - The callback to be invoked when the response is received from the remote server.

func SetMeshCommandHandler

func SetMeshCommandHandler(cmd uint16, handler MeshCommandHandler)

SetMeshCommandHandler assigns a callback to the given mesh command handler to the given cmd.

Important

This function must be used BEFORE invoking diarkisexec.StartDiarkis()

Important

You may NOT assign a callback that is used by built-in internal mesh command handlers.
Diarkis internally uses cmd from 0 to 10000.

Important

You may NOT assign multiple callbacks to the same cmd.

func SetMeshRPCHandler

func SetMeshRPCHandler(cmd uint16, handler MeshRPCHandler)

SetMeshRPCHandler assigns a callback to the given mesh RPC handler to the given cmd.

Important

This function must be used BEFORE invoking diarkisexec.StartDiarkis()

Important

You may NOT assign a callback that is used by built-in internal mesh RPC handlers.
Diarkis internally uses cmd from 0 to 10000.

Important

You may NOT assign multiple callbacks to the same cmd.

Parameters

cmd      - RPC command ID.
handler  - Callback associated to the RPC ID.
           The handler callback will be passed two parameters:
           - data     []byte -   The byte array sent from another server node.
                                 The byte array can be encoded by mesh.TransportData.
                                 If mesh.TransPortData is used,
                                 you may decode data using mesh.TransportData.
           - senderAddr string - The private address of the sender server node.

func SetOnSharedDataRemove

func SetOnSharedDataRemove(cb func(key string, updated int64))

SetOnSharedDataRemove assigns a callback to be invoked when a shared data is deleted.

Note

To remove the assigned callback, use RemoveOnSharedDataRemove(cb func(key string)).

func SetOnSharedDataUpdate

func SetOnSharedDataUpdate(cb func(key string, value int16, updated int64))

SetOnSharedDataUpdate assigns a callback to be invoked when a shared data is updated.

Note

To remove the assigned callback use RemoveOnSharedDataUpdate(cb func(key string, value int16)).

func SetServerCommandHandler

func SetServerCommandHandler(ver uint8, cmd uint16, handler CommandHandler)

SetServerCommandHandler assigns a callback to the given command ver and cmd.

Important

This function must be invoked BEFORE calling diarkisexec.StartDiarkis()

Important

Diarkis' built-in commands use ver ranging from 0 to 1.
You may NOT assign callbacks with those ver values.

Important

You may NOT assign a callback to the same ver and cmd combination.

Important

Attempting to assign multiple callbacks to the same ver and cmd combination
as the built-in commands of Diarkis will result in panic.
Even if you do not use any built-in commands by setting ExposeCommands to false,
Diarkis start does NOT allow you to use built-in commands' ver and cmd.

func SetSharedData

func SetSharedData(key string, value int16) bool

SetSharedData updates a shared data to be propagated to all server nodes in the cluster.

The propagation of the shared data may take some time.

Important

The number of shared data keys you may store is limited to 10 keys.

Important

Updated value may suffer from race condition.
If multiple server nodes attempt to update the same key,
The value of the key maybe overwritten.

func SetupDiarkis

func SetupDiarkis(logConfigPath, meshConfigPath string, m *Modules)

SetupDiarkis initializes core and optional modules.

Note

The configuration paths must be relative to the executable server binary file location.

func SetupDiarkisHTTPServer

func SetupDiarkisHTTPServer(config string)

SetupDiarkisHTTPServer declares the server to be HTTP server.

Important

A server cannot have multiple network protocols (HTTP, TCP, and UDP).

Note

The configuration paths must be relative to the executable server binary file location.

func SetupDiarkisTCPServer

func SetupDiarkisTCPServer(config string)

SetupDiarkisTCPServer declares the server to be TCP server.

Important

A server cannot have multiple network protocols (HTTP, TCP, and UDP).

Note

The configuration paths must be relative to the executable server binary file location.

func SetupDiarkisUDPServer

func SetupDiarkisUDPServer(config string)

SetupDiarkisUDPServer declares the server to be UDP server.

Important

A server cannot have multiple network protocols (HTTP, TCP, and UDP).

Note

The configuration paths must be relative to the executable server binary file location.

func SetupNotificationService

func SetupNotificationService(name string, interval int64, callback func() (*Notification, error))

SetupNotificationService starts a notification service loop on the server.

The notification loop will execute the given callback at the given interval in seconds.

If the callback returns, *diarkisexec.Notification, the server will send the notification message along with ver and cmd to all the clients connected to the server.

Important

The server with HTTP role is not allowed to use Notifier.

Important

In order to deliver notifications, all server process must start the same notification service.

Important

This function does NOT guarantee the delivery of notification message to all user clients.
The possible failure of notification message delivery may include the following:
- Duplicate message ID will cause the message to be sent or ignored.
- User clients that are not connected at the time of this function's execution.
- User clients that are connected to non-responsive server process.
- TTL expiration.

Note

The returned value of the callback will be sent as a notification.

Parameters

name     - A name of the notification service.
interval - Notification delivery cycle interval in milliseconds
callback - A callback to be invoked on each notification service loop tick. The returned values will be the notification.
           If the callback returns a nil, notification will not be sent to the clients.

func SetupNotificationServiceBySharedData

func SetupNotificationServiceBySharedData(name string, sharedDataName string, cb func(sharedDataValue int16) (*Notification, error))

SetupNotificationServiceBySharedData starts a goroutine that listens to a shared data change for the given shared data name and value. When the shared data that matches the given name changes its value, the NotificationLoader callback is invoked to handle notifications.

If the callback returns, *diarkisexec.Notification, the server will send the notification message along with ver and cmd to all the clients connected to the server.

Important

The server with HTTP role is not allowed to use Notifier.

Important

In order to deliver notifications, all server process must start the same notification service.

Important

This function does NOT guarantee the delivery of notification message to all user clients.
The possible failure of notification message delivery may include the following:
- Duplicate message ID will cause the message to be sent or ignored.
- User clients that are not connected at the time of this function's execution.
- User clients that are connected to non-responsive server process.
- TTL expiration.

Note

The returned value of the callback will be sent as a notification.

Parameters

name            - A name of the notification service.
sharedDataName  - A shared data name that the notification service listens to.
cb              - A callback to be invoked on each notification service loop tick. The returned values will be the notification.
                  If the callback returns a nil, notification will not be sent to the clients.

func StartDiarkis

func StartDiarkis()

StartDiarkis starts the Diarkis server.

Important

This function blocks because it starts the process as a server,
which means that no operations after calling of this function will be executed at all.

Important

SetupDiarkis must be called before calling StartDiarkis to properly setup Diarkis server.

Types

type CommandHandler

type CommandHandler func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error))

CommandHandler callback for a UDP/TCP server command.

Important

At the end of callback operations, you MUST call next func(error).
Not calling next func(error) will cause the server not to be able to handle the next incoming commands from the client.

type MeshCommandHandler

type MeshCommandHandler func(req map[string]interface{}) (response []byte, err error)

MeshCommandHandler callback for a mesh command.

Important

In order to return a response value for SendMeshRequest, the handler function must return the response value as a byte array.

type MeshRPCHandler

type MeshRPCHandler func(req []byte, senderAddr string) (response []byte, err error)

MeshRPCHandler callback for a mesh command.

Important

In order to return a response value for SendMeshRPC, the handler function must return the response value as a byte array.

type Modules

type Modules struct {
	DGS        *Options
	Dive       *Options
	DM         *Options
	Field      *Options
	Group      *Options
	Room       *Options
	MatchMaker *Options
	Session    *Options
	Metrics    *Options
	Notifier   *Options
	MARS       *Options
	// In order to use P2P module properly, you must provide enableP2P:true config to Diarkis UDP server.
	// P2P module is only compatible with Diarkis UDP server.
	P2P *Options
}

Modules represents module declarations.

type Notification

type Notification struct {
	// Message ID
	ID string
	// Name is used to associate the notification with a handler callback
	Name string
	// Message command ver to be sent to the user clients
	Ver uint8
	// Message command ID to be sent to the user clients
	Cmd uint16
	// Message to be sent to the user clients
	Message []byte
	// TTL of the message
	TTL int64
}

Notification represents the notification data to be propagated to all connected Diarkis clients.

type Options

type Options struct {
	// Configuration file path for the module that needs configuration JSON file provided.
	// The path to configuration JSON file must be a relative to the server executable binary file location.
	ConfigPath string
	// If true, Diarkis server will expose built-in commands of the modules to the client.
	// There are modules that do not have built-in commands.
	ExposeCommands bool
}

Options represents module configurations.