Creating a Channel

TEAMSPEAK. YOUR VOICE. YOUR WAY.

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;
  // Set channel name
  if ((error = ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_NAME, "Test channel name")) != ERROR_ok) { 
      printf("Error setting channel name variable: %d\n", error); 
  }
  // Set channel topic
  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);
  }

Now we need to decide whether we want the channel to be permanent, semi-permanent or temporary.

// Permanent channel
if ((error = ts3server_setChannelVariableAsInt(serverID, 0, CHANNEL_FLAG_PERMANENT, 1)) != ERROR_ok) {
  printf("Error setting channel flag permanent variable: %d\n", error);
}

To set the channel type to semi permanent use this:

// Semi Permanent channel:
if ((error = ts3server_setChannelVariableAsInt(serverID, 0, CHANNEL_FLAG_SEMI_PERMANENT, 1)) != ERROR_ok) {
    printf("Error setting channel semi permanent variable: %d\n", error);
}

If neither of the above flags are set, the channel will default to be temporary.

Then initiate the channel creation:

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.