Initial commit

This commit is contained in:
Wruczek
2016-06-28 23:18:59 +02:00
parent e321e10551
commit e49c2c27ad
390 changed files with 22561 additions and 0 deletions

View File

@ -0,0 +1,160 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Abstract.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Abstract
* @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server.
*/
abstract class TeamSpeak3_Adapter_Abstract
{
/**
* Stores user-provided options.
*
* @var array
*/
protected $options = null;
/**
* Stores an TeamSpeak3_Transport_Abstract object.
*
* @var TeamSpeak3_Transport_Abstract
*/
protected $transport = null;
/**
* The TeamSpeak3_Adapter_Abstract constructor.
*
* @param array $options
* @return TeamSpeak3_Adapter_Abstract
*/
public function __construct(array $options)
{
$this->options = $options;
if($this->transport === null)
{
$this->syn();
}
}
/**
* The TeamSpeak3_Adapter_Abstract destructor.
*
* @return void
*/
abstract public function __destruct();
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
abstract protected function syn();
/**
* Commit pending data.
*
* @return array
*/
public function __sleep()
{
return array("options");
}
/**
* Reconnects to the remote server.
*
* @return void
*/
public function __wakeup()
{
$this->syn();
}
/**
* Returns the profiler timer used for this connection adapter.
*
* @return TeamSpeak3_Helper_Profiler_Timer
*/
public function getProfiler()
{
return TeamSpeak3_Helper_Profiler::get(spl_object_hash($this));
}
/**
* Returns the transport object used for this connection adapter.
*
* @return TeamSpeak3_Transport_Abstract
*/
public function getTransport()
{
return $this->transport;
}
/**
* Loads the transport object object used for the connection adapter and passes a given set
* of options.
*
* @param array $options
* @param string $transport
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
protected function initTransport($options, $transport = "TeamSpeak3_Transport_TCP")
{
if(!is_array($options))
{
throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array");
}
$this->transport = new $transport($options);
}
/**
* Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object
* is connected to.
*
* @return string
*/
public function getTransportHost()
{
return $this->getTransport()->getConfig("host", "0.0.0.0");
}
/**
* Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object
* is connected to.
*
* @return string
*/
public function getTransportPort()
{
return $this->getTransport()->getConfig("port", "0");
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Blacklist.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Blacklist
* @brief Provides methods to check if an IP address is currently blacklisted.
*/
class TeamSpeak3_Adapter_Blacklist extends TeamSpeak3_Adapter_Abstract
{
/**
* The IPv4 address or FQDN of the TeamSpeak Systems update server.
*
* @var string
*/
protected $default_host = "blacklist.teamspeak.com";
/**
* The UDP port number of the TeamSpeak Systems update server.
*
* @var integer
*/
protected $default_port = 17385;
/**
* Stores an array containing the latest build numbers.
*
* @var array
*/
protected $build_numbers = null;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @return void
*/
public function syn()
{
if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("blacklistConnected", $this);
}
/**
* The TeamSpeak3_Adapter_Blacklist destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Returns TRUE if a specified $host IP address is currently blacklisted.
*
* @param string $host
* @throws TeamSpeak3_Adapter_Blacklist_Exception
* @return boolean
*/
public function isBlacklisted($host)
{
if(ip2long($host) === FALSE)
{
$addr = gethostbyname($host);
if($addr == $host)
{
throw new TeamSpeak3_Adapter_Blacklist_Exception("unable to resolve IPv4 address (" . $host . ")");
}
$host = $addr;
}
$this->getTransport()->send("ip4:" . $host);
$repl = $this->getTransport()->read(1);
$this->getTransport()->disconnect();
if(!count($repl))
{
return FALSE;
}
return ($repl->toInt()) ? FALSE : TRUE;
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Blacklist_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Blacklist objects.
*/
class TeamSpeak3_Adapter_Blacklist_Exception extends TeamSpeak3_Adapter_Exception {}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Abstract objects.
*/
class TeamSpeak3_Adapter_Exception extends TeamSpeak3_Exception {}

View File

@ -0,0 +1,190 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: FileTransfer.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_FileTransfer
* @brief Provides low-level methods for file transfer communication with a TeamSpeak 3 Server.
*/
class TeamSpeak3_Adapter_FileTransfer extends TeamSpeak3_Adapter_Abstract
{
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferConnected", $this);
}
/**
* The TeamSpeak3_Adapter_FileTransfer destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Sends a valid file transfer key to the server to initialize the file transfer.
*
* @param string $ftkey
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
protected function init($ftkey)
{
if(strlen($ftkey) != 32)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("invalid file transfer key format");
}
$this->getProfiler()->start();
$this->getTransport()->send($ftkey);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferHandshake", $this);
}
/**
* Sends the content of a file to the server.
*
* @param string $ftkey
* @param integer $seek
* @param string $data
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
public function upload($ftkey, $seek, $data)
{
$this->init($ftkey);
$size = strlen($data);
$seek = intval($seek);
$pack = 4096;
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadStarted", $ftkey, $seek, $size);
for(;$seek < $size;)
{
$rest = $size-$seek;
$pack = $rest < $pack ? $rest : $pack;
$buff = substr($data, $seek, $pack);
$seek = $seek+$pack;
$this->getTransport()->send($buff);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadProgress", $ftkey, $seek, $size);
}
$this->getProfiler()->stop();
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadFinished", $ftkey, $seek, $size);
if($seek < $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file upload (" . $seek . " of " . $size . " bytes)");
}
}
/**
* Returns the content of a downloaded file as a TeamSpeak3_Helper_String object.
*
* @param string $ftkey
* @param integer $size
* @param boolean $passthru
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return TeamSpeak3_Helper_String
*/
public function download($ftkey, $size, $passthru = FALSE)
{
$this->init($ftkey);
if($passthru)
{
return $this->passthru($size);
}
$buff = new TeamSpeak3_Helper_String("");
$size = intval($size);
$pack = 4096;
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadStarted", $ftkey, count($buff), $size);
for($seek = 0;$seek < $size;)
{
$rest = $size-$seek;
$pack = $rest < $pack ? $rest : $pack;
$data = $this->getTransport()->read($rest < $pack ? $rest : $pack);
$seek = $seek+$pack;
$buff->append($data);
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
}
$this->getProfiler()->stop();
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);
if(strlen($buff) != $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)");
}
return $buff;
}
/**
* Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru()
* function.
*
* @param integer $size
* @throws TeamSpeak3_Adapter_FileTransfer_Exception
* @return void
*/
protected function passthru($size)
{
$buff_size = fpassthru($this->getTransport()->getStream());
if($buff_size != $size)
{
throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . intval($buff_size) . " of " . $size . " bytes)");
}
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_FileTransfer_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
*/
class TeamSpeak3_Adapter_FileTransfer_Exception extends TeamSpeak3_Adapter_Exception {}

View File

@ -0,0 +1,261 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: ServerQuery.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery
* @brief Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server.
*/
class TeamSpeak3_Adapter_ServerQuery extends TeamSpeak3_Adapter_Abstract
{
/**
* Stores a singleton instance of the active TeamSpeak3_Node_Host object.
*
* @var TeamSpeak3_Node_Host
*/
protected $host = null;
/**
* Stores the timestamp of the last command.
*
* @var integer
*/
protected $timer = null;
/**
* Number of queries executed on the server.
*
* @var integer
*/
protected $count = 0;
/**
* Stores an array with unsupported commands.
*
* @var array
*/
protected $block = array("help");
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
protected function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
if(!$this->getTransport()->readLine()->startsWith(TeamSpeak3::READY))
{
throw new TeamSpeak3_Adapter_Exception("invalid reply from the server");
}
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryConnected", $this);
}
/**
* The TeamSpeak3_Adapter_ServerQuery destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->transport->isConnected())
{
try
{
$this->request("quit");
}
catch(Exception $e)
{
return;
}
}
}
/**
* Sends a prepared command to the server and returns the result.
*
* @param string $cmd
* @param boolean $throw
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function request($cmd, $throw = TRUE)
{
$query = TeamSpeak3_Helper_String::factory($cmd)->section(TeamSpeak3::SEPARATOR_CELL);
if(strstr($cmd, "\r") || strstr($cmd, "\n"))
{
throw new TeamSpeak3_Adapter_Exception("illegal characters in command '" . $query . "'");
}
elseif(in_array($query, $this->block))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("command not found", 0x100);
}
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandStarted", $cmd);
$this->getProfiler()->start();
$this->getTransport()->sendLine($cmd);
$this->timer = time();
$this->count++;
$rpl = array();
do {
$str = $this->getTransport()->readLine();
$rpl[] = $str;
} while($str instanceof TeamSpeak3_Helper_String && $str->section(TeamSpeak3::SEPARATOR_CELL) != TeamSpeak3::ERROR);
$this->getProfiler()->stop();
$reply = new TeamSpeak3_Adapter_ServerQuery_Reply($rpl, $cmd, $this->getHost(), $throw);
TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply);
return $reply;
}
/**
* Waits for the server to send a notification message and returns the result.
*
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Event
*/
public function wait()
{
if($this->getTransport()->getConfig("blocking"))
{
throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode");
}
do {
$evt = $this->getTransport()->readLine();
} while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT));
return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
}
/**
* Uses given parameters and returns a prepared ServerQuery command.
*
* @param string $cmd
* @param array $params
* @return string
*/
public function prepare($cmd, array $params = array())
{
$args = array();
$cells = array();
foreach($params as $ident => $value)
{
$ident = is_numeric($ident) ? "" : strtolower($ident) . TeamSpeak3::SEPARATOR_PAIR;
if(is_array($value))
{
$value = array_values($value);
for($i = 0; $i < count($value); $i++)
{
if($value[$i] === null) continue;
elseif($value[$i] === FALSE) $value[$i] = 0x00;
elseif($value[$i] === TRUE) $value[$i] = 0x01;
elseif($value[$i] instanceof TeamSpeak3_Node_Abstract) $value[$i] = $value[$i]->getId();
$cells[$i][] = $ident . TeamSpeak3_Helper_String::factory($value[$i])->escape()->toUtf8();
}
}
else
{
if($value === null) continue;
elseif($value === FALSE) $value = 0x00;
elseif($value === TRUE) $value = 0x01;
elseif($value instanceof TeamSpeak3_Node_Abstract) $value = $value->getId();
$args[] = $ident . TeamSpeak3_Helper_String::factory($value)->escape()->toUtf8();
}
}
foreach(array_keys($cells) as $ident) $cells[$ident] = implode(TeamSpeak3::SEPARATOR_CELL, $cells[$ident]);
if(count($args)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_CELL, $args);
if(count($cells)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_LIST, $cells);
return trim($cmd);
}
/**
* Returns the timestamp of the last command.
*
* @return integer
*/
public function getQueryLastTimestamp()
{
return $this->timer;
}
/**
* Returns the number of queries executed on the server.
*
* @return integer
*/
public function getQueryCount()
{
return $this->count;
}
/**
* Returns the total runtime of all queries.
*
* @return mixed
*/
public function getQueryRuntime()
{
return $this->getProfiler()->getRuntime();
}
/**
* Returns the TeamSpeak3_Node_Host object of the current connection.
*
* @return TeamSpeak3_Node_Host
*/
public function getHost()
{
if($this->host === null)
{
$this->host = new TeamSpeak3_Node_Host($this);
}
return $this->host;
}
}

