Creating a new channel
Creating a channel is done in a similar fashion as editing a channel.
First you set all the properties of the channel on channel ID 0 which will indicate that you intend to create a new channel. Use the appropriate function for the property you are setting:
-
unsigned int ts3server_setChannelVariableAsInt(uint64 serverID, uint64 channelID, enum ChannelProperties flag, int value)
set the variable of a channel to a new value.
Call ts3server_flushChannelVariable after having set all variables you need to change.
- Parameters:
serverID – specifies the server the channel is located on
channelID – specifies the channel on which to change the variable
flag – specifies which variable to change. One of the values from the ChannelProperties enum
value – the new value to set
- Returns:
An Error code from the Ts3ErrorType enum indicating either success or the failure reason
-
unsigned int ts3server_setChannelVariableAsUInt64(uint64 serverID, uint64 channelID, enum ChannelProperties flag, uint64 value)
set a channel variable
Call ts3server_flushChannelVariable after having set all variables you need to change.
- Parameters:
serverID – the server on which the channel is located
channelID – the id of the channel to set the variable for
flag – specifies which variable to set. One of the values from the ChannelProperties enum
value – the new value to set
- Returns:
An Error code from the Ts3ErrorType enum indicating either success or the failure reason
-
unsigned int ts3server_setChannelVariableAsString(uint64 serverID, uint64 channelID, enum ChannelProperties flag, const char *value)
Call ts3server_flushChannelVariable after having set all variables you need to change.
- Parameters:
serverID – the server on which the channel is located
channelID – the id of the channel to set the variable for
flag – specifies which variable to set. One of the values from the ChannelProperties enum
value – the new value to set
- Returns:
An Error code from the Ts3ErrorType enum indicating either success or the failure reason
Actually create the channel
To actually create the channel you will then call
-
unsigned int ts3server_flushChannelCreation(uint64 serverID, uint64 channelParentID, uint64 *result)
After setting the channel properties on a new channel, call this function to publish the channel to clients.
- Parameters:
serverID – the server on which to create the channel
channelParentID – the id of the parent channel for the new channel
result – address of a variable to receive the channel id of the newly created channel
- Returns:
An Error code from the Ts3ErrorType enum indicating either success or the failure reason
Note
Once the channel has been created the ServerLibFunctions.onChannelCreated()
callback is called.
Example
Example code to create a channel:
1#define CHECK_ERROR(x) if ((error = x) != ERROR_ok) { goto on_error; }
2
3int createChannel(uint64 serverID, uint64 parentChannelID, const char* name, const char* topic,
4 const char* description, const char* password, int codec, int codecQuality,
5 int maxClients, int familyMaxClients, int order, int perm, int semiperm,
6 int default) {
7 unsigned int error;
8 uint64 newChannelID;
9
10 /* Set channel data, pass 0 as channel ID */
11 CHECK_ERROR(ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_NAME, name));
12 CHECK_ERROR(ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_TOPIC, topic));
13 CHECK_ERROR(ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_DESCRIPTION, description));
14 CHECK_ERROR(ts3server_setChannelVariableAsString(serverID, 0, CHANNEL_PASSWORD, password));
15 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_CODEC, codec));
16 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_CODEC_QUALITY, codecQuality));
17 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_MAXCLIENTS, maxClients));
18 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_MAXFAMILYCLIENTS, familyMaxClients));
19 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_ORDER, order));
20 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_FLAG_PERMANENT, perm));
21 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_FLAG_SEMI_PERMANENT, semiperm));
22 CHECK_ERROR(ts3server_setChannelVariableAsInt (serverID, 0, CHANNEL_FLAG_DEFAULT, default));
23
24 /* Flush changes to server */
25 CHECK_ERROR(ts3server_flushChannelCreation(serverID, parentChannelID, &newChannelID));
26
27 printf("Created new channel with ID: %u\n", newChannelID);
28 return 0; /* Success */
29
30on_error:
31 printf("Error creating channel: %d\n", error);
32 return 1; /* Failure */
33}