HTTP server is the entry point for Diarkis. The application server connects to HTTP server to retrieve the real-time connection endpoint and encryption keys.
We will be explaining how to write the basic HTTP server code and explain configurations.
HTTP Configurations
address |
“127.0.0.1” |
The address or hostname for HTTP server. |
port |
“7000” |
The port for HTTP server. |
useFixedPort |
false |
If true, HTTP server will bind with the given port only. |
enableEncryption |
true |
If false, real-time communication encryption will be disabled. You must set the same configurations for other servers as well. |
The server code
This is the main source file of HTTP server.
servers/http/main.go |
package main |
How To Write Custom HTTP REST EndPoint
Diarkis’ HTTP server allows you to write custom REST endpoints.
cmds/http/main.go |
package httpcmds } func handleHello(res *http.Response, req *http.Request, params *http.Params, next func(error)) { message := params.GetAsString("message") res.Respond(message, http.Ok) // move on to other handlers next(nil) } |
Match Making Configurations
HTTP server and TCP and/or UDP server both need to have this configuration in order to use Match Making.
distributionRate |
30 |
Ratio of sharded match making data saturation among the HTTP server nodes in percentage: e.i. 30 means 30% |
How To Define Match Conditions For Match Making
Diarkis Match Making allows you to define multiple search conditions. Match Making definitions must be defined in HTTP server.
levelAndRank := "levelAndRank" conds := make(map[string]int) // Search will be in the range of level 0 to 10, 11 to 20, 21 to 30... conds["level"] = 10 // Search will be in the range of rank 0 to 50, 51 to 100, 101 to 150... conds["rank"] = 50 // levelAndRank will search against level and rank within their ranges. matching.Define(levelAndRank, conds) |
How To Define Complex Match Conditions For Match Making
The example below shows how to define compound match conditions to be used by search to match with strict conditions first and less strict conditions if not enough matches are not found. Match Making definitions must be defined in HTTP server.
strict = "strict" strictConds := make(map[string]int) strictConds["power"] = 5 strictConds["league"] = 1 // This is the definition of the first strict search condition matching.Define(strict, strictConds) lessStrict = "lessStrict" lessStrictConds := make(map[string]int) lessStrictConds["power"] = 10 lessStrictConds["league"] = 5 // This is the second definition and it is less strict than the first condition matching.Define(lessStrict, lessStrictConds) |
Auth API
In order to connect to Diarkis server cluster, you must retrieve a connection endpoint from Diarkis HTTP server.
The API is shown below:
GET /auth/<application user ID> |
{ "WS":"<websocket endpoint address and port>", "UDP":"<udp endpoint address and port>", "TCP":"<tcp endpoint address and port>" } |
Metrics API
Diarkis has metrics REST API to see what is going on with your Diarkis application in real-time. By scraping this API and forwarding the data to analytic tools such as Prometheus + Grafana, Datadog etc, will give you detailed analytic tools immediately.
Prometheus Format:
GET /metrics/prometheus/v/2 |
JSON Format:
GET /metrics/json |
Metrics Data - Prometheus Format
NOTE: There are more metrics data other than shown below.
Users_<protocol>_node |
CCU (Concurrent Users) per node of each protocol. |
<protocol>_Packets_In_<protocol> |
Inbound packets per node of each protocol. |
<protocol>_Packets_Out_<protocol> |
Outbound packets per node of each protocol. |
Mesh_Packets_In_<protocol>_node |
Inbound internal packets per node of each protocol. |
Mesh_Packets_Out_<protocol>_node |
Outbound internal packets per node of each protocol. |