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

Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server. More...

+ Inheritance diagram for TeamSpeak3_Adapter_ServerQuery:

Public Member Functions

 __destruct ()
 The TeamSpeak3_Adapter_ServerQuery destructor. More...
 
 getHost ()
 Returns the TeamSpeak3_Node_Host object of the current connection. More...
 
 getQueryCount ()
 Returns the number of queries executed on the server. More...
 
 getQueryLastTimestamp ()
 Returns the timestamp of the last command. More...
 
 getQueryRuntime ()
 Returns the total runtime of all queries. More...
 
 prepare ($cmd, array $params=array())
 Uses given parameters and returns a prepared ServerQuery command. More...
 
 request ($cmd, $throw=TRUE)
 Sends a prepared command to the server and returns the result. More...
 
 wait ()
 Waits for the server to send a notification message and returns the result. More...
 
- Public Member Functions inherited from TeamSpeak3_Adapter_Abstract
 __construct (array $options)
 The TeamSpeak3_Adapter_Abstract constructor. More...
 
 __destruct ()
 The TeamSpeak3_Adapter_Abstract destructor. More...
 
 __sleep ()
 Commit pending data. More...
 
 __wakeup ()
 Reconnects to the remote server. More...
 
 getProfiler ()
 Returns the profiler timer used for this connection adapter. More...
 
 getTransport ()
 Returns the transport object used for this connection adapter. More...
 
 getTransportHost ()
 Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object is connected to. More...
 
 getTransportPort ()
 Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object is connected to. More...
 

Protected Member Functions

 syn ()
 Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server. More...
 
- Protected Member Functions inherited from TeamSpeak3_Adapter_Abstract
 initTransport ($options, $transport="TeamSpeak3_Transport_TCP")
 Loads the transport object object used for the connection adapter and passes a given set of options. More...
 
 syn ()
 Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server. More...
 

Detailed Description

Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server.

Constructor & Destructor Documentation

◆ __destruct()

__destruct ( )

The TeamSpeak3_Adapter_ServerQuery destructor.

Returns
void
89  {
90  if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->transport->isConnected())
91  {
92  try
93  {
94  $this->request("quit");
95  }
96  catch(Exception $e)
97  {
98  return;
99  }
100  }
101  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
isConnected()
Returns TRUE if the transport is connected.
Definition: Abstract.php:237
Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport.
Definition: Abstract.php:29
request($cmd, $throw=TRUE)
Sends a prepared command to the server and returns the result.
Definition: ServerQuery.php:111

Member Function Documentation

◆ getHost()

getHost ( )

Returns the TeamSpeak3_Node_Host object of the current connection.

Returns
TeamSpeak3_Node_Host
252  {
253  if($this->host === null)
254  {
255  $this->host = new TeamSpeak3_Node_Host($this);
256  }
257 
258  return $this->host;
259  }
Class describing a TeamSpeak 3 server instance and all it's parameters.
Definition: Host.php:29

◆ getQueryCount()

getQueryCount ( )

Returns the number of queries executed on the server.

Returns
integer
232  {
233  return $this->count;
234  }

◆ getQueryLastTimestamp()

getQueryLastTimestamp ( )

Returns the timestamp of the last command.

Returns
integer
222  {
223  return $this->timer;
224  }

◆ getQueryRuntime()

getQueryRuntime ( )

Returns the total runtime of all queries.

Returns
mixed
242  {
243  return $this->getProfiler()->getRuntime();
244  }
getProfiler()
Returns the profiler timer used for this connection adapter.
Definition: Abstract.php:102

◆ prepare()

prepare (   $cmd,
array  $params = array() 
)

Uses given parameters and returns a prepared ServerQuery command.

Parameters
string$cmd
array$params
Returns
string
175  {
176  $args = array();
177  $cells = array();
178 
179  foreach($params as $ident => $value)
180  {
181  $ident = is_numeric($ident) ? "" : strtolower($ident) . TeamSpeak3::SEPARATOR_PAIR;
182 
183  if(is_array($value))
184  {
185  $value = array_values($value);
186 
187  for($i = 0; $i < count($value); $i++)
188  {
189  if($value[$i] === null) continue;
190  elseif($value[$i] === FALSE) $value[$i] = 0x00;
191  elseif($value[$i] === TRUE) $value[$i] = 0x01;
192  elseif($value[$i] instanceof TeamSpeak3_Node_Abstract) $value[$i] = $value[$i]->getId();
193 
194  $cells[$i][] = $ident . TeamSpeak3_Helper_String::factory($value[$i])->escape()->toUtf8();
195  }
196  }
197  else
198  {
199  if($value === null) continue;
200  elseif($value === FALSE) $value = 0x00;
201  elseif($value === TRUE) $value = 0x01;
202  elseif($value instanceof TeamSpeak3_Node_Abstract) $value = $value->getId();
203 
204  $args[] = $ident . TeamSpeak3_Helper_String::factory($value)->escape()->toUtf8();
205  }
206  }
207 
208  foreach(array_keys($cells) as $ident) $cells[$ident] = implode(TeamSpeak3::SEPARATOR_CELL, $cells[$ident]);
209 
210  if(count($args)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_CELL, $args);
211  if(count($cells)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_LIST, $cells);
212 
213  return trim($cmd);
214  }
const SEPARATOR_CELL
protocol cell separator
Definition: TeamSpeak3.php:76
Abstract class describing a TeamSpeak 3 node and all it&#39;s parameters.
Definition: Abstract.php:29
const SEPARATOR_PAIR
protocol pair separator
Definition: TeamSpeak3.php:77
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60
const SEPARATOR_LIST
protocol list separator
Definition: TeamSpeak3.php:75

