Hello World Server

TEAMSPEAK. YOUR VOICE. YOUR WAY.

Hello World

Introduction

This article will guide you through creating your first TeamSpeak SDK server. This Hello World application will be able to host connections for TeamSpeak SDK clients.

Learn how to

  • Initialize the client/server libraries
  • Initialize client audio
  • Start a server
  • Connect to and disconnect from a server
  • Shut down the client/server libraries

Overview of the TeamSpeak SDK architecture

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.

Let’s code

Topics:
  • Initialization of the server library
  • Starting a TeamSpeak SDK server
  • Shutting down the server library

Initialization

Let’s have a look at the server library’s initialization function.
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.

Now we’re ready to initialize the TeamSpeak Server library:

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;
}

Starting a TeamSpeak 3 SDK Server

Now we’re ready to create the TeamSpeak SDK Server.
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;
};

Shutdown

When you’re finished using the TeamSpeak SDK, shut it down: 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.

Congratulations!

You have created your first application using the TeamSpeak SDK and have learned the basics to build upon.