View File

@ -0,0 +1,170 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Event.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Event
* @brief Provides methods to analyze and format a ServerQuery event.
*/
class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess
{
/**
* Stores the event type.
*
* @var TeamSpeak3_Helper_String
*/
protected $type = null;
/**
* Stores the event data.
*
* @var array
*/
protected $data = null;
/**
* Stores the event data as an unparsed string.
*
* @var TeamSpeak3_Helper_String
*/
protected $mesg = null;
/**
* Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
*
* @param TeamSpeak3_Helper_String $evt
* @param TeamSpeak3_Node_Host $con
* @throws TeamSpeak3_Adapter_Exception
* @return TeamSpeak3_Adapter_ServerQuery_Event
*/
public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null)
{
if(!$evt->startsWith(TeamSpeak3::EVENT))
{
throw new TeamSpeak3_Adapter_Exception("invalid notification event format");
}
list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
if(empty($data))
{
throw new TeamSpeak3_Adapter_Exception("invalid notification event data");
}
$fake = new TeamSpeak3_Helper_String(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok");
$repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type);
$this->type = $type->substr(strlen(TeamSpeak3::EVENT));
$this->data = $repl->toList();
$this->mesg = $data;
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con);
TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
}
/**
* Returns the event type string.
*
* @return TeamSpeak3_Helper_String
*/
public function getType()
{
return $this->type;
}
/**
* Returns the event data array.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Returns the event data as an unparsed string.
*
* @return TeamSpeak3_Helper_String
*/
public function getMessage()
{
return $this->mesg;
}
/**
* @ignore
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data) ? TRUE : FALSE;
}
/**
* @ignore
*/
public function offsetGet($offset)
{
if(!$this->offsetExists($offset))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
return $this->data[$offset];
}
/**
* @ignore
*/
public function offsetSet($offset, $value)
{
throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only");
}
/**
* @ignore
*/
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
/**
* @ignore
*/
public function __get($offset)
{
return $this->offsetGet($offset);
}
/**
* @ignore
*/
public function __set($offset, $value)
{
$this->offsetSet($offset, $value);
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects.
*/
class TeamSpeak3_Adapter_ServerQuery_Exception extends TeamSpeak3_Adapter_Exception {}

View File

@ -0,0 +1,346 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Reply.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_ServerQuery_Reply
* @brief Provides methods to analyze and format a ServerQuery reply.
*/
class TeamSpeak3_Adapter_ServerQuery_Reply
{
/**
* Stores the command used to get this reply.
*
* @var TeamSpeak3_Helper_String
*/
protected $cmd = null;
/**
* Stores the servers reply (if available).
*
* @var TeamSpeak3_Helper_String
*/
protected $rpl = null;
/**
* Stores connected TeamSpeak3_Node_Host object.
*
* @var TeamSpeak3_Node_Host
*/
protected $con = null;
/**
* Stores an assoc array containing the error info for this reply.
*
* @var array
*/
protected $err = array();
/**
* Sotres an array of events that occured before or during this reply.
*
* @var array
*/
protected $evt = array();
/**
* Indicates whether exceptions should be thrown or not.
*
* @var boolean
*/
protected $exp = TRUE;
/**
* Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object.
*
* @param array $rpl
* @param string $cmd
* @param boolean $exp
* @param TeamSpeak3_Node_Host $con
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function __construct(array $rpl, $cmd = null, TeamSpeak3_Node_Host $con = null, $exp = TRUE)
{
$this->cmd = new TeamSpeak3_Helper_String($cmd);
$this->con = $con;
$this->exp = (bool) $exp;
$this->fetchError(array_pop($rpl));
$this->fetchReply($rpl);
}
/**
* Returns the reply as an TeamSpeak3_Helper_String object.
*
* @return TeamSpeak3_Helper_String
*/
public function toString()
{
return (!func_num_args()) ? $this->rpl->unescape() : $this->rpl;
}
/**
* Returns the reply as a standard PHP array where each element represents one item.
*
* @return array
*/
public function toLines()
{
if(!count($this->rpl)) return array();
$list = $this->toString(0)->split(TeamSpeak3::SEPARATOR_LIST);
if(!func_num_args())
{
for($i = 0; $i < count($list); $i++) $list[$i]->unescape();
}
return $list;
}
/**
* Returns the reply as a standard PHP array where each element represents one item in table format.
*
* @return array
*/
public function toTable()
{
$table = array();
foreach($this->toLines(0) as $cells)
{
$pairs = $cells->split(TeamSpeak3::SEPARATOR_CELL);
if(!func_num_args())
{
for($i = 0; $i < count($pairs); $i++) $pairs[$i]->unescape();
}
$table[] = $pairs;
}
return $table;
}
/**
* Returns a multi-dimensional array containing the reply splitted in multiple rows and columns.
*
* @return array
*/
public function toArray()
{
$array = array();
$table = $this->toTable(1);
for($i = 0; $i < count($table); $i++)
{
foreach($table[$i] as $pair)
{
if(!count($pair))
{
continue;
}
if(!$pair->contains(TeamSpeak3::SEPARATOR_PAIR))
{
$array[$i][$pair->toString()] = null;
}
else
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR, 2);
$array[$i][$ident->toString()] = $value->isInt() ? $value->toInt() : (!func_num_args() ? $value->unescape() : $value);
}
}
}
return $array;
}
/**
* Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns.
* The identifier specified by key will be used while indexing the array.
*
* @param $key
* @return array
*/
public function toAssocArray($ident)
{
$nodes = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
$array = array();
foreach($nodes as $node)
{
if(isset($node[$ident]))
{
$array[(is_object($node[$ident])) ? $node[$ident]->toString() : $node[$ident]] = $node;
}
else
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
}
return $array;
}
/**
* Returns an array containing the reply splitted in multiple rows and columns.
*
* @return array
*/
public function toList()
{
$array = func_num_args() ? $this->toArray(1) : $this->toArray();
if(count($array) == 1)
{
return array_shift($array);
}
return $array;
}
/**
* Returns an array containing stdClass objects.
*
* @return ArrayObject
*/
public function toObjectArray()
{
$array = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
for($i = 0; $i < count($array); $i++)
{
$array[$i] = (object) $array[$i];
}
return $array;
}
/**
* Returns the command used to get this reply.
*
* @return TeamSpeak3_Helper_String
*/
public function getCommandString()
{
return new TeamSpeak3_Helper_String($this->cmd);
}
/**
* Returns an array of events that occured before or during this reply.
*
* @return array
*/
public function getNotifyEvents()
{
return $this->evt;
}
/**
* Returns the value for a specified error property.
*
* @param string $ident
* @param mixed $default
* @return mixed
*/
public function getErrorProperty($ident, $default = null)
{
return (array_key_exists($ident, $this->err)) ? $this->err[$ident] : $default;
}
/**
* Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if
* there's an error.
*
* @param string $err
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return void
*/
protected function fetchError($err)
{
$cells = $err->section(TeamSpeak3::SEPARATOR_CELL, 1, 3);
foreach($cells->split(TeamSpeak3::SEPARATOR_CELL) as $pair)
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR);
$this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
}
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyError", $this);
if($this->getErrorProperty("id", 0x00) != 0x00 && $this->exp)
{
if($permid = $this->getErrorProperty("failed_permid"))
{
if($permsid = key($this->con->request("permget permid=" . $permid, FALSE)->toAssocArray("permsid")))
{
$suffix = " (failed on " . $permsid . ")";
}
else
{
$suffix = " (failed on " . $this->cmd->section(TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
}
}
elseif($details = $this->getErrorProperty("extra_msg"))
{
$suffix = " (" . trim($details) . ")";
}
else
{
$suffix = "";
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
}
}
/**
* Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.
*
* @param string $rpl
* @return void
*/
protected function fetchReply($rpl)
{
foreach($rpl as $key => $val)
{
if($val->startsWith(TeamSpeak3::GREET))
{
unset($rpl[$key]);
}
elseif($val->startsWith(TeamSpeak3::EVENT))
{
$this->evt[] = new TeamSpeak3_Adapter_ServerQuery_Event($rpl[$key], $this->con);
unset($rpl[$key]);
}
}
$this->rpl = new TeamSpeak3_Helper_String(implode(TeamSpeak3::SEPARATOR_LIST, $rpl));
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: TSDNS.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_TSDNS
* @brief Provides methods to query a TSDNS server.
*/
class TeamSpeak3_Adapter_TSDNS extends TeamSpeak3_Adapter_Abstract
{
/**
* The TCP port number used by any TSDNS server.
*
* @var integer
*/
protected $default_port = 41144;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsConnected", $this);
}
/**
* The TeamSpeak3_Adapter_FileTransfer destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Queries the TSDNS server for a specified virtual hostname and returns the result.
*
* @param string $tsdns
* @throws TeamSpeak3_Adapter_TSDNS_Exception
* @return TeamSpeak3_Helper_String
*/
public function resolve($tsdns)
{
$this->getTransport()->sendLine($tsdns);
$repl = $this->getTransport()->readLine();
$this->getTransport()->disconnect();
if($repl->section(":", 0)->toInt() == 404)
{
throw new TeamSpeak3_Adapter_TSDNS_Exception("unable to resolve TSDNS hostname (" . $tsdns . ")");
}
TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl);
return $repl;
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_TSDNS_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_TSDNS objects.
*/
class TeamSpeak3_Adapter_TSDNS_Exception extends TeamSpeak3_Adapter_Exception {}

View File

@ -0,0 +1,217 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Update.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Update
* @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server.
*/
class TeamSpeak3_Adapter_Update extends TeamSpeak3_Adapter_Abstract
{
/**
* The IPv4 address or FQDN of the TeamSpeak Systems update server.
*
* @var string
*/
protected $default_host = "update.teamspeak.com";
/**
* The UDP port number of the TeamSpeak Systems update server.
*
* @var integer
*/
protected $default_port = 17384;
/**
* Stores an array containing the latest build numbers (integer timestamps).
*
* @var array
*/
protected $build_datetimes = null;
/**
* Stores an array containing the latest version strings.
*
* @var array
*/
protected $version_strings = null;
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Update_Exception
* @return void
*/
public function syn()
{
if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
$this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
$this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33));
if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2]))
{
throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server");
}
$this->build_datetimes = $matches[1];
$this->version_strings = $matches[2];
TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this);
}
/**
* The TeamSpeak3_Adapter_Update destructor.
*
* @return void
*/
public function __destruct()
{
if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
{
$this->getTransport()->disconnect();
}
}
/**
* Returns the current build number for a specified update channel. Note that since version
* 3.0.0, the build number represents an integer timestamp. $channel must be set to one of
* the following values:
*
* - stable
* - beta
* - alpha
* - server
*
* @param string $channel
* @throws TeamSpeak3_Adapter_Update_Exception
* @return integer
*/
public function getRev($channel = "stable")
{
switch($channel)
{
case "stable":
return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null;
case "beta":
return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null;
case "alpha":
return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null;
case "server":
return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null;
default:
throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
}
}
/**
* Returns the current version string for a specified update channel. $channel must be set to
* one of the following values:
*
* - stable
* - beta
* - alpha
* - server
*
* @param string $channel
* @throws TeamSpeak3_Adapter_Update_Exception
* @return integer
*/
public function getVersion($channel = "stable")
{
switch($channel)
{
case "stable":
return isset($this->version_strings[0]) ? $this->version_strings[0] : null;
case "beta":
return isset($this->version_strings[1]) ? $this->version_strings[1] : null;
case "alpha":
return isset($this->version_strings[2]) ? $this->version_strings[2] : null;
case "server":
return isset($this->version_strings[3]) ? $this->version_strings[3] : null;
default:
throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
}
}
/**
* Alias for getRev() using the 'stable' update channel.
*
* @param string $channel
* @return integer
*/
public function getClientRev()
{
return $this->getRev("stable");
}
/**
* Alias for getRev() using the 'server' update channel.
*
* @param string $channel
* @return integer
*/
public function getServerRev()
{
return $this->getRev("server");
}
/**
* Alias for getVersion() using the 'stable' update channel.
*
* @param string $channel
* @return integer
*/
public function getClientVersion()
{
return $this->getVersion("stable");
}
/**
* Alias for getVersion() using the 'server' update channel.
*
* @param string $channel
* @return integer
*/
public function getServerVersion()
{
return $this->getVersion("server");
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* $Id: Exception.php 06/06/2016 22:27:13 scp@Svens-iMac $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @version 1.1.24
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Adapter_Update_Exception
* @brief Enhanced exception class for TeamSpeak3_Adapter_Update objects.
*/
class TeamSpeak3_Adapter_Update_Exception extends TeamSpeak3_Adapter_Exception {}