TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
TeamSpeak3 Class Reference

Factory class all for TeamSpeak 3 PHP Framework objects. More...

Static Public Member Functions

static autoload ($class)
 spl_autoload() suitable implementation for supporting class autoloading. More...
 
static dump ($var, $echo=TRUE)
 Debug helper function. More...
 
static factory ($uri)
 Factory for TeamSpeak3_Adapter_Abstract classes. More...
 
static getEscapePatterns ()
 Returns an assoc array containing all escape patterns available on a TeamSpeak 3 Server. More...
 
static init ()
 Checks for required PHP features, enables autoloading and starts a default profiler. More...
 

Data Fields

const CLIENT_TYPE_REGULAR = 0x00
 0: regular client
 
const CLIENT_TYPE_SERVERQUERY = 0x01
 1: query client
 
const CODEC_CELT_MONO = 0x03
 3: celt mono (mono, 16bit, 48kHz)
 
const CODEC_CRYPT_DISABLED = 0x01
 1: globally disabled
 
const CODEC_CRYPT_ENABLED = 0x02
 2: globally enabled
 
const CODEC_CRYPT_INDIVIDUAL = 0x00
 0: configure per channel
 
const CODEC_OPUS_MUSIC = 0x05
 3: opus music (interactive)
 
const CODEC_OPUS_VOICE = 0x04
 3: opus voice (interactive)
 
const CODEC_SPEEX_NARROWBAND = 0x00
 0: speex narrowband (mono, 16bit, 8kHz)
 
const CODEC_SPEEX_ULTRAWIDEBAND = 0x02
 2: speex ultra-wideband (mono, 16bit, 32kHz)
 
const CODEC_SPEEX_WIDEBAND = 0x01
 1: speex wideband (mono, 16bit, 16kHz)
 
const ERROR = "error"
 TeamSpeak 3 protocol error message prefix.
 
const EVENT = "notify"
 TeamSpeak 3 protocol event message prefix.
 
const FILE_TYPE_DIRECTORY = 0x00
 0: file is directory
 
const FILE_TYPE_REGULAR = 0x01
 1: file is regular
 
const GREET = "Welcome"
 TeamSpeak 3 protocol greeting message prefix.
 
const GROUP_DBTYPE_REGULAR = 0x01
 1: regular group (used for regular clients)
 
const GROUP_DBTYPE_SERVERQUERY = 0x02
 2: global query group (used for ServerQuery clients)
 
const GROUP_DBTYPE_TEMPLATE = 0x00
 0: template group (used for new virtual servers)
 
const GROUP_IDENTIFIY_STRONGEST = 0x01
 1: identify most powerful group
 
const GROUP_IDENTIFIY_WEAKEST = 0x02
 2: identify weakest group
 
const GROUP_NAMEMODE_BEFORE = 0x01
 1: display name before client nickname
 
const GROUP_NAMEMODE_BEHIND = 0x02
 2: display name after client nickname
 
const GROUP_NAMEMODE_HIDDEN = 0x00
 0: display no name
 
const HOSTBANNER_IGNORE_ASPECT = 0x01
 1: adjust but ignore aspect ratio
 
const HOSTBANNER_KEEP_ASPECT = 0x02
 2: adjust and keep aspect ratio
 
const HOSTBANNER_NO_ADJUST = 0x00
 0: do not adjust
 
const HOSTMSG_LOG = 0x01
 1: display message in chatlog
 
const HOSTMSG_MODAL = 0x02
 2: display message in modal dialog
 
const HOSTMSG_MODALQUIT = 0x03
 3: display message in modal dialog and close connection
 
const HOSTMSG_NONE = 0x00
 0: display no message
 
const KICK_CHANNEL = 0x04
 4: kick client from channel
 
const KICK_SERVER = 0x05
 5: kick client from server
 
const LIB_VERSION = "1.1.32"
 TeamSpeak 3 PHP Framework version.
 
const LOGLEVEL_CRITICAL = 0x00
 0: these messages stop the program
 
const LOGLEVEL_DEBUG = 0x03
 3: output that might help find a problem
 
const LOGLEVEL_DEVEL = 0x05
 5: development output
 
const LOGLEVEL_ERROR = 0x01
 1: everything that is really bad
 
