示例#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);
 }
 /**
  * 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";
 }
示例#4
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();
 }
示例#5
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);
 }
示例#6
0
 /**
  * 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;
 }