├── LICENSE ├── README.md ├── README_EN.md ├── data └── config.php ├── iconizar.php ├── iconos └── geticonos.php ├── index.php ├── lang ├── en.php ├── es.php ├── loadlang.php └── pl.php ├── libraries └── TeamSpeak3 │ ├── Adapter │ ├── Abstract.php │ ├── Blacklist.php │ ├── Blacklist │ │ └── Exception.php │ ├── Exception.php │ ├── FileTransfer.php │ ├── FileTransfer │ │ └── Exception.php │ ├── ServerQuery.php │ ├── ServerQuery │ │ ├── Event.php │ │ ├── Exception.php │ │ └── Reply.php │ ├── TSDNS.php │ ├── TSDNS │ │ └── Exception.php │ ├── Update.php │ └── Update │ │ └── Exception.php │ ├── Exception.php │ ├── Helper │ ├── Char.php │ ├── Convert.php │ ├── Crypt.php │ ├── Exception.php │ ├── Profiler.php │ ├── Profiler │ │ ├── Exception.php │ │ └── Timer.php │ ├── Signal.php │ ├── Signal │ │ ├── Exception.php │ │ ├── Handler.php │ │ └── Interface.php │ ├── String.php │ └── Uri.php │ ├── Node │ ├── Abstract.php │ ├── Channel.php │ ├── Channelgroup.php │ ├── Client.php │ ├── Exception.php │ ├── Host.php │ ├── Server.php │ └── Servergroup.php │ ├── TeamSpeak3.php │ ├── Transport │ ├── Abstract.php │ ├── Exception.php │ ├── TCP.php │ └── UDP.php │ └── Viewer │ ├── Html.php │ ├── Interface.php │ └── Text.php ├── modulos ├── iconizador.php └── listador.php ├── noty └── js │ ├── jquery.noty.js │ ├── layouts │ ├── bottom.js │ ├── bottomCenter.js │ ├── bottomLeft.js │ ├── bottomRight.js │ ├── center.js │ ├── centerLeft.js │ ├── centerRight.js │ ├── inline.js │ ├── top.js │ ├── topCenter.js │ ├── topLeft.js │ └── topRight.js │ ├── packaged │ ├── jquery.noty.packaged.js │ └── jquery.noty.packaged.min.js │ ├── promise.js │ └── themes │ ├── bootstrap.js │ ├── default.js │ └── relax.js └── procesar.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015-2018 Pedro Arenas and Franco Sanllehi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TS3IconManager 2 | English Version of this file [here](./README_EN.md) 3 | 4 | Manejo de rangos de servidor TeamSpeak3 mediande UID 5 | 6 | Este script permite poder asignarse rangos (basado en el sort_id de los rangos en ts) en base a una UID de manera automatica sin necesidad de un administrador. 7 | 8 | ## Funciones 9 | - Asignar iconos usando UID 10 | - Listado de iconos segun el SORT_ID 11 | - Confirmacion via codigo enviado por POKE en ts3 12 | - Asignacion limpia y ahorrando recursos de la conexion query 13 | - Registro de los cambios realizados (Soon) 14 | - Sistema de idiomas (Actualmente disponible: ES,EN,PL) 15 | 16 | ## Requisitos 17 | - PHP 5.6.4+ o superior (Con modulo Sockets activo) 18 | - Servidor HTTP con soporte PHP (Ejemplo: Apache, Nginx, XAMPP) 19 | 20 | ## Instalacion 21 | - Editar archivo data/config.php 22 | 23 | ## Sync de iconos 24 | - Opcion 1 (Manual): 25 | Este script tiene en la carpeta de "iconos" un archivo PHP el cual debes ejecutar periodicamente segun edites uno u otro rango ya que para ahorrar recursos y para evitar un posible "Banned From Query" los iconos no se descargan automaticamente a menos que se ejecute cada cierto tiempo el archivo geticonos.php. 26 | 27 | - Opcion 2 (CRON): 28 | ```sh 29 | */10 * * * * /usr/bin/php /opt/test.php 30 | ``` 31 | 32 | ## Changelog 33 | [V 1.5] 34 | - Inicio remantencion de proyecto 35 | - Migrar Bootstrap 3 a Bootstrap 4 (Lavado de cara) 36 | - Agregado License 37 | - Actualizacion TS3API 38 | 39 | [V 1.4] 40 | - Ahora los footer muestran la version del script en base a un nuevo parametro en el archivo config.php (Uso del Dev) 41 | - Añadido soporte para usar mas de un SortID group de TS3 42 | - Añadido archivo idioma PL, Aportado por Luki 43 | 44 | [V 1.3] 45 | - Arreglado en archivo (./icons/geticonos.php) el cual tenia un error de lectura del archivo de configuracion. 46 | - Implementado un sistema de idioma, actualmente esta disponible el español y el ingles (Se puede añadir un nuevo idioma usando de base a ./lang/es.php para crear nuevos idiomas). 47 | 48 | [V 1.2] 49 | - Arreglado un warning en ./modulos/iconizar.php el cual al no haber cambios intentaba tomar una variable null. 50 | - Añadido sistema de confirmacion via codigo enviado por poke en ts. 51 | - Correcciones ligeras de codigo. 52 | 53 | ## Permisos TSQuery 54 | Estos permisos son necesarios para que el script funcione correctamente 55 | 56 | | Permiso | Descripcion | 57 | | ------ | ------ | 58 | | b_virtualserver_client_list | Para listar usuarios del servidor | 59 | | b_virtualserver_servergroup_list | Listar los grupos del servidor | 60 | | b_virtualserver_servergroup_client_list | Listar los miembros de dicho grupo | 61 | | i_group_member_add_power | Poder para añadir a un miembro | 62 | | i_group_member_remove_power | Poder para remover a un miembro | 63 | | i_client_poke_power | Poder para enviar poke | 64 | 65 | 66 | License 67 | ---- 68 | 69 | MIT 70 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | # TS3IconManager 2 | Management ranges ts by UID 3 | This little script uses Bootstrap and TS3PHP Framework, this script allows to assign ranges (based on sort_id ranges in ts) based on a UID 4 | 5 | # Functions 6 | 7 | -Assign Icons using UID 8 | 9 | -List Of icons according to the SORT_ID 10 | 11 | -Confirmation Via code sent by POKE in ts3 12 | 13 | -Assigning Clean and saving resources of the connection query 14 | 15 | -Record Changes (Soon) 16 | 17 | -System Languages (ES,EN,PL) 18 | 19 | #Requisites 20 | -Support PHP5 21 | -WebHost whit socket connection (Recommend Linux WebHost) 22 | 23 | 24 | # Installation 25 | You just have to edit the file (data / config.php) to use the script without any problem. 26 | 27 | # Sync icons 28 | This script is in the folder "icons" a PHP file which should run periodically according to editing one or another range as to save resources and to avoid a possible "Banned From Query" icons are not automatically downloaded unless run every so often the geticonos.php file 29 | 30 | # Changelog 31 | [V 1.4] 32 | -Now the footer shows the version of the script based on a new parameter in config.php file (Using Dev) 33 | 34 | -Added support for using more than one group of TS3 SortID 35 | 36 | -Added File language PL, Contributed by Luki 37 | 38 | [V 1.3] 39 | 40 | -Fixed File (./icons/geticonos.php) which had an error reading configuration file. 41 | 42 | -implemented Language system currently available in Spanish and English (To add a new language using ./lang/es.php basis for creating new languages). 43 | 44 | [V 1.2] 45 | 46 | -Fixed One warning in ./modulos/iconizar.php which by no change was trying to take a null variable. 47 | 48 | -Added Confirmation system via code sent by poke in ts. 49 | 50 | -Correcciones Of code. 51 | 52 | # Connection permissions for the query 53 | Below the permissions that you must have the account used in the query connection is ready. 54 | 55 | -b_virtualserver_client_list || Para listar usuarios del servidor 56 | 57 | -b_virtualserver_servergroup_list || Listar los grupos del servidor 58 | 59 | -b_virtualserver_servergroup_client_list || Listar los miembros de dicho grupo 60 | 61 | -i_group_member_add_power || Poder para añadir a un miembro 62 | 63 | -i_group_member_remove_power || Poder para remover a un miembro 64 | 65 | -i_client_poke_power || Poder para enviar poke 66 | 67 | License 68 | ---- 69 | 70 | MIT 71 | -------------------------------------------------------------------------------- /data/config.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | $script_version = "V1.5"; 10 | 11 | /* Configuracion de conexion query hacia TS3 */ 12 | $HOST_QUERY = "localhost"; //HOST:QUERY_PORT Que usa tu servidor de ts3 13 | $PORT_QUERY = "10011"; //Puerto de query por default es 10011 14 | $USER_QUERY = "QUERYUSER"; //Usuario de conexion a query 15 | $PASS_QUERY = "QUERYPASS"; //Clave generada para a conexion query 16 | $SERVER_PORT = "9987"; //Puerto del servidor ts3 17 | 18 | /* Configuracion de variables Front-end */ 19 | $NAME_TITLE = 'Manager TS3'; //Titulo principal de la web 20 | $IDIOMA = "ES"; // (Options: en, es) Idioma de ejecucion 21 | $SID_GROUP = array(75); //SORT_ID del grupo que sera listado Example array(1,2,3,4,5) 22 | $NICK_QUERY = "AdminSystem"; //Nickname de la conexion query 23 | $MAX_ICONS = 8; //Maximo de iconos seleccionar 24 | $DEBUG = false; //Activa los mensajes de error detallados 25 | -------------------------------------------------------------------------------- /iconizar.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | include './data/config.php'; //Importamos la configuracion 10 | include './lang/loadlang.php'; 11 | ?> 12 | 13 | 15 | 16 | 17 | <?= $NAME_TITLE ?> | TS3 Icons 18 | 19 | 20 | 21 | 22 | 23 | 24 |


25 |
26 |
27 |
28 |

29 |
30 | 31 |
32 |
33 |
34 |
35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /iconos/geticonos.php: -------------------------------------------------------------------------------- 1 | "; 7 | $connect = "serverquery://".$USER_QUERY.":".$PASS_QUERY."@".$HOST_QUERY.":".$PORT_QUERY."/?server_port=".$SERVER_PORT.""; 8 | $ts3_VirtualServer = TeamSpeak3::factory($connect); 9 | $server_groups = $ts3_VirtualServer->serverGroupList(); 10 | $servergroups = array(); 11 | foreach($server_groups as $group) { 12 | if($group->type != 1) { continue; } 13 | if(in_array($group["sortid"], $SID_GROUP)) { 14 | $servergroups[] = array('name' => (string)$group, 'id' => $group->sgid, 'type' => $group->type, 'icon' => $group->iconDownload() ); 15 | } 16 | } 17 | echo "Iniciando Descarga de iconos...
"; 18 | if (!file_exists('./icons/')) { 19 | mkdir('./icons/', 0777, true); 20 | } 21 | foreach($servergroups as $group) { 22 | file_put_contents("./icons/" . $group['id'] . ".png", $group['icon']); 23 | echo "Archivo iconos/icons/" . $group['id'] . ".png" . " Creado para el grupo " . $group['name'] . "
"; 24 | 25 | } 26 | 27 | } catch(Exception $e) { 28 | if($DEBUG == True) { 29 | echo "[DEBUG] Ha ocurrido un error inesperado
"; 30 | echo "[DEBUG] Mensaje de error DEBUG: ".$e->getMessage()."
"; 31 | echo "[DEBUG] El codigo de error fue ".$e->getCode()."
"; 32 | } 33 | echo "ERROR: ".$e->getMessage(); 34 | if($e->getCode() == 0) 35 | { 36 | echo "Error desconocido. Metodo invalido"; 37 | } else if($e->getCode() == 10060) { //Codigo de error de error en la conexion 38 | echo "No se pudo conectar con el servidor de teamspeak 3"; 39 | } else if($e->getCode() == 512) { //Codigo de error cuando la UUID no es valida 40 | echo "La UUID ingresada no es valida o no esta actualmente conectada al ts3"; 41 | } else if($e->getCode() == 520) { //Codigo de error cuando login o pass estan mal 42 | echo "Los datos de acceso query no son correctos"; 43 | } else if($e->getCode() == 3329) { //Codigo de error cuando la conexion fue baneada por el tsquery 44 | echo "La conexion fue baneada por query. Intenta mas tarde"; 45 | } 46 | } 47 | ?> 48 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | include './data/config.php'; 10 | include './lang/loadlang.php'; 11 | ?> 12 | 13 | 15 | 16 | 17 | <?= $NAME_TITLE ?> | TS3 Icons 18 | 19 | 20 | 21 | 22 | 23 | 24 |








25 |
26 |
27 |
28 |

29 |