◆ request()

request (   $cmd,
  $throw = TRUE 
)

Sends a prepared command to the server and returns the result.

Parameters
string$cmd
boolean$throw
Exceptions
TeamSpeak3_Adapter_Exception
Returns
TeamSpeak3_Adapter_ServerQuery_Reply
112  {
114 
115  if(strstr($cmd, "\r") || strstr($cmd, "\n"))
116  {
117  throw new TeamSpeak3_Adapter_Exception("illegal characters in command '" . $query . "'");
118  }
119  elseif(in_array($query, $this->block))
120  {
121  throw new TeamSpeak3_Adapter_ServerQuery_Exception("command not found", 0x100);
122  }
123 
124  TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandStarted", $cmd);
125 
126  $this->getProfiler()->start();
127  $this->getTransport()->sendLine($cmd);
128  $this->timer = time();
129  $this->count++;
130 
131  $rpl = array();
132 
133  do {
134  $str = $this->getTransport()->readLine();
135  $rpl[] = $str;
137 
138  $this->getProfiler()->stop();
139 
140  $reply = new TeamSpeak3_Adapter_ServerQuery_Reply($rpl, $cmd, $this->getHost(), $throw);
141 
142  TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply);
143 
144  return $reply;
145  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Helper class for string handling.
Definition: String.php:29
const SEPARATOR_CELL
protocol cell separator
Definition: TeamSpeak3.php:76
Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects.
Definition: Exception.php:29
section($separator, $first=0, $last=0)
Returns a section of the string.
Definition: String.php:264
getHost()
Returns the TeamSpeak3_Node_Host object of the current connection.
Definition: ServerQuery.php:251
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getProfiler()
Returns the profiler timer used for this connection adapter.
Definition: Abstract.php:102
Provides methods to analyze and format a ServerQuery reply.
Definition: Reply.php:29
const ERROR
TeamSpeak 3 protocol error message prefix.
Definition: TeamSpeak3.php:44
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

◆ syn()

syn ( )
protected

Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server.

Exceptions
TeamSpeak3_Adapter_Exception
Returns
void
67  {
68  $this->initTransport($this->options);
69  $this->transport->setAdapter($this);
70 
71  TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
72 
73  $rdy = $this->getTransport()->readLine();
74 
75  if(!$rdy->startsWith(TeamSpeak3::READY) && !$rdy->startsWith(TeamSpeak3::TEA_READY))
76  {
77  throw new TeamSpeak3_Adapter_Exception("invalid reply from the server (" . $rdy . ")");
78  }
79 
80  TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryConnected", $this);
81  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
static init($name="default")
Inits a timer.
Definition: Profiler.php:44
const READY
TeamSpeak 3 protocol welcome message.
Definition: TeamSpeak3.php:34
const TEA_READY
TeaSpeak protocol welcome message.
Definition: TeamSpeak3.php:59
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
Enhanced exception class for TeamSpeak3_Adapter_Abstract objects.
Definition: Exception.php:29
initTransport($options, $transport="TeamSpeak3_Transport_TCP")
Loads the transport object object used for the connection adapter and passes a given set of options...
Definition: Abstract.php:126

◆ wait()

wait ( )

Waits for the server to send a notification message and returns the result.

Exceptions
TeamSpeak3_Adapter_Exception
Returns
TeamSpeak3_Adapter_ServerQuery_Event
154  {
155  if($this->getTransport()->getConfig("blocking"))
156  {
157  throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode");
158  }
159 
160  do {
161  $evt = $this->getTransport()->readLine();
162  } while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT));
163 
164  return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
165  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Helper class for string handling.
Definition: String.php:29
const SEPARATOR_CELL
protocol cell separator
Definition: TeamSpeak3.php:76
Provides methods to analyze and format a ServerQuery event.
Definition: Event.php:29
section($separator, $first=0, $last=0)
Returns a section of the string.
Definition: String.php:264
getHost()
Returns the TeamSpeak3_Node_Host object of the current connection.
Definition: ServerQuery.php:251
Enhanced exception class for TeamSpeak3_Adapter_Abstract objects.
Definition: Exception.php:29
const EVENT
TeamSpeak 3 protocol event message prefix.
Definition: TeamSpeak3.php:49

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