protected function connection()
 {
     if (!self::$tsServer) {
         self::$tsServer = TeamSpeak3::factory('serverquery://' . $this->config->queryLogin . ':' . $this->config->queryPassword . '@' . $this->config->queryHost . ':' . $this->config->queryPort . '/?server_port=' . $this->config->voicePort . '#no_query_clients');
     }
     return self::$tsServer;
 }
Exemplo n.º 2
0
 function open()
 {
     $config = Config::getInstance();
     try {
         $this->server = TeamSpeak3::factory('serverquery://' . $config->queryLogin . ':' . $config->queryPassword . '@' . $config->queryHost . ':' . $config->queryPort . '/?server_port=' . $config->voicePort . '&blocking=0#no_query_clients');
         $this->server->execute('instanceedit', array('serverinstance_serverquery_flood_commands' => 20, 'serverinstance_serverquery_flood_time' => 1, 'serverinstance_serverquery_flood_ban_time' => 1));
     } catch (\Exception $e) {
         $this->server = null;
         return;
     }
     // Threading is really useful for this plugin !!!
     $this->processHandler = ThreadHandler::getInstance();
     $this->processId = $this->processHandler->launchThread();
     // Enable events (from ML and from TS)
     Dispatcher::register(AppEvent::getClass(), $this, AppEvent::ON_PRE_LOOP);
     Dispatcher::register(TickEvent::getClass(), $this);
     $this->server->notifyRegister('channel');
     // Find players group id or create a new group for privilege keys
     foreach ($this->server->serverGroupList() as $group) {
         if ($group['name'] == 'ManiaPlanet Player') {
             $this->playersGroupId = $group['sgid'];
             break;
         }
     }
     $this->server->serverGroupListReset();
     if (!$this->playersGroupId) {
         $this->playersGroupId = $this->server->serverGroupCreate('ManiaPlanet Player');
         foreach ($config->groupPermissions as $permission => $value) {
             $this->server->serverGroupPermAssign($this->playersGroupId, $permission, $value);
         }
     } else {
         // Find existing tokens to avoid duplicates
         try {
             foreach ($this->server->privilegeKeyList() as $token => $tokenInfo) {
                 if (!$tokenInfo['token_type'] && $tokenInfo['token_id1'] == $this->playersGroupId && preg_match('/`([a-z\\._-]{1,25})`$/', $tokenInfo['token_description'], $matches)) {
                     $this->privilegeKeys[$matches[1]] = $token;
                 }
             }
         } catch (\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Adapter\ServerQuery\Exception $e) {
             /* thanks for launching exception instead of just returning an empty array... */
         }
     }
     // Populate
     foreach ($this->server->channelList() as $channel) {
         new Channel($channel, $this->getChannelPermissionList($channel));
     }
     foreach ($this->server->clientList() as $client) {
         new Client($client, $this->getCustomInfo($client));
     }
     // Handle default channels
     $this->createChannelsIFN();
 }
Exemplo n.º 3
0
 /**
  * Returns the first TeamSpeak3_Node_Server object matching the given TSDNS hostname. Like the
  * TeamSpeak 3 Client, this method will start looking for a TSDNS server on the second-level
  * domain including a fallback to the third-level domain of the specified $tsdns parameter.
  *
  * @param  string $tsdns
  * @throws \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Adapter\ServerQuery\Exception
  * @return Server
  */
 public function serverGetByTSDNS($tsdns)
 {
     $parts = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Uri::getFQDNParts($tsdns);
     $query = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String::factory(array_shift($parts));
     while ($part = array_shift($parts)) {
         $query->prepend($part);
         try {
             $port = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::factory("tsdns://" . $query . "/?timeout=3")->resolve($tsdns)->section(":", 1);
             return $this->serverGetByPort($port == "" ? 9987 : $port);
         } catch (\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Transport\Exception $e) {
             /* skip "Connection timed out" and "Connection refused" */
             if ($e->getCode() != 10060 && $e->getCode() != 10061) {
                 throw $e;
             }
         }
     }
     throw new \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Adapter\ServerQuery\Exception("invalid serverID", 0x400);
 }
Exemplo n.º 4
0
 /**
  * Downloads and returns the clients icon file content.
  *
  * @return \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\String
  */
 public function iconDownload()
 {
     if ($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) {
         return;
     }
     $download = $this->getParent()->transferInitDownload(rand(0x0, 0xffff), 0, $this->iconGetName("client_icon_id"));
     $transfer = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
     return $transfer->download($download["ftkey"], $download["size"]);
 }
Exemplo n.º 5
0
 /**
  * Uploads a given icon file content to the server and returns the ID of the icon.
  *
  * @param  string $data
  * @return integer
  */
 public function iconUpload($data)
 {
     $crc = crc32($data);
     $size = strlen($data);
     $upload = $this->transferInitUpload(rand(0x0, 0xffff), 0, "/icon_" . $crc, $size);
     $transfer = \ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\TeamSpeak3::factory("filetransfer://" . $upload["host"] . ":" . $upload["port"]);
     $transfer->upload($upload["ftkey"], $upload["seekpos"], $data);
     return $crc;
 }