TeamSpeak 3 SDK Create a Channel

Hello World

Introduction

This article will guide you through creating a channel on a TeamSpeak SDK server. This Hello World application will be able to host connections for TeamSpeak SDK clients with a second channel.

Let's code

Topics:

  • Set channel variables
  • Flush channel creation
  • Example Code

Set channel variables

To create a channel, first set the desired channel variables using ts3server_setChannelVariableAsInt and ts3server_setChannelVariableAsString. Pass zero as the channel ID parameter.

unsigned int ts3server_setChannelVariableAsInt(
    uint64 serverID,
    uint64 channelID,
    enum ChannelProperties flag,
    int value);

unsigned int ts3server_setChannelVariableAsString(
    uint64 serverID,
    uint64 channelID,
    enum ChannelProperties flag,
    const char* value);

Flush channel creation

Next send the request to the server by calling ts3server_flushChannelCreation.

unsigned int ts3server_flushChannelCreation(
    uint64 serverID,
    uint64 channelParentID,
    uint64* result);

serverID: ID of the virtual server on which that channel should be created.

channelParentID: ID of the parent channel, if the new channel is to be created as subchannel. Pass zero if the channel should be created as top-level channel.

result: Address of a variable that receives the ID of the newly created channel.

Example Code

Now we're ready to create the channel on our TeamSpeak SDK Server.

First set the channel data:

unsigned int error;
if ((error = ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_NAME, "Test channel name")) != ERROR_ok) { printf("Error setting channel name variable: %d\n", error); }
if ((error = ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_TOPIC, "Test channel topic")) != ERROR_ok) { printf("Error setting channel topic variable: %d\n", error); }
if ((error = ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_DESCRIPTION, "Test channel description")) != ERROR_ok) { printf("Error setting channel description variable: %d\n", error); }
if ((error = ts3server_setChannelVariableAsInt(serverID, 0, CHANNEL_FLAG_PERMANENT, 1)) != ERROR_ok) { printf("Error setting channel flag permanent variable: %d\n", error); }
if ((error = ts3server_setChannelVariableAsInt(serverID, 0, CHANNEL_FLAG_SEMI_PERMANENT, 0)) != ERROR_ok) { printf("Error setting channel semi permanent variable: %d\n", error); }

Then initiate the channel creation:

uint64 server_id;
unsigned int channelID;
unsigned int error;
if ((error = ts3server_flushChannelCreation(serverID, 0, &channelID)) != ERROR_ok)
{
    printf("Error Creating Channel: %d\n", error);
}

Congratulations!

You have created your first channel on a TeamSpeak Server using the TeamSpeak SDK and have learned the basics channel creation.