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 |
---|---|
This function must not be called more than once. |
Parameters
functionPointers
Callback function pointers. See below.
usedLogTypes
Defines the log output types. The Server Lib can output log messages to a file (located in the logs
directory relative to the server executable), to stdout or to user defined callbacks. If user callbacks are activated, the onUserLoggingMessageEvent
event needs to be implemented.
Available values are defined by the enum LogTypes (see public_definitions.h
):
enum LogTypes { LogType_NONE = 0x0000, LogType_FILE = 0x0001, LogType_CONSOLE = 0x0002, LogType_USERLOGGING = 0x0004, LogType_NO_NETLOGGING = 0x0008, LogType_DATABASE = 0x0010, };
Multiple log types can be combined with a binary OR. If only LogType_NONE
is used, local logging is disabled.
![]() | Note |
---|---|
Logging to console can slow down the application on Windows. Hence we do not recommend to log to the console on Windows other than in debug builds. |
![]() | Note |
---|---|
|
logFileFolder
Location where the logfiles produced if file logging is enabled will be saved to. Pass NULL for the default behaviour, which is to use a folder called logs
in the current working directory.
Returns ERROR_ok
on success, otherwise an error code as defined in public_errors.h
.
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 |
---|---|
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.