const LOGLEVEL_INFO = 0x04
 4: informational output
 
const LOGLEVEL_WARNING = 0x02
 2: everything that might be bad
 
const PERM_CAT_CHANNEL = 0x30
 00110000: channel permissions
 
const PERM_CAT_CHANNEL_ACCESS = 0x35
 00110101: channel permissions -> access channels
 
const PERM_CAT_CHANNEL_CREATE = 0x32
 00110010: channel permissions -> create channels
 
const PERM_CAT_CHANNEL_DELETE = 0x34
 00110100: channel permissions -> delete channels
 
const PERM_CAT_CHANNEL_INFORMATION = 0x31
 00110001: channel permissions -> channel information
 
const PERM_CAT_CHANNEL_MODIFY = 0x33
 00110011: channel permissions -> edit channels
 
const PERM_CAT_CLIENT = 0x50
 01010000: client permissions
 
const PERM_CAT_CLIENT_ADM_ACTIONS = 0x52
 01010010: client permissions -> client administrative actions
 
const PERM_CAT_CLIENT_BASICS = 0x53
 01010011: client permissions -> client basic communication
 
const PERM_CAT_CLIENT_INFORMATION = 0x51
 01010001: client permissions -> client information
 
const PERM_CAT_CLIENT_MODIFY = 0x54
 01010100: client permissions -> edit clients
 
const PERM_CAT_FILETRANSFER = 0x60
 01100000: file transfer permissions
 
const PERM_CAT_GLOBAL = 0x10
 00010000: global permissions
 
const PERM_CAT_GLOBAL_ADM_ACTIONS = 0x13
 00010011: global permissions -> global administrative actions
 
const PERM_CAT_GLOBAL_INFORMATION = 0x11
 00010001: global permissions -> global information
 
const PERM_CAT_GLOBAL_SERVER_MGMT = 0x12
 00010010: global permissions -> virtual server management
 
const PERM_CAT_GLOBAL_SETTINGS = 0x14
 00010100: global permissions -> global settings
 
const PERM_CAT_GROUP = 0x40
 01000000: group permissions
 
const PERM_CAT_GROUP_CREATE = 0x42
 01000010: group permissions -> create groups
 
const PERM_CAT_GROUP_DELETE = 0x44
 01000100: group permissions -> delete groups
 
const PERM_CAT_GROUP_INFORMATION = 0x41
 01000001: group permissions -> group information
 
const PERM_CAT_GROUP_MODIFY = 0x43
 01000011: group permissions -> edit groups
 
const PERM_CAT_NEEDED_MODIFY_POWER = 0xFF
 11111111: needed permission modify power (grant) permissions
 
const PERM_CAT_SERVER = 0x20
 00100000: virtual server permissions
 
const PERM_CAT_SERVER_ADM_ACTIONS = 0x22
 00100010: virtual server permissions -> virtual server administrative actions
 
const PERM_CAT_SERVER_INFORMATION = 0x21
 00100001: virtual server permissions -> virtual server information
 
const PERM_CAT_SERVER_SETTINGS = 0x23
 00100011: virtual server permissions -> virtual server settings
 
const PERM_TYPE_CHANNEL = 0x02
 2: channel specific permission
 
const PERM_TYPE_CHANNELCLIENT = 0x04
 4: channel-client specific permission
 
const PERM_TYPE_CHANNELGROUP = 0x03
 3: channel group permission
 
const PERM_TYPE_CLIENT = 0x01
 1: client specific permission
 
const PERM_TYPE_SERVERGROUP = 0x00
 0: server group permission
 
const PLUGINCMD_CHANNEL = 0x01
 1: send plugincmd to all clients in current channel
 
const PLUGINCMD_CHANNEL_SUBSCRIBED = 0x04
 4: send plugincmd to all subscribed clients in current channel
 
const PLUGINCMD_CLIENT = 0x03
 3: send plugincmd to all given client ids
 
const PLUGINCMD_SERVER = 0x02
 2: send plugincmd to all clients on server
 
const READY = "TS3"
 TeamSpeak 3 protocol welcome message.
 
const REASON_CHANNEL_EDIT = 0x0A
 10: channel information edited
 
