コード例 #1
0
 /**
  * Queries the TSDNS server for a specified virtual hostname and returns the result.
  *
  * @param  string $tsdns
  * @throws TSDNS\Exception
  * @return TeamSpeak3_Helper_String
  */
 public function resolve($tsdns)
 {
     $this->getTransport()->sendLine($tsdns);
     $repl = $this->getTransport()->readLine();
     $this->getTransport()->disconnect();
     if ($repl->section(":", 0)->toInt() == 404) {
         throw new TSDNS\Exception("unable to resolve TSDNS hostname (" . $tsdns . ")");
     }
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl);
     return $repl;
 }
コード例 #2
0
 function onLoad()
 {
     $config = Config::getInstance();
     if (!$config->serverChannelName) {
         $config->serverChannelName = substr('ManiaPlanet> ' . Formatting::stripStyles($this->connection->getMainServerPlayerInfo()->nickName), 0, 40);
     }
     $this->tsConnection = Connection::getInstance();
     $this->tsConnection->open();
     if (!$this->tsConnection->isConnected()) {
         $this->enableTickerEvent();
     }
     Signal::getInstance()->subscribe('notifyEvent', array($this, 'onTeamSpeakEvent'));
     $this->enableDedicatedEvents(ServerEvent::ON_PLAYER_CONNECT | ServerEvent::ON_PLAYER_DISCONNECT | ServerEvent::ON_PLAYER_INFO_CHANGED);
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 /**
  * Sends a prepared command to the server and returns the result.
  *
  * @param  string $cmd
  * @throws Exception
  * @return ServerQuery\Reply
  */
 public function request($cmd)
 {
     $query = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory($cmd)->section(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL);
     if (strstr($cmd, "\r") || strstr($cmd, "\n")) {
         throw new Exception("illegal characters in command '" . $query . "'");
     } elseif (in_array($query, $this->block)) {
         throw new ServerQuery\Exception("command not found", 0x100);
     }
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("serverqueryCommandStarted", $cmd);
     $this->getProfiler()->start();
     $this->getTransport()->sendLine($cmd);
     $this->timer = time();
     $this->count++;
     $rpl = array();
     do {
         $str = $this->getTransport()->readLine();
         $rpl[] = $str;
     } while ($str instanceof \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String && $str->section(\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::SEPARATOR_CELL) != \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::ERROR);
     $this->getProfiler()->stop();
     $reply = new ServerQuery\Reply($rpl, $cmd, $this->getHost());
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply);
     return $reply;
 }
コード例 #5
0
 /**
  * Blocks a stream until data is available for reading if the stream is connected
  * in non-blocking mode.
  *
  * @param  integer $time
  * @return void
  */
 protected function waitForReadyRead($time = 0)
 {
     if (!$this->isConnected() || $this->config["blocking"]) {
         return;
     }
     do {
         $read = array($this->stream);
         $null = null;
         if ($time) {
             \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
         }
         $time = $time + $this->config["timeout"];
     } while (@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
 }
コード例 #6
0
 /**
  * Returns the content of a downloaded file as a \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String object.
  *
  * @param  string  $ftkey
  * @param  integer $size
  * @param  boolean $passthru
  * @throws FileTransfer\Exception
  * @return \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String
  */
 public function download($ftkey, $size, $passthru = FALSE)
 {
     $this->init($ftkey);
     if ($passthru) {
         return $this->passthru($size);
     }
     $buff = new \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String("");
     $size = intval($size);
     $pack = 4096;
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\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);
         \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
     }
     $this->getProfiler()->stop();
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);
     if (strlen($buff) != $size) {
         throw new FileTransfer\Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)");
     }
     return $buff;
 }
コード例 #7
0
 /**
  * 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"));
     }
 }
コード例 #8
0
ファイル: TCP.php プロジェクト: maniaplanet/manialive-plugins
 /**
  * Writes data to the stream.
  *
  * @param  string $data
  * @return void
  */
 public function send($data)
 {
     $this->connect();
     @fputs($this->stream, $data);
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
 }
コード例 #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");
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("notifyLogout", $this);
 }
コード例 #10
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 \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String
  */
 public function privilegeKeyCreate($type = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::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();
     \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
     return $token["token"];
 }