Ejemplo n.º 1
0
 /**
  * Factory for TeamSpeak3_Adapter_Abstract classes. $uri must be formatted as
  * "<adapter>://<user>:<pass>@<host>:<port>/<options>#<flags>". All parameters
  * except adapter, host and port are optional.
  *
  * === Supported Options ===
  *   - timeout
  *   - blocking
  *   - nickname
  *   - no_query_clients
  *   - use_offline_as_virtual
  *   - clients_before_channels
  *   - server_id|server_uid|server_port|server_name|server_tsdns
  *   - channel_id|channel_name
  *   - client_id|client_uid|client_name
  *
  * === Supported Flags (only one per $uri) ===
  *   - no_query_clients
  *   - use_offline_as_virtual
  *   - clients_before_channels
  *
  * === URI Examples ===
  *   - serverquery://127.0.0.1:10011/
  *   - serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1
  *   - serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1#no_query_clients
  *   - serverquery://127.0.0.1:10011/?server_port=9987&client_name=ScP
  *   - filetransfer://127.0.0.1:30011/
  *   - blacklist
  *   - update
  *
  * @param  string $uri
  * @return TeamSpeak3_Adapter_Abstract
  * @return TeamSpeak3_Node_Abstract
  */
 public static function factory($uri)
 {
     self::init();
     $uri = new TeamSpeak3_Helper_Uri($uri);
     $adapter = self::getAdapterName($uri->getScheme());
     $options = array("host" => $uri->getHost(), "port" => $uri->getPort(), "timeout" => intval($uri->getQueryVar("timeout", 10)), "blocking" => intval($uri->getQueryVar("blocking", 1)));
     self::loadClass($adapter);
     $object = new $adapter($options);
     if ($object instanceof TeamSpeak3_Adapter_ServerQuery) {
         $node = $object->getHost();
         if ($uri->hasUser() && $uri->hasPass()) {
             $node->login($uri->getUser(), $uri->getPass());
         }
         /* option to pre-define nickname */
         if ($uri->hasQueryVar("nickname")) {
             $node->setPredefinedQueryName($uri->getQueryVar("nickname"));
         }
         /* flag to use offline servers in virtual mode */
         if ($uri->getFragment() == "use_offline_as_virtual") {
             $node->setUseOfflineAsVirtual(TRUE);
         } elseif ($uri->hasQueryVar("use_offline_as_virtual")) {
             $node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual") ? TRUE : FALSE);
         }
         /* flag to fetch clients before sub-channels */
         if ($uri->getFragment() == "clients_before_channels") {
             $node->setLoadClientlistFirst(TRUE);
         } elseif ($uri->hasQueryVar("clients_before_channels")) {
             $node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels") ? TRUE : FALSE);
         }
         /* flag to hide ServerQuery clients */
         if ($uri->getFragment() == "no_query_clients") {
             $node->setExcludeQueryClients(TRUE);
         } elseif ($uri->hasQueryVar("no_query_clients")) {
             $node->setExcludeQueryClients($uri->getQueryVar("no_query_clients") ? TRUE : FALSE);
         }
         /* access server node object */
         if ($uri->hasQueryVar("server_id")) {
             $node = $node->serverGetById($uri->getQueryVar("server_id"));
         } elseif ($uri->hasQueryVar("server_uid")) {
             $node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
         } elseif ($uri->hasQueryVar("server_port")) {
             $node = $node->serverGetByPort($uri->getQueryVar("server_port"));
         } elseif ($uri->hasQueryVar("server_name")) {
             $node = $node->serverGetByName($uri->getQueryVar("server_name"));
         } elseif ($uri->hasQueryVar("server_tsdns")) {
             $node = $node->serverGetByTSDNS($uri->getQueryVar("server_tsdns"));
         }
         /* direct access to node objects */
         if ($node instanceof TeamSpeak3_Node_Server) {
             /* access channel node object */
             if ($uri->hasQueryVar("channel_id")) {
                 $node = $node->channelGetById($uri->getQueryVar("channel_id"));
             } elseif ($uri->hasQueryVar("channel_name")) {
                 $node = $node->channelGetByName($uri->getQueryVar("channel_name"));
             }
             /* access client node object */
             if ($uri->hasQueryVar("client_id")) {
                 $node = $node->clientGetById($uri->getQueryVar("client_id"));
             }
             if ($uri->hasQueryVar("client_uid")) {
                 $node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
             } elseif ($uri->hasQueryVar("client_name")) {
                 $node = $node->clientGetByName($uri->getQueryVar("client_name"));
             }
         }
         return $node;
     }
     return $object;
 }
