Server Configuration File

The server configuration file encompasses multiple parameters necessary for its operation.

To specify the path to the configuration file, you can use the command line argument -C when executing gcs. If no path is specified, the gcs.json file in the current directory will be utilized.

The configuration file follows the JSON format. Each JSON object may include a "comment" field, which serves as a brief description for readers and is disregarded by the gcs application. To ensure accuracy in the configuration file, gcs will terminate with an error if unexpected names or values are encountered.

Root Parameters

Here are the root-level parameters found in the configuration file, along with their corresponding types and descriptions:

Name Type Description
"server_name" str Specify the server name to be displayed in the Statistics section of the Dashboard
"ssl_keys_path" str Path to SSL certificate files (without extension), refer to SSL Files
"auth_file" str Authentication file (default: authentication.dat)
"working_dir" str Working directory for gcs
"extra_adapters" str Path for searching custom dynamic adapters
"max_connections" uint Maximum allowed total connections
"max_client_connections" uint Maximum allowed client connections from the server

Server Name

By specifying the value in the "server_name" you instruct the gcs to display the name of your server in the Statistics section of the Dashboard and enrich it with data related to the application counters.

Working Directory

The working directory path is set based on the configuration file read at the beginning of the gcs application. The current directory is changed to this working directory, and all related paths are resolved relative to it. The default working directory is $HOME/.gc.

SSL Files

To configure an SSL certificate, you need to provide three files with the extensions .key, .cert, and .cacert. These files can have the same name but different extensions. The "ssl_keys_path" field in the root section of the configuration file should be set to the path and filename without extensions. The default path is tls/game_carrier relative to the working directory.

Connection Monitoring

The "conn_notice" and "conn_critical" sections are used to configure connection monitoring parameters. These parameters include:

Name Type Description
"msg_per_second" uint Specifies the maximum number of messages allowed from a game client to the application per second.
"kbytes_per_second" uint Specifies the maximum number of received bytes allowed from a game client to the application per second.
"max_msg_size" uint Specifies the maximum size allowed for a single message from a game client to the application.
"output_queue_size" uint Specifies the maximum size of the output queue for a game client.

If any of these parameters in the "conn_notice" section are exceeded, the on_issue handler will be called. If any of these parameters in the "conn_critical" section are exceeded, the connection will be dropped.

"conn_notice" and "conn_critical" sets parameters for connection monitoring. The parameters are

Threading Parameters

The threading parameters are located in the threading section of the configuration file. These parameters govern the behavior of the gcs threads. The supported parameters are:

Name Type Description
"worker_count" uint Specifies the number of worker threads.
"use_libuv" bool Indicates whether to use "libuv" loops for the worker threads.

A recommended initial value for "worker_count" is typically the number of CPU cores minus one.

Counters Parameters

The counter parameters are located in the "counters" section of the configuration file. These parameters govern the behavior of performance counters in the gcs. The supported parameters are:

Name Type Description
"per_second_window" uint The duration in seconds used for calculating per second counters.
"update_interval" uint The frequency at which counter values are updated on the stat server.

Logging Parameters

The logging parameters are located in the "logging" section of the configuration file. The following parameters are supported:

Name Type Description
"log_file" str The path to the log file. The %p wildcard will be replaced with the gcs PID.
"level" uint The log level mask. Please refer to Log level mask for more information.
"flags" uint The log level mask. Please refer to Flags details for more information.

Log Levels

The log level mask is a bit mask where each bit corresponds to a specific level of logging messages. The supported log levels, starting from the zeroth bit, are ERROR, WARNING, NOTICE, INFO, and DEBUG. The 10th bit represents the USER level.

Level Description
"ERROR" Indicates errors, typically indicating that the application is not functioning correctly.
"WARN" Warnings that suggest potential issues with the application’s operation.
"NOTICE" Messages about regular operations.
"USER" Level for messages related to application operations.
"INFO" Debugging messages with details.
"DEBUG" Low-level debugging messages.

Additionally, there are two constants: "NORMAL" and "VERBOSE". The "NORMAL" includes "ERROR", "WARNING", "NOTICE", and "USER", while the "VERBOSE" includes "INFO" and "DEBUG" in addition to "NORMAL".

The log level can be configured both for the server and the application, for the server you must add the "gcs" property and the corresponding masks to the "level" object, while for the user you have to add the "user" property to the “level” object and the required masks. See the example below:

    "level": {
        "gcs": "ERROR | WARN | NOTICE",
        "user": "USER | ERROR"
    }

Flags

Flags represent bit masks where each bit corresponds to a specific level of logging messages. The supported log levels, starting from the zeroth bit, are "APPEND", "AUTOFLUSH", "THREADID", "STDERR", "NORMAL", and "DEFAULT".

Flags Description
"DEFAULT" The default logging level is identical to “NORMAL”.
"NORMAL" Defines the normal logging level.
"STDERR" Outputs logs to STDERR.
"THREADID" Adds ThreadID to each outputted message. If not set, then ThreadId is not added to the message.
"AUTOFLUSH" Cleans buffers after each message. This setting affects the performance.
"APPEND" Continues appending messages to the file used in the last session. If not set, the new log file will be created, while the old one deleted.

Adapters Parameters

The configuration file includes an "adapters" section where adapter parameters are specified. The "adapters" section consists of an array of objects, each describing an adapter and its associated applications. It is important to set at least one adapter for the proper functioning of the "gcs". Each adapter supports the following parameters:

Name Type Description
"type" str Specifies the type of the adapter, which can be "native", "nethost", or "python". Refer to Adapter types for more information.
"dir" path Specifies the path to the directory that contains the adapter binaries.
"name" str Name of object to be load, the value depends on "type".
"apps" array of objects Specifies the name of the object to be loaded, with the actual value depending on the adapter type.

Additionally, specific adapter types may have additional parameters associated with them.

Adapter Types

native

This adapter type is the lowest level, where the adapter is a shared object file with the necessary exports. The dir parameter specifies the path to the directory where the shared object file is located. The name parameter corresponds to the name of the shared object file. In most cases, you can omit OS-specific details from the name, such as using "myadapter" instead of "libmyadapter.so" on Linux. Adapters for the .NET Framework are loaded as native adapters.

nethost

This adapter is designed to load .NET Core applications.

Name Type Description
"dir" str Specifies the path to "%GC_PATH/bin/net6.0" (or "net5.0" depending on the .NET version being used).
"name" str Always set to "GC.Runtime".
"path_to_nethost" str Can optionally contain a path to a specific .NET Core installation.
"nethost_version" str Allows selecting a specific .NET Core runtime version. If "path_to_nethost" is set, the "nethost_version" is ignored. If the version number is incomplete (e.g., 5), the highest possible runtime version will be loaded. If neither "nethost_version" nor "path_to_nethost" is set, the runtime with the highest version will be loaded.

dynamic

This adapter is a user-customized implementation. Users can leverage the Game Carrier Adapter API to create their own adapters for various programming languages.

Name Type Description
"dir" str Specifies the path to the directory where the shared object file is located. By default, dynamic adapters are searched in the "extra_adapters" directory. A dynamic adapter is a directory containing binary files for the adapter.
"type" str Corresponds to the name of the directory where files for custom adapter are stored.
"args" str Represents a string value that is passed to the adapter’s initialization function and contains initialization parameters in a format specified by the adapter.

Adapter Applications

The "apps" array encompasses information about all the applications associated with the adapter. These parameters are provided to the adapter during the creation of applications. The common parameters include:

Name Type Description
"name" str Represents the name of the application. Serves as the identifier that games (clients) can use to establish connections with the application, referenced by the "app_name" argument in gc_client_start.
"conn_notice" str Refers to the application-specific overrides for the global "conn_notice" values.
"conn_critical" str Represents the application-specific overrides for the global "conn_critical" values.

native No extra parameters, "type_name" and "file_name" are ignored.

nethost

Name Type Description
"name" str Represents the name of the application.
"type_name" str Specifies the class name for "nethost".
"file_name" str Indicates the path to the file that contains the required class.

dynamic The "args" argument is utilized for initializing the application with a specific string. The format of this string is determined by the dynamic adapter.

Vhost Parameters

The parameters for virtual hosts are defined within the vhosts section of the configuration file. Each virtual host is described by an object with the following properties:

Name Type Description
"ip" str IP address to listen on.
"port" uint Port to listen on.
"protocol" str Protocol to use. Supported values are "ws" (WebSocket) and "wss" (Secure WebSocket).
"app" str Default application for the virtual host.
"cloudflare" obj Additional settings for Cloudflare (see Cloudflare)

Cloudflare

The cloudflare section includes additional settings specifically for Cloudflare. The following parameters are available:

Name Type Description
"mode" enum Cloudflare mode: "OFF", "OPTIONAL", or "REQUIRED"
"inet_proto" enum Interned protocol: "TCP4", "TCP6", or "ALL"
"version" int Cloudflare protocol version

The "mode" parameter determines the Cloudflare mode for the virtual host:

  • "OFF": The virtual host accepts connections with or without Cloudflare. If a connection goes through Cloudflare, the header is not parsed and the connection is typically rejected.
  • "OPTIONAL": The virtual host accepts connections with or without Cloudflare. If a connection goes through Cloudflare, the header is parsed, and the connection is accepted if the header is valid.
  • "REQUIRED": The virtual host only accepts connections with Cloudflare. If a connection goes through Cloudflare, the header is parsed, and the connection is accepted if the header is valid. Connections without a Cloudflare header are rejected.

The "inet_proto" parameter determines the Interned protocol behavior:

  • "TCP4": The virtual host only accepts connections specified as "IPv4" in the Cloudflare header.
  • "TCP6": The virtual host only accepts connections specified as "IPv6" in the Cloudflare header.

The "version" parameter specifies the required Cloudflare protocol version: 1, 2, or "ALL" to support both versions.

Example

The example below showcases the usage of the server configuration file:

{
    "adapters": [
        {
            "comment": "Native adapter",
            "type": "native",
            "dir": "/home/gc/minimal_app/",
            "name": "minimal_app",
            "apps": [
                {
                    "name": "minimal_app",
                    "type_name": "minimal_app",
                    "file_name": "minimal_app"
                }
            ]
        }
    ],

    "vhosts": [
        {
            "comment": "Primary host",
            "ip": "0.0.0.0",
            "port": 7681,
            "protocol": "wss",
            "app": "minimal_app"
        }
    ],

    "logging": {
        "comment": "%p means PID",
        "log_file": "gcs.%p.log",
        "level": "NORMAL"
    },

    "keep_alive": {
        "comment": "zero timeout means no keep alive",
        "timeout": 0,
        "retries": 5,
        "interval": 100
    },

    "threading": {
        "worker_count": 12,
        "use_libuv": true
    },

    "counters": {
        "per_second_window": 10,
        "update_interval": 10
    },

    "group_max_size": 42,
    "max_groups": 1000,
    "max_client_connections": 99
}