const REASON_CHANNEL_KICK = 0x04
 4: client kicked from channel
 
const REASON_CHANNEL_UPDATE = 0x09
 9: channel information updated
 
const REASON_DISCONNECT = 0x08
 8: client disconnected
 
const REASON_DISCONNECT_SHUTDOWN = 0x0B
 11: client disconnected on server shutdown
 
const REASON_MOVE = 0x01
 1: channel switched or moved
 
const REASON_NONE = 0x00
 0: no reason
 
const REASON_SERVER_BAN = 0x06
 6: client banned from server
 
const REASON_SERVER_KICK = 0x05
 5: client kicked from server
 
const REASON_SERVER_STOP = 0x07
 7: server stopped
 
const REASON_SUBSCRIPTION = 0x02
 2: subscription added or removed
 
const REASON_TIMEOUT = 0x03
 3: client connection timed out
 
const SCHID = "selected"
 TeamSpeak 3 protocol server connection handler ID prefix.
 
const SEPARATOR_CELL = " "
 protocol cell separator
 
const SEPARATOR_LINE = "\n"
 protocol line separator
 
const SEPARATOR_LIST = "|"
 protocol list separator
 
const SEPARATOR_PAIR = "="
 protocol pair separator
 
const SNAPSHOT_BASE64 = 0x01
 1: base64 string
 
const SNAPSHOT_HEXDEC = 0x02
 2: hexadecimal string
 
const SNAPSHOT_STRING = 0x00
 0: default string
 
const SPACER_ALIGN_CENTER = 0x02
 2: alignment center
 
const SPACER_ALIGN_LEFT = 0x00
 0: alignment left
 
const SPACER_ALIGN_REPEAT = 0x03
 3: repeat until the whole line is filled
 
const SPACER_ALIGN_RIGHT = 0x01
 1: alignment right
 
const SPACER_CUSTOM = 0x05
 5: custom format
 
const SPACER_DASHDOTDOTLINE = 0x04
 4: dash dot dot line
 
const SPACER_DASHDOTLINE = 0x03
 3: dash dot line
 
const SPACER_DASHLINE = 0x01
 1: dash line
 
const SPACER_DOTLINE = 0x02
 2: dot line
 
const SPACER_SOLIDLINE = 0x00
 0: solid line
 
const TEA_GREET = "Welcome"
 TeaSpeak protocol greeting message prefix.
 
const TEA_READY = "TeaSpeak"
 TeaSpeak protocol welcome message.
 
const TEXTMSG_CHANNEL = 0x02
 2: target is a channel
 
const TEXTMSG_CLIENT = 0x01
 1: target is a client
 
const TEXTMSG_SERVER = 0x03
 3: target is a virtual server
 
const TOKEN_CHANNELGROUP = 0x01
 1: channel group token (id1={groupID} id2={channelID})
 
const TOKEN_SERVERGROUP = 0x00
 0: server group token (id1={groupID} id2=0)
 

Static Protected Member Functions

static getAdapterName ($name, $namespace="TeamSpeak3_Adapter_")
 Returns the name of an adapter class by $name. More...
 
static getFilePath ($name)
 Generates a possible file path for $name. More...
 
static loadClass ($class)
 Loads a class from a PHP file. More...
 

Detailed Description

Factory class all for TeamSpeak 3 PHP Framework objects.

Member Function Documentation

◆ autoload()

static autoload (   $class)
static

spl_autoload() suitable implementation for supporting class autoloading.

Parameters
string$class
Returns
boolean
502  {
503  if(substr($class, 0, strlen(__CLASS__)) != __CLASS__) return;
504 
505  try
506  {
507  self::loadClass($class);
508 
509  return TRUE;
510  }
511  catch(Exception $e)
512  {
513  return FALSE;
514  }
515  }

◆ dump()

static dump (   $var,
  $echo = TRUE 
)
static

Debug helper function.

This is a wrapper for var_dump() that adds the pre-format tags, cleans up newlines and indents, and runs htmlentities() before output.

