Beispiel #1
0
 /**
  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  *
  * @param  \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Node\AbstractNode $node
  * @param  array $siblings
  * @return string
  */
 public function fetchObject(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Node\AbstractNode $node, array $siblings = array())
 {
     $this->currObj = $node;
     $this->currSib = $siblings;
     $args = array($this->getPrefix(), $this->getCorpusIcon(), $this->getCorpusName());
     return \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($this->pattern)->arg($args);
 }
 /**
  * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
  * server.
  *
  * @throws 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, '\\ManiaLivePlugins\\Standard\\TeamSpeak\\TeamSpeak3\\Transport\\UDP');
     $this->transport->setAdapter($this);
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Profiler::init(spl_object_hash($this));
     $this->getTransport()->send(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::fromHex(32));
     if (!preg_match_all("/,?(\\d+),?/", $this->getTransport()->read(32), $matches) || !isset($matches[1])) {
         throw new Update\Exception("invalid reply from the server");
     }
     $this->build_numbers = $matches[1];
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("updateConnected", $this);
 }
 /**
  * Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if
  * there's an error.
  *
  * @param  string $err
  * @throws Exception
  * @return void
  */
 protected function fetchError($err)
 {
     $cells = $err->section(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL, 1, 3);
     foreach ($cells->split(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL) as $pair) {
         list($ident, $value) = $pair->split(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_PAIR);
         $this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
     }
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("notifyError", $this);
     if ($this->getErrorProperty("id", 0x0) != 0x0) {
         if ($permid = $this->getErrorProperty("failed_permid")) {
             try {
                 $suffix = " (failed on " . $this->con->permissionGetNameById($permid) . ")";
             } catch (Exception $e) {
                 $suffix = " (failed on " . $this->cmd->section(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
             }
         } elseif ($details = $this->getErrorProperty("extra_msg")) {
             $suffix = " (" . $details . ")";
         } else {
             $suffix = "";
         }
         throw new Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
     }
 }
 /**
  * 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) . \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\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 \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Node\AbstractNode) {
                     $value[$i] = $value[$i]->getId();
                 }
                 $cells[$i][] = $ident . \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($value[$i])->escape();
                 //->toUtf8();
             }
         } else {
             if ($value === null) {
                 continue;
             } elseif ($value === FALSE) {
                 $value = 0x0;
             } elseif ($value === TRUE) {
                 $value = 0x1;
             } elseif ($value instanceof \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Node\AbstractNode) {
                 $value = $value->getId();
             }
             $args[] = $ident . \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($value)->escape();
             //->toUtf8();
         }
     }
     foreach (array_keys($cells) as $ident) {
         $cells[$ident] = implode(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL, $cells[$ident]);
     }
     if (count($args)) {
         $cmd .= " " . implode(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL, $args);
     }
     if (count($cells)) {
         $cmd .= " " . implode(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_LIST, $cells);
     }
     return trim($cmd);
 }
 /**
  * Returns the adapter type.
  *
  * @return string
  */
 public function getAdapterType()
 {
     if ($this->adapter instanceof \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Adapter\AbstractAdapter) {
         $string = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory(get_class($this->adapter));
         return $string->substr($string->findLast("\\"))->replace(array("\\", " "), "")->toString();
     }
     return "Unknown";
 }
Beispiel #6
0
 /**
  * Reads a single line of data from the stream.
  *
  * @param  string $token
  * @throws Exception
  * @return \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String
  */
 public function readLine($token = "\n", $useCR = false)
 {
     $this->connect();
     $line = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory("");
     while (!$line->endsWith($token) && !($useCR && $line->endsWith("\r"))) {
         $this->waitForReadyRead();
         $data = @fgets($this->stream, 4096);
         \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
         if ($data === FALSE) {
             if ($line->count()) {
                 $line->append($token);
             } else {
                 throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
             }
         } else {
             $line->append($data);
         }
     }
     return $line->trim();
 }
Beispiel #7
0
 /**
  * Sets a single value in the current ServerQuery connection info.
  *
  * @param  string $ident
  * @param  mixed  $value
  * @return mixed
  */
 public function whoamiSet($ident, $value = null)
 {
     $this->whoami();
     $this->whoami[$ident] = is_numeric($value) ? intval($value) : \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($value);
 }
 /**
  * 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 void
  */
 public function snapshotDeploy($data, $mode = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SNAPSHOT_STRING)
 {
     switch ($mode) {
         case \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SNAPSHOT_BASE64:
             $data = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::fromBase64($data);
             break;
         case \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SNAPSHOT_HEXDEC:
             $data = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::fromHex($data);
             break;
         default:
             $data = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($data);
             break;
     }
     $this->request("serversnapshotdeploy " . $data);
 }
 /**
  * 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 = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($key);
             if ($key->contains("_bytes_")) {
                 $info[$key->toString()] = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Convert::bytes($val);
             } elseif ($key->contains("_bandwidth_")) {
                 $info[$key->toString()] = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\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()] = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Convert::seconds($val);
             } elseif ($key->endsWith("_version")) {
                 $info[$key->toString()] = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Convert::version($val);
             } elseif ($key->endsWith("_icon_id")) {
                 $info[$key->toString()] = $this->iconGetName($key)->filterDigits();
             }
         }
         return $info;
     }
     return $this->nodeInfo;
 }