30 |
31 |
32 |
33 |
34 | 35 |
36 |
37 |
38 | 39 |
40 |
41 | 42 | 58 |
59 |
60 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /lang/en.php: -------------------------------------------------------------------------------- 1 | 34 | -------------------------------------------------------------------------------- /lang/es.php: -------------------------------------------------------------------------------- 1 | 34 | -------------------------------------------------------------------------------- /lang/loadlang.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | include './data/config.php'; 10 | include './lang/'.$IDIOMA.'.php'; 11 | 12 | ?> 13 | -------------------------------------------------------------------------------- /lang/pl.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Abstract.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_Abstract 30 | * @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server. 31 | */ 32 | abstract class TeamSpeak3_Adapter_Abstract 33 | { 34 | /** 35 | * Stores user-provided options. 36 | * 37 | * @var array 38 | */ 39 | protected $options = null; 40 | 41 | /** 42 | * Stores an TeamSpeak3_Transport_Abstract object. 43 | * 44 | * @var TeamSpeak3_Transport_Abstract 45 | */ 46 | protected $transport = null; 47 | 48 | /** 49 | * The TeamSpeak3_Adapter_Abstract constructor. 50 | * 51 | * @param array $options 52 | * @return TeamSpeak3_Adapter_Abstract 53 | */ 54 | public function __construct(array $options) 55 | { 56 | $this->options = $options; 57 | 58 | if($this->transport === null) 59 | { 60 | $this->syn(); 61 | } 62 | } 63 | 64 | /** 65 | * The TeamSpeak3_Adapter_Abstract destructor. 66 | * 67 | * @return void 68 | */ 69 | abstract public function __destruct(); 70 | 71 | /** 72 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 73 | * server. 74 | * 75 | * @throws TeamSpeak3_Adapter_Exception 76 | * @return void 77 | */ 78 | abstract protected function syn(); 79 | 80 | /** 81 | * Commit pending data. 82 | * 83 | * @return array 84 | */ 85 | public function __sleep() 86 | { 87 | return array("options"); 88 | } 89 | 90 | /** 91 | * Reconnects to the remote server. 92 | * 93 | * @return void 94 | */ 95 | public function __wakeup() 96 | { 97 | $this->syn(); 98 | } 99 | 100 | /** 101 | * Returns the profiler timer used for this connection adapter. 102 | * 103 | * @return TeamSpeak3_Helper_Profiler_Timer 104 | */ 105 | public function getProfiler() 106 | { 107 | return TeamSpeak3_Helper_Profiler::get(spl_object_hash($this)); 108 | } 109 | 110 | /** 111 | * Returns the transport object used for this connection adapter. 112 | * 113 | * @return TeamSpeak3_Transport_Abstract 114 | */ 115 | public function getTransport() 116 | { 117 | return $this->transport; 118 | } 119 | 120 | /** 121 | * Loads the transport object object used for the connection adapter and passes a given set 122 | * of options. 123 | * 124 | * @param array $options 125 | * @param string $transport 126 | * @throws TeamSpeak3_Adapter_Exception 127 | * @return void 128 | */ 129 | protected function initTransport($options, $transport = "TeamSpeak3_Transport_TCP") 130 | { 131 | if(!is_array($options)) 132 | { 133 | throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array"); 134 | } 135 | 136 | $this->transport = new $transport($options); 137 | } 138 | 139 | /** 140 | * Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object 141 | * is connected to. 142 | * 143 | * @return string 144 | */ 145 | public function getTransportHost() 146 | { 147 | return $this->getTransport()->getConfig("host", "0.0.0.0"); 148 | } 149 | 150 | /** 151 | * Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object 152 | * is connected to. 153 | * 154 | * @return string 155 | */ 156 | public function getTransportPort() 157 | { 158 | return $this->getTransport()->getConfig("port", "0"); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Blacklist.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_Blacklist 30 | * @brief Provides methods to check if an IP address is currently blacklisted. 31 | */ 32 | class TeamSpeak3_Adapter_Blacklist extends TeamSpeak3_Adapter_Abstract 33 | { 34 | /** 35 | * The IPv4 address or FQDN of the TeamSpeak Systems update server. 36 | * 37 | * @var string 38 | */ 39 | protected $default_host = "blacklist.teamspeak.com"; 40 | 41 | /** 42 | * The UDP port number of the TeamSpeak Systems update server. 43 | * 44 | * @var integer 45 | */ 46 | protected $default_port = 17385; 47 | 48 | /** 49 | * Stores an array containing the latest build numbers. 50 | * 51 | * @var array 52 | */ 53 | protected $build_numbers = null; 54 | 55 | /** 56 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 57 | * server. 58 | * 59 | * @return void 60 | */ 61 | public function syn() 62 | { 63 | if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host; 64 | if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 65 | 66 | $this->initTransport($this->options, "TeamSpeak3_Transport_UDP"); 67 | $this->transport->setAdapter($this); 68 | 69 | TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 70 | 71 | TeamSpeak3_Helper_Signal::getInstance()->emit("blacklistConnected", $this); 72 | } 73 | 74 | /** 75 | * The TeamSpeak3_Adapter_Blacklist destructor. 76 | * 77 | * @return void 78 | */ 79 | public function __destruct() 80 | { 81 | if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 82 | { 83 | $this->getTransport()->disconnect(); 84 | } 85 | } 86 | 87 | /** 88 | * Returns TRUE if a specified $host IP address is currently blacklisted. 89 | * 90 | * @param string $host 91 | * @throws TeamSpeak3_Adapter_Blacklist_Exception 92 | * @return boolean 93 | */ 94 | public function isBlacklisted($host) 95 | { 96 | if(ip2long($host) === FALSE) 97 | { 98 | $addr = gethostbyname($host); 99 | 100 | if($addr == $host) 101 | { 102 | throw new TeamSpeak3_Adapter_Blacklist_Exception("unable to resolve IPv4 address (" . $host . ")"); 103 | } 104 | 105 | $host = $addr; 106 | } 107 | 108 | $this->getTransport()->send("ip4:" . $host); 109 | $repl = $this->getTransport()->read(1); 110 | $this->getTransport()->disconnect(); 111 | 112 | if(!count($repl)) 113 | { 114 | return FALSE; 115 | } 116 | 117 | return ($repl->toInt()) ? FALSE : TRUE; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Blacklist/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_Blacklist_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_Blacklist objects. 31 | */ 32 | class TeamSpeak3_Adapter_Blacklist_Exception extends TeamSpeak3_Adapter_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_Abstract objects. 31 | */ 32 | class TeamSpeak3_Adapter_Exception extends TeamSpeak3_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/FileTransfer.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_FileTransfer 30 | * @brief Provides low-level methods for file transfer communication with a TeamSpeak 3 Server. 31 | */ 32 | class TeamSpeak3_Adapter_FileTransfer extends TeamSpeak3_Adapter_Abstract 33 | { 34 | /** 35 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 36 | * server. 37 | * 38 | * @throws TeamSpeak3_Adapter_Exception 39 | * @return void 40 | */ 41 | public function syn() 42 | { 43 | $this->initTransport($this->options); 44 | $this->transport->setAdapter($this); 45 | 46 | TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 47 | 48 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferConnected", $this); 49 | } 50 | 51 | /** 52 | * The TeamSpeak3_Adapter_FileTransfer destructor. 53 | * 54 | * @return void 55 | */ 56 | public function __destruct() 57 | { 58 | if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 59 | { 60 | $this->getTransport()->disconnect(); 61 | } 62 | } 63 | 64 | /** 65 | * Sends a valid file transfer key to the server to initialize the file transfer. 66 | * 67 | * @param string $ftkey 68 | * @throws TeamSpeak3_Adapter_FileTransfer_Exception 69 | * @return void 70 | */ 71 | protected function init($ftkey) 72 | { 73 | if(strlen($ftkey) != 32) 74 | { 75 | throw new TeamSpeak3_Adapter_FileTransfer_Exception("invalid file transfer key format"); 76 | } 77 | 78 | $this->getProfiler()->start(); 79 | $this->getTransport()->send($ftkey); 80 | 81 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferHandshake", $this); 82 | } 83 | 84 | /** 85 | * Sends the content of a file to the server. 86 | * 87 | * @param string $ftkey 88 | * @param integer $seek 89 | * @param string $data 90 | * @throws TeamSpeak3_Adapter_FileTransfer_Exception 91 | * @return void 92 | */ 93 | public function upload($ftkey, $seek, $data) 94 | { 95 | $this->init($ftkey); 96 | 97 | $size = strlen($data); 98 | $seek = intval($seek); 99 | $pack = 4096; 100 | 101 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadStarted", $ftkey, $seek, $size); 102 | 103 | for(;$seek < $size;) 104 | { 105 | $rest = $size-$seek; 106 | $pack = $rest < $pack ? $rest : $pack; 107 | $buff = substr($data, $seek, $pack); 108 | $seek = $seek+$pack; 109 | 110 | $this->getTransport()->send($buff); 111 | 112 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadProgress", $ftkey, $seek, $size); 113 | } 114 | 115 | $this->getProfiler()->stop(); 116 | 117 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadFinished", $ftkey, $seek, $size); 118 | 119 | if($seek < $size) 120 | { 121 | throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file upload (" . $seek . " of " . $size . " bytes)"); 122 | } 123 | } 124 | 125 | /** 126 | * Returns the content of a downloaded file as a TeamSpeak3_Helper_String object. 127 | * 128 | * @param string $ftkey 129 | * @param integer $size 130 | * @param boolean $passthru 131 | * @throws TeamSpeak3_Adapter_FileTransfer_Exception 132 | * @return TeamSpeak3_Helper_String 133 | */ 134 | public function download($ftkey, $size, $passthru = FALSE) 135 | { 136 | $this->init($ftkey); 137 | 138 | if($passthru) 139 | { 140 | return $this->passthru($size); 141 | } 142 | 143 | $buff = new TeamSpeak3_Helper_String(""); 144 | $size = intval($size); 145 | $pack = 4096; 146 | 147 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadStarted", $ftkey, count($buff), $size); 148 | 149 | for($seek = 0;$seek < $size;) 150 | { 151 | $rest = $size-$seek; 152 | $pack = $rest < $pack ? $rest : $pack; 153 | $data = $this->getTransport()->read($rest < $pack ? $rest : $pack); 154 | $seek = $seek+$pack; 155 | 156 | $buff->append($data); 157 | 158 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size); 159 | } 160 | 161 | $this->getProfiler()->stop(); 162 | 163 | TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size); 164 | 165 | if(strlen($buff) != $size) 166 | { 167 | throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)"); 168 | } 169 | 170 | return $buff; 171 | } 172 | 173 | /** 174 | * Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru() 175 | * function. 176 | * 177 | * @param integer $size 178 | * @throws TeamSpeak3_Adapter_FileTransfer_Exception 179 | * @return void 180 | */ 181 | protected function passthru($size) 182 | { 183 | $buff_size = fpassthru($this->getTransport()->getStream()); 184 | 185 | if($buff_size != $size) 186 | { 187 | throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . intval($buff_size) . " of " . $size . " bytes)"); 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/FileTransfer/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_FileTransfer_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects. 31 | */ 32 | class TeamSpeak3_Adapter_FileTransfer_Exception extends TeamSpeak3_Adapter_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/ServerQuery.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_ServerQuery 30 | * @brief Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server. 31 | */ 32 | class TeamSpeak3_Adapter_ServerQuery extends TeamSpeak3_Adapter_Abstract 33 | { 34 | /** 35 | * Stores a singleton instance of the active TeamSpeak3_Node_Host object. 36 | * 37 | * @var TeamSpeak3_Node_Host 38 | */ 39 | protected $host = null; 40 | 41 | /** 42 | * Stores the timestamp of the last command. 43 | * 44 | * @var integer 45 | */ 46 | protected $timer = null; 47 | 48 | /** 49 | * Number of queries executed on the server. 50 | * 51 | * @var integer 52 | */ 53 | protected $count = 0; 54 | 55 | /** 56 | * Stores an array with unsupported commands. 57 | * 58 | * @var array 59 | */ 60 | protected $block = array("help"); 61 | 62 | /** 63 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 64 | * server. 65 | * 66 | * @throws TeamSpeak3_Adapter_Exception 67 | * @return void 68 | */ 69 | protected function syn() 70 | { 71 | $this->initTransport($this->options); 72 | $this->transport->setAdapter($this); 73 | 74 | TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 75 | 76 | if(!$this->getTransport()->readLine()->startsWith(TeamSpeak3::READY)) 77 | { 78 | throw new TeamSpeak3_Adapter_Exception("invalid reply from the server"); 79 | } 80 | 81 | TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryConnected", $this); 82 | } 83 | 84 | /** 85 | * The TeamSpeak3_Adapter_ServerQuery destructor. 86 | * 87 | * @return void 88 | */ 89 | public function __destruct() 90 | { 91 | if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->transport->isConnected()) 92 | { 93 | try 94 | { 95 | $this->request("quit"); 96 | } 97 | catch(Exception $e) 98 | { 99 | return; 100 | } 101 | } 102 | } 103 | 104 | /** 105 | * Sends a prepared command to the server and returns the result. 106 | * 107 | * @param string $cmd 108 | * @param boolean $throw 109 | * @throws TeamSpeak3_Adapter_Exception 110 | * @return TeamSpeak3_Adapter_ServerQuery_Reply 111 | */ 112 | public function request($cmd, $throw = TRUE) 113 | { 114 | $query = TeamSpeak3_Helper_String::factory($cmd)->section(TeamSpeak3::SEPARATOR_CELL); 115 | 116 | if(strstr($cmd, "\r") || strstr($cmd, "\n")) 117 | { 118 | throw new TeamSpeak3_Adapter_Exception("illegal characters in command '" . $query . "'"); 119 | } 120 | elseif(in_array($query, $this->block)) 121 | { 122 | throw new TeamSpeak3_Adapter_ServerQuery_Exception("command not found", 0x100); 123 | } 124 | 125 | TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandStarted", $cmd); 126 | 127 | $this->getProfiler()->start(); 128 | $this->getTransport()->sendLine($cmd); 129 | $this->timer = time(); 130 | $this->count++; 131 | 132 | $rpl = array(); 133 | 134 | do { 135 | $str = $this->getTransport()->readLine(); 136 | $rpl[] = $str; 137 | } while($str instanceof TeamSpeak3_Helper_String && $str->section(TeamSpeak3::SEPARATOR_CELL) != TeamSpeak3::ERROR); 138 | 139 | $this->getProfiler()->stop(); 140 | 141 | $reply = new TeamSpeak3_Adapter_ServerQuery_Reply($rpl, $cmd, $this->getHost(), $throw); 142 | 143 | TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply); 144 | 145 | return $reply; 146 | } 147 | 148 | /** 149 | * Waits for the server to send a notification message and returns the result. 150 | * 151 | * @throws TeamSpeak3_Adapter_Exception 152 | * @return TeamSpeak3_Adapter_ServerQuery_Event 153 | */ 154 | public function wait() 155 | { 156 | if($this->getTransport()->getConfig("blocking")) 157 | { 158 | throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode"); 159 | } 160 | 161 | do { 162 | $evt = $this->getTransport()->readLine(); 163 | } while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT)); 164 | 165 | return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost()); 166 | } 167 | 168 | /** 169 | * Uses given parameters and returns a prepared ServerQuery command. 170 | * 171 | * @param string $cmd 172 | * @param array $params 173 | * @return string 174 | */ 175 | public function prepare($cmd, array $params = array()) 176 | { 177 | $args = array(); 178 | $cells = array(); 179 | 180 | foreach($params as $ident => $value) 181 | { 182 | $ident = is_numeric($ident) ? "" : strtolower($ident) . TeamSpeak3::SEPARATOR_PAIR; 183 | 184 | if(is_array($value)) 185 | { 186 | $value = array_values($value); 187 | 188 | for($i = 0; $i < count($value); $i++) 189 | { 190 | if($value[$i] === null) continue; 191 | elseif($value[$i] === FALSE) $value[$i] = 0x00; 192 | elseif($value[$i] === TRUE) $value[$i] = 0x01; 193 | elseif($value[$i] instanceof TeamSpeak3_Node_Abstract) $value[$i] = $value[$i]->getId(); 194 | 195 | $cells[$i][] = $ident . TeamSpeak3_Helper_String::factory($value[$i])->escape()->toUtf8(); 196 | } 197 | } 198 | else 199 | { 200 | if($value === null) continue; 201 | elseif($value === FALSE) $value = 0x00; 202 | elseif($value === TRUE) $value = 0x01; 203 | elseif($value instanceof TeamSpeak3_Node_Abstract) $value = $value->getId(); 204 | 205 | $args[] = $ident . TeamSpeak3_Helper_String::factory($value)->escape()->toUtf8(); 206 | } 207 | } 208 | 209 | foreach(array_keys($cells) as $ident) $cells[$ident] = implode(TeamSpeak3::SEPARATOR_CELL, $cells[$ident]); 210 | 211 | if(count($args)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_CELL, $args); 212 | if(count($cells)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_LIST, $cells); 213 | 214 | return trim($cmd); 215 | } 216 | 217 | /** 218 | * Returns the timestamp of the last command. 219 | * 220 | * @return integer 221 | */ 222 | public function getQueryLastTimestamp() 223 | { 224 | return $this->timer; 225 | } 226 | 227 | /** 228 | * Returns the number of queries executed on the server. 229 | * 230 | * @return integer 231 | */ 232 | public function getQueryCount() 233 | { 234 | return $this->count; 235 | } 236 | 237 | /** 238 | * Returns the total runtime of all queries. 239 | * 240 | * @return mixed 241 | */ 242 | public function getQueryRuntime() 243 | { 244 | return $this->getProfiler()->getRuntime(); 245 | } 246 | 247 | /** 248 | * Returns the TeamSpeak3_Node_Host object of the current connection. 249 | * 250 | * @return TeamSpeak3_Node_Host 251 | */ 252 | public function getHost() 253 | { 254 | if($this->host === null) 255 | { 256 | $this->host = new TeamSpeak3_Node_Host($this); 257 | } 258 | 259 | return $this->host; 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/ServerQuery/Event.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_ServerQuery_Event 30 | * @brief Provides methods to analyze and format a ServerQuery event. 31 | */ 32 | class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess 33 | { 34 | /** 35 | * Stores the event type. 36 | * 37 | * @var TeamSpeak3_Helper_String 38 | */ 39 | protected $type = null; 40 | 41 | /** 42 | * Stores the event data. 43 | * 44 | * @var array 45 | */ 46 | protected $data = null; 47 | 48 | /** 49 | * Stores the event data as an unparsed string. 50 | * 51 | * @var TeamSpeak3_Helper_String 52 | */ 53 | protected $mesg = null; 54 | 55 | /** 56 | * Creates a new TeamSpeak3_Adapter_ServerQuery_Event object. 57 | * 58 | * @param TeamSpeak3_Helper_String $evt 59 | * @param TeamSpeak3_Node_Host $con 60 | * @throws TeamSpeak3_Adapter_Exception 61 | * @return TeamSpeak3_Adapter_ServerQuery_Event 62 | */ 63 | public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null) 64 | { 65 | if(!$evt->startsWith(TeamSpeak3::EVENT)) 66 | { 67 | throw new TeamSpeak3_Adapter_Exception("invalid notification event format"); 68 | } 69 | 70 | list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2); 71 | 72 | if(empty($data)) 73 | { 74 | throw new TeamSpeak3_Adapter_Exception("invalid notification event data"); 75 | } 76 | 77 | $fake = new TeamSpeak3_Helper_String(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok"); 78 | $repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type); 79 | 80 | $this->type = $type->substr(strlen(TeamSpeak3::EVENT)); 81 | $this->data = $repl->toList(); 82 | $this->mesg = $data; 83 | 84 | TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con); 85 | TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con); 86 | } 87 | 88 | /** 89 | * Returns the event type string. 90 | * 91 | * @return TeamSpeak3_Helper_String 92 | */ 93 | public function getType() 94 | { 95 | return $this->type; 96 | } 97 | 98 | /** 99 | * Returns the event data array. 100 | * 101 | * @return array 102 | */ 103 | public function getData() 104 | { 105 | return $this->data; 106 | } 107 | 108 | /** 109 | * Returns the event data as an unparsed string. 110 | * 111 | * @return TeamSpeak3_Helper_String 112 | */ 113 | public function getMessage() 114 | { 115 | return $this->mesg; 116 | } 117 | 118 | /** 119 | * @ignore 120 | */ 121 | public function offsetExists($offset) 122 | { 123 | return array_key_exists($offset, $this->data) ? TRUE : FALSE; 124 | } 125 | 126 | /** 127 | * @ignore 128 | */ 129 | public function offsetGet($offset) 130 | { 131 | if(!$this->offsetExists($offset)) 132 | { 133 | throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602); 134 | } 135 | 136 | return $this->data[$offset]; 137 | } 138 | 139 | /** 140 | * @ignore 141 | */ 142 | public function offsetSet($offset, $value) 143 | { 144 | throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only"); 145 | } 146 | 147 | /** 148 | * @ignore 149 | */ 150 | public function offsetUnset($offset) 151 | { 152 | unset($this->data[$offset]); 153 | } 154 | 155 | /** 156 | * @ignore 157 | */ 158 | public function __get($offset) 159 | { 160 | return $this->offsetGet($offset); 161 | } 162 | 163 | /** 164 | * @ignore 165 | */ 166 | public function __set($offset, $value) 167 | { 168 | $this->offsetSet($offset, $value); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/ServerQuery/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_ServerQuery_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects. 31 | */ 32 | class TeamSpeak3_Adapter_ServerQuery_Exception extends TeamSpeak3_Adapter_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/ServerQuery/Reply.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_ServerQuery_Reply 30 | * @brief Provides methods to analyze and format a ServerQuery reply. 31 | */ 32 | class TeamSpeak3_Adapter_ServerQuery_Reply 33 | { 34 | /** 35 | * Stores the command used to get this reply. 36 | * 37 | * @var TeamSpeak3_Helper_String 38 | */ 39 | protected $cmd = null; 40 | 41 | /** 42 | * Stores the servers reply (if available). 43 | * 44 | * @var TeamSpeak3_Helper_String 45 | */ 46 | protected $rpl = null; 47 | 48 | /** 49 | * Stores connected TeamSpeak3_Node_Host object. 50 | * 51 | * @var TeamSpeak3_Node_Host 52 | */ 53 | protected $con = null; 54 | 55 | /** 56 | * Stores an assoc array containing the error info for this reply. 57 | * 58 | * @var array 59 | */ 60 | protected $err = array(); 61 | 62 | /** 63 | * Sotres an array of events that occured before or during this reply. 64 | * 65 | * @var array 66 | */ 67 | protected $evt = array(); 68 | 69 | /** 70 | * Indicates whether exceptions should be thrown or not. 71 | * 72 | * @var boolean 73 | */ 74 | protected $exp = TRUE; 75 | 76 | /** 77 | * Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object. 78 | * 79 | * @param array $rpl 80 | * @param string $cmd 81 | * @param boolean $exp 82 | * @param TeamSpeak3_Node_Host $con 83 | * @return TeamSpeak3_Adapter_ServerQuery_Reply 84 | */ 85 | public function __construct(array $rpl, $cmd = null, TeamSpeak3_Node_Host $con = null, $exp = TRUE) 86 | { 87 | $this->cmd = new TeamSpeak3_Helper_String($cmd); 88 | $this->con = $con; 89 | $this->exp = (bool) $exp; 90 | 91 | $this->fetchError(array_pop($rpl)); 92 | $this->fetchReply($rpl); 93 | } 94 | 95 | /** 96 | * Returns the reply as an TeamSpeak3_Helper_String object. 97 | * 98 | * @return TeamSpeak3_Helper_String 99 | */ 100 | public function toString() 101 | { 102 | return (!func_num_args()) ? $this->rpl->unescape() : $this->rpl; 103 | } 104 | 105 | /** 106 | * Returns the reply as a standard PHP array where each element represents one item. 107 | * 108 | * @return array 109 | */ 110 | public function toLines() 111 | { 112 | if(!count($this->rpl)) return array(); 113 | 114 | $list = $this->toString(0)->split(TeamSpeak3::SEPARATOR_LIST); 115 | 116 | if(!func_num_args()) 117 | { 118 | for($i = 0; $i < count($list); $i++) $list[$i]->unescape(); 119 | } 120 | 121 | return $list; 122 | } 123 | 124 | /** 125 | * Returns the reply as a standard PHP array where each element represents one item in table format. 126 | * 127 | * @return array 128 | */ 129 | public function toTable() 130 | { 131 | $table = array(); 132 | 133 | foreach($this->toLines(0) as $cells) 134 | { 135 | $pairs = $cells->split(TeamSpeak3::SEPARATOR_CELL); 136 | 137 | if(!func_num_args()) 138 | { 139 | for($i = 0; $i < count($pairs); $i++) $pairs[$i]->unescape(); 140 | } 141 | 142 | $table[] = $pairs; 143 | } 144 | 145 | return $table; 146 | } 147 | 148 | /** 149 | * Returns a multi-dimensional array containing the reply splitted in multiple rows and columns. 150 | * 151 | * @return array 152 | */ 153 | public function toArray() 154 | { 155 | $array = array(); 156 | $table = $this->toTable(1); 157 | 158 | for($i = 0; $i < count($table); $i++) 159 | { 160 | foreach($table[$i] as $pair) 161 | { 162 | if(!count($pair)) 163 | { 164 | continue; 165 | } 166 | 167 | if(!$pair->contains(TeamSpeak3::SEPARATOR_PAIR)) 168 | { 169 | $array[$i][$pair->toString()] = null; 170 | } 171 | else 172 | { 173 | list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR, 2); 174 | 175 | $array[$i][$ident->toString()] = $value->isInt() ? $value->toInt() : (!func_num_args() ? $value->unescape() : $value); 176 | } 177 | } 178 | } 179 | 180 | return $array; 181 | } 182 | 183 | /** 184 | * Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns. 185 | * The identifier specified by key will be used while indexing the array. 186 | * 187 | * @param $key 188 | * @return array 189 | */ 190 | public function toAssocArray($ident) 191 | { 192 | $nodes = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray(); 193 | $array = array(); 194 | 195 | foreach($nodes as $node) 196 | { 197 | if(isset($node[$ident])) 198 | { 199 | $array[(is_object($node[$ident])) ? $node[$ident]->toString() : $node[$ident]] = $node; 200 | } 201 | else 202 | { 203 | throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602); 204 | } 205 | } 206 | 207 | return $array; 208 | } 209 | 210 | /** 211 | * Returns an array containing the reply splitted in multiple rows and columns. 212 | * 213 | * @return array 214 | */ 215 | public function toList() 216 | { 217 | $array = func_num_args() ? $this->toArray(1) : $this->toArray(); 218 | 219 | if(count($array) == 1) 220 | { 221 | return array_shift($array); 222 | } 223 | 224 | return $array; 225 | } 226 | 227 | /** 228 | * Returns an array containing stdClass objects. 229 | * 230 | * @return ArrayObject 231 | */ 232 | public function toObjectArray() 233 | { 234 | $array = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray(); 235 | 236 | for($i = 0; $i < count($array); $i++) 237 | { 238 | $array[$i] = (object) $array[$i]; 239 | } 240 | 241 | return $array; 242 | } 243 | 244 | /** 245 | * Returns the command used to get this reply. 246 | * 247 | * @return TeamSpeak3_Helper_String 248 | */ 249 | public function getCommandString() 250 | { 251 | return new TeamSpeak3_Helper_String($this->cmd); 252 | } 253 | 254 | /** 255 | * Returns an array of events that occured before or during this reply. 256 | * 257 | * @return array 258 | */ 259 | public function getNotifyEvents() 260 | { 261 | return $this->evt; 262 | } 263 | 264 | /** 265 | * Returns the value for a specified error property. 266 | * 267 | * @param string $ident 268 | * @param mixed $default 269 | * @return mixed 270 | */ 271 | public function getErrorProperty($ident, $default = null) 272 | { 273 | return (array_key_exists($ident, $this->err)) ? $this->err[$ident] : $default; 274 | } 275 | 276 | /** 277 | * Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if 278 | * there's an error. 279 | * 280 | * @param string $err 281 | * @throws TeamSpeak3_Adapter_ServerQuery_Exception 282 | * @return void 283 | */ 284 | protected function fetchError($err) 285 | { 286 | $cells = $err->section(TeamSpeak3::SEPARATOR_CELL, 1, 3); 287 | 288 | foreach($cells->split(TeamSpeak3::SEPARATOR_CELL) as $pair) 289 | { 290 | list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR); 291 | 292 | $this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape(); 293 | } 294 | 295 | TeamSpeak3_Helper_Signal::getInstance()->emit("notifyError", $this); 296 | 297 | if($this->getErrorProperty("id", 0x00) != 0x00 && $this->exp) 298 | { 299 | if($permid = $this->getErrorProperty("failed_permid")) 300 | { 301 | if($permsid = key($this->con->request("permget permid=" . $permid, FALSE)->toAssocArray("permsid"))) 302 | { 303 | $suffix = " (failed on " . $permsid . ")"; 304 | } 305 | else 306 | { 307 | $suffix = " (failed on " . $this->cmd->section(TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")"; 308 | } 309 | } 310 | elseif($details = $this->getErrorProperty("extra_msg")) 311 | { 312 | $suffix = " (" . trim($details) . ")"; 313 | } 314 | else 315 | { 316 | $suffix = ""; 317 | } 318 | 319 | throw new TeamSpeak3_Adapter_ServerQuery_Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id")); 320 | } 321 | } 322 | 323 | /** 324 | * Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object. 325 | * 326 | * @param string $rpl 327 | * @return void 328 | */ 329 | protected function fetchReply($rpl) 330 | { 331 | foreach($rpl as $key => $val) 332 | { 333 | if($val->startsWith(TeamSpeak3::GREET)) 334 | { 335 | unset($rpl[$key]); 336 | } 337 | elseif($val->startsWith(TeamSpeak3::EVENT)) 338 | { 339 | $this->evt[] = new TeamSpeak3_Adapter_ServerQuery_Event($rpl[$key], $this->con); 340 | unset($rpl[$key]); 341 | } 342 | } 343 | 344 | $this->rpl = new TeamSpeak3_Helper_String(implode(TeamSpeak3::SEPARATOR_LIST, $rpl)); 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/TSDNS.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_TSDNS 30 | * @brief Provides methods to query a TSDNS server. 31 | */ 32 | class TeamSpeak3_Adapter_TSDNS extends TeamSpeak3_Adapter_Abstract 33 | { 34 | /** 35 | * The TCP port number used by any TSDNS server. 36 | * 37 | * @var integer 38 | */ 39 | protected $default_port = 41144; 40 | 41 | /** 42 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 43 | * server. 44 | * 45 | * @throws TeamSpeak3_Adapter_Exception 46 | * @return void 47 | */ 48 | public function syn() 49 | { 50 | if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 51 | 52 | $this->initTransport($this->options); 53 | $this->transport->setAdapter($this); 54 | 55 | TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 56 | 57 | TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsConnected", $this); 58 | } 59 | 60 | /** 61 | * The TeamSpeak3_Adapter_FileTransfer destructor. 62 | * 63 | * @return void 64 | */ 65 | public function __destruct() 66 | { 67 | if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 68 | { 69 | $this->getTransport()->disconnect(); 70 | } 71 | } 72 | 73 | /** 74 | * Queries the TSDNS server for a specified virtual hostname and returns the result. 75 | * 76 | * @param string $tsdns 77 | * @throws TeamSpeak3_Adapter_TSDNS_Exception 78 | * @return TeamSpeak3_Helper_String 79 | */ 80 | public function resolve($tsdns) 81 | { 82 | $this->getTransport()->sendLine($tsdns); 83 | $repl = $this->getTransport()->readLine(); 84 | $this->getTransport()->disconnect(); 85 | 86 | if($repl->section(":", 0)->toInt() == 404) 87 | { 88 | throw new TeamSpeak3_Adapter_TSDNS_Exception("unable to resolve TSDNS hostname (" . $tsdns . ")"); 89 | } 90 | 91 | TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl); 92 | 93 | return $repl; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/TSDNS/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_TSDNS_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_TSDNS objects. 31 | */ 32 | class TeamSpeak3_Adapter_TSDNS_Exception extends TeamSpeak3_Adapter_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Update.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * @package TeamSpeak3 21 | * @author Sven 'ScP' Paulsen 22 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 23 | */ 24 | 25 | /** 26 | * @deprecated 27 | * 28 | * @class TeamSpeak3_Adapter_Update 29 | * @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server. 30 | */ 31 | class TeamSpeak3_Adapter_Update extends TeamSpeak3_Adapter_Abstract 32 | { 33 | /** 34 | * The IPv4 address or FQDN of the TeamSpeak Systems update server. 35 | * 36 | * @var string 37 | */ 38 | protected $default_host = "update.teamspeak.com"; 39 | 40 | /** 41 | * The UDP port number of the TeamSpeak Systems update server. 42 | * 43 | * @var integer 44 | */ 45 | protected $default_port = 17384; 46 | 47 | /** 48 | * Stores an array containing the latest build numbers (integer timestamps). 49 | * 50 | * @var array 51 | */ 52 | protected $build_datetimes = null; 53 | 54 | /** 55 | * Stores an array containing the latest version strings. 56 | * 57 | * @var array 58 | */ 59 | protected $version_strings = null; 60 | 61 | /** 62 | * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 63 | * server. 64 | * 65 | * @throws TeamSpeak3_Adapter_Update_Exception 66 | * @return void 67 | */ 68 | public function syn() 69 | { 70 | if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host; 71 | if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 72 | 73 | $this->initTransport($this->options, "TeamSpeak3_Transport_UDP"); 74 | $this->transport->setAdapter($this); 75 | 76 | TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 77 | 78 | $this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33)); 79 | 80 | if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2])) 81 | { 82 | throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server"); 83 | } 84 | 85 | $this->build_datetimes = $matches[1]; 86 | $this->version_strings = $matches[2]; 87 | 88 | TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this); 89 | } 90 | 91 | /** 92 | * The TeamSpeak3_Adapter_Update destructor. 93 | * 94 | * @return void 95 | */ 96 | public function __destruct() 97 | { 98 | if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 99 | { 100 | $this->getTransport()->disconnect(); 101 | } 102 | } 103 | 104 | /** 105 | * Returns the current build number for a specified update channel. Note that since version 106 | * 3.0.0, the build number represents an integer timestamp. $channel must be set to one of 107 | * the following values: 108 | * 109 | * - stable 110 | * - beta 111 | * - alpha 112 | * - server 113 | * 114 | * @param string $channel 115 | * @throws TeamSpeak3_Adapter_Update_Exception 116 | * @return integer 117 | */ 118 | public function getRev($channel = "stable") 119 | { 120 | switch($channel) 121 | { 122 | case "stable": 123 | return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null; 124 | 125 | case "beta": 126 | return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null; 127 | 128 | case "alpha": 129 | return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null; 130 | 131 | case "server": 132 | return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null; 133 | 134 | default: 135 | throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")"); 136 | } 137 | } 138 | 139 | /** 140 | * Returns the current version string for a specified update channel. $channel must be set to 141 | * one of the following values: 142 | * 143 | * - stable 144 | * - beta 145 | * - alpha 146 | * - server 147 | * 148 | * @param string $channel 149 | * @throws TeamSpeak3_Adapter_Update_Exception 150 | * @return integer 151 | */ 152 | public function getVersion($channel = "stable") 153 | { 154 | switch($channel) 155 | { 156 | case "stable": 157 | return isset($this->version_strings[0]) ? $this->version_strings[0] : null; 158 | 159 | case "beta": 160 | return isset($this->version_strings[1]) ? $this->version_strings[1] : null; 161 | 162 | case "alpha": 163 | return isset($this->version_strings[2]) ? $this->version_strings[2] : null; 164 | 165 | case "server": 166 | return isset($this->version_strings[3]) ? $this->version_strings[3] : null; 167 | 168 | default: 169 | throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")"); 170 | } 171 | } 172 | 173 | /** 174 | * Alias for getRev() using the 'stable' update channel. 175 | * 176 | * @param string $channel 177 | * @return integer 178 | */ 179 | public function getClientRev() 180 | { 181 | return $this->getRev("stable"); 182 | } 183 | 184 | /** 185 | * Alias for getRev() using the 'server' update channel. 186 | * 187 | * @param string $channel 188 | * @return integer 189 | */ 190 | public function getServerRev() 191 | { 192 | return $this->getRev("server"); 193 | } 194 | 195 | /** 196 | * Alias for getVersion() using the 'stable' update channel. 197 | * 198 | * @param string $channel 199 | * @return integer 200 | */ 201 | public function getClientVersion() 202 | { 203 | return $this->getVersion("stable"); 204 | } 205 | 206 | /** 207 | * Alias for getVersion() using the 'server' update channel. 208 | * 209 | * @param string $channel 210 | * @return integer 211 | */ 212 | public function getServerVersion() 213 | { 214 | return $this->getVersion("server"); 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Adapter/Update/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Adapter_Update_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Adapter_Update objects. 31 | */ 32 | class TeamSpeak3_Adapter_Update_Exception extends TeamSpeak3_Adapter_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Exception 30 | * @brief Enhanced exception class for TeamSpeak3 objects. 31 | */ 32 | class TeamSpeak3_Exception extends Exception 33 | { 34 | /** 35 | * Stores custom error messages. 36 | * 37 | * @var array 38 | */ 39 | protected static $messages = array(); 40 | 41 | /** 42 | * The TeamSpeak3_Exception constructor. 43 | * 44 | * @param string $mesg 45 | * @param integer $code 46 | * @return TeamSpeak3_Exception 47 | */ 48 | public function __construct($mesg, $code = 0x00) 49 | { 50 | parent::__construct($mesg, $code); 51 | 52 | if(array_key_exists((int) $code, self::$messages)) 53 | { 54 | $this->message = $this->prepareCustomMessage(self::$messages[intval($code)]); 55 | } 56 | 57 | TeamSpeak3_Helper_Signal::getInstance()->emit("errorException", $this); 58 | } 59 | 60 | /** 61 | * Prepares a custom error message by replacing pre-defined signs with given values. 62 | * 63 | * @param TeamSpeak3_Helper_String $mesg 64 | * @return TeamSpeak3_Helper_String 65 | */ 66 | protected function prepareCustomMessage(TeamSpeak3_Helper_String $mesg) 67 | { 68 | $args = array( 69 | "code" => $this->getCode(), 70 | "mesg" => $this->getMessage(), 71 | "line" => $this->getLine(), 72 | "file" => $this->getFile(), 73 | ); 74 | 75 | return $mesg->arg($args)->toString(); 76 | } 77 | 78 | /** 79 | * Registers a custom error message to $code. 80 | * 81 | * @param integer $code 82 | * @param string $mesg 83 | * @throws TeamSpeak3_Exception 84 | * @return void 85 | */ 86 | public static function registerCustomMessage($code, $mesg) 87 | { 88 | if(array_key_exists((int) $code, self::$messages)) 89 | { 90 | throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is already registered"); 91 | } 92 | 93 | if(!is_string($mesg)) 94 | { 95 | throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " must be a string"); 96 | } 97 | 98 | self::$messages[(int) $code] = new TeamSpeak3_Helper_String($mesg); 99 | } 100 | 101 | /** 102 | * Unregisters a custom error message from $code. 103 | * 104 | * @param integer $code 105 | * @throws TeamSpeak3_Exception 106 | * @return void 107 | */ 108 | public static function unregisterCustomMessage($code) 109 | { 110 | if(!array_key_exists((int) $code, self::$messages)) 111 | { 112 | throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is not registered"); 113 | } 114 | 115 | unset(self::$messages[(int) $code]); 116 | } 117 | 118 | /** 119 | * Returns the class from which the exception was thrown. 120 | * 121 | * @return string 122 | */ 123 | public function getSender() 124 | { 125 | $trace = $this->getTrace(); 126 | 127 | return (isset($trace[0]["class"])) ? $trace[0]["class"] : "{main}"; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Char.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Char 30 | * @brief Helper class for char handling. 31 | */ 32 | class TeamSpeak3_Helper_Char 33 | { 34 | /** 35 | * Stores the original character. 36 | * 37 | * @var string 38 | */ 39 | protected $char = null; 40 | 41 | /** 42 | * The TeamSpeak3_Helper_Char constructor. 43 | * 44 | * @param string $var 45 | * @throws TeamSpeak3_Helper_Exception 46 | * @return TeamSpeak3_Helper_Char 47 | */ 48 | public function __construct($char) 49 | { 50 | if(strlen($char) != 1) 51 | { 52 | throw new TeamSpeak3_Helper_Exception("char parameter may not contain more or less than one character"); 53 | } 54 | 55 | $this->char = strval($char); 56 | } 57 | 58 | /** 59 | * Returns true if the character is a letter. 60 | * 61 | * @return boolean 62 | */ 63 | public function isLetter() 64 | { 65 | return ctype_alpha($this->char); 66 | } 67 | 68 | /** 69 | * Returns true if the character is a decimal digit. 70 | * 71 | * @return boolean 72 | */ 73 | public function isDigit() 74 | { 75 | return ctype_digit($this->char); 76 | } 77 | 78 | /** 79 | * Returns true if the character is a space. 80 | * 81 | * @return boolean 82 | */ 83 | public function isSpace() 84 | { 85 | return ctype_space($this->char); 86 | } 87 | 88 | /** 89 | * Returns true if the character is a mark. 90 | * 91 | * @return boolean 92 | */ 93 | public function isMark() 94 | { 95 | return ctype_punct($this->char); 96 | } 97 | 98 | /** 99 | * Returns true if the character is a control character (i.e. "\t"). 100 | * 101 | * @return boolean 102 | */ 103 | public function isControl() 104 | { 105 | return ctype_cntrl($this->char); 106 | } 107 | 108 | /** 109 | * Returns true if the character is a printable character. 110 | * 111 | * @return boolean 112 | */ 113 | public function isPrintable() 114 | { 115 | return ctype_print($this->char); 116 | } 117 | 118 | /** 119 | * Returns true if the character is the Unicode character 0x0000 ("\0"). 120 | * 121 | * @return boolean 122 | */ 123 | public function isNull() 124 | { 125 | return ($this->char === "\0") ? TRUE : FALSE; 126 | } 127 | 128 | /** 129 | * Returns true if the character is an uppercase letter. 130 | * 131 | * @return boolean 132 | */ 133 | public function isUpper() 134 | { 135 | return ($this->char === strtoupper($this->char)) ? TRUE : FALSE; 136 | } 137 | 138 | /** 139 | * Returns true if the character is a lowercase letter. 140 | * 141 | * @return boolean 142 | */ 143 | public function isLower() 144 | { 145 | return ($this->char === strtolower($this->char)) ? TRUE : FALSE; 146 | } 147 | 148 | /** 149 | * Returns the uppercase equivalent if the character is lowercase. 150 | * 151 | * @return TeamSpeak3_Helper_Char 152 | */ 153 | public function toUpper() 154 | { 155 | return ($this->isUpper()) ? $this : new self(strtoupper($this)); 156 | } 157 | 158 | /** 159 | * Returns the lowercase equivalent if the character is uppercase. 160 | * 161 | * @return TeamSpeak3_Helper_Char 162 | */ 163 | public function toLower() 164 | { 165 | return ($this->isLower()) ? $this : new self(strtolower($this)); 166 | } 167 | 168 | /** 169 | * Returns the ascii value of the character. 170 | * 171 | * @return integer 172 | */ 173 | public function toAscii() 174 | { 175 | return ord($this->char); 176 | } 177 | 178 | /** 179 | * Returns the Unicode value of the character. 180 | * 181 | * @return integer 182 | */ 183 | public function toUnicode() 184 | { 185 | $h = ord($this->char{0}); 186 | 187 | if($h <= 0x7F) 188 | { 189 | return $h; 190 | } 191 | else if($h < 0xC2) 192 | { 193 | return FALSE; 194 | } 195 | else if($h <= 0xDF) 196 | { 197 | return ($h & 0x1F) << 6 | (ord($this->char{1}) & 0x3F); 198 | } 199 | else if($h <= 0xEF) 200 | { 201 | return ($h & 0x0F) << 12 | (ord($this->char{1}) & 0x3F) << 6 | (ord($this->char{2}) & 0x3F); 202 | } 203 | else if($h <= 0xF4) 204 | { 205 | return ($h & 0x0F) << 18 | (ord($this->char{1}) & 0x3F) << 12 | (ord($this->char{2}) & 0x3F) << 6 | (ord($this->char{3}) & 0x3F); 206 | } 207 | else 208 | { 209 | return FALSE; 210 | } 211 | } 212 | 213 | /** 214 | * Returns the hexadecimal value of the char. 215 | * 216 | * @return string 217 | */ 218 | public function toHex() 219 | { 220 | return strtoupper(dechex($this->toAscii())); 221 | } 222 | 223 | /** 224 | * Returns the TeamSpeak3_Helper_Char based on a given hex value. 225 | * 226 | * @param string $hex 227 | * @throws TeamSpeak3_Helper_Exception 228 | * @return TeamSpeak3_Helper_Char 229 | */ 230 | public static function fromHex($hex) 231 | { 232 | if(strlen($hex) != 2) 233 | { 234 | throw new TeamSpeak3_Helper_Exception("given parameter '" . $hex . "' is not a valid hexadecimal number"); 235 | } 236 | 237 | return new self(chr(hexdec($hex))); 238 | } 239 | 240 | /** 241 | * Returns the character as a standard string. 242 | * 243 | * @return string 244 | */ 245 | public function toString() 246 | { 247 | return $this->char; 248 | } 249 | 250 | /** 251 | * Returns the integer value of the character. 252 | * 253 | * @return integer 254 | */ 255 | public function toInt() 256 | { 257 | return intval($this->char); 258 | } 259 | 260 | /** 261 | * Returns the character as a standard string. 262 | * 263 | * @return string 264 | */ 265 | public function __toString() 266 | { 267 | return $this->char; 268 | } 269 | } 270 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Convert.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * @package TeamSpeak3 21 | * @author Sven 'ScP' Paulsen 22 | * @copyright Copyright (c) Planet TeamSpeak. All rights reserved. 23 | */ 24 | 25 | /** 26 | * @class TeamSpeak3_Helper_Convert 27 | * @brief Helper class for data conversion. 28 | */ 29 | class TeamSpeak3_Helper_Convert 30 | { 31 | /** 32 | * Converts bytes to a human readable value. 33 | * 34 | * @param integer $bytes 35 | * @return string 36 | */ 37 | public static function bytes($bytes) 38 | { 39 | $kbytes = sprintf("%.02f", $bytes/1024); 40 | $mbytes = sprintf("%.02f", $kbytes/1024); 41 | $gbytes = sprintf("%.02f", $mbytes/1024); 42 | $tbytes = sprintf("%.02f", $gbytes/1024); 43 | 44 | if($tbytes >= 1) 45 | return $tbytes . " TB"; 46 | if($gbytes >= 1) 47 | return $gbytes . " GB"; 48 | if($mbytes >= 1) 49 | return $mbytes . " MB"; 50 | if($kbytes >= 1) 51 | return $kbytes . " KB"; 52 | 53 | return $bytes . " B"; 54 | } 55 | 56 | /** 57 | * Converts seconds/milliseconds to a human readable value. 58 | * 59 | * @param integer $seconds 60 | * @param boolean $is_ms 61 | * @param string $format 62 | * @return string 63 | */ 64 | public static function seconds($seconds, $is_ms = FALSE, $format = "%dD %02d:%02d:%02d") 65 | { 66 | if($is_ms) $seconds = $seconds/1000; 67 | 68 | return sprintf($format, $seconds/60/60/24, ($seconds/60/60)%24, ($seconds/60)%60, $seconds%60); 69 | } 70 | 71 | /** 72 | * Converts a given codec ID to a human readable name. 73 | * 74 | * @param integer $codec 75 | * @return string 76 | */ 77 | public static function codec($codec) 78 | { 79 | if($codec == TeamSpeak3::CODEC_SPEEX_NARROWBAND) 80 | return "Speex Narrowband"; 81 | if($codec == TeamSpeak3::CODEC_SPEEX_WIDEBAND) 82 | return "Speex Wideband"; 83 | if($codec == TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND) 84 | return "Speex Ultra-Wideband"; 85 | if($codec == TeamSpeak3::CODEC_CELT_MONO) 86 | return "CELT Mono"; 87 | if($codec == TeamSpeak3::CODEC_OPUS_VOICE) 88 | return "Opus Voice"; 89 | if($codec == TeamSpeak3::CODEC_OPUS_MUSIC) 90 | return "Opus Music"; 91 | 92 | return "Unknown"; 93 | } 94 | 95 | /** 96 | * Converts a given group type ID to a human readable name. 97 | * 98 | * @param integer $type 99 | * @return string 100 | */ 101 | public static function groupType($type) 102 | { 103 | if($type == TeamSpeak3::GROUP_DBTYPE_TEMPLATE) 104 | return "Template"; 105 | if($type == TeamSpeak3::GROUP_DBTYPE_REGULAR) 106 | return "Regular"; 107 | if($type == TeamSpeak3::GROUP_DBTYPE_SERVERQUERY) 108 | return "ServerQuery"; 109 | 110 | return "Unknown"; 111 | } 112 | 113 | /** 114 | * Converts a given permission type ID to a human readable name. 115 | * 116 | * @param integer $type 117 | * @return string 118 | */ 119 | public static function permissionType($type) 120 | { 121 | if($type == TeamSpeak3::PERM_TYPE_SERVERGROUP) 122 | return "Server Group"; 123 | if($type == TeamSpeak3::PERM_TYPE_CLIENT) 124 | return "Client"; 125 | if($type == TeamSpeak3::PERM_TYPE_CHANNEL) 126 | return "Channel"; 127 | if($type == TeamSpeak3::PERM_TYPE_CHANNELGROUP) 128 | return "Channel Group"; 129 | if($type == TeamSpeak3::PERM_TYPE_CHANNELCLIENT) 130 | return "Channel Client"; 131 | 132 | return "Unknown"; 133 | } 134 | 135 | /** 136 | * Converts a given permission category value to a human readable name. 137 | * 138 | * @param integer $pcat 139 | * @return string 140 | */ 141 | public static function permissionCategory($pcat) 142 | { 143 | if($pcat == TeamSpeak3::PERM_CAT_GLOBAL) 144 | return "Global"; 145 | if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_INFORMATION) 146 | return "Global / Information"; 147 | if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_SERVER_MGMT) 148 | return "Global / Virtual Server Management"; 149 | if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_ADM_ACTIONS) 150 | return "Global / Administration"; 151 | if($pcat == TeamSpeak3::PERM_CAT_GLOBAL_SETTINGS) 152 | return "Global / Settings"; 153 | if($pcat == TeamSpeak3::PERM_CAT_SERVER) 154 | return "Virtual Server"; 155 | if($pcat == TeamSpeak3::PERM_CAT_SERVER_INFORMATION) 156 | return "Virtual Server / Information"; 157 | if($pcat == TeamSpeak3::PERM_CAT_SERVER_ADM_ACTIONS) 158 | return "Virtual Server / Administration"; 159 | if($pcat == TeamSpeak3::PERM_CAT_SERVER_SETTINGS) 160 | return "Virtual Server / Settings"; 161 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL) 162 | return "Channel"; 163 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_INFORMATION) 164 | return "Channel / Information"; 165 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_CREATE) 166 | return "Channel / Create"; 167 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_MODIFY) 168 | return "Channel / Modify"; 169 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_DELETE) 170 | return "Channel / Delete"; 171 | if($pcat == TeamSpeak3::PERM_CAT_CHANNEL_ACCESS) 172 | return "Channel / Access"; 173 | if($pcat == TeamSpeak3::PERM_CAT_GROUP) 174 | return "Group"; 175 | if($pcat == TeamSpeak3::PERM_CAT_GROUP_INFORMATION) 176 | return "Group / Information"; 177 | if($pcat == TeamSpeak3::PERM_CAT_GROUP_CREATE) 178 | return "Group / Create"; 179 | if($pcat == TeamSpeak3::PERM_CAT_GROUP_MODIFY) 180 | return "Group / Modify"; 181 | if($pcat == TeamSpeak3::PERM_CAT_GROUP_DELETE) 182 | return "Group / Delete"; 183 | if($pcat == TeamSpeak3::PERM_CAT_CLIENT) 184 | return "Client"; 185 | if($pcat == TeamSpeak3::PERM_CAT_CLIENT_INFORMATION) 186 | return "Client / Information"; 187 | if($pcat == TeamSpeak3::PERM_CAT_CLIENT_ADM_ACTIONS) 188 | return "Client / Admin"; 189 | if($pcat == TeamSpeak3::PERM_CAT_CLIENT_BASICS) 190 | return "Client / Basics"; 191 | if($pcat == TeamSpeak3::PERM_CAT_CLIENT_MODIFY) 192 | return "Client / Modify"; 193 | if($pcat == TeamSpeak3::PERM_CAT_FILETRANSFER) 194 | return "File Transfer"; 195 | if($pcat == TeamSpeak3::PERM_CAT_NEEDED_MODIFY_POWER) 196 | return "Grant"; 197 | 198 | return "Unknown"; 199 | } 200 | 201 | /** 202 | * Converts a given log level ID to a human readable name and vice versa. 203 | * 204 | * @param mixed $level 205 | * @return string 206 | */ 207 | public static function logLevel($level) 208 | { 209 | if(is_numeric($level)) 210 | { 211 | if($level == TeamSpeak3::LOGLEVEL_CRITICAL) 212 | return "CRITICAL"; 213 | if($level == TeamSpeak3::LOGLEVEL_ERROR) 214 | return "ERROR"; 215 | if($level == TeamSpeak3::LOGLEVEL_DEBUG) 216 | return "DEBUG"; 217 | if($level == TeamSpeak3::LOGLEVEL_WARNING) 218 | return "WARNING"; 219 | if($level == TeamSpeak3::LOGLEVEL_INFO) 220 | return "INFO"; 221 | 222 | return "DEVELOP"; 223 | } 224 | else 225 | { 226 | if(strtoupper($level) == "CRITICAL") 227 | return TeamSpeak3::LOGLEVEL_CRITICAL; 228 | if(strtoupper($level) == "ERROR") 229 | return TeamSpeak3::LOGLEVEL_ERROR; 230 | if(strtoupper($level) == "DEBUG") 231 | return TeamSpeak3::LOGLEVEL_DEBUG; 232 | if(strtoupper($level) == "WARNING") 233 | return TeamSpeak3::LOGLEVEL_WARNING; 234 | if(strtoupper($level) == "INFO") 235 | return TeamSpeak3::LOGLEVEL_INFO; 236 | 237 | return TeamSpeak3::LOGLEVEL_DEVEL; 238 | } 239 | } 240 | 241 | /** 242 | * Converts a specified log entry string into an array containing the data. 243 | * 244 | * @param string $entry 245 | * @return array 246 | */ 247 | public static function logEntry($entry) 248 | { 249 | $parts = explode("|", $entry, 5); 250 | $array = array(); 251 | 252 | if(count($parts) != 5) 253 | { 254 | $array["timestamp"] = 0; 255 | $array["level"] = TeamSpeak3::LOGLEVEL_ERROR; 256 | $array["channel"] = "ParamParser"; 257 | $array["server_id"] = ""; 258 | $array["msg"] = TeamSpeak3_Helper_String::factory("convert error (" . trim($entry) . ")"); 259 | $array["msg_plain"] = $entry; 260 | $array["malformed"] = TRUE; 261 | } 262 | else 263 | { 264 | $array["timestamp"] = strtotime(trim($parts[0])); 265 | $array["level"] = self::logLevel(trim($parts[1])); 266 | $array["channel"] = trim($parts[2]); 267 | $array["server_id"] = trim($parts[3]); 268 | $array["msg"] = TeamSpeak3_Helper_String::factory(trim($parts[4])); 269 | $array["msg_plain"] = $entry; 270 | $array["malformed"] = FALSE; 271 | } 272 | 273 | return $array; 274 | } 275 | 276 | /** 277 | * Converts a given string to a ServerQuery password hash. 278 | * 279 | * @param string $plain 280 | * @return string 281 | */ 282 | public static function password($plain) 283 | { 284 | return base64_encode(sha1($plain, TRUE)); 285 | } 286 | 287 | /** 288 | * Returns a client-like formatted version of the TeamSpeak 3 version string. 289 | * 290 | * @param string $version 291 | * @param string $format 292 | * @return string 293 | */ 294 | public static function version($version, $format = "Y-m-d h:i:s") 295 | { 296 | if(!$version instanceof TeamSpeak3_Helper_String) 297 | { 298 | $version = new TeamSpeak3_Helper_String($version); 299 | } 300 | 301 | $buildno = $version->section("[", 1)->filterDigits()->toInt(); 302 | 303 | return ($buildno <= 15001) ? $version : $version->section("[")->append("(" . date($format, $buildno) . ")"); 304 | } 305 | 306 | /** 307 | * Returns a client-like short-formatted version of the TeamSpeak 3 version string. 308 | * 309 | * @param string $version 310 | * @return string 311 | */ 312 | public static function versionShort($version) 313 | { 314 | if(!$version instanceof TeamSpeak3_Helper_String) 315 | { 316 | $version = new TeamSpeak3_Helper_String($version); 317 | } 318 | 319 | return $version->section(" ", 0); 320 | } 321 | 322 | /** 323 | * Tries to detect the type of an image by a given string and returns it. 324 | * 325 | * @param string $binary 326 | * @return string 327 | */ 328 | public static function imageMimeType($binary) 329 | { 330 | if(!preg_match('/\A(?:(\xff\xd8\xff)|(GIF8[79]a)|(\x89PNG\x0d\x0a)|(BM)|(\x49\x49(\x2a\x00|\x00\x4a))|(FORM.{4}ILBM))/', $binary, $matches)) 331 | { 332 | return "image/svg+xml"; 333 | } 334 | 335 | $type = array( 336 | 1 => "image/jpeg", 337 | 2 => "image/gif", 338 | 3 => "image/png", 339 | 4 => "image/x-windows-bmp", 340 | 5 => "image/tiff", 341 | 6 => "image/x-ilbm", 342 | ); 343 | 344 | return $type[count($matches)-1]; 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Helper_* objects. 31 | */ 32 | class TeamSpeak3_Helper_Exception extends TeamSpeak3_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Profiler.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Profiler 30 | * @brief Helper class for profiler handling. 31 | */ 32 | class TeamSpeak3_Helper_Profiler 33 | { 34 | /** 35 | * Stores various timers for code profiling. 36 | * 37 | * @var array 38 | */ 39 | protected static $timers = array(); 40 | 41 | /** 42 | * Inits a timer. 43 | * 44 | * @param string $name 45 | * @return void 46 | */ 47 | public static function init($name = "default") 48 | { 49 | self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name); 50 | } 51 | 52 | /** 53 | * Starts a timer. 54 | * 55 | * @param string $name 56 | * @return void 57 | */ 58 | public static function start($name = "default") 59 | { 60 | if(array_key_exists($name, self::$timers)) 61 | { 62 | self::$timers[$name]->start(); 63 | } 64 | else 65 | { 66 | self::$timers[$name] = new TeamSpeak3_Helper_Profiler_Timer($name); 67 | } 68 | } 69 | 70 | /** 71 | * Stops a timer. 72 | * 73 | * @param string $name 74 | * @return void 75 | */ 76 | public static function stop($name = "default") 77 | { 78 | if(!array_key_exists($name, self::$timers)) 79 | { 80 | self::init($name); 81 | } 82 | 83 | self::$timers[$name]->stop(); 84 | } 85 | 86 | /** 87 | * Returns a timer. 88 | * 89 | * @param string $name 90 | * @return TeamSpeak3_Helper_Profiler_Timer 91 | */ 92 | public static function get($name = "default") 93 | { 94 | if(!array_key_exists($name, self::$timers)) 95 | { 96 | self::init($name); 97 | } 98 | 99 | return self::$timers[$name]; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Profiler/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Profiler_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Helper_Profiler objects. 31 | */ 32 | class TeamSpeak3_Helper_Profiler_Exception extends TeamSpeak3_Helper_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Profiler/Timer.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Profiler_Timer 30 | * @brief Helper class providing profiler timers. 31 | */ 32 | class TeamSpeak3_Helper_Profiler_Timer 33 | { 34 | /** 35 | * Indicates wether the timer is running or not. 36 | * 37 | * @var boolean 38 | */ 39 | protected $running = FALSE; 40 | 41 | /** 42 | * Stores the timestamp when the timer was last started. 43 | * 44 | * @var integer 45 | */ 46 | protected $started = 0; 47 | 48 | /** 49 | * Stores the timer name. 50 | * 51 | * @var string 52 | */ 53 | protected $name = null; 54 | 55 | /** 56 | * Stores various information about the server environment. 57 | * 58 | * @var array 59 | */ 60 | protected $data = array(); 61 | 62 | /** 63 | * The TeamSpeak3_Helper_Profiler_Timer constructor. 64 | * 65 | * @param string $name 66 | * @return TeamSpeak3_Helper_Profiler_Timer 67 | */ 68 | public function __construct($name) 69 | { 70 | $this->name = (string) $name; 71 | 72 | $this->data["runtime"] = 0; 73 | $this->data["realmem"] = 0; 74 | $this->data["emalloc"] = 0; 75 | 76 | $this->start(); 77 | } 78 | 79 | /** 80 | * Starts the timer. 81 | * 82 | * @return void 83 | */ 84 | public function start() 85 | { 86 | if($this->isRunning()) return; 87 | 88 | $this->data["realmem_start"] = memory_get_usage(TRUE); 89 | $this->data["emalloc_start"] = memory_get_usage(); 90 | 91 | $this->started = microtime(TRUE); 92 | $this->running = TRUE; 93 | } 94 | 95 | /** 96 | * Stops the timer. 97 | * 98 | * @return void 99 | */ 100 | public function stop() 101 | { 102 | if(!$this->isRunning()) return; 103 | 104 | $this->data["runtime"] += microtime(TRUE) - $this->started; 105 | $this->data["realmem"] += memory_get_usage(TRUE) - $this->data["realmem_start"]; 106 | $this->data["emalloc"] += memory_get_usage() - $this->data["emalloc_start"]; 107 | 108 | $this->started = 0; 109 | $this->running = FALSE; 110 | } 111 | 112 | /** 113 | * Return the timer runtime. 114 | * 115 | * @return mixed 116 | */ 117 | public function getRuntime() 118 | { 119 | if($this->isRunning()) 120 | { 121 | $this->stop(); 122 | $this->start(); 123 | } 124 | 125 | return $this->data["runtime"]; 126 | } 127 | 128 | /** 129 | * Returns the amount of memory allocated to PHP in bytes. 130 | * 131 | * @param boolean $realmem 132 | * @return integer 133 | */ 134 | public function getMemUsage($realmem = FALSE) 135 | { 136 | if($this->isRunning()) 137 | { 138 | $this->stop(); 139 | $this->start(); 140 | } 141 | 142 | return ($realmem !== FALSE) ? $this->data["realmem"] : $this->data["emalloc"]; 143 | } 144 | 145 | /** 146 | * Returns TRUE if the timer is running. 147 | * 148 | * @return boolean 149 | */ 150 | public function isRunning() 151 | { 152 | return $this->running; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Signal.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Signal 30 | * @brief Helper class for signal slots. 31 | */ 32 | class TeamSpeak3_Helper_Signal 33 | { 34 | /** 35 | * Stores the TeamSpeak3_Helper_Signal object. 36 | * 37 | * @var TeamSpeak3_Helper_Signal 38 | */ 39 | protected static $instance = null; 40 | 41 | /** 42 | * Stores subscribed signals and their slots. 43 | * 44 | * @var array 45 | */ 46 | protected $sigslots = array(); 47 | 48 | /** 49 | * Emits a signal with a given set of parameters. 50 | * 51 | * @param string $signal 52 | * @param mixed $params 53 | * @return mixed 54 | */ 55 | public function emit($signal, $params = null) 56 | { 57 | if(!$this->hasHandlers($signal)) 58 | { 59 | return; 60 | } 61 | 62 | if(!is_array($params)) 63 | { 64 | $params = func_get_args(); 65 | $params = array_slice($params, 1); 66 | } 67 | 68 | foreach($this->sigslots[$signal] as $slot) 69 | { 70 | $return = $slot->call($params); 71 | } 72 | 73 | return $return; 74 | } 75 | 76 | /** 77 | * Generates a MD5 hash based on a given callback. 78 | * 79 | * @param mixed $callback 80 | * @param string 81 | * @return void 82 | */ 83 | public function getCallbackHash($callback) 84 | { 85 | if(!is_callable($callback, TRUE, $callable_name)) 86 | { 87 | throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified"); 88 | } 89 | 90 | return md5($callable_name); 91 | } 92 | 93 | /** 94 | * Subscribes to a signal and returns the signal handler. 95 | * 96 | * @param string $signal 97 | * @param mixed $callback 98 | * @return TeamSpeak3_Helper_Signal_Handler 99 | */ 100 | public function subscribe($signal, $callback) 101 | { 102 | if(empty($this->sigslots[$signal])) 103 | { 104 | $this->sigslots[$signal] = array(); 105 | } 106 | 107 | $index = $this->getCallbackHash($callback); 108 | 109 | if(!array_key_exists($index, $this->sigslots[$signal])) 110 | { 111 | $this->sigslots[$signal][$index] = new TeamSpeak3_Helper_Signal_Handler($signal, $callback); 112 | } 113 | 114 | return $this->sigslots[$signal][$index]; 115 | } 116 | 117 | /** 118 | * Unsubscribes from a signal. 119 | * 120 | * @param string $signal 121 | * @param mixed $callback 122 | * @return void 123 | */ 124 | public function unsubscribe($signal, $callback = null) 125 | { 126 | if(!$this->hasHandlers($signal)) 127 | { 128 | return; 129 | } 130 | 131 | if($callback !== null) 132 | { 133 | $index = $this->getCallbackHash($callback); 134 | 135 | if(!array_key_exists($index, $this->sigslots[$signal])) 136 | { 137 | return; 138 | } 139 | 140 | unset($this->sigslots[$signal][$index]); 141 | } 142 | else 143 | { 144 | unset($this->sigslots[$signal]); 145 | } 146 | } 147 | 148 | /** 149 | * Returns all registered signals. 150 | * 151 | * @return array 152 | */ 153 | public function getSignals() 154 | { 155 | return array_keys($this->sigslots); 156 | } 157 | 158 | /** 159 | * Returns TRUE there are slots subscribed for a specified signal. 160 | * 161 | * @param string $signal 162 | * @return boolean 163 | */ 164 | public function hasHandlers($signal) 165 | { 166 | return empty($this->sigslots[$signal]) ? FALSE : TRUE; 167 | } 168 | 169 | /** 170 | * Returns all slots for a specified signal. 171 | * 172 | * @param string $signal 173 | * @return array 174 | */ 175 | public function getHandlers($signal) 176 | { 177 | if(!$this->hasHandlers($signal)) 178 | { 179 | return $this->sigslots[$signal]; 180 | } 181 | 182 | return array(); 183 | } 184 | 185 | /** 186 | * Clears all slots for a specified signal. 187 | * 188 | * @param string $signal 189 | * @return void 190 | */ 191 | public function clearHandlers($signal) 192 | { 193 | if(!$this->hasHandlers($signal)) 194 | { 195 | unset($this->sigslots[$signal]); 196 | } 197 | } 198 | 199 | /** 200 | * Returns a singleton instance of TeamSpeak3_Helper_Signal. 201 | * 202 | * @return TeamSpeak3_Helper_Signal 203 | */ 204 | public static function getInstance() 205 | { 206 | if(self::$instance === null) 207 | { 208 | self::$instance = new self(); 209 | } 210 | 211 | return self::$instance; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Signal/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Signal_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Helper_Signal objects. 31 | */ 32 | class TeamSpeak3_Helper_Signal_Exception extends TeamSpeak3_Helper_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Helper/Signal/Handler.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Helper_Signal_Handler 30 | * @brief Helper class providing handler functions for signals. 31 | */ 32 | class TeamSpeak3_Helper_Signal_Handler 33 | { 34 | /** 35 | * Stores the name of the subscribed signal. 36 | * 37 | * @var string 38 | */ 39 | protected $signal = null; 40 | 41 | /** 42 | * Stores the callback function for the subscribed signal. 43 | * 44 | * @var mixed 45 | */ 46 | protected $callback = null; 47 | 48 | /** 49 | * The TeamSpeak3_Helper_Signal_Handler constructor. 50 | * 51 | * @param string $signal 52 | * @param mixed $callback 53 | * @throws TeamSpeak3_Helper_Signal_Exception 54 | * @return TeamSpeak3_Helper_Signal_Handler 55 | */ 56 | public function __construct($signal, $callback) 57 | { 58 | $this->signal = (string) $signal; 59 | 60 | if(!is_callable($callback)) 61 | { 62 | throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified for signal '" . $signal . "'"); 63 | } 64 | 65 | $this->callback = $callback; 66 | } 67 | 68 | /** 69 | * Invoke the signal handler. 70 | * 71 | * @param array $args 72 | * @return mixed 73 | */ 74 | public function call(array $args = array()) 75 | { 76 | return call_user_func_array($this->callback, $args); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Node/Channelgroup.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Node_Channelgroup 30 | * @brief Class describing a TeamSpeak 3 channel group and all it's parameters. 31 | */ 32 | class TeamSpeak3_Node_Channelgroup extends TeamSpeak3_Node_Abstract 33 | { 34 | /** 35 | * The TeamSpeak3_Node_Channelgroup constructor. 36 | * 37 | * @param TeamSpeak3_Node_Server $server 38 | * @param array $info 39 | * @param string $index 40 | * @throws TeamSpeak3_Adapter_ServerQuery_Exception 41 | * @return TeamSpeak3_Node_Channelgroup 42 | */ 43 | public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "cgid") 44 | { 45 | $this->parent = $server; 46 | $this->nodeInfo = $info; 47 | 48 | if(!array_key_exists($index, $this->nodeInfo)) 49 | { 50 | throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 51 | } 52 | 53 | $this->nodeId = $this->nodeInfo[$index]; 54 | } 55 | 56 | /** 57 | * Renames the channel group specified. 58 | * 59 | * @param string $name 60 | * @return void 61 | */ 62 | public function rename($name) 63 | { 64 | $this->getParent()->channelGroupRename($this->getId(), $name); 65 | } 66 | 67 | /** 68 | * Deletes the channel group. If $force is set to TRUE, the channel group will be 69 | * deleted even if there are clients within. 70 | * 71 | * @param boolean $force 72 | * @return void 73 | */ 74 | public function delete($force = FALSE) 75 | { 76 | $this->getParent()->channelGroupDelete($this->getId(), $force); 77 | } 78 | 79 | /** 80 | * Creates a copy of the channel group and returns the new groups ID. 81 | * 82 | * @param string $name 83 | * @param integer $tcgid 84 | * @param integer $type 85 | * @return integer 86 | */ 87 | public function copy($name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 88 | { 89 | return $this->getParent()->channelGroupCopy($this->getId(), $name, $tcgid, $type); 90 | } 91 | 92 | /** 93 | * Returns a list of permissions assigned to the channel group. 94 | * 95 | * @param boolean $permsid 96 | * @return array 97 | */ 98 | public function permList($permsid = FALSE) 99 | { 100 | return $this->getParent()->channelGroupPermList($this->getId(), $permsid); 101 | } 102 | 103 | /** 104 | * Adds a set of specified permissions to the channel group. Multiple permissions 105 | * can be added by providing the two parameters of each permission in separate arrays. 106 | * 107 | * @param integer $permid 108 | * @param integer $permvalue 109 | * @return void 110 | */ 111 | public function permAssign($permid, $permvalue) 112 | { 113 | $this->getParent()->channelGroupPermAssign($this->getId(), $permid, $permvalue); 114 | } 115 | 116 | /** 117 | * Alias for permAssign(). 118 | * 119 | * @deprecated 120 | */ 121 | public function permAssignByName($permname, $permvalue) 122 | { 123 | $this->permAssign($permname, $permvalue); 124 | } 125 | 126 | /** 127 | * Removes a set of specified permissions from the channel group. Multiple 128 | * permissions can be removed at once. 129 | * 130 | * @param integer $permid 131 | * @return void 132 | */ 133 | public function permRemove($permid) 134 | { 135 | $this->getParent()->channelGroupPermRemove($this->getId(), $permid); 136 | } 137 | 138 | /** 139 | * Alias for permAssign(). 140 | * 141 | * @deprecated 142 | */ 143 | public function permRemoveByName($permname) 144 | { 145 | $this->permRemove($permname); 146 | } 147 | 148 | /** 149 | * Returns a list of clients assigned to the server group specified. 150 | * 151 | * @return array|TeamSpeak3_Node_Client[] 152 | */ 153 | public function clientList() 154 | { 155 | return $this->getParent()->channelGroupClientList($this->getId()); 156 | } 157 | 158 | /** 159 | * Alias for privilegeKeyCreate(). 160 | * 161 | * @deprecated 162 | */ 163 | public function tokenCreate($cid, $description = null, $customset = null) 164 | { 165 | return $this->privilegeKeyCreate($cid, $description, $customset); 166 | } 167 | 168 | /** 169 | * Creates a new privilege key (token) for the channel group and returns the key. 170 | * 171 | * @param integer $cid 172 | * @param string $description 173 | * @param string $customset 174 | * @return TeamSpeak3_Helper_String 175 | */ 176 | public function privilegeKeyCreate($cid, $description = null, $customset = null) 177 | { 178 | return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_CHANNELGROUP, $this->getId(), $cid, $description, $customset); 179 | } 180 | 181 | /** 182 | * Sends a text message to all clients residing in the channel group on the virtual server. 183 | * 184 | * @param string $msg 185 | * @return void 186 | */ 187 | public function message($msg) 188 | { 189 | foreach($this as $client) 190 | { 191 | try 192 | { 193 | $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 194 | } 195 | catch(TeamSpeak3_Adapter_ServerQuery_Exception $e) 196 | { 197 | /* ERROR_client_invalid_id */ 198 | if($e->getCode() != 0x0200) throw $e; 199 | } 200 | } 201 | } 202 | 203 | /** 204 | * Downloads and returns the channel groups icon file content. 205 | * 206 | * @return TeamSpeak3_Helper_String 207 | */ 208 | public function iconDownload() 209 | { 210 | if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return; 211 | 212 | $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid")); 213 | $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]); 214 | 215 | return $transfer->download($download["ftkey"], $download["size"]); 216 | } 217 | 218 | /** 219 | * @ignore 220 | */ 221 | protected function fetchNodeList() 222 | { 223 | $this->nodeList = array(); 224 | 225 | foreach($this->getParent()->clientList() as $client) 226 | { 227 | if($client["client_channel_group_id"] == $this->getId()) 228 | { 229 | $this->nodeList[] = $client; 230 | } 231 | } 232 | } 233 | 234 | /** 235 | * Returns a unique identifier for the node which can be used as a HTML property. 236 | * 237 | * @return string 238 | */ 239 | public function getUniqueId() 240 | { 241 | return $this->getParent()->getUniqueId() . "_cg" . $this->getId(); 242 | } 243 | 244 | /** 245 | * Returns the name of a possible icon to display the node object. 246 | * 247 | * @return string 248 | */ 249 | public function getIcon() 250 | { 251 | return "group_channel"; 252 | } 253 | 254 | /** 255 | * Returns a symbol representing the node. 256 | * 257 | * @return string 258 | */ 259 | public function getSymbol() 260 | { 261 | return "%"; 262 | } 263 | 264 | /** 265 | * Returns a string representation of this node. 266 | * 267 | * @return string 268 | */ 269 | public function __toString() 270 | { 271 | return (string) $this["name"]; 272 | } 273 | } 274 | 275 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Node/Client.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Node_Client 30 | * @brief Class describing a TeamSpeak 3 client and all it's parameters. 31 | */ 32 | class TeamSpeak3_Node_Client extends TeamSpeak3_Node_Abstract 33 | { 34 | /** 35 | * The TeamSpeak3_Node_Client constructor. 36 | * 37 | * @param TeamSpeak3_Node_Server $server 38 | * @param array $info 39 | * @param string $index 40 | * @throws TeamSpeak3_Adapter_ServerQuery_Exception 41 | * @return TeamSpeak3_Node_Client 42 | */ 43 | public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "clid") 44 | { 45 | $this->parent = $server; 46 | $this->nodeInfo = $info; 47 | 48 | if(!array_key_exists($index, $this->nodeInfo)) 49 | { 50 | throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 51 | } 52 | 53 | $this->nodeId = $this->nodeInfo[$index]; 54 | } 55 | 56 | /** 57 | * Changes the clients properties using given properties. 58 | * 59 | * @param array $properties 60 | * @return void 61 | */ 62 | public function modify(array $properties) 63 | { 64 | $properties["clid"] = $this->getId(); 65 | 66 | $this->execute("clientedit", $properties); 67 | $this->resetNodeInfo(); 68 | } 69 | 70 | /** 71 | * Changes the clients properties using given properties. 72 | * 73 | * @param array $properties 74 | * @return void 75 | */ 76 | public function modifyDb(array $properties) 77 | { 78 | $this->getParent()->clientModifyDb($this["client_database_id"], $properties); 79 | } 80 | 81 | /** 82 | * Deletes the clients properties from the database. 83 | * 84 | * @return void 85 | */ 86 | public function deleteDb() 87 | { 88 | $this->getParent()->clientDeleteDb($this["client_database_id"]); 89 | } 90 | 91 | /** 92 | * Returns a list of properties from the database for the client. 93 | * 94 | * @return array 95 | */ 96 | public function infoDb() 97 | { 98 | return $this->getParent()->clientInfoDb($this["client_database_id"]); 99 | } 100 | 101 | /** 102 | * Sends a text message to the client. 103 | * 104 | * @param string $msg 105 | * @return void 106 | */ 107 | public function message($msg) 108 | { 109 | $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 110 | } 111 | 112 | /** 113 | * Moves the client to another channel. 114 | * 115 | * @param integer $cid 116 | * @param string $cpw 117 | * @return void 118 | */ 119 | public function move($cid, $cpw = null) 120 | { 121 | $this->getParent()->clientMove($this->getId(), $cid, $cpw); 122 | } 123 | 124 | /** 125 | * Kicks the client from his currently joined channel or from the server. 126 | * 127 | * @param integer $reasonid 128 | * @param string $reasonmsg 129 | * @return void 130 | */ 131 | public function kick($reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null) 132 | { 133 | $this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg); 134 | } 135 | 136 | /** 137 | * Sends a poke message to the client. 138 | * 139 | * @param string $msg 140 | * @return void 141 | */ 142 | public function poke($msg) 143 | { 144 | $this->getParent()->clientPoke($this->getId(), $msg); 145 | } 146 | 147 | /** 148 | * Bans the client from the server. Please note that this will create two separate 149 | * ban rules for the targeted clients IP address and his unique identifier. 150 | * 151 | * @param integer $timeseconds 152 | * @param string $reason 153 | * @return array 154 | */ 155 | public function ban($timeseconds = null, $reason = null) 156 | { 157 | return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason); 158 | } 159 | 160 | /** 161 | * Returns a list of custom properties for the client. 162 | * 163 | * @return array 164 | */ 165 | public function customInfo() 166 | { 167 | return $this->getParent()->customInfo($this["client_database_id"]); 168 | } 169 | 170 | /** 171 | * Returns an array containing the permission overview of the client. 172 | * 173 | * @param integer $cid 174 | * @return array 175 | */ 176 | public function permOverview($cid) 177 | { 178 | return $this->execute("permoverview", array("cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0))->toArray(); 179 | } 180 | 181 | /** 182 | * Returns a list of permissions defined for the client. 183 | * 184 | * @param boolean $permsid 185 | * @return array 186 | */ 187 | public function permList($permsid = FALSE) 188 | { 189 | return $this->getParent()->clientPermList($this["client_database_id"], $permsid); 190 | } 191 | 192 | /** 193 | * Adds a set of specified permissions to the client. Multiple permissions can be added by providing 194 | * the three parameters of each permission. 195 | * 196 | * @param integer $permid 197 | * @param integer $permvalue 198 | * @param integer $permskip 199 | * @return void 200 | */ 201 | public function permAssign($permid, $permvalue, $permskip = FALSE) 202 | { 203 | $this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip); 204 | } 205 | 206 | /** 207 | * Alias for permAssign(). 208 | * 209 | * @deprecated 210 | */ 211 | public function permAssignByName($permname, $permvalue, $permskip = FALSE) 212 | { 213 | $this->permAssign($permname, $permvalue, $permskip); 214 | } 215 | 216 | /** 217 | * Removes a set of specified permissions from a client. Multiple permissions can be removed at once. 218 | * 219 | * @param integer $permid 220 | * @return void 221 | */ 222 | public function permRemove($permid) 223 | { 224 | $this->getParent()->clientPermRemove($this["client_database_id"], $permid); 225 | } 226 | 227 | /** 228 | * Alias for permRemove(). 229 | * 230 | * @deprecated 231 | */ 232 | public function permRemoveByName($permname) 233 | { 234 | $this->permRemove($permname); 235 | } 236 | 237 | /** 238 | * Sets the channel group of a client to the ID specified. 239 | * 240 | * @param integer $cid 241 | * @param integer $cgid 242 | * @return void 243 | */ 244 | public function setChannelGroup($cid, $cgid) 245 | { 246 | $this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid); 247 | } 248 | 249 | /** 250 | * Adds the client to the server group specified with $sgid. 251 | * 252 | * @param integer $sgid 253 | * @return void 254 | */ 255 | public function addServerGroup($sgid) 256 | { 257 | $this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]); 258 | } 259 | 260 | /** 261 | * Removes the client from the server group specified with $sgid. 262 | * 263 | * @param integer $sgid 264 | * @return void 265 | */ 266 | public function remServerGroup($sgid) 267 | { 268 | $this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]); 269 | } 270 | 271 | /** 272 | * Returns the possible name of the clients avatar. 273 | * 274 | * @return TeamSpeak3_Helper_String 275 | */ 276 | public function avatarGetName() 277 | { 278 | return new TeamSpeak3_Helper_String("/avatar_" . $this["client_base64HashClientUID"]); 279 | } 280 | 281 | /** 282 | * Downloads and returns the clients avatar file content. 283 | * 284 | * @return TeamSpeak3_Helper_String 285 | */ 286 | public function avatarDownload() 287 | { 288 | if($this["client_flag_avatar"] == NULL) return; 289 | 290 | $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName()); 291 | $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]); 292 | 293 | return $transfer->download($download["ftkey"], $download["size"]); 294 | } 295 | 296 | /** 297 | * Returns a list of client connections using the same identity as this client. 298 | * 299 | * @return array 300 | */ 301 | public function getClones() 302 | { 303 | return $this->execute("clientgetids", array("cluid" => $this["client_unique_identifier"]))->toAssocArray("clid"); 304 | } 305 | 306 | /** 307 | * Returns the revision/build number from the clients version string. 308 | * 309 | * @return integer 310 | */ 311 | public function getRev() 312 | { 313 | return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits(); 314 | } 315 | 316 | /** 317 | * Returns all server and channel groups the client is currently residing in. 318 | * 319 | * @return array 320 | */ 321 | public function memberOf() 322 | { 323 | $groups = array($this->getParent()->channelGroupGetById($this["client_channel_group_id"])); 324 | 325 | foreach(explode(",", $this["client_servergroups"]) as $sgid) 326 | { 327 | $groups[] = $this->getParent()->serverGroupGetById($sgid); 328 | } 329 | 330 | return $groups; 331 | } 332 | 333 | /** 334 | * Downloads and returns the clients icon file content. 335 | * 336 | * @return TeamSpeak3_Helper_String 337 | */ 338 | public function iconDownload() 339 | { 340 | if($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) return; 341 | 342 | $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("client_icon_id")); 343 | $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]); 344 | 345 | return $transfer->download($download["ftkey"], $download["size"]); 346 | } 347 | 348 | /** 349 | * Sends a plugin command to the client. 350 | * 351 | * @param string $plugin 352 | * @param string $data 353 | * @return void 354 | */ 355 | public function sendPluginCmd($plugin, $data) 356 | { 357 | $this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_CLIENT, "target" => $this->getId())); 358 | } 359 | 360 | /** 361 | * @ignore 362 | */ 363 | protected function fetchNodeInfo() 364 | { 365 | if($this->offsetExists("client_type") && $this["client_type"] == 1) return; 366 | 367 | $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("clientinfo", array("clid" => $this->getId()))->toList()); 368 | } 369 | 370 | /** 371 | * Returns a unique identifier for the node which can be used as a HTML property. 372 | * 373 | * @return string 374 | */ 375 | public function getUniqueId() 376 | { 377 | return $this->getParent()->getUniqueId() . "_cl" . $this->getId(); 378 | } 379 | 380 | /** 381 | * Returns the name of a possible icon to display the node object. 382 | * 383 | * @return string 384 | */ 385 | public function getIcon() 386 | { 387 | if($this["client_type"]) 388 | { 389 | return "client_query"; 390 | } 391 | elseif($this["client_away"]) 392 | { 393 | return "client_away"; 394 | } 395 | elseif(!$this["client_output_hardware"]) 396 | { 397 | return "client_snd_disabled"; 398 | } 399 | elseif($this["client_output_muted"]) 400 | { 401 | return "client_snd_muted"; 402 | } 403 | elseif(!$this["client_input_hardware"]) 404 | { 405 | return "client_mic_disabled"; 406 | } 407 | elseif($this["client_input_muted"]) 408 | { 409 | return "client_mic_muted"; 410 | } 411 | elseif($this["client_is_channel_commander"]) 412 | { 413 | return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle"; 414 | } 415 | else 416 | { 417 | return $this["client_flag_talking"] ? "client_talk" : "client_idle"; 418 | } 419 | } 420 | 421 | /** 422 | * Returns a symbol representing the node. 423 | * 424 | * @return string 425 | */ 426 | public function getSymbol() 427 | { 428 | return "@"; 429 | } 430 | 431 | /** 432 | * Returns a string representation of this node. 433 | * 434 | * @return string 435 | */ 436 | public function __toString() 437 | { 438 | return (string) $this["client_nickname"]; 439 | } 440 | } 441 | 442 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Node/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Node_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Node_Abstract objects. 31 | */ 32 | class TeamSpeak3_Node_Exception extends TeamSpeak3_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Node/Servergroup.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Node_Servergroup 30 | * @brief Class describing a TeamSpeak 3 server group and all it's parameters. 31 | */ 32 | class TeamSpeak3_Node_Servergroup extends TeamSpeak3_Node_Abstract 33 | { 34 | /** 35 | * The TeamSpeak3_Node_Servergroup constructor. 36 | * 37 | * @param TeamSpeak3_Node_Server $server 38 | * @param array $info 39 | * @param string $index 40 | * @throws TeamSpeak3_Node_Exception 41 | * @return TeamSpeak3_Node_Servergroup 42 | */ 43 | public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "sgid") 44 | { 45 | $this->parent = $server; 46 | $this->nodeInfo = $info; 47 | 48 | if(!array_key_exists($index, $this->nodeInfo)) 49 | { 50 | throw new TeamSpeak3_Node_Exception("invalid groupID", 0xA00); 51 | } 52 | 53 | $this->nodeId = $this->nodeInfo[$index]; 54 | } 55 | 56 | /** 57 | * Renames the server group specified. 58 | * 59 | * @param string $name 60 | * @return void 61 | */ 62 | public function rename($name) 63 | { 64 | $this->getParent()->serverGroupRename($this->getId(), $name); 65 | } 66 | 67 | /** 68 | * Deletes the server group. If $force is set to 1, the server group will be 69 | * deleted even if there are clients within. 70 | * 71 | * @param boolean $force 72 | * @return void 73 | */ 74 | public function delete($force = FALSE) 75 | { 76 | $this->getParent()->serverGroupDelete($this->getId(), $force); 77 | } 78 | 79 | /** 80 | * Creates a copy of the server group and returns the new groups ID. 81 | * 82 | * @param string $name 83 | * @param integer $tsgid 84 | * @param integer $type 85 | * @return integer 86 | */ 87 | public function copy($name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 88 | { 89 | return $this->getParent()->serverGroupCopy($this->getId(), $name, $tsgid, $type); 90 | } 91 | 92 | /** 93 | * Returns a list of permissions assigned to the server group. 94 | * 95 | * @param boolean $permsid 96 | * @return array 97 | */ 98 | public function permList($permsid = FALSE) 99 | { 100 | return $this->getParent()->serverGroupPermList($this->getId(), $permsid); 101 | } 102 | 103 | /** 104 | * Adds a set of specified permissions to the server group. Multiple permissions 105 | * can be added by providing the four parameters of each permission in separate arrays. 106 | * 107 | * @param integer $permid 108 | * @param integer $permvalue 109 | * @param integer $permnegated 110 | * @param integer $permskip 111 | * @return void 112 | */ 113 | public function permAssign($permid, $permvalue, $permnegated = FALSE, $permskip = FALSE) 114 | { 115 | $this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip); 116 | } 117 | 118 | /** 119 | * Alias for permAssign(). 120 | * 121 | * @deprecated 122 | */ 123 | public function permAssignByName($permname, $permvalue, $permnegated = FALSE, $permskip = FALSE) 124 | { 125 | $this->permAssign($permname, $permvalue, $permnegated, $permskip); 126 | } 127 | 128 | /** 129 | * Removes a set of specified permissions from the server group. Multiple 130 | * permissions can be removed at once. 131 | * 132 | * @param integer $permid 133 | * @return void 134 | */ 135 | public function permRemove($permid) 136 | { 137 | $this->getParent()->serverGroupPermRemove($this->getId(), $permid); 138 | } 139 | 140 | /** 141 | * Alias for permRemove(). 142 | * 143 | * @deprecated 144 | */ 145 | public function permRemoveByName($permname) 146 | { 147 | $this->permRemove($permname); 148 | } 149 | 150 | /** 151 | * Returns a list of clients assigned to the server group specified. 152 | * 153 | * @return array|TeamSpeak3_Node_Client[] 154 | */ 155 | public function clientList() 156 | { 157 | return $this->getParent()->serverGroupClientList($this->getId()); 158 | } 159 | 160 | /** 161 | * Adds a client to the server group specified. Please note that a client cannot be 162 | * added to default groups or template groups. 163 | * 164 | * @param integer $cldbid 165 | * @return void 166 | */ 167 | public function clientAdd($cldbid) 168 | { 169 | $this->getParent()->serverGroupClientAdd($this->getId(), $cldbid); 170 | } 171 | 172 | /** 173 | * Removes a client from the server group. 174 | * 175 | * @param integer $cldbid 176 | * @return void 177 | */ 178 | public function clientDel($cldbid) 179 | { 180 | $this->getParent()->serverGroupClientDel($this->getId(), $cldbid); 181 | } 182 | 183 | /** 184 | * Alias for privilegeKeyCreate(). 185 | * 186 | * @deprecated 187 | */ 188 | public function tokenCreate($description = null, $customset = null) 189 | { 190 | return $this->privilegeKeyCreate($description, $customset); 191 | } 192 | 193 | /** 194 | * Creates a new privilege key (token) for the server group and returns the key. 195 | * 196 | * @param string $description 197 | * @param string $customset 198 | * @return TeamSpeak3_Helper_String 199 | */ 200 | public function privilegeKeyCreate($description = null, $customset = null) 201 | { 202 | return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_SERVERGROUP, $this->getId(), 0, $description, $customset); 203 | } 204 | 205 | /** 206 | * Sends a text message to all clients residing in the server group on the virtual server. 207 | * 208 | * @param string $msg 209 | * @return void 210 | */ 211 | public function message($msg) 212 | { 213 | foreach($this as $client) 214 | { 215 | try 216 | { 217 | $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 218 | } 219 | catch(TeamSpeak3_Adapter_ServerQuery_Exception $e) 220 | { 221 | /* ERROR_client_invalid_id */ 222 | if($e->getCode() != 0x0200) throw $e; 223 | } 224 | } 225 | } 226 | 227 | /** 228 | * Downloads and returns the server groups icon file content. 229 | * 230 | * @return TeamSpeak3_Helper_String 231 | */ 232 | public function iconDownload() 233 | { 234 | if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return; 235 | 236 | $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid")); 237 | $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]); 238 | 239 | return $transfer->download($download["ftkey"], $download["size"]); 240 | } 241 | 242 | /** 243 | * @ignore 244 | */ 245 | protected function fetchNodeList() 246 | { 247 | $this->nodeList = array(); 248 | 249 | foreach($this->getParent()->clientList() as $client) 250 | { 251 | if(in_array($this->getId(), explode(",", $client["client_servergroups"]))) 252 | { 253 | $this->nodeList[] = $client; 254 | } 255 | } 256 | } 257 | 258 | /** 259 | * Returns a unique identifier for the node which can be used as a HTML property. 260 | * 261 | * @return string 262 | */ 263 | public function getUniqueId() 264 | { 265 | return $this->getParent()->getUniqueId() . "_sg" . $this->getId(); 266 | } 267 | 268 | /** 269 | * Returns the name of a possible icon to display the node object. 270 | * 271 | * @return string 272 | */ 273 | public function getIcon() 274 | { 275 | return "group_server"; 276 | } 277 | 278 | /** 279 | * Returns a symbol representing the node. 280 | * 281 | * @return string 282 | */ 283 | public function getSymbol() 284 | { 285 | return "%"; 286 | } 287 | 288 | /** 289 | * Returns a string representation of this node. 290 | * 291 | * @return string 292 | */ 293 | public function __toString() 294 | { 295 | return (string) $this["name"]; 296 | } 297 | } 298 | 299 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Transport/Abstract.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Transport_Abstract 30 | * @brief Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport. 31 | */ 32 | abstract class TeamSpeak3_Transport_Abstract 33 | { 34 | /** 35 | * Stores user-provided configuration settings. 36 | * 37 | * @var array 38 | */ 39 | protected $config = null; 40 | 41 | /** 42 | * Stores the stream resource of the connection. 43 | * 44 | * @var resource 45 | */ 46 | protected $stream = null; 47 | 48 | /** 49 | * Stores the TeamSpeak3_Adapter_Abstract object using this transport. 50 | * 51 | * @var TeamSpeak3_Adapter_Abstract 52 | */ 53 | protected $adapter = null; 54 | 55 | /** 56 | * The TeamSpeak3_Transport_Abstract constructor. 57 | * 58 | * @param array $config 59 | * @throws TeamSpeak3_Transport_Exception 60 | * @return TeamSpeak3_Transport_Abstract 61 | */ 62 | public function __construct(array $config) 63 | { 64 | if(!array_key_exists("host", $config)) 65 | { 66 | throw new TeamSpeak3_Transport_Exception("config must have a key for 'host' which specifies the server host name"); 67 | } 68 | 69 | if(!array_key_exists("port", $config)) 70 | { 71 | throw new TeamSpeak3_Transport_Exception("config must have a key for 'port' which specifies the server port number"); 72 | } 73 | 74 | if(!array_key_exists("timeout", $config)) 75 | { 76 | $config["timeout"] = 10; 77 | } 78 | 79 | if(!array_key_exists("blocking", $config)) 80 | { 81 | $config["blocking"] = 1; 82 | } 83 | 84 | $this->config = $config; 85 | } 86 | 87 | /** 88 | * Commit pending data. 89 | * 90 | * @return array 91 | */ 92 | public function __sleep() 93 | { 94 | return array("config"); 95 | } 96 | 97 | /** 98 | * Reconnects to the remote server. 99 | * 100 | * @return void 101 | */ 102 | public function __wakeup() 103 | { 104 | $this->connect(); 105 | } 106 | 107 | /** 108 | * The TeamSpeak3_Transport_Abstract destructor. 109 | * 110 | * @return void 111 | */ 112 | public function __destruct() 113 | { 114 | if($this->adapter instanceof TeamSpeak3_Adapter_Abstract) 115 | { 116 | $this->adapter->__destruct(); 117 | } 118 | 119 | $this->disconnect(); 120 | } 121 | 122 | /** 123 | * Connects to a remote server. 124 | * 125 | * @throws TeamSpeak3_Transport_Exception 126 | * @return void 127 | */ 128 | abstract public function connect(); 129 | 130 | /** 131 | * Disconnects from a remote server. 132 | * 133 | * @return void 134 | */ 135 | abstract public function disconnect(); 136 | 137 | /** 138 | * Reads data from the stream. 139 | * 140 | * @param integer $length 141 | * @throws TeamSpeak3_Transport_Exception 142 | * @return TeamSpeak3_Helper_String 143 | */ 144 | abstract public function read($length = 4096); 145 | 146 | /** 147 | * Writes data to the stream. 148 | * 149 | * @param string $data 150 | * @return void 151 | */ 152 | abstract public function send($data); 153 | 154 | /** 155 | * Returns the underlying stream resource. 156 | * 157 | * @return resource 158 | */ 159 | public function getStream() 160 | { 161 | return $this->stream; 162 | } 163 | 164 | /** 165 | * Returns the configuration variables in this adapter. 166 | * 167 | * @param string $key 168 | * @param mixed $default 169 | * @return array 170 | */ 171 | public function getConfig($key = null, $default = null) 172 | { 173 | if($key !== null) 174 | { 175 | return array_key_exists($key, $this->config) ? $this->config[$key] : $default; 176 | } 177 | 178 | return $this->config; 179 | } 180 | 181 | /** 182 | * Sets the TeamSpeak3_Adapter_Abstract object using this transport. 183 | * 184 | * @param TeamSpeak3_Adapter_Abstract $adapter 185 | * @return void 186 | */ 187 | public function setAdapter(TeamSpeak3_Adapter_Abstract $adapter) 188 | { 189 | $this->adapter = $adapter; 190 | } 191 | 192 | /** 193 | * Returns the TeamSpeak3_Adapter_Abstract object using this transport. 194 | * 195 | * @return TeamSpeak3_Adapter_Abstract 196 | */ 197 | public function getAdapter() 198 | { 199 | return $this->adapter; 200 | } 201 | 202 | /** 203 | * Returns the adapter type. 204 | * 205 | * @return string 206 | */ 207 | public function getAdapterType() 208 | { 209 | if($this->adapter instanceof TeamSpeak3_Adapter_Abstract) 210 | { 211 | $string = TeamSpeak3_Helper_String::factory(get_class($this->adapter)); 212 | 213 | return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString(); 214 | } 215 | 216 | return "Unknown"; 217 | } 218 | 219 | /** 220 | * Returns header/meta data from stream pointer. 221 | * 222 | * @throws TeamSpeak3_Transport_Exception 223 | * @return array 224 | */ 225 | public function getMetaData() 226 | { 227 | if($this->stream === null) 228 | { 229 | throw new TeamSpeak3_Transport_Exception("unable to retrieve header/meta data from stream pointer"); 230 | } 231 | 232 | return stream_get_meta_data($this->stream); 233 | } 234 | 235 | /** 236 | * Returns TRUE if the transport is connected. 237 | * 238 | * @return boolean 239 | */ 240 | public function isConnected() 241 | { 242 | return (is_resource($this->stream)) ? TRUE : FALSE; 243 | } 244 | 245 | /** 246 | * Blocks a stream until data is available for reading if the stream is connected 247 | * in non-blocking mode. 248 | * 249 | * @param integer $time 250 | * @return void 251 | */ 252 | protected function waitForReadyRead($time = 0) 253 | { 254 | if(!$this->isConnected() || $this->config["blocking"]) return; 255 | 256 | do 257 | { 258 | $read = array($this->stream); 259 | $null = null; 260 | 261 | if($time) 262 | { 263 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter()); 264 | } 265 | 266 | $time = $time+$this->config["timeout"]; 267 | } 268 | while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0); 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Transport/Exception.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Transport_Exception 30 | * @brief Enhanced exception class for TeamSpeak3_Transport_Abstract objects. 31 | */ 32 | class TeamSpeak3_Transport_Exception extends TeamSpeak3_Exception {} 33 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Transport/TCP.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Transport_TCP 30 | * @brief Class for connecting to a remote server through TCP. 31 | */ 32 | class TeamSpeak3_Transport_TCP extends TeamSpeak3_Transport_Abstract 33 | { 34 | /** 35 | * Connects to a remote server. 36 | * 37 | * @throws TeamSpeak3_Transport_Exception 38 | * @return void 39 | */ 40 | public function connect() 41 | { 42 | if($this->stream !== null) return; 43 | 44 | $host = strval($this->config["host"]); 45 | $port = strval($this->config["port"]); 46 | 47 | $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port; 48 | $timeout = (int) $this->config["timeout"]; 49 | 50 | $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout); 51 | 52 | if($this->stream === FALSE) 53 | { 54 | throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno); 55 | } 56 | 57 | @stream_set_timeout($this->stream, $timeout); 58 | @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0); 59 | } 60 | 61 | /** 62 | * Disconnects from a remote server. 63 | * 64 | * @return void 65 | */ 66 | public function disconnect() 67 | { 68 | if($this->stream === null) return; 69 | 70 | $this->stream = null; 71 | 72 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected"); 73 | } 74 | 75 | /** 76 | * Reads data from the stream. 77 | * 78 | * @param integer $length 79 | * @throws TeamSpeak3_Transport_Exception 80 | * @return TeamSpeak3_Helper_String 81 | */ 82 | public function read($length = 4096) 83 | { 84 | $this->connect(); 85 | $this->waitForReadyRead(); 86 | 87 | $data = @stream_get_contents($this->stream, $length); 88 | 89 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); 90 | 91 | if($data === FALSE) 92 | { 93 | throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); 94 | } 95 | 96 | return new TeamSpeak3_Helper_String($data); 97 | } 98 | 99 | /** 100 | * Reads a single line of data from the stream. 101 | * 102 | * @param string $token 103 | * @throws TeamSpeak3_Transport_Exception 104 | * @return TeamSpeak3_Helper_String 105 | */ 106 | public function readLine($token = "\n") 107 | { 108 | $this->connect(); 109 | 110 | $line = TeamSpeak3_Helper_String::factory(""); 111 | 112 | while(!$line->endsWith($token)) 113 | { 114 | $this->waitForReadyRead(); 115 | 116 | $data = @fgets($this->stream, 4096); 117 | 118 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); 119 | 120 | if($data === FALSE) 121 | { 122 | if($line->count()) 123 | { 124 | $line->append($token); 125 | } 126 | else 127 | { 128 | throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); 129 | } 130 | } 131 | else 132 | { 133 | $line->append($data); 134 | } 135 | } 136 | 137 | return $line->trim(); 138 | } 139 | 140 | /** 141 | * Writes data to the stream. 142 | * 143 | * @param string $data 144 | * @return void 145 | */ 146 | public function send($data) 147 | { 148 | $this->connect(); 149 | 150 | @stream_socket_sendto($this->stream, $data); 151 | 152 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data); 153 | } 154 | 155 | /** 156 | * Writes a line of data to the stream. 157 | * 158 | * @param string $data 159 | * @param string $separator 160 | * @return void 161 | */ 162 | public function sendLine($data, $separator = "\n") 163 | { 164 | $size = strlen($data); 165 | $pack = 4096; 166 | 167 | for($seek = 0 ;$seek < $size;) 168 | { 169 | $rest = $size-$seek; 170 | $pack = $rest < $pack ? $rest : $pack; 171 | $buff = substr($data, $seek, $pack); 172 | $seek = $seek+$pack; 173 | 174 | if($seek >= $size) $buff .= $separator; 175 | 176 | $this->send($buff); 177 | } 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Transport/UDP.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Transport_UDP 30 | * @brief Class for connecting to a remote server through UDP. 31 | */ 32 | class TeamSpeak3_Transport_UDP extends TeamSpeak3_Transport_Abstract 33 | { 34 | /** 35 | * Connects to a remote server. 36 | * 37 | * @throws TeamSpeak3_Transport_Exception 38 | * @return void 39 | */ 40 | public function connect() 41 | { 42 | if($this->stream !== null) return; 43 | 44 | $host = strval($this->config["host"]); 45 | $port = strval($this->config["port"]); 46 | 47 | $address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port; 48 | $timeout = (int) $this->config["timeout"]; 49 | 50 | $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout); 51 | 52 | if($this->stream === FALSE) 53 | { 54 | throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno); 55 | } 56 | 57 | @stream_set_timeout($this->stream, $timeout); 58 | @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0); 59 | } 60 | 61 | /** 62 | * Disconnects from a remote server. 63 | * 64 | * @return void 65 | */ 66 | public function disconnect() 67 | { 68 | if($this->stream === null) return; 69 | 70 | $this->stream = null; 71 | 72 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected"); 73 | } 74 | 75 | /** 76 | * Reads data from the stream. 77 | * 78 | * @param integer $length 79 | * @throws TeamSpeak3_Transport_Exception 80 | * @return TeamSpeak3_Helper_String 81 | */ 82 | public function read($length = 4096) 83 | { 84 | $this->connect(); 85 | $this->waitForReadyRead(); 86 | 87 | $data = @fread($this->stream, $length); 88 | 89 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); 90 | 91 | if($data === FALSE) 92 | { 93 | throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); 94 | } 95 | 96 | return new TeamSpeak3_Helper_String($data); 97 | } 98 | 99 | /** 100 | * Writes data to the stream. 101 | * 102 | * @param string $data 103 | * @return void 104 | */ 105 | public function send($data) 106 | { 107 | $this->connect(); 108 | 109 | @stream_socket_sendto($this->stream, $data); 110 | 111 | TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Viewer/Interface.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Viewer_Interface 30 | * @brief Interface class describing a TeamSpeak 3 viewer. 31 | */ 32 | interface TeamSpeak3_Viewer_Interface 33 | { 34 | /** 35 | * Returns the code needed to display a node in a TeamSpeak 3 viewer. 36 | * 37 | * @param TeamSpeak3_Node_Abstract $node 38 | * @param array $siblings 39 | * @return string 40 | */ 41 | public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array()); 42 | } 43 | -------------------------------------------------------------------------------- /libraries/TeamSpeak3/Viewer/Text.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | * @package TeamSpeak3 23 | * @version 1.1.24 24 | * @author Sven 'ScP' Paulsen 25 | * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 26 | */ 27 | 28 | /** 29 | * @class TeamSpeak3_Viewer_Text 30 | * @brief Renders nodes used in ASCII-based TeamSpeak 3 viewers. 31 | */ 32 | class TeamSpeak3_Viewer_Text implements TeamSpeak3_Viewer_Interface 33 | { 34 | /** 35 | * A pre-defined pattern used to display a node in a TeamSpeak 3 viewer. 36 | * 37 | * @var string 38 | */ 39 | protected $pattern = "%0%1 %2\n"; 40 | 41 | /** 42 | * Returns the code needed to display a node in a TeamSpeak 3 viewer. 43 | * 44 | * @param TeamSpeak3_Node_Abstract $node 45 | * @param array $siblings 46 | * @return string 47 | */ 48 | public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array()) 49 | { 50 | $this->currObj = $node; 51 | $this->currSib = $siblings; 52 | 53 | $args = array( 54 | $this->getPrefix(), 55 | $this->getCorpusIcon(), 56 | $this->getCorpusName(), 57 | ); 58 | 59 | return TeamSpeak3_Helper_String::factory($this->pattern)->arg($args); 60 | } 61 | 62 | /** 63 | * Returns the ASCII string to display the prefix of the current node. 64 | * 65 | * @return string 66 | */ 67 | protected function getPrefix() 68 | { 69 | $prefix = ""; 70 | 71 | if(count($this->currSib)) 72 | { 73 | $last = array_pop($this->currSib); 74 | 75 | foreach($this->currSib as $sibling) 76 | { 77 | $prefix .= ($sibling) ? "| " : " "; 78 | } 79 | 80 | $prefix .= ($last) ? "\\-" : "|-"; 81 | } 82 | 83 | return $prefix; 84 | } 85 | 86 | /** 87 | * Returns an ASCII string which can be used to display the status icon for a 88 | * TeamSpeak_Node_Abstract object. 89 | * 90 | * @return string 91 | */ 92 | protected function getCorpusIcon() 93 | { 94 | return $this->currObj->getSymbol(); 95 | } 96 | 97 | /** 98 | * Returns a string for the current corpus element which contains the display name 99 | * for the current TeamSpeak_Node_Abstract object. 100 | * 101 | * @return string 102 | */ 103 | protected function getCorpusName() 104 | { 105 | return $this->currObj; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /modulos/iconizador.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | include './lang/loadlang.php'; 10 | require_once("libraries/TeamSpeak3/TeamSpeak3.php"); //Libreria del FRAMEWORK TS3 11 | session_start(); 12 | $client_uid = $_SESSION['client_uid']; 13 | $grupos = $_SESSION['grupos']; 14 | $client_db = $_SESSION['client_db']; 15 | $codigo = $_SESSION['codigo']; 16 | $i_code = $_POST["i_code"]; 17 | 18 | try { 19 | 20 | $connect = "serverquery://".$USER_QUERY.":".$PASS_QUERY."@".$HOST_QUERY.":".$PORT_QUERY."/?server_port=".$SERVER_PORT.""; 21 | $ts3_VirtualServer = TeamSpeak3::factory($connect); 22 | $ts3_VirtualServer->execute("clientupdate", array("client_nickname" => $NICK_QUERY)); 23 | $client = $ts3_VirtualServer->clientGetByUid($client_uid); 24 | echo '
'; 34 | 35 | 36 | if(empty($_POST["grupos"])) { 37 | echo "

".$lang['f_msgemptysave'].".


"; 38 | header("refresh: 10; url = ./"); 39 | die; 40 | } else { 41 | $n_grupos = $_POST["grupos"]; 42 | } 43 | if($i_code != $codigo) { 44 | echo "

".$lang['f_msgfailcode']."!


"; 45 | header("refresh: 10; url = ./"); 46 | die; 47 | } 48 | try { 49 | foreach($grupos as $group) { 50 | $needle = $group['id']; 51 | $miembros = $ts3_VirtualServer->serverGroupClientList($needle); 52 | $estaengrupo = False; 53 | foreach($miembros as $m) { 54 | if($m["client_unique_identifier"] == $client_uid) { 55 | $estaengrupo = True; 56 | } 57 | } 58 | if(in_array($needle,$n_grupos)) { 59 | if($estaengrupo == False) { 60 | $ts3_VirtualServer->serverGroupClientAdd($group["id"],$client_db); 61 | } 62 | } else { 63 | if($estaengrupo == True) { 64 | $ts3_VirtualServer->serverGroupClientDel($group["id"],$client_db); 65 | } 66 | } 67 | } 68 | header("refresh: 10; url = ./"); 69 | echo "
".$lang['succes']."
"; 70 | } catch(Exception $e) { 71 | if($DEBUG == True) { 72 | echo "[DEBUG] ".$lang['f_derrortitle']."
"; 73 | echo "[DEBUG] ".$lang['f_dmsg'].": ".$e->getMessage()."
"; 74 | echo "[DEBUG] ".$lang['f_dcode']." ".$e->getCode()."
"; 75 | } 76 | } 77 | 78 | 79 | 80 | } catch(Exception $e) { 81 | if($DEBUG == True) { 82 | echo "[DEBUG] ".$lang['f_derrortitle']."
"; 83 | echo "[DEBUG] ".$lang['f_dmsg'].": ".$e->getMessage()."
"; 84 | echo "[DEBUG] ".$lang['f_dcode']." ".$e->getCode()."
"; 85 | } 86 | if($e->getCode() == 0) { 87 | echo $lang['f_unk']; 88 | } else if($e->getCode() == 10060) { //Codigo de error de error en la conexion 89 | echo $lang['f_connectts']; 90 | } else if($e->getCode() == 512) { //Codigo de error cuando la UUID no es valida 91 | echo $lang['f_uuid']; 92 | } else if($e->getCode() == 520) { //Codigo de error cuando login o pass estan mal 93 | echo $lang['f_querydata']; 94 | } else if($e->getCode() == 3329) { //Codigo de error cuando la conexion fue baneada por el tsquery 95 | echo $lang['f_banned']; 96 | } else if($e->getCode() == 513) { //Codigo de error cuando ya hay una conexion del nombre 97 | echo $lang['f_twoconnect']; 98 | } else if($e->getCode() == 2568) { //Codigo de error cuando ya hay una conexion del nombre 99 | echo $lang['f_perms']; 100 | } 101 | 102 | } 103 | ?> 104 | -------------------------------------------------------------------------------- /modulos/listador.php: -------------------------------------------------------------------------------- 1 | 5 | * 6 | * @license MIT 7 | */ 8 | 9 | include './lang/loadlang.php'; 10 | require_once("libraries/TeamSpeak3/TeamSpeak3.php"); //Libreria del FRAMEWORK TS3 11 | session_start(); 12 | $_SESSION['client_uid'] = $_POST['uniid']; 13 | $client_uid = $_POST['uniid']; 14 | try { 15 | $connect = "serverquery://".$USER_QUERY.":".$PASS_QUERY."@".$HOST_QUERY.":".$PORT_QUERY."/?server_port=".$SERVER_PORT.""; 16 | $ts3_VirtualServer = TeamSpeak3::factory($connect); 17 | $ts3_VirtualServer->selfUpdate(array('client_nickname'=>$NICK_QUERY)); 18 | $client = $ts3_VirtualServer->clientGetByUid($client_uid); 19 | //echo $lang['l_idt'].": ".$client_uid."
"; 20 | $proceder = True; 21 | $conectado = False; 22 | $_SESSION['client_db'] = $client["client_database_id"]; 23 | if($client["client_nickname"] == $NICK_QUERY) { 24 | //echo $lang['l_lastname'].": NO DISPONIBLE
"; 25 | $proceder = False; 26 | } else { 27 | //echo $lang['l_lastname'].": ".$client["client_nickname"]."
"; 28 | $conectado = True; 29 | } 30 | echo '
'; 40 | if($proceder == True) 41 | { 42 | echo "
"; 43 | $iconosm = 0; 44 | $server_groups = $ts3_VirtualServer->serverGroupList(); 45 | $servergroups = array(); 46 | # En vez de iterar por todos los grupos intenten 47 | foreach($server_groups as $group) { 48 | if($group->type != 1) { continue; } 49 | if(in_array($group["sortid"], $SID_GROUP)) { 50 | $servergroups[] = array('name' => (string)$group, 'id' => $group->sgid, 'type' => $group->type); 51 | } 52 | } 53 | $_SESSION['grupos'] = $servergroups; 54 | echo '
55 | 56 | 57 | 58 | 59 | 60 | 61 | '; 62 | foreach($servergroups as $group) { 63 | $miembros = $ts3_VirtualServer->serverGroupClientList($group["id"]); 64 | $estaengrupo = False; 65 | foreach($miembros as $m) { 66 | if($m["client_unique_identifier"] == $client_uid) { 67 | $estaengrupo = True; 68 | } 69 | } 70 | if($estaengrupo) { 71 | $iconosm = $iconosm + 1; 72 | echo ''; 73 | } else { 74 | echo ''; 75 | } 76 | } 77 | echo '
ActivoIconoNombre
'.$group["name"].'
'.$group["name"].'

'.$lang["l_checkalert"].'


'; 78 | $codigo = RandomString(); 79 | $_SESSION['codigo'] = $codigo; 80 | $mensaje = $lang['l_checkmsg'].": ".$codigo." "; 81 | $client->poke($mensaje); 82 | 83 | //echo "

".$lang['l_checkalert']."

"; 84 | //echo "
"; 85 | //echo "
"; 86 | //echo "
"; 87 | } else { 88 | if($conectado == False) { 89 | header("refresh: 10; url = ./"); 90 | echo "
ERROR: ".$lang['f_connect']."
"; 91 | } 92 | } 93 | } catch(Exception $e) { 94 | echo "ERROR: "; 95 | if($DEBUG == True) { 96 | echo "[DEBUG] ".$lang['f_derrortitle']."
"; 97 | echo "[DEBUG] ".$lang['f_dmsg'].": ".$e->getMessage()."
"; 98 | echo "[DEBUG] ".$lang['f_dcode']." ".$e->getCode()."
"; 99 | } 100 | if($e->getCode() == 0) { 101 | echo $lang['f_unk']; 102 | } else if($e->getCode() == 10060) { //Codigo de error de error en la conexion 103 | echo $lang['f_connectts']; 104 | } else if($e->getCode() == 512) { //Codigo de error cuando la UUID no es valida 105 | echo $lang['f_uuid']; 106 | } else if($e->getCode() == 520) { //Codigo de error cuando login o pass estan mal 107 | echo $lang['f_querydata']; 108 | } else if($e->getCode() == 3329) { //Codigo de error cuando la conexion fue baneada por el tsquery 109 | echo $lang['f_banned']; 110 | } else if($e->getCode() == 513) { //Codigo de error cuando ya hay una conexion del nombre 111 | echo $lang['f_twoconnect']; 112 | } else if($e->getCode() == 2568) { //Codigo de error cuando ya hay una conexion del nombre 113 | echo $lang['f_perms']; 114 | } 115 | } 116 | function RandomString() { 117 | $an = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ%$#"; 118 | $su = strlen($an) - 1; 119 | return substr($an, rand(0, $su), 1) . 120 | substr($an, rand(0, $su), 1) . 121 | substr($an, rand(0, $su), 1) . 122 | substr($an, rand(0, $su), 1) . 123 | substr($an, rand(0, $su), 1) . 124 | substr($an, rand(0, $su), 1); 125 | } 126 | ?> 127 | -------------------------------------------------------------------------------- /noty/js/layouts/bottom.js: -------------------------------------------------------------------------------- 1 | $.noty.layouts.bottom = { 2 | name : 'bottom', 3 | options : {}, 4 | container: { 5 | object : '