Parameters
mixed$var
bool$echo
Returns
string
568  {
569  ob_start();
570  var_dump($var);
571 
572  $output = preg_replace("/\]\=>\n(\s+)/m", "] => ", ob_get_clean());
573 
574  if(PHP_SAPI == "cli")
575  {
576  $output = PHP_EOL . PHP_EOL . $output . PHP_EOL;
577  }
578  else
579  {
580  $output = "<pre>" . htmlspecialchars($output, ENT_QUOTES, "utf-8") . "</pre>";
581  }
582 
583  if($echo) echo($output);
584 
585  return $output;
586  }

◆ factory()

static factory (   $uri)
static

Factory for TeamSpeak3_Adapter_Abstract classes.

$uri must be formatted as "<adapter>://<user>:<pass>@<host>:<port>/<options>#<flags>". All parameters except adapter, host and port are optional.

=== Supported Options ===

  • timeout
  • blocking
  • nickname
  • no_query_clients
  • use_offline_as_virtual
  • clients_before_channels
  • server_id|server_uid|server_port|server_name
  • channel_id|channel_name
  • client_id|client_uid|client_name

=== Supported Flags (only one per $uri) ===

  • no_query_clients
  • use_offline_as_virtual
  • clients_before_channels

=== URI Examples ===

  • serverquery://127.0.0.1:10011/
  • serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1
  • serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1#no_query_clients
  • serverquery://127.0.0.1:10011/?server_port=9987&client_name=ScP
  • filetransfer://127.0.0.1:30011/
Parameters
string$uri
Returns
TeamSpeak3_Adapter_Abstract
TeamSpeak3_Node_Abstract
TeamSpeak3_Node_Host
TeamSpeak3_Node_Server
317  {
318  self::init();
319 
320  $uri = new TeamSpeak3_Helper_Uri($uri);
321 
322  $adapter = self::getAdapterName($uri->getScheme());
323  $options = array("host" => $uri->getHost(), "port" => $uri->getPort(), "timeout" => (int) $uri->getQueryVar("timeout", 10), "blocking" => (int) $uri->getQueryVar("blocking", 1));
324 
325  self::loadClass($adapter);
326 
327  $object = new $adapter($options);
328 
329  if($object instanceof TeamSpeak3_Adapter_ServerQuery)
330  {
331  $node = $object->getHost();
332 
333  if($uri->hasUser() && $uri->hasPass())
334  {
335  $node->login($uri->getUser(), $uri->getPass());
336  }
337 
338  if($uri->hasQueryVar("nickname"))
339  {
340  $node->setPredefinedQueryName($uri->getQueryVar("nickname"));
341  }
342 
343  if($uri->getFragment() == "use_offline_as_virtual")
344  {
345  $node->setUseOfflineAsVirtual(TRUE);
346  }
347  elseif($uri->hasQueryVar("use_offline_as_virtual"))
348  {
349  $node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual") ? TRUE : FALSE);
350  }
351 
352  if($uri->getFragment() == "clients_before_channels")
353  {
354  $node->setLoadClientlistFirst(TRUE);
355  }
356  elseif($uri->hasQueryVar("clients_before_channels"))
357  {
358  $node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels") ? TRUE : FALSE);
359  }
360 
361  if($uri->getFragment() == "no_query_clients")
362  {
363  $node->setExcludeQueryClients(TRUE);
364  }
365  elseif($uri->hasQueryVar("no_query_clients"))
366  {
367  $node->setExcludeQueryClients($uri->getQueryVar("no_query_clients") ? TRUE : FALSE);
368  }
369 
370  if($uri->hasQueryVar("server_id"))
371  {
372  $node = $node->serverGetById($uri->getQueryVar("server_id"));
373  }
374  elseif($uri->hasQueryVar("server_uid"))
375  {
376  $node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
377  }
378  elseif($uri->hasQueryVar("server_port"))
379  {
380  $node = $node->serverGetByPort($uri->getQueryVar("server_port"));
381  }
382  elseif($uri->hasQueryVar("server_name"))
383  {
384  $node = $node->serverGetByName($uri->getQueryVar("server_name"));
385  }
386 
387  if($node instanceof TeamSpeak3_Node_Server)
388  {
389  if($uri->hasQueryVar("channel_id"))
390  {
391  $node = $node->channelGetById($uri->getQueryVar("channel_id"));
392  }
393  elseif($uri->hasQueryVar("channel_name"))
394  {
395  $node = $node->channelGetByName($uri->getQueryVar("channel_name"));
396  }
397 
398  if($uri->hasQueryVar("client_id"))
399  {
400  $node = $node->clientGetById($uri->getQueryVar("client_id"));
401  }
402  if($uri->hasQueryVar("client_uid"))
403  {
404  $node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
405  }
406  elseif($uri->hasQueryVar("client_name"))
407  {
408  $node = $node->clientGetByName($uri->getQueryVar("client_name"));
409  }
410  }
411 
412  return $node;
413  }
414 
415  return $object;
416  }
Class describing a TeamSpeak 3 virtual server and all it&#39;s parameters.
Definition: Server.php:29
Helper class for URI handling.
Definition: Uri.php:29
Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server.
Definition: ServerQuery.php:29

