NAME

s2sDestroy - close server to server connection.

SYNOPSIS

#include <game-carrier/server.h>

typedef void (GC_CORE_API *S2SDestroy)(
    GCT_INTPTR s2s_handle);

typedef struct s2sDestroy {
    /* ... Some fields ... */
    S2SDestroy s2sDestroy;
    /* ... Some fields ... */
}

Parameters:

  • s2s_handle GCT_INTPTR The client connection handle.

RETURN VALUE

None.

DESCRIPTION

The gc_client_stop function closes a specific active connection established with another Game Carrier server application. It must be called only after successful receiving on_client_connect event.

The s2s_handle parameter represents the client connection handle, which is used to identify a specific connection that must be closed. The handle is returned after the successful connection establishing in on_client_connect event.

After calling s2sDestroy function all messages, added by the s2sAddMessage function, will be sent. At the same time, it will not process any new messages.

There is a possibility of receiving on_client_message events after the successful gc_client_stop call. It happens when a message is received and queued up to be processed by the application, but at that moment the application hasn’t had a chance to handle it yet. In that case, the message will still be processed and the on_client_message event will be triggered, even if gc_client_stop has been called and the connection is being closed.

In case of client library the analogeous function is gc_client_stop.

EXAMPLE

#include <game-carrier/server.h>

#include <stdio.h>

static struct core_api api;

#define STAT_SERVER 1
#define CACHE_SERVER 2

GCT_INT adapter_id;
GCT_INTPTR s2s_stat_handle, s2s_cache_handle;

GC_ADAPTER_EVENT
GCT_INT adapter_initialize(
    GCT_INT id,
    struct core_api * core_api,
    GCT_CPTR load_path)
{
    adapter_id = id;
    api = *core_api;
}

void on_client_connect(GCT_INTPTR conn_user, GCT_INTPTR handle)
{
    if (conn_user == STAT_SERVER) {
        api.logMessage(GCL_NOTICE, "Connected to the stat server");
        s2s_stat_handle = handle;
        api.s2sDestroy(s2s_stat_handle);
        return;
    }

    if (conn_user == CACHE_SERVER) {
        api.logMessage(GCL_NOTICE, "Connected to the cache server");
        s2s_cache_handle = handle;
        api.s2sDestroy(s2s_cache_handle);
        return;
    }

    api.logMessage(GCL_ERR, "??? Connected to an unknown server");
}

void on_client_connection_error(GCT_INTPTR conn_user, GCT_CSTR reason)
{
    char buf[256];

    if (conn_user == STAT_SERVER) {
        snprintf(buf, sizeof(buf), "Failed to connect to the stat server: %s.", reason);
        api.logMessage(GCL_ERR, buf);
        return;
    }

    if (conn_user == CACHE_SERVER) {
        snprintf(buf, sizeof(buf), "Failed to connect to the cache server: %s", reason);
        api.logMessage(GCL_ERR, buf);
        return;
    }

    snprintf(buf, sizeof(buf), "??? Failed to connect to an unknown server: %s", reason);
    api.logMessage(GCL_ERR, buf);
}

void on_client_disconnect(GCT_INTPTR conn_user)
{
    if (conn_user == STAT_SERVER) {
        api.logMessage(GCL_NOTICE, "Disconect from stat server");
        return;
    }

    if (conn_user == CACHE_SERVER) {
        api.logMessage(GCL_NOTICE, "Disconect from cache server");
        return;
    }

    api.logMessage(GCL_ERR, "??? Disconect from unknown server");
}

GC_ADAPTER_EVENT
void application_start(GCT_INT app_id)
{
    int status;

    ClientEvents events;
    events.on_client_connect = on_client_connect;
    events.on_client_connection_error = on_client_connection_error;
    events.on_client_disconnect = on_client_disconnect;

    status = api.s2sCreate(adapter_id, STAT_SERVER, GC_PROTOCOL_WSS, "stat.example.com", 7681, "stat", &events);
    if (status != 0) {
        api.logMessage(GCL_ERR, "Failed to connect to the game server.");
    }

    status = api.s2sCreate(adapter_id, CACHE_SERVER, GC_PROTOCOL_WSS, "cache.example.com", 7681, "cache", &events);
    if (status != 0) {
        api.logMessage(GCL_ERR, "Failed to connect to the lobby server.");
    }
}

SEE ALSO

s2sCreate, on_client_connect, on_client_disconnect