Initializing

When starting the server application, initialize the Server Lib with

unsigned int ts3server_initServerLib(functionPointers,  
 usedLogTypes,  
 logFileFolder); 
const struct ServerLibFunctions* functionPointers;
int usedLogTypes;
const char* logFileFolder;
 

[Note]Note

This function must not be called more than once.

Parameters

Returns ERROR_ok on success, otherwise an error code as defined in public_errors.h.

The callback mechanism

The communication from the Server Lib to the server application takes place using callbacks. The server application has to define a series of function pointers using the struct ServerLibFunctions (see serverlib.h). These callbacks are used to let the server application hook into the library and receive notifaction on certain actions.

A callback example in C:

static void my_onClientConnected_callback(uint64 serverID, anyID clientID, uint64 channelID,
                                          unsigned int* removeClientError) {
    printf("Client %u connected on virtual server %u joining channel %u", clientID, serverID, channelID);
}

C++ developers can also use static member functions for the callbacks.

Before calling ts3server_initServerLib, create an instance of struct ServerLibFunctions, initialize all function pointers with NULL and point the structs function pointers to your implemented callback functions:

unsigned int error;

/* Create struct */
ServerLibFunctions slFuncs;

/* Initialize all function pointers with NULL */
memset(&slFuncs, 0, sizeof(struct ServerLibFunctions));

/* Assign those function pointers you implemented */
slFuncs.onVoiceDataEvent           = my_onVoiceDataEvent_callback;
slFuncs.onClientStartTalkingEvent  = my_onClientStartTalkingEvent_callback;
slFuncs.onClientStopTalkingEvent   = my_onClientStopTalkingEvent_callback;
slFuncs.onClientConnected          = my_onClientConnected_callback;
slFuncs.onClientDisconnected       = my_onClientDisconnected_callback;
slFuncs.onClientMoved              = my_onClientMoved_callback;
slFuncs.onChannelCreated           = my_onChannelCreated_callback;
slFuncs.onChannelEdited            = my_onChannelEdited_callback;
slFuncs.onChannelDeleted           = my_onChannelDeleted_callback;
slFuncs.onServerTextMessageEvent   = my_onServerTextMessageEvent_callback;
slFuncs.onChannelTextMessageEvent  = my_onChannelTextMessageEvent_callback;
slFuncs.onUserLoggingMessageEvent  = my_onUserLoggingMessageEvent_callback;
slFuncs.onAccountingErrorEvent     = my_onAccountingErrorEvent_callback;
slFuncs.onCustomPacketEncryptEvent = NULL;  // Not used by your application
slFuncs.onCustomPacketDecryptEvent = NULL;  // Not used by your application

/* Initialize library with callback function pointers */
error = ts3server_initServerLib(&slFuncs, LogType_FILE | LogType_CONSOLE);
if(error != ERROR_ok) {
    printf("Error initializing serverlib: %d\n", error);
    (...)
}
[Important]Important

As long as you initialize unimplemented callbacks with NULL, the Server Lib won't attempt to call those function pointers. However, if you leave unimplemented callbacks undefined, the Server Lib will crash when trying to call them.

The individual callbacks are described in the chapter Events.