This is a php file with useful functions for using the Teamspeak Client Query
Its simple like that you include the api.php
//Include the api file for using the functions
include "api.php";
And then you can use all functions
To start the a connection to the Teamspeak Client Query you simply can run the function teamspeak_socket_init and get the return variable
//Include the api file for using the functions
include "api.php";
//Create a connection to the current client query
$ts3clientquery = teamspeak_socket_init();
In the next step you can use this variable to send and receive something from your clientquery data.
In this example we change your nickname for that we need the teamspeak_socket_send function
//Include the api file for using the functions
include "api.php";
//Create a connection to the current client query
$ts3clientquery = teamspeak_socket_init();
/*
Here we use the teamspeak_socket_send function with
clientupdate command and set with parameter client_nickname
the nickname and escape this nickname
with the teamspeak_escape function
*/
echo teamspeak_socket_send($ts3clientquery,"clientupdate client_nickname=".teamspeak_escape("I am Stupid"));
After you send all what you want the best way to end your program is to use the fclose function
//Include the api file for using the functions
include "api.php";
//Create a connection to the current client query
$ts3clientquery = teamspeak_socket_init();
/*
Here we use the teamspeak_socket_send function with
clientupdate command and set with parameter client_nickname
the nickname and escape this nickname
with the teamspeak_escape function
*/
echo teamspeak_socket_send($ts3clientquery,"clientupdate client_nickname=".teamspeak_escape("I am Stupid"));
//Close the clientquery
fclose($ts3clientquery);
teamspeak_socket_init
teamspeak_socket_send
get_teamspeak_param
get_teamspeak_status
teamspeak_getname
teamspeak_escape
teamspeak_socket_init($clientquery_port=25639)
This is a Function that initalize a local socket connection to the teamspeak client query and gets
and echo
the first 3 lines of the response.
clientquery_port
The Client Query must be a Integer. If not set it is using the default port for the clientquery(25639).
This Function return a simple raw socket for a connection to the teamspeak client query.
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Create a connection to the current client query with a custom port
$ts3query = teamspeak_socket_init(12058);
No Changes
teamspeak_socket_send($socket,$command)
This function use the pre initalized socket (teamspeak_socket_init) to send some command to the client query.
socket
The Client Query Socket must be a raw tcp socket connection. I recommend to use the teamspeak_socket_init function, because you maybe get trouble with getting data from the response stream.
command
The Command must be a String without "\n". I recommend to use the tool.php to find out more about the commands.
This Function return the next line of the response after sending the command.
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Send the Command to Change the nickname to "IamStupid"
echo teamspeak_socket_send($ts3query,"clientupdate client_nickname=IamStupid");
No Changes
get_teamspeak_param($name,$teamspeakreturn)
This function is a parameter reader for the default teamspeak client query output.
name
This is the name of the parameter you can take here for a string or a int
teamspeakreturn
This is a line of returned output.
This Function return the value of the name or count of parameter.
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Use the get_teamspeak_param to get the client id(clid) by the int 0(first parameter)
$clid = get_teamspeak_param(0,teamspeak_socket_send($ts3query,"whoami"));
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Use the get_teamspeak_param to get the client id(clid) by the string "clid"
$clid = get_teamspeak_param("clid",teamspeak_socket_send($ts3query,"whoami"));
No Changes
get_teamspeak_status($teamspeakreturn)
This function is a status code reader from the status message output of teamspeak.
teamspeakreturn
This is a line of returned output.
This function return the status code of the status message of teamspeakreturn
or null if teamspeakreturn
is not a status message the function return null
.
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Get a line of the help page
$line = teamspeak_socket_send($ts3query,"help");
//Echo the next line if the current line is not a status line loop
while(get_teamspeak_status($line) == null){
echo $line;
$line = fgets($ts3query);
}
//Close the connection of the ts3query
fclose($ts3query);
No Changes
teamspeak_getname($socket)
This function read the current name of the client.
socket
The Client Query Socket must be a raw tcp socket connection. I recommend to use the teamspeak_socket_init function, because you maybe get trouble with getting data from the response stream.
This function return the current name of the client.
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Echo the current name of the clientquery
echo teamspeak_getname($ts3query);
No Changes
teamspeak_escape($str)
This function escape the value of a parameter value.
str
This variable is a simple string for a value in teamspeak.
This function return the escaped string for
//Create a connection to the current client query
$ts3query = teamspeak_socket_init();
//Change the Client Name to 'I am Stupid'
echo teamspeak_socket_send($ts3query,"clientupdate client_nickname=".teamspeak_escape("I am Stupid"));
commit 39a15a7b14a05d22704e658ee47204ac850e3df9 add the better escaping for | instead of use │ I use \p