Ejemplo n.º 2
0
 /**
  * Factory for TeamSpeak3_Adapter_Abstract classes. $uri must be formatted as
  * "<adapter>://<user>:<pass>@<host>:<port>/<options>". All parameters except 
  * adapter, host and port are optional.
  * 
  * Supported Options:
  *   - timeout
  *   - nickname
  *   - server_id|server_uid|server_port|server_name
  *   - channel_id|channel_name
  *   - client_id|client_uid|client_name
  * 
  * Examples:
  *   - serverquery://127.0.0.1:10011/
  *   - serverquery://127.0.0.1:10011/?server_port=9987&channel_id=1
  *   - filetransfer://127.0.0.1:30011/
  * 
  * @param  string $uri
  * @throws TeamSpeak3_Exception
  * @return TeamSpeak3_Adapter_Abstract|TeamSpeak3_Node_Abstract
  */
 public static function factory($uri)
 {
     self::init();
     $uri = new TeamSpeak3_Helper_Uri($uri);
     $adapter = self::getAdapterName($uri->getScheme());
     $options = array("host" => $uri->getHost(), "port" => $uri->getPort(), "timeout" => intval($uri->getQueryVar("timeout", 10)));
     self::loadClass($adapter);
     $object = new $adapter(new TeamSpeak3_Transport_TCP($options));
     if ($object instanceof TeamSpeak3_Adapter_ServerQuery) {
         $node = $object->getHost();
         if ($uri->hasUser() && $uri->hasPass()) {
             $node->login($uri->getUser(), $uri->getPass());
         }
         /* option to pre-define nickname */
         if ($uri->hasQueryVar("nickname")) {
             $node->setPredefinedQueryName($uri->getQueryVar("nickname"));
         }
         /* option to hide ServerQuery clients */
         if ($uri->getFragment() == "no_query_clients") {
             $node->setExcludeQueryClients(TRUE);
         }
         /* access server node object */
         if ($uri->hasQueryVar("server_id")) {
             $node = $node->serverGetById($uri->getQueryVar("server_id"));
         } elseif ($uri->hasQueryVar("server_uid")) {
             $node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
         } elseif ($uri->hasQueryVar("server_port")) {
             $node = $node->serverGetByPort($uri->getQueryVar("server_port"));
         } elseif ($uri->hasQueryVar("server_name")) {
             $node = $node->serverGetByName($uri->getQueryVar("server_name"));
         }
         if ($node instanceof TeamSpeak3_Node_Server) {
             /* access channel node object */
             if ($uri->hasQueryVar("channel_id")) {
                 $node = $node->channelGetById($uri->getQueryVar("channel_id"));
             } elseif ($uri->hasQueryVar("channel_name")) {
                 $node = $node->channelGetByName($uri->getQueryVar("channel_name"));
             }
             /* access client node object */
             if ($uri->hasQueryVar("client_id")) {
                 $node = $node->clientGetById($uri->getQueryVar("client_id"));
             }
             if ($uri->hasQueryVar("client_uid")) {
                 $node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
             } elseif ($uri->hasQueryVar("client_name")) {
                 $node = $node->clientGetByName($uri->getQueryVar("client_name"));
             }
         }
         return $node;
     }
     return $object;
 }