Disabling protocol commands

SDK users can opt to disable specific protocol commands in a TeamSpeak server instance, so clients are unable to use these commands. The server can still issue disabled commands by calling the appropriate Server Lib functions.

Commands that can be disabled are described in the ClientCommand enum.

Note

By default all commands are allowed, unless explicitly disabled.

To disable protocol commands for all clients call

unsigned int ts3server_disableClientCommand(int clientCommand)

Prevents clients from performing certain actions. SDK only.

Use this to disable certain features for clients, e.g. deleting channels or moving clients so that the server has authority over these matters and is the only entity who can do so. To disable multiple commands, call this function once for each command you would like to disable for clients.

Parameters:
  • clientCommand – the command to disable. One of the values from the ClientCommand enum

Returns:

An Error code from the Ts3ErrorType enum indicating either success or the failure reason

To disable multiple commands, call this function once per command to disable.

Warning

There is no way to enable commands again once disabled.

To enable all disabled commands again you will have to destroy and initialize the server lib again.

Example

For example, an SDK user may decide that clients should not be able to create channels on a TeamSpeak server and implement this action only on the Server side.

Any client call to ts3client_flushChannelCreation() will be rejected by the server.

 1#include <teamspeak/clientlib.h>
 2#include <teamspeak/serverlib.h>
 3#include <teamspeak/public_definitions.h>
 4#include <teamspeak/public_errors.h>
 5#include <stdio.h> // printf
 6#include <string.h> // memset
 7
 8void onConnect(uint64 schid, int status, unsigned int error) {
 9    if (status == STATUS_CONNECTION_ESTABLISHING) {
10        printf("Creating channel...\n");
11        unsigned int err;
12        if ((err = ts3client_setChannelVariableAsString(schid, 0, CHANNEL_NAME, "TestChannel")) != ERROR_ok) {
13            printf("Failed to set channel variable: 0x%04X\n", err);
14            return;
15        }
16        if ((err = ts3client_setChannelVariableAsInt(schid, 0, CHANNEL_FLAG_PERMANENT, 1)) != ERROR_ok) {
17            printf("Failed to set channel variable: 0x%04X\n", err);
18            return;
19        }
20        if ((err = ts3client_flushChannelCreation(schid, 0, "sdk-channel-create")) != ERROR_ok) {
21            printf("Failed to set channel variable: 0x%04X\n", err);
22            return;
23        }
24    }
25}
26
27void onError(uint64 schid, const char* message, unsigned int error, const char* returnCode, const char* extra) {
28    printf("Connection %llu has error 0x%04X", schid, error);
29    if (returnCode) {
30        printf(" for call %s", returnCode);
31    }
32    printf("\n");
33}
34
35void onChannelCreated(uint64 schid, uint64 channelId, uint64 parentId, anyID invokerId, const char* invokerName, const char* invokerUid) {
36    printf("Channel %llu created by %s as a child of %llu on connection %llu\n", channelId, invokerName, parentId, schid);
37}
38
39int main() {
40    struct ServerLibFunctions sf;
41    memset(&sf, 0, sizeof sf);
42    struct ClientUIFunctions cf;
43    memset(&cf, 0, sizeof cf);
44    cf.onConnectStatusChangeEvent = onConnect;
45    cf.onServerErrorEvent = onError;
46    cf.onNewChannelCreatedEvent = onChannelCreated;
47    unsigned int err = ts3client_initClientLib(&cf, NULL, LogType_NONE, "", "");
48    if (err != ERROR_ok) {
49        printf("Failed to init lib: 0x%04X\n", err);
50        return 1;
51    }
52    if ((err = ts3server_initServerLib(&sf, LogType_NONE, "")) != ERROR_ok) {
53        printf("Failed to init server lib: 0x%04X\n", err);
54        return 2;
55    }
56    ts3server_disableClientCommand(CLIENT_COMMAND_flushChannelCreation);
57    uint64 serverId = 0;
58    if ((err = ts3server_createVirtualServer(9987, "127.0.0.1", "TestServer", NULL, 4, &serverId)) != ERROR_ok) {
59        printf("Failed to create server: 0x%04X\n", err);
60        return 2;
61    }
62
63    uint64 clientTab = 0;
64    ts3client_spawnNewServerConnectionHandler(0, &clientTab);
65
66    char* ident = NULL;
67    ts3client_createIdentity(&ident);
68    if ((err = ts3client_startConnection(clientTab, ident, "127.0.0.1", 9987, "TestUser", NULL, "", "")) != ERROR_ok) {
69        printf("Failed to connect: 0x%04X\n", err);
70        return 1;
71    }
72
73    printf("Press Enter to terminate\n");
74    getchar();
75
76    printf("Terminating...\n");
77    ts3client_stopConnection(clientTab, "bye");
78    ts3server_stopVirtualServer(serverId);
79    ts3client_destroyServerConnectionHandler(clientTab);
80    ts3client_destroyClientLib();
81    ts3server_destroyServerLib();
82
83    return 0;
84}