◆ getAdapterName()

static getAdapterName (   $name,
  $namespace = "TeamSpeak3_Adapter_" 
)
staticprotected

Returns the name of an adapter class by $name.

Parameters
string$name
string$namespace
Exceptions
TeamSpeak3_Adapter_Exception
Returns
string
478  {
479  $path = self::getFilePath($namespace);
480  $scan = scandir($path);
481 
482  foreach($scan as $node)
483  {
484  $file = TeamSpeak3_Helper_String::factory($node)->toLower();
485 
486  if($file->startsWith($name) && $file->endsWith(".php"))
487  {
488  return $namespace . str_replace(".php", "", $node);
489  }
490  }
491 
492  throw new TeamSpeak3_Adapter_Exception("adapter '" . $name . "' does not exist");
493  }
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60
Enhanced exception class for TeamSpeak3_Adapter_Abstract objects.
Definition: Exception.php:29

◆ getEscapePatterns()

static getEscapePatterns ( )
static

Returns an assoc array containing all escape patterns available on a TeamSpeak 3 Server.

Returns
array
555  {
556  return self::$escape_patterns;
557  }

◆ getFilePath()

static getFilePath (   $name)
staticprotected

Generates a possible file path for $name.

Parameters
string$name
Returns
string
462  {
463  $path = str_replace("_", DIRECTORY_SEPARATOR, $name);
464  $path = str_replace(__CLASS__, dirname(__FILE__), $path);
465 
466  return $path;
467  }

◆ init()

static init ( )
static

Checks for required PHP features, enables autoloading and starts a default profiler.

Exceptions
LogicException
Returns
void
524  {
525  if(version_compare(phpversion(), "5.2.1") == -1)
526  {
527  throw new LogicException("this particular software cannot be used with the installed version of PHP");
528  }
529 
530  if(!function_exists("stream_socket_client"))
531  {
532  throw new LogicException("network functions are not available in this PHP installation");
533  }
534 
535  if(!function_exists("spl_autoload_register"))
536  {
537  throw new LogicException("autoload functions are not available in this PHP installation");
538  }
539 
540  if(!class_exists("TeamSpeak3_Helper_Profiler"))
541  {
542  spl_autoload_register(array(__CLASS__, "autoload"));
543  }
544 
546  }
static start($name="default")
Starts a timer.
Definition: Profiler.php:55

◆ loadClass()

static loadClass (   $class)
staticprotected

Loads a class from a PHP file.

The filename must be formatted as "$class.php".

include() is not prefixed with the @ operator because if the file is loaded and contains a parse error, execution will halt silently and this is difficult to debug.

Parameters
string$class
Exceptions
LogicException
Returns
boolean
429  {
430  if(class_exists($class, FALSE) || interface_exists($class, FALSE))
431  {
432  return;
433  }
434 
435  if(preg_match("/[^a-z0-9\\/\\\\_.-]/i", $class))
436  {
437  throw new LogicException("illegal characters in classname '" . $class . "'");
438  }
439 
440  $file = self::getFilePath($class) . ".php";
441 
442  if(!file_exists($file) || !is_readable($file))
443  {
444  throw new LogicException("file '" . $file . "' does not exist or is not readable");
445  }
446 
447  if(class_exists($class, FALSE) || interface_exists($class, FALSE))
448  {
449  throw new LogicException("class '" . $class . "' does not exist");
450  }
451 
452  return include_once($file);
453  }

The documentation for this class was generated from the following file: