The API of the TeamSpeak SDK is written in the C programming language. This allows you to integrate the SDK into various other programming languages including interpreted or bytecode-compiled languages, which all allow interaction with external C API libraries.
The TeamSpeak SDK API includes functions that can be called by your application and callback functions existing inside your code which can be called by the TeamSpeak libraries.
Functions you can call from within your application are prefixed with ts3server_###
: ts3server_initServerLib
, ts3server_createVirtualServer
. These functions can be actively used by your application to trigger TeamSpeak actions such as connecting to a server, switching to another channel, creating new channels, etc.
Callbacks have a naming convention on###
, e.g. onClientConnected
, onClientMoved
. These events are passively called by the TeamSpeak library as notification to your code when certain TeamSpeak actions have occured. For example, when a new channel has been created, onChannelCreated
would be called. When a client moves to another channel, onClientMoved
is called.
See the header serverlib.h for a list of all callbacks and functions. In addition, the included API reference documentation will describe each function and callback in detail.
unsigned int ts3server_initServerLib(const struct ServerLibFunctions* functionPointers, int usedLogTypes, const char* logFileFolder);
Ignoring the other parameters in this example, let’s focus on the function pointers and log types used.
The server library’s initialization takes a ServerLibFunctions instance filled with the callback functions you want to use. Let’s start by creating the struct: struct ServerLibFunctions funcs;
and initializing all callbacks with NULL
: memset(&funcs, 0, sizeof(struct ServerLibFunctions));
. It is sufficient to only assign those callback functions you are using. When adding more callbacks, add those function pointers here.
unsigned int error;
if ((error = ts3server_initServerLib(&funcs, LogType_CONSOLE, NULL)) != ERROR_ok)
{
printf("Error initializing TeamSpeak server library");
return error;
}
That’s it, we’ve finished the initialization code:
struct ServerLibFunctions funcs;
memset(&funcs, 0, sizeof(struct ServerLibFunctions));
unsigned int error;
if ((error = ts3server_initServerLib(&funcs, LogType_CONSOLE, NULL)) != ERROR_ok)
{
printf("Error initializing TeamSpeak server library");
return error;
}
unsigned int ts3server_createVirtualServer(
unsigned int serverPort,
const char* serverIp,
const char* serverName,
const char* serverKeyPair,
unsigned int serverMaxClients,
uint64* result)
uint64 server_id;
unsigned int error;
if((error = ts3server_createVirtualServer(9987, "0.0.0.0, ::", "TeamSpeak SDK Testserver", "", 10, &server_id)) != ERROR_ok) {
return error;
};
unsigned int ts3server_stopVirtualServer(uint64 serverID)
unsigned int ts3server_destroyServerLib();
ts3server_stopVirtualServer(server_id);
ts3server_destroyServerLib();
The stopVirtualServer call must be called for all virtual servers you created before.