/** * The TeamSpeak3_Exception constructor. * * @param string $mesg * @param integer $code * @return TeamSpeak3_Exception */ public function __construct($mesg, $code = 0x0) { parent::__construct($mesg, $code); if (array_key_exists((int) $code, self::$messages)) { $this->message = $this->prepareCustomMessage(self::$messages[intval($code)]); } TeamSpeak3_Helper_Signal::getInstance()->emit("errorException", $this); }
/** * 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; }
/** * 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); }
/** * 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); }
/** * 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(32)); if (!preg_match_all("/,?(\\d+),?/", $this->getTransport()->read(32), $matches) || !isset($matches[1])) { throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server"); } $this->build_numbers = $matches[1]; TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this); }
/** * Creates a new privilege key (token) and returns the key. * * @param integer $type * @param integer $id1 * @param integer $id2 * @param string $description * @param string $customset * @return TeamSpeak3_Helper_String */ public function privilegeKeyCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null) { $token = $this->execute("privilegekeyadd", array("tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset))->toList(); TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]); return $token["token"]; }
/** * Writes data to the stream. * * @param string $data * @return void */ public function send($data) { $this->connect(); @stream_socket_sendto($this->stream, $data); TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data); }
/** * Blocks a stream until data is available for reading if the stream is connected * in non-blocking mode. * * @param integer $time * @return void */ protected function waitForReadyRead($time = 0) { if (!$this->isConnected() || $this->config["blocking"]) { return; } do { $read = array($this->stream); $null = null; if ($time) { TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter()); } $time = $time + $this->config["timeout"]; } while (@stream_select($read, $null, $null, $this->config["timeout"]) == 0); }
/** * 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_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_Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)"); } return $buff; }
/** * 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; }
/** * 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", 0x0) != 0x0 && $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")); } }
/** * Returns a singleton instance of TeamSpeak3_Helper_Signal. * * @return TeamSpeak3_Helper_Signal */ public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; }
/** * Deselects the active virtual server and logs out from the server instance. * * @return void */ public function logout() { $this->request("logout"); $this->whoamiReset(); $this->delStorage("_login_user"); $this->delStorage("_login_pass"); TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogout", $this); }
/** * Deploys snapshot data on the selected virtual server. If no virtual server is selected (ID 0), * the data will be used to create a new virtual server from scratch. * * @param string $data * @param string $mode * @return array */ public function snapshotDeploy($data, $mode = TeamSpeak3::SNAPSHOT_STRING) { switch ($mode) { case TeamSpeak3::SNAPSHOT_BASE64: $data = TeamSpeak3_Helper_String::fromBase64($data); break; case TeamSpeak3::SNAPSHOT_HEXDEC: $data = TeamSpeak3_Helper_String::fromHex($data); break; default: $data = TeamSpeak3_Helper_String::factory($data); break; } $detail = $this->request("serversnapshotdeploy " . $data)->toList(); if (array_key_exists("sid", $detail)) { TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail["sid"]); } return $detail; }