NAME

getOpt - Reads the contents of the server configuration file.

SYNOPSIS

#include <game-carrier/server.h>

typedef GCT_INT (GC_CORE_API *GetOpt)(
    GCT_CSTR name,
    GCT_INT type,
    GCT_PTR value);

typedef struct getOpt {
    /* ... Some fields ... */
    GetOpt getOpt;
    /* ... Some fields ... */
}

Parameters:

  • name GCT_CSTR Name of the requested property.
  • type GCT_INT Data type associated with the parameter.
  • value GCT_PTR Pointer to the value.

RETURN VALUE

Returns 0 if the invocation is successful.

Returns an error code, such as errno, if the invocation is unsuccessful.

DESCRIPTION

The getOpt function reads the contents of the server configuration file.

The name parameter must be a path to a specific property in the configuration file. Properties in the configuration file can be accessed by using a special syntax for instance: adapters[0].type allows retrieving the type configuration property from an array of elements. The square brackets allow setting the index position of an element in the array, while dots are used as a separator between sections and properties.

The type parameter controls the data type of the value to be written to the value parameter. Supported data types: GC_OPT_TYPE_NULL (0) - Null type. GC_OPT_TYPE_STRING (1) - String type. GC_OPT_TYPE_UINT64 (2) - Unsigned 64-bit integer. GC_OPT_TYPE_INT (3) - Signed 32-bit integer.

Every type represents a pointer to a value which is assigned to the memory location specified by the value parameter.

The value value parameter represents a pointer to the value. The size of written data depends on type parameter.

EXAMPLE

#include <game-carrier/server.h>

static struct core_api api;

GC_ADAPTER_EVENT
int adapter_initialize(int id, struct core_api *core_api, const void *load_path)
{
    api = *core_api;
    return 0;
}

GC_ADAPTER_EVENT
GCT_INT application_initialize(
    GCT_INT id,
    GCT_CSTR name,
    GCT_CSTR type_name,
    GCT_CSTR file_name)
{
    /* Read apps.len */
    GCT_INT apps_len;
    GCT_INT status = api.getOpt("apps.len", GC_OPT_TYPE_INT, &apps_len);
    if (status != 0) {
        api.logMessage(GCL_ERR, "Config reading failure!");
        return -1;
    }

    char buf[256];
    snprintf (buf, sizeof(buf), "Applications: %d", apps_len);
    api.logMessage(GCL_USER, buf);

    /* Continue application initialization */
    return 0;
}

SEE ALSO

gc_opt_type, gc_cloudflare_inet_proto, gc_cloudflare_mode