Ejemplo n.º 1
0
 /**
  * Queries the TSDNS server for a specified virtual hostname and returns the result.
  *
  * @param  string $tsdns
  *
  * @throws TsDnsException
  * @return String
  */
 public function resolve($tsdns)
 {
     $this->getTransport()->sendLine($tsdns);
     $repl = $this->getTransport()->readLine();
     $this->getTransport()->disconnect();
     if ($repl->section(":", 0)->toInt() == 404) {
         throw new TsDnsException("unable to resolve TSDNS hostname (" . $tsdns . ")");
     }
     Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl);
     return $repl;
 }
 /**
  * Connects the AbstractTransport 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, "Udp");
     $this->transport->setAdapter($this);
     Profiler::init(spl_object_hash($this));
     Signal::getInstance()->emit("blacklistConnected", $this);
 }
Ejemplo n.º 3
0
 /**
  * Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
  *
  * @param String $evt
  * @param Host   $con
  *
  * @throws AdapterException
  * @return Event
  */
 public function __construct(string $evt, Host $con = null)
 {
     if (!$evt->startsWith(Constant::EVENT)) {
         throw new AdapterException("invalid notification event format");
     }
     list($type, $data) = $evt->split(Constant::SEPARATOR_CELL, 2);
     if (empty($data)) {
         throw new AdapterException("invalid notification event data");
     }
     $fake = new String(Constant::ERROR . Constant::SEPARATOR_CELL . "id" . Constant::SEPARATOR_PAIR . 0 . Constant::SEPARATOR_CELL . "msg" . Constant::SEPARATOR_PAIR . "ok");
     $repl = new Reply(array($data, $fake), $type);
     $this->type = $type->substr(strlen(Constant::EVENT));
     $this->data = $repl->toList();
     $this->mesg = $data;
     Signal::getInstance()->emit("notifyEvent", $this, $con);
     Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
 }
 /**
  * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
  * server.
  *
  * @throws UpdateException
  * @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);
     Profiler::init(spl_object_hash($this));
     $this->getTransport()->send(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 UpdateException("invalid reply from the server");
     }
     $this->build_datetimes = $matches[1];
     $this->version_strings = $matches[2];
     Signal::getInstance()->emit("updateConnected", $this);
 }
Ejemplo n.º 5
0
 /**
  * Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if
  * there's an error.
  *
  * @param  string $err
  *
  * @throws ServerQueryException
  * @return void
  */
 protected function fetchError($err)
 {
     $cells = $err->section(Constant::SEPARATOR_CELL, 1, 3);
     foreach ($cells->split(Constant::SEPARATOR_CELL) as $pair) {
         list($ident, $value) = $pair->split(Constant::SEPARATOR_PAIR);
         $this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
     }
     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(Constant::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
             }
         } elseif ($details = $this->getErrorProperty("extra_msg")) {
             $suffix = " (" . trim($details) . ")";
         } else {
             $suffix = "";
         }
         throw new ServerQueryException($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
     }
 }
Ejemplo n.º 6
0
 /**
  * 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 String
  */
 public function privilegeKeyCreate($type = Constant::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();
     Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
     return $token["token"];
 }
Ejemplo n.º 7
0
 /**
  * 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);
     Profiler::init(spl_object_hash($this));
     if (!$this->getTransport()->readLine()->startsWith(Constant::READY)) {
         throw new AdapterException("invalid reply from the server");
     }
     Signal::getInstance()->emit("serverqueryConnected", $this);
 }
 /**
  * Returns the content of a downloaded file as a TeamSpeak3_Helper_String object.
  *
  * @param  string  $ftkey
  * @param  integer $size
  * @param  boolean $passthru
  *
  * @throws FileTransferException
  * @return String
  */
 public function download($ftkey, $size, $passthru = false)
 {
     $this->init($ftkey);
     if ($passthru) {
         return $this->passthru($size);
     }
     $buff = new String("");
     $size = intval($size);
     $pack = 4096;
     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);
         Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
     }
     $this->getProfiler()->stop();
     Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);
     if (strlen($buff) != $size) {
         throw new FileTransferException("incomplete file download (" . count($buff) . " of " . $size . " bytes)");
     }
     return $buff;
 }
Ejemplo n.º 9
0
 /**
  * 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");
     Signal::getInstance()->emit("notifyLogout", $this);
 }