NAME

logMessage - Outputs the log message.

SYNOPSIS

#include <game-carrier/server.h>

typedef void (GC_CORE_API *LogMessage)(
    GCT_INT level,
    GCT_PTR msg);

typedef struct logMessage {
    /* ... Some fields ... */
    LogMessage logMessage;
    /* ... Some fields ... */
}

Parameters:

  • level GCT_INT Sets the logging level for a message.
  • msg msg The message to output.

RETURN VALUE

None.

DESCRIPTION

The logMessage function outputs the log message.

The level parameter sets the logging level to determine the severity of logs to be generated. Supported values: GCL_NORMAL, GCL_VERBOSE, GCL_ERR, GCL_WARN, GCL_NOTICE, GCL_INFO, GCL_DEBUG, GCL_USER.

The msg parameter identifies a string value representing the message to output.

EXAMPLE

#include <game-carrier/server.h>

#include <stdlib.h>
#include <string.h>

#define COOKIE_MAGIC  0xFACE

static struct core_api api;

struct connection_data {
    GCT_INTPTR handle;
    /* Another user data asociated with connection */
};

int is_good_connection(GCT_INT rport, GCT_CSTR rip, GCT_CSTR udata);

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_INTPTR on_connect(
    GCT_INT app_id,
    GCT_INTPTR handle,
    GCT_INT pid,
    GCT_CSTR rip,
    GCT_INT rport,
    GCT_CSTR lip,
    GCT_INT lport,
    GCT_CSTR udata)
{
    /* Check if this connection can be accepted */
    if (!is_good_connection(rport, rip, udata)) {
        return GC_DROP_CONNECTION;
    }

    /* Allocate user data */
    struct connection_data * conn = malloc(sizeof(struct connection_data));
    if (conn == NULL) {
        return GC_DROP_CONNECTION;
    }

    /* Save connection handle */
    conn->handle = handle;

    /* Send greetings */
    const char * msg = "Hello!";
    int status = api.connectionAddMessage(handle, msg, strlen(msg), COOKIE_MAGIC);
    if (status != 0) {
        api.logMessage(GCL_ERR, "Failed to send message");
        return GC_DROP_CONNECTION;
    }

    /* Return user data */
    return (GCT_INTPTR)conn;
}

GC_ADAPTER_EVENT
void on_message_sent(
    GCT_INTPTR conn_user,
    GCT_INTPTR cookie,
    GCT_SIZE len,
    GCT_INT status)
{
    if (cookie != COOKIE_MAGIC) {
        api.logMessage(GCL_ERR, "Invalid cookie!");
        return;
    }
}

SEE ALSO

gcl_flags, gcl_level