Example #1
0
 /**
  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  *
  * @param  AbstractNode $node
  * @param  array                    $siblings
  *
  * @return string
  */
 public function fetchObject(AbstractNode $node, array $siblings = array())
 {
     $this->currObj = $node;
     $this->currSib = $siblings;
     $args = array($this->getPrefix(), $this->getCorpusIcon(), $this->getCorpusName());
     return String::factory($this->pattern)->arg($args);
 }
 /**
  * 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 = Constant::SNAPSHOT_STRING)
 {
     switch ($mode) {
         case Constant::SNAPSHOT_BASE64:
             $data = String::fromBase64($data);
             break;
         case Constant::SNAPSHOT_HEXDEC:
             $data = String::fromHex($data);
             break;
         default:
             $data = String::factory($data);
             break;
     }
     $detail = $this->request("serversnapshotdeploy " . $data)->toList();
     if (array_key_exists("sid", $detail)) {
         Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail["sid"]);
     }
     return $detail;
 }
 /**
  * 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) . Constant::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 . String::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 . String::factory($value)->escape()->toUtf8();
         }
     }
     foreach (array_keys($cells) as $ident) {
         $cells[$ident] = implode(Constant::SEPARATOR_CELL, $cells[$ident]);
     }
     if (count($args)) {
         $cmd .= " " . implode(Constant::SEPARATOR_CELL, $args);
     }
     if (count($cells)) {
         $cmd .= " " . implode(Constant::SEPARATOR_LIST, $cells);
     }
     return trim($cmd);
 }
 /**
  * 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 = String::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;
 }
 /**
  * Converts a specified log entry string into an array containing the data.
  *
  * @param  string $entry
  *
  * @return array
  */
 public static function logEntry($entry)
 {
     $parts = explode("|", $entry, 5);
     $array = array();
     if (count($parts) != 5) {
         $array["timestamp"] = 0;
         $array["level"] = Constant::LOGLEVEL_ERROR;
         $array["channel"] = "ParamParser";
         $array["server_id"] = "";
         $array["msg"] = String::factory("convert error (" . trim($entry) . ")");
         $array["msg_plain"] = $entry;
         $array["malformed"] = true;
     } else {
         $array["timestamp"] = strtotime(trim($parts[0]));
         $array["level"] = self::logLevel(trim($parts[1]));
         $array["channel"] = trim($parts[2]);
         $array["server_id"] = trim($parts[3]);
         $array["msg"] = String::factory(trim($parts[4]));
         $array["msg_plain"] = $entry;
         $array["malformed"] = false;
     }
     return $array;
 }
 /**
  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
  *
  * @param  AbstractNode $node
  * @param  array                    $siblings
  *
  * @return string
  */
 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 String::factory($this->pattern)->arg($args);
 }
 /**
  * @ignore
  */
 protected function fetchPermissionCats()
 {
     $permcats = array();
     $reflects = new ReflectionClass("TeamSpeak3");
     foreach ($reflects->getConstants() as $key => $val) {
         if (!String::factory($key)->startsWith("PERM_CAT") || $val == 0xff) {
             continue;
         }
         $permcats[$key] = $val;
     }
     $this->permissionCats = $permcats;
 }