Пример #1
0
 /**
  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  *
  * @param  AbstractNode $node
  * @param  array $siblings
  * @return StringHelper
  */
 public function fetchObject(AbstractNode $node, array $siblings = array())
 {
     $this->currObj = $node;
     $this->currSib = $siblings;
     $args = array($this->getPrefix(), $this->getCorpusIcon(), $this->getCorpusName());
     return StringHelper::factory($this->pattern)->arg($args);
 }
Пример #2
0
 /**
  * Creates a new Event object.
  *
  * @param  StringHelper $evt
  * @param  Host $con
  * @throws Ts3Exception
  * @return Event
  */
 public function __construct(StringHelper $evt, Host $con = null)
 {
     if (!$evt->startsWith(TeamSpeak3::EVENT)) {
         throw new Ts3Exception("invalid notification event format");
     }
     list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
     if (empty($data)) {
         throw new Ts3Exception("invalid notification event data");
     }
     $fake = new StringHelper(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok");
     $repl = new Reply(array($data, $fake), $type);
     $this->type = $type->substr(strlen(TeamSpeak3::EVENT));
     $this->data = $repl->toList();
     $this->mesg = $data;
     Signal::getInstance()->emit("notifyEvent", $this, $con);
     Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
 }
Пример #3
0
 /**
  * Connects to a remote server.
  *
  * @throws Ts3Exception
  * @return void
  */
 public function connect()
 {
     if ($this->stream !== null) {
         return;
     }
     $host = strval($this->config["host"]);
     $port = strval($this->config["port"]);
     $address = "udp://" . $host . ":" . $port;
     $timeout = intval($this->config["timeout"]);
     $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
     if ($this->stream === false) {
         throw new Ts3Exception(StringHelper::factory($errstr)->toUtf8()->toString(), $errno);
     }
     @stream_set_timeout($this->stream, $timeout);
     @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
 }
Пример #4
0
 /**
  * Connects the AbstractTransport object and performs initial actions on the remote
  * server.
  *
  * @throws Ts3Exception
  * @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));
     $this->getTransport()->send(StringHelper::fromHex(33));
     if (!preg_match_all("/,?(\\d+)#([0-9a-zA-Z\\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2])) {
         throw new Ts3Exception("invalid reply from the server");
     }
     $this->build_datetimes = $matches[1];
     $this->version_strings = $matches[2];
     Signal::getInstance()->emit("updateConnected", $this);
 }
 /**
  * Returns the adapter type.
  *
  * @return string
  */
 public function getAdapterType()
 {
     if ($this->adapter instanceof AbstractAdapter) {
         $string = StringHelper::factory(get_class($this->adapter));
         return $string->substr($string->findLast("\\"))->replace(array("\\", " "), "")->toString();
     }
     return "Unknown";
 }
 /**
  * Prepares a custom error message by replacing pre-defined signs with given values.
  *
  * @param \Teamspeak3\Helper\StringHelper $mesg
  * @return \Teamspeak3\Helper\StringHelper
  */
 protected function prepareCustomMessage(StringHelper $mesg)
 {
     $args = array("code" => $this->getCode(), "mesg" => $this->getMessage(), "line" => $this->getLine(), "file" => $this->getFile());
     return $mesg->arg($args)->toString();
 }
 /**
  * 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] = 0x0;
                 } elseif ($value[$i] === true) {
                     $value[$i] = 0x1;
                 } elseif ($value[$i] instanceof AbstractNode) {
                     $value[$i] = $value[$i]->getId();
                 }
                 $cells[$i][] = $ident . StringHelper::factory($value[$i])->escape()->toUtf8();
             }
         } else {
             if ($value === null) {
                 continue;
             } elseif ($value === false) {
                 $value = 0x0;
             } elseif ($value === true) {
                 $value = 0x1;
             } elseif ($value instanceof AbstractNode) {
                 $value = $value->getId();
             }
             $args[] = $ident . StringHelper::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);
 }
Пример #8
0
 /**
  * Parses a ServerQuery error and throws a Ts3Exception object if
  * there's an error.
  *
  * @param  StringHelper|string $err
  * @throws Ts3Exception
  * @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();
     }
     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 Ts3Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
     }
 }
Пример #9
0
 /**
  * Reads a single line of data from the stream.
  *
  * @param  string $token
  * @throws Ts3Exception
  * @return StringHelper
  */
 public function readLine($token = "\n")
 {
     $this->connect();
     $line = StringHelper::factory("");
     while (!$line->endsWith($token)) {
         $this->waitForReadyRead();
         $data = @fgets($this->stream, 4096);
         Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
         if ($data === false) {
             if ($line->count()) {
                 $line->append($token);
             } else {
                 throw new Ts3Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
             }
         } else {
             $line->append($data);
         }
     }
     return $line->trim();
 }
Пример #10
0
 /**
  * @ignore
  */
 protected function fetchPermissionCats()
 {
     $permcats = array();
     $reflects = new \ReflectionClass("TeamSpeak3");
     foreach ($reflects->getConstants() as $key => $val) {
         if (!StringHelper::factory($key)->startsWith("PERM_CAT") || $val == 0xff) {
             continue;
         }
         $permcats[$key] = $val;
     }
     $this->permissionCats = $permcats;
 }
Пример #11
0
 /**
  * Returns the name of an adapter class by $name.
  *
  * @param  string $name
  * @param  string $namespace
  * @throws Ts3Exception
  * @return string
  */
 protected static function getAdapterName($name, $namespace = "Adapter/")
 {
     $path = self::getFilePath($namespace);
     $scan = scandir($path);
     foreach ($scan as $node) {
         $file = StringHelper::factory($node)->toLower();
         if ($file->startsWith($name) && $file->endsWith(".php")) {
             return str_replace(".php", "", "TeamSpeak3\\Adapter\\" . $node);
         }
     }
     throw new Ts3Exception("adapter '" . $name . "' does not exist");
 }
 /**
  * Returns all information available on this node. If $convert is enabled, some property
  * values will be converted to human-readable values.
  *
  * @param  boolean $extend
  * @param  boolean $convert
  * @return array
  */
 public function getInfo($extend = true, $convert = false)
 {
     if ($extend) {
         $this->fetchNodeInfo();
     }
     if ($convert) {
         $info = $this->nodeInfo;
         foreach ($info as $key => $val) {
             $key = StringHelper::factory($key);
             if ($key->contains("_bytes_")) {
                 $info[$key->toString()] = Convert::bytes($val);
             } elseif ($key->contains("_bandwidth_")) {
                 $info[$key->toString()] = Convert::bytes($val) . "/s";
             } elseif ($key->contains("_packets_")) {
                 $info[$key->toString()] = number_format($val, null, null, ".");
             } elseif ($key->contains("_packetloss_")) {
                 $info[$key->toString()] = sprintf("%01.2f", floatval($val->toString()) * 100) . "%";
             } elseif ($key->endsWith("_uptime")) {
                 $info[$key->toString()] = Convert::seconds($val);
             } elseif ($key->endsWith("_version")) {
                 $info[$key->toString()] = Convert::version($val);
             } elseif ($key->endsWith("_icon_id")) {
                 $info[$key->toString()] = $this->iconGetName($key)->filterDigits();
             }
         }
         return $info;
     }
     return $this->nodeInfo;
 }
Пример #13
0
 /**
  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  *
  * @param  AbstractNode $node
  * @param  array $siblings
  * @return StringHelper
  */
 public function fetchObject(AbstractNode $node, array $siblings = array())
 {
     $this->currObj = $node;
     $this->currSib = $siblings;
     $args = array($this->getContainerIdent(), $this->getContainerClass(), $this->getContainerSummary(), $this->getRowClass(), $this->getPrefixClass(), $this->getPrefix(), $this->getCorpusClass(), $this->getCorpusTitle(), $this->getCorpusIcon(), $this->getCorpusName(), $this->getSuffixClass(), $this->getSuffixIcon(), $this->getSuffixFlag());
     return StringHelper::factory($this->pattern)->arg($args);
 }