TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Host.php 2/18/2012 12:42:46 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Node_Host 00030 * @brief Class describing a TeamSpeak 3 server instance and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Host extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * @ignore 00036 */ 00037 protected $whoami = null; 00038 00039 /** 00040 * @ignore 00041 */ 00042 protected $version = null; 00043 00044 /** 00045 * @ignore 00046 */ 00047 protected $serverList = null; 00048 00049 /** 00050 * @ignore 00051 */ 00052 protected $permissionList = null; 00053 00054 /** 00055 * @ignore 00056 */ 00057 protected $predefined_query_name = null; 00058 00059 /** 00060 * @ignore 00061 */ 00062 protected $exclude_query_clients = FALSE; 00063 00064 /** 00065 * @ignore 00066 */ 00067 protected $start_offline_virtual = FALSE; 00068 00069 /** 00070 * @ignore 00071 */ 00072 protected $sort_clients_channels = FALSE; 00073 00074 /** 00075 * The TeamSpeak3_Node_Host constructor. 00076 * 00077 * @param TeamSpeak3_Adapter_ServerQuery $squery 00078 * @return TeamSpeak3_Node_Host 00079 */ 00080 public function __construct(TeamSpeak3_Adapter_ServerQuery $squery) 00081 { 00082 $this->parent = $squery; 00083 } 00084 00085 /** 00086 * Returns the primary ID of the selected virtual server. 00087 * 00088 * @return integer 00089 */ 00090 public function serverSelectedId() 00091 { 00092 return $this->whoamiGet("virtualserver_id", 0); 00093 } 00094 00095 /** 00096 * Returns the primary UDP port of the selected virtual server. 00097 * 00098 * @return integer 00099 */ 00100 public function serverSelectedPort() 00101 { 00102 return $this->whoamiGet("virtualserver_port", 0); 00103 } 00104 00105 /** 00106 * Returns the servers version information including platform and build number. 00107 * 00108 * @param string $ident 00109 * @return mixed 00110 */ 00111 public function version($ident = null) 00112 { 00113 if($this->version === null) 00114 { 00115 $this->version = $this->request("version")->toList(); 00116 } 00117 00118 return ($ident && array_key_exists($ident, $this->version)) ? $this->version[$ident] : $this->version; 00119 } 00120 00121 /** 00122 * Selects a virtual server by ID to allow further interaction. 00123 * 00124 * @param integer $sid 00125 * @param boolean $virtual 00126 * @return void 00127 */ 00128 public function serverSelect($sid, $virtual = null) 00129 { 00130 if($this->whoami !== null && $this->serverSelectedId() == $sid) return; 00131 00132 $virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual; 00133 $getargs = func_get_args(); 00134 00135 $this->execute("use", array("sid" => $sid, $virtual ? "-virtual" : null)); 00136 00137 if($sid != 0 && $this->predefined_query_name !== null) 00138 { 00139 $this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name)); 00140 } 00141 00142 $this->whoamiReset(); 00143 00144 $this->setStorage("_server_use", array(__FUNCTION__, $getargs)); 00145 00146 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this); 00147 } 00148 00149 /** 00150 * Alias for serverSelect(). 00151 * 00152 * @param integer $sid 00153 * @param boolean $virtual 00154 * @return void 00155 */ 00156 public function serverSelectById($sid, $virtual = null) 00157 { 00158 $this->serverSelect($sid, $virtual); 00159 } 00160 00161 /** 00162 * Selects a virtual server by UDP port to allow further interaction. 00163 * 00164 * @param integer $port 00165 * @param boolean $virtual 00166 * @return void 00167 */ 00168 public function serverSelectByPort($port, $virtual = null) 00169 { 00170 if($this->whoami !== null && $this->serverSelectedPort() == $port) return; 00171 00172 $virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual; 00173 $getargs = func_get_args(); 00174 00175 $this->execute("use", array("port" => $port, $virtual ? "-virtual" : null)); 00176 00177 if($port != 0 && $this->predefined_query_name !== null) 00178 { 00179 $this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name)); 00180 } 00181 00182 $this->whoamiReset(); 00183 00184 $this->setStorage("_server_use", array(__FUNCTION__, $getargs)); 00185 00186 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this); 00187 } 00188 00189 /** 00190 * Deselects the active virtual server. 00191 * 00192 * @return void 00193 */ 00194 public function serverDeselect() 00195 { 00196 $this->serverSelect(0); 00197 00198 $this->delStorage("_server_use"); 00199 } 00200 00201 /** 00202 * Returns the ID of a virtual server matching the given port. 00203 * 00204 * @param integer $port 00205 * @return integer 00206 */ 00207 public function serverIdGetByPort($port) 00208 { 00209 $sid = $this->execute("serveridgetbyport", array("virtualserver_port" => $port))->toList(); 00210 00211 return $sid["server_id"]; 00212 } 00213 00214 /** 00215 * Returns the port of a virtual server matching the given ID. 00216 * 00217 * @param integer $sid 00218 * @return integer 00219 */ 00220 public function serverGetPortById($sid) 00221 { 00222 if(!array_key_exists((string) $sid, $this->serverList())) 00223 { 00224 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400); 00225 } 00226 00227 return $this->serverList[intval((string) $sid)]["virtualserver_port"]; 00228 } 00229 00230 /** 00231 * Returns the TeamSpeak3_Node_Server object matching the currently selected ID. 00232 * 00233 * @return TeamSpeak3_Node_Server 00234 */ 00235 public function serverGetSelected() 00236 { 00237 return $this->serverGetById($this->serverSelectedId()); 00238 } 00239 00240 /** 00241 * Returns the TeamSpeak3_Node_Server object matching the given ID. 00242 * 00243 * @param integer $sid 00244 * @return TeamSpeak3_Node_Server 00245 */ 00246 public function serverGetById($sid) 00247 { 00248 $this->serverSelectById($sid); 00249 00250 return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($sid))); 00251 } 00252 00253 /** 00254 * Returns the TeamSpeak3_Node_Server object matching the given port number. 00255 * 00256 * @param integer $port 00257 * @return TeamSpeak3_Node_Server 00258 */ 00259 public function serverGetByPort($port) 00260 { 00261 $this->serverSelectByPort($port); 00262 00263 return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => $this->serverSelectedId())); 00264 } 00265 00266 /** 00267 * Returns the first TeamSpeak3_Node_Server object matching the given name. 00268 * 00269 * @param string $name 00270 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00271 * @return TeamSpeak3_Node_Server 00272 */ 00273 public function serverGetByName($name) 00274 { 00275 foreach($this->serverList() as $server) 00276 { 00277 if($server["virtualserver_name"] == $name) return $server; 00278 } 00279 00280 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400); 00281 } 00282 00283 /** 00284 * Returns the first TeamSpeak3_Node_Server object matching the given unique identifier. 00285 * 00286 * @param string $uid 00287 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00288 * @return TeamSpeak3_Node_Server 00289 */ 00290 public function serverGetByUid($uid) 00291 { 00292 foreach($this->serverList() as $server) 00293 { 00294 if($server["virtualserver_unique_identifier"] == $uid) return $server; 00295 } 00296 00297 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400); 00298 } 00299 00300 /** 00301 * Returns the first TeamSpeak3_Node_Server object matching the given TSDNS hostname. Like the 00302 * TeamSpeak 3 Client, this method will start looking for a TSDNS server on the second-level 00303 * domain including a fallback to the third-level domain of the specified $tsdns parameter. 00304 * 00305 * @param string $tsdns 00306 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00307 * @return TeamSpeak3_Node_Server 00308 */ 00309 public function serverGetByTSDNS($tsdns) 00310 { 00311 $parts = TeamSpeak3_Helper_Uri::getFQDNParts($tsdns); 00312 $query = TeamSpeak3_Helper_String::factory(array_shift($parts)); 00313 00314 while($part = array_shift($parts)) 00315 { 00316 $query->prepend($part); 00317 00318 try 00319 { 00320 $port = TeamSpeak3::factory("tsdns://" . $query . "/?timeout=3")->resolve($tsdns)->section(":", 1); 00321 00322 return $this->serverGetByPort($port == "" ? 9987 : $port); 00323 } 00324 catch(TeamSpeak3_Transport_Exception $e) 00325 { 00326 /* skip "Connection timed out" and "Connection refused" */ 00327 if($e->getCode() != 10060 && $e->getCode() != 10061) throw $e; 00328 } 00329 } 00330 00331 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400); 00332 } 00333 00334 /** 00335 * Creates a new virtual server using given properties and returns an assoc 00336 * array containing the new ID and initial admin token. 00337 * 00338 * @param array $properties 00339 * @return array 00340 */ 00341 public function serverCreate(array $properties = array()) 00342 { 00343 $this->serverListReset(); 00344 00345 $detail = $this->execute("servercreate", $properties)->toList(); 00346 $server = new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($detail["sid"]))); 00347 00348 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this, $detail["sid"]); 00349 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $server, $detail["token"]); 00350 00351 return $detail; 00352 } 00353 00354 /** 00355 * Deletes the virtual server specified by ID. 00356 * 00357 * @param integer $sid 00358 * @return void 00359 */ 00360 public function serverDelete($sid) 00361 { 00362 $this->serverListReset(); 00363 00364 $this->execute("serverdelete", array("sid" => $sid)); 00365 00366 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerdeleted", $this, $sid); 00367 } 00368 00369 /** 00370 * Starts the virtual server specified by ID. 00371 * 00372 * @param integer $sid 00373 * @return void 00374 */ 00375 public function serverStart($sid) 00376 { 00377 if($sid == $this->serverSelectedId()) 00378 { 00379 $this->serverDeselect(); 00380 } 00381 00382 $this->execute("serverstart", array("sid" => $sid)); 00383 $this->serverListReset(); 00384 00385 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstarted", $this, $sid); 00386 } 00387 00388 /** 00389 * Stops the virtual server specified by ID. 00390 * 00391 * @param integer $sid 00392 * @return void 00393 */ 00394 public function serverStop($sid) 00395 { 00396 if($sid == $this->serverSelectedId()) 00397 { 00398 $this->serverDeselect(); 00399 } 00400 00401 $this->execute("serverstop", array("sid" => $sid)); 00402 $this->serverListReset(); 00403 00404 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstopped", $this, $sid); 00405 } 00406 00407 /** 00408 * Stops the entire TeamSpeak 3 Server instance by shutting down the process. 00409 * 00410 * @return void 00411 */ 00412 public function serverStopProcess() 00413 { 00414 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServershutdown", $this); 00415 00416 $this->execute("serverprocessstop"); 00417 } 00418 00419 /** 00420 * Returns an array filled with TeamSpeak3_Node_Server objects. 00421 * 00422 * @param array $filter 00423 * @return array 00424 */ 00425 public function serverList(array $filter = array()) 00426 { 00427 if($this->serverList === null) 00428 { 00429 $servers = $this->request("serverlist -uid")->toAssocArray("virtualserver_id"); 00430 00431 $this->serverList = array(); 00432 00433 foreach($servers as $sid => $server) 00434 { 00435 $this->serverList[$sid] = new TeamSpeak3_Node_Server($this, $server); 00436 } 00437 00438 $this->resetNodeList(); 00439 } 00440 00441 return $this->filterList($this->serverList, $filter); 00442 } 00443 00444 /** 00445 * Resets the list of virtual servers. 00446 * 00447 * @return void 00448 */ 00449 public function serverListReset() 00450 { 00451 $this->resetNodeList(); 00452 $this->serverList = null; 00453 } 00454 00455 /** 00456 * Returns a list of IP addresses used by the server instance on multi-homed machines. 00457 * 00458 * @return array 00459 */ 00460 public function bindingList() 00461 { 00462 return $this->request("bindinglist")->toArray(); 00463 } 00464 00465 /** 00466 * Returns a list of permissions available on the server instance. 00467 * 00468 * @return array 00469 */ 00470 public function permissionList() 00471 { 00472 if($this->permissionList === null) 00473 { 00474 $this->permissionList = $this->request("permissionlist")->toAssocArray("permname"); 00475 00476 foreach($this->permissionList as $permname => $permdata) 00477 { 00478 $this->permissionList[$permname]["permcatid"] = $this->permissionGetCategoryById($permdata["permid"]); 00479 $this->permissionList[$permname]["permgrant"] = $this->permissionGetGrantById($permdata["permid"]); 00480 } 00481 } 00482 00483 return $this->permissionList; 00484 } 00485 00486 /** 00487 * Returns an array filled with all permission categories known to the server including 00488 * their ID, name and parent. 00489 * 00490 * @return array 00491 */ 00492 public function permissionTree() 00493 { 00494 $permtree = array(); 00495 $reflects = new ReflectionClass("TeamSpeak3"); 00496 00497 foreach($reflects->getConstants() as $key => $val) 00498 { 00499 if(!TeamSpeak3_Helper_String::factory($key)->startsWith("PERM_CAT") || $val == 0xFF) 00500 { 00501 continue; 00502 } 00503 00504 $permtree[$val]["permcatid"] = $val; 00505 $permtree[$val]["permcathex"] = "0x" . dechex($val); 00506 $permtree[$val]["permcatname"] = TeamSpeak3_Helper_String::factory(TeamSpeak3_Helper_Convert::permissionCategory($val)); 00507 $permtree[$val]["permcatparent"] = $permtree[$val]["permcathex"]{3} == 0 ? 0 : hexdec($permtree[$val]["permcathex"]{2} . 0); 00508 $permtree[$val]["permcatchilren"] = 0; 00509 $permtree[$val]["permcatcount"] = 0; 00510 00511 if(isset($permtree[$permtree[$val]["permcatparent"]])) 00512 { 00513 $permtree[$permtree[$val]["permcatparent"]]["permcatchilren"]++; 00514 } 00515 00516 if($permtree[$val]["permcatname"]->contains("/")) 00517 { 00518 $permtree[$val]["permcatname"] = $permtree[$val]["permcatname"]->section("/", 1)->trim(); 00519 } 00520 00521 foreach($this->permissionList() as $permission) 00522 { 00523 if($this->permissionGetCategoryById($permission["permid"]) == $val) 00524 { 00525 $permtree[$val]["permcatcount"]++; 00526 } 00527 } 00528 } 00529 00530 return $permtree; 00531 } 00532 00533 /** 00534 * Returns the IDs of all clients, channels or groups using the permission with the 00535 * specified ID. 00536 * 00537 * @param integer $permid 00538 * @return array 00539 */ 00540 public function permissionFind($permid) 00541 { 00542 if(!is_array($permid)) 00543 { 00544 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00545 } 00546 else 00547 { 00548 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00549 } 00550 00551 return $this->execute("permfind", array($permident => $permid))->toArray(); 00552 } 00553 00554 /** 00555 * Returns the ID of the permission matching the given name. 00556 * 00557 * @param string $name 00558 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00559 * @return integer 00560 */ 00561 public function permissionGetIdByName($name) 00562 { 00563 if(!array_key_exists((string) $name, $this->permissionList())) 00564 { 00565 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02); 00566 } 00567 00568 return $this->permissionList[(string) $name]["permid"]; 00569 } 00570 00571 /** 00572 * Returns the name of the permission matching the given ID. 00573 * 00574 * @param integer $permid 00575 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00576 * @return TeamSpeak3_Helper_String 00577 */ 00578 public function permissionGetNameById($permid) 00579 { 00580 foreach($this->permissionList() as $name => $perm) 00581 { 00582 if($perm["permid"] == $permid) return new TeamSpeak3_Helper_String($name); 00583 } 00584 00585 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02); 00586 } 00587 00588 /** 00589 * Returns the internal category of the permission matching the given ID. 00590 * 00591 * All permission IDs are are 2 bytes wide. The first byte identifies the category while the second 00592 * byte is the permission count within that group. 00593 * 00594 * @param integer $permid 00595 * @return integer 00596 */ 00597 public function permissionGetCategoryById($permid) 00598 { 00599 if(!is_numeric($permid)) 00600 { 00601 $permid = $this->permissionGetIdByName($permid); 00602 } 00603 00604 return (int) $permid >> 8; 00605 } 00606 00607 /** 00608 * Returns the internal ID of the i_needed_modify_power_* or grant permission. 00609 * 00610 * Every permission has an associated i_needed_modify_power_* permission, for example b_client_ban_create has an 00611 * associated permission called i_needed_modify_power_client_ban_create. 00612 * 00613 * @param integer $permid 00614 * @return integer 00615 */ 00616 public function permissionGetGrantById($permid) 00617 { 00618 if(!is_numeric($permid)) 00619 { 00620 $permid = $this->permissionGetIdByName($permid); 00621 } 00622 00623 return (int) bindec(substr(decbin($permid), -8))+0xFF00; 00624 } 00625 00626 /** 00627 * Returns an array containing the value of a specified permission for your own client. 00628 * 00629 * @param integer $permid 00630 * @return array 00631 */ 00632 public function selfPermCheck($permid) 00633 { 00634 if(!is_array($permid)) 00635 { 00636 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00637 } 00638 else 00639 { 00640 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00641 } 00642 00643 return $this->execute("permget", array($permident => $permid))->toAssocArray("permsid"); 00644 } 00645 00646 /** 00647 * Changes the server instance configuration using given properties. 00648 * 00649 * @param array $properties 00650 * @return void 00651 */ 00652 public function modify(array $properties) 00653 { 00654 $this->execute("instanceedit", $properties); 00655 $this->resetNodeInfo(); 00656 } 00657 00658 /** 00659 * Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance. 00660 * 00661 * @param string $msg 00662 * @return void 00663 */ 00664 public function message($msg) 00665 { 00666 $this->execute("gm", array("msg" => $msg)); 00667 } 00668 00669 /** 00670 * Displays a specified number of entries (1-100) from the servers log. 00671 * 00672 * @param integer $lines 00673 * @param integer $begin_pos 00674 * @param boolean $reverse 00675 * @param boolean $instance 00676 * @return array 00677 */ 00678 public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = TRUE) 00679 { 00680 return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray(); 00681 } 00682 00683 /** 00684 * Writes a custom entry into the server instance log. 00685 * 00686 * @param string $logmsg 00687 * @param integer $loglevel 00688 * @return void 00689 */ 00690 public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO) 00691 { 00692 $sid = $this->serverSelectedId(); 00693 00694 $this->serverDeselect(); 00695 $this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel)); 00696 $this->serverSelect($sid); 00697 } 00698 00699 /** 00700 * Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials. 00701 * 00702 * @param string $username 00703 * @param string $password 00704 * @return void 00705 */ 00706 public function login($username, $password) 00707 { 00708 $this->execute("login", array("client_login_name" => $username, "client_login_password" => $password)); 00709 $this->whoamiReset(); 00710 00711 $crypt = new TeamSpeak3_Helper_Crypt($username); 00712 00713 $this->setStorage("_login_user", $username); 00714 $this->setStorage("_login_pass", $crypt->encrypt($password)); 00715 00716 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogin", $this); 00717 } 00718 00719 /** 00720 * Deselects the active virtual server and logs out from the server instance. 00721 * 00722 * @return void 00723 */ 00724 public function logout() 00725 { 00726 $this->request("logout"); 00727 $this->whoamiReset(); 00728 00729 $this->delStorage("_login_user"); 00730 $this->delStorage("_login_pass"); 00731 00732 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogout", $this); 00733 } 00734 00735 /** 00736 * Returns information about your current ServerQuery connection. 00737 * 00738 * @return array 00739 */ 00740 public function whoami() 00741 { 00742 if($this->whoami === null) 00743 { 00744 $this->whoami = $this->request("whoami")->toList(); 00745 } 00746 00747 return $this->whoami; 00748 } 00749 00750 /** 00751 * Returns a single value from the current ServerQuery connection info. 00752 * 00753 * @param string $ident 00754 * @param mixed $default 00755 * @return mixed 00756 */ 00757 public function whoamiGet($ident, $default = null) 00758 { 00759 if(array_key_exists($ident, $this->whoami())) 00760 { 00761 return $this->whoami[$ident]; 00762 } 00763 00764 return $default; 00765 } 00766 00767 /** 00768 * Sets a single value in the current ServerQuery connection info. 00769 * 00770 * @param string $ident 00771 * @param mixed $value 00772 * @return mixed 00773 */ 00774 public function whoamiSet($ident, $value = null) 00775 { 00776 $this->whoami(); 00777 00778 $this->whoami[$ident] = (is_numeric($value)) ? intval($value) : TeamSpeak3_Helper_String::factory($value); 00779 } 00780 00781 /** 00782 * Resets the current ServerQuery connection info. 00783 * 00784 * @return void 00785 */ 00786 public function whoamiReset() 00787 { 00788 $this->whoami = null; 00789 } 00790 00791 /** 00792 * Returns the hostname or IPv4 address the adapter is connected to. 00793 * 00794 * @return string 00795 */ 00796 public function getAdapterHost() 00797 { 00798 return $this->getParent()->getTransportHost(); 00799 } 00800 00801 /** 00802 * Returns the network port the adapter is connected to. 00803 * 00804 * @return string 00805 */ 00806 public function getAdapterPort() 00807 { 00808 return $this->getParent()->getTransportPort(); 00809 } 00810 00811 /** 00812 * @ignore 00813 */ 00814 protected function fetchNodeList() 00815 { 00816 $servers = $this->serverList(); 00817 00818 foreach($servers as $server) 00819 { 00820 $this->nodeList[] = $server; 00821 } 00822 } 00823 00824 /** 00825 * @ignore 00826 */ 00827 protected function fetchNodeInfo() 00828 { 00829 $info1 = $this->request("hostinfo")->toList(); 00830 $info2 = $this->request("instanceinfo")->toList(); 00831 00832 $this->nodeInfo = array_merge($this->nodeInfo, $info1, $info2); 00833 } 00834 00835 /** 00836 * Sets a pre-defined nickname for ServerQuery clients which will be used automatically 00837 * after selecting a virtual server. 00838 * 00839 * @param string $name 00840 * @return void 00841 */ 00842 public function setPredefinedQueryName($name = null) 00843 { 00844 $this->setStorage("_query_nick", $name); 00845 00846 $this->predefined_query_name = $name; 00847 } 00848 00849 /** 00850 * Returns the pre-defined nickname for ServerQuery clients which will be used automatically 00851 * after selecting a virtual server. 00852 * 00853 * @return string 00854 */ 00855 public function getPredefinedQueryName() 00856 { 00857 return $this->predefined_query_name; 00858 } 00859 00860 /** 00861 * Sets the option to decide whether ServerQuery clients should be excluded from node 00862 * lists or not. 00863 * 00864 * @param boolean $exclude 00865 * @return void 00866 */ 00867 public function setExcludeQueryClients($exclude = FALSE) 00868 { 00869 $this->setStorage("_query_hide", $exclude); 00870 00871 $this->exclude_query_clients = $exclude; 00872 } 00873 00874 /** 00875 * Returns the option to decide whether ServerQuery clients should be excluded from node 00876 * lists or not. 00877 * 00878 * @return boolean 00879 */ 00880 public function getExcludeQueryClients() 00881 { 00882 return $this->exclude_query_clients; 00883 } 00884 00885 /** 00886 * Sets the option to decide whether offline servers will be started in virtual mode 00887 * by default or not. 00888 * 00889 * @param boolean $virtual 00890 * @return void 00891 */ 00892 public function setUseOfflineAsVirtual($virtual = FALSE) 00893 { 00894 $this->setStorage("_do_virtual", $virtual); 00895 00896 $this->start_offline_virtual = $virtual; 00897 } 00898 00899 /** 00900 * Returns the option to decide whether offline servers will be started in virtual mode 00901 * by default or not. 00902 * 00903 * @return boolean 00904 */ 00905 public function getUseOfflineAsVirtual() 00906 { 00907 return $this->start_offline_virtual; 00908 } 00909 00910 /** 00911 * Sets the option to decide whether clients should be sorted before sub-channels to support 00912 * the new TeamSpeak 3 Client display mode or not. 00913 * 00914 * @param boolean $first 00915 * @return void 00916 */ 00917 public function setLoadClientlistFirst($first = FALSE) 00918 { 00919 $this->setStorage("_client_top", $first); 00920 00921 $this->sort_clients_channels = $first; 00922 } 00923 00924 /** 00925 * Returns the option to decide whether offline servers will be started in virtual mode 00926 * by default or not. 00927 * 00928 * @return boolean 00929 */ 00930 public function getLoadClientlistFirst() 00931 { 00932 return $this->sort_clients_channels; 00933 } 00934 00935 /** 00936 * Returns the underlying TeamSpeak3_Adapter_ServerQuery object. 00937 * 00938 * @return TeamSpeak3_Adapter_ServerQuery 00939 */ 00940 public function getAdapter() 00941 { 00942 return $this->getParent(); 00943 } 00944 00945 /** 00946 * Returns a unique identifier for the node which can be used as a HTML property. 00947 * 00948 * @return string 00949 */ 00950 public function getUniqueId() 00951 { 00952 return "ts3_h"; 00953 } 00954 00955 /** 00956 * Returns the name of a possible icon to display the node object. 00957 * 00958 * @return string 00959 */ 00960 public function getIcon() 00961 { 00962 return "host"; 00963 } 00964 00965 /** 00966 * Returns a symbol representing the node. 00967 * 00968 * @return string 00969 */ 00970 public function getSymbol() 00971 { 00972 return "+"; 00973 } 00974 00975 /** 00976 * Re-authenticates with the TeamSpeak 3 Server instance using given ServerQuery login 00977 * credentials and re-selects a previously selected virtual server. 00978 * 00979 * @return void 00980 */ 00981 public function __wakeup() 00982 { 00983 $username = $this->getStorage("_login_user"); 00984 $password = $this->getStorage("_login_pass"); 00985 00986 if($username && $password) 00987 { 00988 $crypt = new TeamSpeak3_Helper_Crypt($username); 00989 00990 $this->login($username, $crypt->decrypt($password)); 00991 } 00992 00993 $this->predefined_query_name = $this->getStorage("_query_nick"); 00994 $this->exclude_query_clients = $this->getStorage("_query_hide", FALSE); 00995 $this->start_offline_virtual = $this->getStorage("_do_virtual", FALSE); 00996 $this->sort_clients_channels = $this->getStorage("_client_top", FALSE); 00997 00998 if($server = $this->getStorage("_server_use")) 00999 { 01000 $func = array_shift($server); 01001 $args = array_shift($server); 01002 01003 call_user_func_array(array($this, $func), $args); 01004 } 01005 } 01006 01007 /** 01008 * Returns a string representation of this node. 01009 * 01010 * @return string 01011 */ 01012 public function __toString() 01013 { 01014 return (string) $this->getAdapterHost(); 01015 } 01016 } 01017