TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Server.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_Server 00030 * @brief Class describing a TeamSpeak 3 virtual server and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * @ignore 00036 */ 00037 protected $channelList = null; 00038 00039 /** 00040 * @ignore 00041 */ 00042 protected $clientList = null; 00043 00044 /** 00045 * @ignore 00046 */ 00047 protected $sgroupList = null; 00048 00049 /** 00050 * @ignore 00051 */ 00052 protected $cgroupList = null; 00053 00054 /** 00055 * The TeamSpeak3_Node_Server constructor. 00056 * 00057 * @param TeamSpeak3_Node_Host $host 00058 * @param array $info 00059 * @param string $index 00060 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00061 * @return TeamSpeak3_Node_Server 00062 */ 00063 public function __construct(TeamSpeak3_Node_Host $host, array $info, $index = "virtualserver_id") 00064 { 00065 $this->parent = $host; 00066 $this->nodeInfo = $info; 00067 00068 if(!array_key_exists($index, $this->nodeInfo)) 00069 { 00070 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400); 00071 } 00072 00073 $this->nodeId = $this->nodeInfo[$index]; 00074 } 00075 00076 /** 00077 * Sends a prepared command to the server and returns the result. 00078 * 00079 * @param string $cmd 00080 * @return TeamSpeak3_Adapter_ServerQuery_Reply 00081 */ 00082 public function request($cmd) 00083 { 00084 if($this->getId() != $this->getParent()->serverSelectedId()) 00085 { 00086 $this->getParent()->serverSelect($this->getId()); 00087 } 00088 00089 return $this->getParent()->request($cmd); 00090 } 00091 00092 /** 00093 * Returns an array filled with TeamSpeak3_Node_Channel objects. 00094 * 00095 * @param array $filter 00096 * @return array 00097 */ 00098 public function channelList(array $filter = array()) 00099 { 00100 if($this->channelList === null) 00101 { 00102 $channels = $this->request("channellist -topic -flags -voice -limits -icon")->toAssocArray("cid"); 00103 00104 $this->channelList = array(); 00105 00106 foreach($channels as $cid => $channel) 00107 { 00108 $this->channelList[$cid] = new TeamSpeak3_Node_Channel($this, $channel); 00109 } 00110 00111 $this->resetNodeList(); 00112 } 00113 00114 return $this->filterList($this->channelList, $filter); 00115 } 00116 00117 /** 00118 * Resets the list of channels online. 00119 * 00120 * @return void 00121 */ 00122 public function channelListReset() 00123 { 00124 $this->resetNodeList(); 00125 $this->channelList = null; 00126 } 00127 00128 /** 00129 * Creates a new channel using given properties and returns the new ID. 00130 * 00131 * @param array $properties 00132 * @return integer 00133 */ 00134 public function channelCreate(array $properties) 00135 { 00136 $cid = $this->execute("channelcreate", $properties)->toList(); 00137 $this->channelListReset(); 00138 00139 if(!isset($properties["client_flag_permanent"]) && !isset($properties["client_flag_semi_permanent"])) 00140 { 00141 $this->getParent()->whoamiSet("client_channel_id", $cid["cid"]); 00142 } 00143 00144 return $cid["cid"]; 00145 } 00146 00147 /** 00148 * Deletes the channel specified by $cid. 00149 * 00150 * @param integer $cid 00151 * @param boolean $force 00152 * @return void 00153 */ 00154 public function channelDelete($cid, $force = FALSE) 00155 { 00156 $this->execute("channeldelete", array("cid" => $cid, "force" => $force)); 00157 $this->channelListReset(); 00158 00159 if(($cid instanceof TeamSpeak3_Node_Abstract ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id")) 00160 { 00161 $this->getParent()->whoamiReset(); 00162 } 00163 } 00164 00165 /** 00166 * Moves the channel specified by $cid to the parent channel specified with $pid. 00167 * 00168 * @param integer $cid 00169 * @param integer $pid 00170 * @param integer $order 00171 * @return void 00172 */ 00173 public function channelMove($cid, $pid, $order = null) 00174 { 00175 $this->execute("channelmove", array("cid" => $cid, "cpid" => $pid, "order" => $order)); 00176 $this->channelListReset(); 00177 } 00178 00179 /** 00180 * Returns TRUE if the given TeamSpeak3_Node_Channel object is a spacer. 00181 * 00182 * @param TeamSpeak3_Node_Channel $channel 00183 * @return boolean 00184 */ 00185 public function channelIsSpacer(TeamSpeak3_Node_Channel $channel) 00186 { 00187 return (preg_match("/\[[^\]]*spacer[^\]]*\]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"]) ? TRUE : FALSE; 00188 } 00189 00190 /** 00191 * Creates a new channel spacer and returns the new ID. The first parameter $ident is used to create a 00192 * unique spacer name on the virtual server. 00193 * 00194 * @param string $ident 00195 * @param mixed $type 00196 * @param integer $align 00197 * @param integer $order 00198 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00199 * @return integer 00200 */ 00201 public function channelSpacerCreate($ident, $type = TeamSpeak3::SPACER_SOLIDLINE, $align = TeamSpeak3::SPACER_ALIGN_REPEAT, $order = null) 00202 { 00203 $properties = array( 00204 "channel_name_phonetic" => "channel spacer", 00205 "channel_codec" => TeamSpeak3::CODEC_SPEEX_NARROWBAND, 00206 "channel_codec_quality" => 0x00, 00207 "channel_flag_permanent" => TRUE, 00208 "channel_flag_maxclients_unlimited" => FALSE, 00209 "channel_flag_maxfamilyclients_unlimited" => FALSE, 00210 "channel_flag_maxfamilyclients_inherited" => FALSE, 00211 "channel_order" => $order, 00212 ); 00213 00214 switch($align) 00215 { 00216 case TeamSpeak3::SPACER_ALIGN_REPEAT: 00217 $properties["channel_name"] = "[*spacer" . strval($ident) . "]"; 00218 break; 00219 00220 case TeamSpeak3::SPACER_ALIGN_LEFT: 00221 $properties["channel_name"] = "[lspacer" . strval($ident) . "]"; 00222 break; 00223 00224 case TeamSpeak3::SPACER_ALIGN_RIGHT: 00225 $properties["channel_name"] = "[rspacer" . strval($ident) . "]"; 00226 break; 00227 00228 case TeamSpeak3::SPACER_ALIGN_CENTER: 00229 $properties["channel_name"] = "[cspacer" . strval($ident) . "]"; 00230 break; 00231 00232 default: 00233 throw new TeamSpeak3_Adapter_ServerQuery_Exception("missing required parameter", 0x606); 00234 break; 00235 } 00236 00237 switch($type) 00238 { 00239 case (string) TeamSpeak3::SPACER_SOLIDLINE: 00240 $properties["channel_name"] .= "___"; 00241 break; 00242 00243 case (string) TeamSpeak3::SPACER_DASHLINE: 00244 $properties["channel_name"] .= "---"; 00245 break; 00246 00247 case (string) TeamSpeak3::SPACER_DOTLINE: 00248 $properties["channel_name"] .= "..."; 00249 break; 00250 00251 case (string) TeamSpeak3::SPACER_DASHDOTLINE: 00252 $properties["channel_name"] .= "-.-"; 00253 break; 00254 00255 case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE: 00256 $properties["channel_name"] .= "-.."; 00257 break; 00258 00259 default: 00260 $properties["channel_name"] .= strval($type); 00261 break; 00262 } 00263 00264 return $this->channelCreate($properties); 00265 } 00266 00267 /** 00268 * Returns the possible type of a channel spacer. 00269 * 00270 * @param integer $cid 00271 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00272 * @return integer 00273 */ 00274 public function channelSpacerGetType($cid) 00275 { 00276 $channel = $this->channelGetById($cid); 00277 00278 if(!$this->channelIsSpacer($channel)) 00279 { 00280 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307); 00281 } 00282 00283 switch($channel["channel_name"]->section("]", 1)) 00284 { 00285 case "___": 00286 return TeamSpeak3::SPACER_SOLIDLINE; 00287 00288 case "---": 00289 return TeamSpeak3::SPACER_DASHLINE; 00290 00291 case "...": 00292 return TeamSpeak3::SPACER_DOTLINE; 00293 00294 case "-.-": 00295 return TeamSpeak3::SPACER_DASHDOTLINE; 00296 00297 case "-..": 00298 return TeamSpeak3::SPACER_DASHDOTDOTLINE; 00299 00300 default: 00301 return TeamSpeak3::SPACER_CUSTOM; 00302 } 00303 } 00304 00305 /** 00306 * Returns the possible alignment of a channel spacer. 00307 * 00308 * @param integer $cid 00309 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00310 * @return integer 00311 */ 00312 public function channelSpacerGetAlign($cid) 00313 { 00314 $channel = $this->channelGetById($cid); 00315 00316 if(!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*\]/", $channel, $matches) || !isset($matches[1])) 00317 { 00318 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307); 00319 } 00320 00321 switch($matches[1]) 00322 { 00323 case "*": 00324 return TeamSpeak3::SPACER_ALIGN_REPEAT; 00325 00326 case "c": 00327 return TeamSpeak3::SPACER_ALIGN_CENTER; 00328 00329 case "r": 00330 return TeamSpeak3::SPACER_ALIGN_RIGHT; 00331 00332 default: 00333 return TeamSpeak3::SPACER_ALIGN_LEFT; 00334 } 00335 } 00336 00337 /** 00338 * Returns a list of permissions defined for a specific channel. 00339 * 00340 * @param integer $cid 00341 * @param boolean $permsid 00342 * @return array 00343 */ 00344 public function channelPermList($cid, $permsid = FALSE) 00345 { 00346 return $this->execute("channelpermlist", array("cid" => $cid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid"); 00347 } 00348 00349 /** 00350 * Adds a set of specified permissions to a channel. Multiple permissions can be added by 00351 * providing the two parameters of each permission. 00352 * 00353 * @param integer $cid 00354 * @param integer $permid 00355 * @param integer $permvalue 00356 * @return void 00357 */ 00358 public function channelPermAssign($cid, $permid, $permvalue) 00359 { 00360 if(!is_array($permid)) 00361 { 00362 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00363 } 00364 else 00365 { 00366 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00367 } 00368 00369 $this->execute("channeladdperm", array("cid" => $cid, $permident => $permid, "permvalue" => $permvalue)); 00370 } 00371 00372 /** 00373 * Removes a set of specified permissions from a channel. Multiple permissions can be removed at once. 00374 * 00375 * @param integer $cid 00376 * @param integer $permid 00377 * @return void 00378 */ 00379 public function channelPermRemove($cid, $permid) 00380 { 00381 if(!is_array($permid)) 00382 { 00383 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00384 } 00385 else 00386 { 00387 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00388 } 00389 00390 $this->execute("channeldelperm", array("cid" => $cid, $permident => $permid)); 00391 } 00392 00393 /** 00394 * Returns a list of permissions defined for a client in a specific channel. 00395 * 00396 * @param integer $cid 00397 * @param integer $cldbid 00398 * @param boolean $permsid 00399 * @return array 00400 */ 00401 public function channelClientPermList($cid, $cldbid, $permsid = FALSE) 00402 { 00403 return $this->execute("channelclientpermlist", array("cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid"); 00404 } 00405 00406 /** 00407 * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by 00408 * providing the two parameters of each permission. 00409 * 00410 * @param integer $cid 00411 * @param integer $cldbid 00412 * @param integer $permid 00413 * @param integer $permvalue 00414 * @return void 00415 */ 00416 public function channelClientPermAssign($cid, $cldbid, $permid, $permvalue) 00417 { 00418 if(!is_array($permid)) 00419 { 00420 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00421 } 00422 else 00423 { 00424 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00425 } 00426 00427 $this->execute("channelclientaddperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue)); 00428 } 00429 00430 /** 00431 * Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once. 00432 * 00433 * @param integer $cid 00434 * @param integer $cldbid 00435 * @param integer $permid 00436 * @return void 00437 */ 00438 public function channelClientPermRemove($cid, $cldbid, $permid) 00439 { 00440 if(!is_array($permid)) 00441 { 00442 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00443 } 00444 else 00445 { 00446 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00447 } 00448 00449 $this->execute("channelclientdelperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid)); 00450 } 00451 00452 /** 00453 * Returns a list of files and directories stored in the specified channels file repository. 00454 * 00455 * @param integer $cid 00456 * @param string $cpw 00457 * @param string $path 00458 * @param boolean $recursive 00459 * @return array 00460 */ 00461 public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE) 00462 { 00463 $files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray(); 00464 $count = count($files); 00465 00466 for($i = 0; $i < $count; $i++) 00467 { 00468 $files[$i]["sid"] = $this->getId(); 00469 $files[$i]["cid"] = $files[0]["cid"]; 00470 $files[$i]["path"] = $files[0]["path"]; 00471 $files[$i]["src"] = new TeamSpeak3_Helper_String($cid ? $files[$i]["path"] : "/"); 00472 00473 if(!$files[$i]["src"]->endsWith("/")) 00474 { 00475 $files[$i]["src"]->append("/"); 00476 } 00477 00478 $files[$i]["src"]->append($files[$i]["name"]); 00479 00480 if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY) 00481 { 00482 $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive)); 00483 } 00484 } 00485 00486 uasort($files, array(__CLASS__, "sortFileList")); 00487 00488 return $files; 00489 } 00490 00491 /** 00492 * Returns detailed information about the specified file stored in a channels file repository. 00493 * 00494 * @param integer $cid 00495 * @param string $cpw 00496 * @param string $name 00497 * @return array 00498 */ 00499 public function channelFileInfo($cid, $cpw = "", $name = "/") 00500 { 00501 return array_pop($this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray()); 00502 } 00503 00504 /** 00505 * Renames a file in a channels file repository. If the two parameters $tcid and $tcpw are specified, the file 00506 * will be moved into another channels file repository. 00507 * 00508 * @param integer $cid 00509 * @param string $cpw 00510 * @param string $oldname 00511 * @param string $newname 00512 * @param integer $tcid 00513 * @param string $tcpw 00514 * @return void 00515 */ 00516 public function channelFileRename($cid, $cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null) 00517 { 00518 $this->execute("ftrenamefile", array("cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw)); 00519 } 00520 00521 /** 00522 * Deletes one or more files stored in a channels file repository. 00523 * 00524 * @param integer $cid 00525 * @param string $cpw 00526 * @param string $name 00527 * @return void 00528 */ 00529 public function channelFileDelete($cid, $cpw = "", $name = "/") 00530 { 00531 $this->execute("ftdeletefile", array("cid" => $cid, "cpw" => $cpw, "name" => $name)); 00532 } 00533 00534 /** 00535 * Creates new directory in a channels file repository. 00536 * 00537 * @param integer $cid 00538 * @param string $cpw 00539 * @param string $dirname 00540 * @return void 00541 */ 00542 public function channelDirCreate($cid, $cpw = "", $dirname = "/") 00543 { 00544 $this->execute("ftcreatedir", array("cid" => $cid, "cpw" => $cpw, "dirname" => $dirname)); 00545 } 00546 00547 /** 00548 * Returns the level of a channel. 00549 * 00550 * @param integer $cid 00551 * @return integer 00552 */ 00553 public function channelGetLevel($cid) 00554 { 00555 $channel = $this->channelGetById($cid); 00556 $levelno = 0; 00557 00558 if($channel["pid"]) 00559 { 00560 $levelno = $this->channelGetLevel($channel["pid"])+1; 00561 } 00562 00563 return $levelno; 00564 } 00565 00566 /** 00567 * Returns the pathway of a channel which can be used as a clients default channel. 00568 * 00569 * @param integer $cid 00570 * @return string 00571 */ 00572 public function channelGetPathway($cid) 00573 { 00574 $channel = $this->channelGetById($cid); 00575 $pathway = $channel["channel_name"]; 00576 00577 if($channel["pid"]) 00578 { 00579 $pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"]; 00580 } 00581 00582 return $pathway; 00583 } 00584 00585 /** 00586 * Returns the TeamSpeak3_Node_Channel object matching the given ID. 00587 * 00588 * @param integer $cid 00589 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00590 * @return TeamSpeak3_Node_Channel 00591 */ 00592 public function channelGetById($cid) 00593 { 00594 if(!array_key_exists((string) $cid, $this->channelList())) 00595 { 00596 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300); 00597 } 00598 00599 return $this->channelList[intval((string) $cid)]; 00600 } 00601 00602 /** 00603 * Returns the TeamSpeak3_Node_Channel object matching the given name. 00604 * 00605 * @param string $name 00606 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00607 * @return TeamSpeak3_Node_Channel 00608 */ 00609 public function channelGetByName($name) 00610 { 00611 foreach($this->channelList() as $channel) 00612 { 00613 if($channel["channel_name"] == $name) return $channel; 00614 } 00615 00616 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300); 00617 } 00618 00619 /** 00620 * Returns an array filled with TeamSpeak3_Node_Client objects. 00621 * 00622 * @param array $filter 00623 * @return array 00624 */ 00625 public function clientList(array $filter = array()) 00626 { 00627 if($this->clientList === null) 00628 { 00629 $clients = $this->request("clientlist -uid -away -voice -info -times -groups -icon -country")->toAssocArray("clid"); 00630 00631 $this->clientList = array(); 00632 00633 foreach($clients as $clid => $client) 00634 { 00635 if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue; 00636 00637 $this->clientList[$clid] = new TeamSpeak3_Node_Client($this, $client); 00638 } 00639 00640 uasort($this->clientList, array(__CLASS__, "sortClientList")); 00641 00642 $this->resetNodeList(); 00643 } 00644 00645 return $this->filterList($this->clientList, $filter); 00646 } 00647 00648 /** 00649 * Resets the list of clients online. 00650 * 00651 * @return void 00652 */ 00653 public function clientListReset() 00654 { 00655 $this->resetNodeList(); 00656 $this->clientList = null; 00657 } 00658 00659 /** 00660 * Returns a list of clients matching a given name pattern. 00661 * 00662 * @param string $pattern 00663 * @return array 00664 */ 00665 public function clientFind($pattern) 00666 { 00667 return $this->execute("clientfind", array("pattern" => $pattern))->toAssocArray("clid"); 00668 } 00669 00670 /** 00671 * Returns a list of client identities known by the virtual server. 00672 * 00673 * @param integer $offset 00674 * @param integer $limit 00675 * @return array 00676 */ 00677 public function clientListDb($offset = null, $limit = null) 00678 { 00679 return $this->execute("clientdblist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("cldbid"); 00680 } 00681 00682 /** 00683 * Returns the number of client identities known by the virtual server. 00684 * 00685 * @return integer 00686 */ 00687 public function clientCountDb() 00688 { 00689 return current($this->execute("clientdblist -count", array("duration" => 1))->toList("count")); 00690 } 00691 00692 /** 00693 * Returns a list of properties from the database for the client specified by $cldbid. 00694 * 00695 * @param integer $cldbid 00696 * @return array 00697 */ 00698 public function clientInfoDb($cldbid) 00699 { 00700 return $this->execute("clientdbinfo", array("cldbid" => $cldbid))->toList(); 00701 } 00702 00703 /** 00704 * Returns a list of client database IDs matching a given pattern. You can either search for a clients 00705 * last known nickname or his unique identity by using the $uid option. 00706 * 00707 * @param string $pattern 00708 * @param boolean $uid 00709 * @return array 00710 */ 00711 public function clientFindDb($pattern, $uid = FALSE) 00712 { 00713 return array_keys($this->execute("clientdbfind", array("pattern" => $pattern, ($uid) ? "-uid" : null))->toAssocArray("cldbid")); 00714 } 00715 00716 /** 00717 * Returns the number of regular clients online. 00718 * 00719 * @return integer 00720 */ 00721 public function clientCount() 00722 { 00723 if($this->isOffline()) return 0; 00724 00725 return $this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"]; 00726 } 00727 00728 /** 00729 * Returns the TeamSpeak3_Node_Client object matching the given ID. 00730 * 00731 * @param integer $clid 00732 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00733 * @return TeamSpeak3_Node_Client 00734 */ 00735 public function clientGetById($clid) 00736 { 00737 if(!array_key_exists((string) $clid, $this->clientList())) 00738 { 00739 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00740 } 00741 00742 return $this->clientList[intval((string) $clid)]; 00743 } 00744 00745 /** 00746 * Returns the TeamSpeak3_Node_Client object matching the given name. 00747 * 00748 * @param string $name 00749 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00750 * @return TeamSpeak3_Node_Client 00751 */ 00752 public function clientGetByName($name) 00753 { 00754 foreach($this->clientList() as $client) 00755 { 00756 if($client["client_nickname"] == $name) return $client; 00757 } 00758 00759 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00760 } 00761 00762 /** 00763 * Returns the TeamSpeak3_Node_Client object matching the given unique identifier. 00764 * 00765 * @param string $uid 00766 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00767 * @return TeamSpeak3_Node_Client 00768 */ 00769 public function clientGetByUid($uid) 00770 { 00771 foreach($this->clientList() as $client) 00772 { 00773 if($client["client_unique_identifier"] == $uid) return $client; 00774 } 00775 00776 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00777 } 00778 00779 /** 00780 * Returns an array containing the last known nickname and the database ID of the client matching 00781 * the unique identifier specified with $cluid. 00782 * 00783 * @param string $cluid 00784 * @return array 00785 */ 00786 public function clientGetNameByUid($cluid) 00787 { 00788 return $this->execute("clientgetnamefromuid", array("cluid" => $cluid))->toList(); 00789 } 00790 00791 /** 00792 * Returns an array containing a list of active client connections using the unique identifier 00793 * specified with $cluid. 00794 * 00795 * @param string $cluid 00796 * @return array 00797 */ 00798 public function clientGetIdsByUid($cluid) 00799 { 00800 return $this->execute("clientgetids", array("cluid" => $cluid))->toAssocArray("clid"); 00801 } 00802 00803 /** 00804 * Returns an array containing the last known nickname and the unique identifier of the client 00805 * matching the database ID specified with $cldbid. 00806 * 00807 * @param string $cldbid 00808 * @return array 00809 */ 00810 public function clientGetNameByDbid($cldbid) 00811 { 00812 return $this->execute("clientgetnamefromdbid", array("cldbid" => $cldbid))->toList(); 00813 } 00814 00815 /** 00816 * Returns an array containing the names and IDs of all server groups the client specified with 00817 * $cldbid is is currently residing in. 00818 * 00819 * @param string $cldbid 00820 * @return array 00821 */ 00822 public function clientGetServerGroupsByDbid($cldbid) 00823 { 00824 return $this->execute("servergroupsbyclientid", array("cldbid" => $cldbid))->toAssocArray("sgid"); 00825 } 00826 00827 /** 00828 * Moves a client to another channel. 00829 * 00830 * @param integer $clid 00831 * @param integer $cid 00832 * @param string $cpw 00833 * @return void 00834 */ 00835 public function clientMove($clid, $cid, $cpw = null) 00836 { 00837 $this->clientListReset(); 00838 00839 $this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw)); 00840 00841 if($clid instanceof TeamSpeak3_Node_Abstract) 00842 { 00843 $clid = $clid->getId(); 00844 } 00845 00846 if($cid instanceof TeamSpeak3_Node_Abstract) 00847 { 00848 $cid = $cid->getId(); 00849 } 00850 00851 if(!is_array($clid) && $clid == $this->whoamiGet("client_id")) 00852 { 00853 $this->getParent()->whoamiSet("client_channel_id", $cid); 00854 } 00855 } 00856 00857 /** 00858 * Kicks one or more clients from their currently joined channel or from the server. 00859 * 00860 * @param integer $clid 00861 * @param integer $reasonid 00862 * @param string $reasonmsg 00863 * @return void 00864 */ 00865 public function clientKick($clid, $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null) 00866 { 00867 $this->clientListReset(); 00868 00869 $this->execute("clientkick", array("clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg)); 00870 } 00871 00872 /** 00873 * Sends a poke message to a client. 00874 * 00875 * @param integer $clid 00876 * @param string $msg 00877 * @return void 00878 */ 00879 public function clientPoke($clid, $msg) 00880 { 00881 $this->execute("clientpoke", array("clid" => $clid, "msg" => $msg)); 00882 } 00883 00884 /** 00885 * Bans the client specified with ID $clid from the server. Please note that this will create two separate 00886 * ban rules for the targeted clients IP address and his unique identifier. 00887 * 00888 * @param integer $clid 00889 * @param integer $timeseconds 00890 * @param string $reason 00891 * @return array 00892 */ 00893 public function clientBan($clid, $timeseconds = null, $reason = null) 00894 { 00895 $this->clientListReset(); 00896 00897 $bans = $this->execute("banclient", array("clid" => $clid, "time" => $timeseconds, "banreason" => $reason))->toAssocArray("banid"); 00898 00899 return array_keys($bans); 00900 } 00901 00902 /** 00903 * Changes the clients properties using given properties. 00904 * 00905 * @param string $cldbid 00906 * @param array $properties 00907 * @return void 00908 */ 00909 public function clientModifyDb($cldbid, array $properties) 00910 { 00911 $properties["cldbid"] = $cldbid; 00912 00913 $this->execute("clientdbedit", $properties); 00914 } 00915 00916 /** 00917 * Deletes a clients properties from the database. 00918 * 00919 * @param string $cldbid 00920 * @return void 00921 */ 00922 public function clientDeleteDb($cldbid) 00923 { 00924 $this->execute("clientdbdelete", array("cldbid" => $cldbid)); 00925 } 00926 00927 /** 00928 * Sets the channel group of a client to the ID specified. 00929 * 00930 * @param integer $cldbid 00931 * @param integer $cid 00932 * @param integer $cgid 00933 * @return void 00934 */ 00935 public function clientSetChannelGroup($cldbid, $cid, $cgid) 00936 { 00937 $this->execute("setclientchannelgroup", array("cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid)); 00938 } 00939 00940 /** 00941 * Returns a list of permissions defined for a client. 00942 * 00943 * @param integer $cldbid 00944 * @param boolean $permsid 00945 * @return array 00946 */ 00947 public function clientPermList($cldbid, $permsid = FALSE) 00948 { 00949 $this->clientListReset(); 00950 00951 return $this->execute("clientpermlist", array("cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid"); 00952 } 00953 00954 /** 00955 * Adds a set of specified permissions to a client. Multiple permissions can be added by providing 00956 * the three parameters of each permission. 00957 * 00958 * @param integer $cldbid 00959 * @param integer $permid 00960 * @param integer $permvalue 00961 * @param integer $permskip 00962 * @return void 00963 */ 00964 public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE) 00965 { 00966 if(!is_array($permid)) 00967 { 00968 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00969 } 00970 else 00971 { 00972 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00973 } 00974 00975 $this->execute("clientaddperm", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip)); 00976 } 00977 00978 /** 00979 * Removes a set of specified permissions from a client. Multiple permissions can be removed at once. 00980 * 00981 * @param integer $cldbid 00982 * @param integer $permid 00983 * @return void 00984 */ 00985 public function clientPermRemove($cldbid, $permid) 00986 { 00987 if(!is_array($permid)) 00988 { 00989 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 00990 } 00991 else 00992 { 00993 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 00994 } 00995 00996 $this->execute("clientdelperm", array("cldbid" => $cldbid, $permident => $permid)); 00997 } 00998 00999 /** 01000 * Returns a list of server groups available. 01001 * 01002 * @param filter $filter 01003 * @return array 01004 */ 01005 public function serverGroupList(array $filter = array()) 01006 { 01007 if($this->sgroupList === null) 01008 { 01009 $this->sgroupList = $this->request("servergrouplist")->toAssocArray("sgid"); 01010 01011 foreach($this->sgroupList as $sgid => $group) 01012 { 01013 $this->sgroupList[$sgid] = new TeamSpeak3_Node_Servergroup($this, $group); 01014 } 01015 01016 uasort($this->sgroupList, array(__CLASS__, "sortGroupList")); 01017 } 01018 01019 return $this->filterList($this->sgroupList, $filter); 01020 } 01021 01022 /** 01023 * Resets the list of server groups. 01024 * 01025 * @return void 01026 */ 01027 public function serverGroupListReset() 01028 { 01029 $this->sgroupList = null; 01030 } 01031 01032 /** 01033 * Creates a new server group using the name specified with $name and returns its ID. 01034 * 01035 * @param string $name 01036 * @param integer $type 01037 * @return integer 01038 */ 01039 public function serverGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01040 { 01041 $this->serverGroupListReset(); 01042 01043 $sgid = $this->execute("servergroupadd", array("name" => $name, "type" => $type))->toList(); 01044 01045 return $sgid["sgid"]; 01046 } 01047 01048 /** 01049 * Creates a copy of an existing server group specified by $ssgid and returns the new groups ID. 01050 * 01051 * @param integer $ssgid 01052 * @param string $name 01053 * @param integer $tsgid 01054 * @param integer $type 01055 * @return integer 01056 */ 01057 public function serverGroupCopy($ssgid, $name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01058 { 01059 $this->serverGroupListReset(); 01060 01061 $sgid = $this->execute("servergroupcopy", array("ssgid" => $ssgid, "tsgid" => $tsgid, "name" => $name, "type" => $type))->toList(); 01062 01063 if($tsgid && $name) 01064 { 01065 $this->serverGroupRename($tsgid, $name); 01066 } 01067 01068 return count($sgid) ? $sgid["sgid"] : intval($tsgid); 01069 } 01070 01071 /** 01072 * Renames the server group specified with $sgid. 01073 * 01074 * @param integer $sgid 01075 * @param string $name 01076 * @return void 01077 */ 01078 public function serverGroupRename($sgid, $name) 01079 { 01080 $this->serverGroupListReset(); 01081 01082 $this->execute("servergrouprename", array("sgid" => $sgid, "name" => $name)); 01083 } 01084 01085 /** 01086 * Deletes the server group specified with $sgid. If $force is set to 1, the server group 01087 * will be deleted even if there are clients within. 01088 * 01089 * @param integer $sgid 01090 * @param boolean $force 01091 * @return void 01092 */ 01093 public function serverGroupDelete($sgid, $force = FALSE) 01094 { 01095 $this->serverGroupListReset(); 01096 01097 $this->execute("servergroupdel", array("sgid" => $sgid, "force" => $force)); 01098 } 01099 01100 /** 01101 * Returns the TeamSpeak3_Node_Servergroup object matching the given ID. 01102 * 01103 * @param integer $sgid 01104 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01105 * @return TeamSpeak3_Node_Servergroup 01106 */ 01107 public function serverGroupGetById($sgid) 01108 { 01109 if(!array_key_exists((string) $sgid, $this->serverGroupList())) 01110 { 01111 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 01112 } 01113 01114 return $this->sgroupList[intval((string) $sgid)]; 01115 } 01116 01117 /** 01118 * Returns the TeamSpeak3_Node_Servergroup object matching the given name. 01119 * 01120 * @param string $name 01121 * @param integer $type 01122 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01123 * @return TeamSpeak3_Node_Servergroup 01124 */ 01125 public function serverGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01126 { 01127 foreach($this->serverGroupList() as $group) 01128 { 01129 if($group["name"] == $name && $group["type"] == $type) return $group; 01130 } 01131 01132 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 01133 } 01134 01135 /** 01136 * Returns a list of permissions assigned to the server group specified. 01137 * 01138 * @param integer $sgid 01139 * @param boolean $permsid 01140 * @return array 01141 */ 01142 public function serverGroupPermList($sgid, $permsid = FALSE) 01143 { 01144 return $this->execute("servergrouppermlist", array("sgid" => $sgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid"); 01145 } 01146 01147 /** 01148 * Adds a set of specified permissions to the server group specified. Multiple permissions 01149 * can be added by providing the four parameters of each permission in separate arrays. 01150 * 01151 * @param integer $sgid 01152 * @param integer $permid 01153 * @param integer $permvalue 01154 * @param integer $permnegated 01155 * @param integer $permskip 01156 * @return void 01157 */ 01158 public function serverGroupPermAssign($sgid, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE) 01159 { 01160 if(!is_array($permid)) 01161 { 01162 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 01163 } 01164 else 01165 { 01166 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 01167 } 01168 01169 $this->execute("servergroupaddperm", array("sgid" => $sgid, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip)); 01170 } 01171 01172 /** 01173 * Removes a set of specified permissions from the server group specified with $sgid. Multiple 01174 * permissions can be removed at once. 01175 * 01176 * @param integer $sgid 01177 * @param integer $permid 01178 * @return void 01179 */ 01180 public function serverGroupPermRemove($sgid, $permid) 01181 { 01182 if(!is_array($permid)) 01183 { 01184 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 01185 } 01186 else 01187 { 01188 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 01189 } 01190 01191 $this->execute("servergroupdelperm", array("sgid" => $sgid, $permident => $permid)); 01192 } 01193 01194 /** 01195 * Returns a list of clients assigned to the server group specified. 01196 * 01197 * @param integer $sgid 01198 * @return array 01199 */ 01200 public function serverGroupClientList($sgid) 01201 { 01202 if($this["virtualserver_default_server_group"] == $sgid) 01203 { 01204 return array(); 01205 } 01206 01207 return $this->execute("servergroupclientlist", array("sgid" => $sgid, "-names"))->toAssocArray("cldbid"); 01208 } 01209 01210 /** 01211 * Adds a client to the server group specified. Please note that a client cannot be 01212 * added to default groups or template groups. 01213 * 01214 * @param integer $sgid 01215 * @param integer $cldbid 01216 * @return void 01217 */ 01218 public function serverGroupClientAdd($sgid, $cldbid) 01219 { 01220 $this->clientListReset(); 01221 01222 $this->execute("servergroupaddclient", array("sgid" => $sgid, "cldbid" => $cldbid)); 01223 } 01224 01225 /** 01226 * Removes a client from the server group specified. 01227 * 01228 * @param integer $sgid 01229 * @param integer $cldbid 01230 * @return void 01231 */ 01232 public function serverGroupClientDel($sgid, $cldbid) 01233 { 01234 $this->execute("servergroupdelclient", array("sgid" => $sgid, "cldbid" => $cldbid)); 01235 } 01236 01237 /** 01238 * Returns an ordered array of regular server groups available based on a pre-defined 01239 * set of rules. 01240 * 01241 * @return array 01242 */ 01243 public function serverGroupGetProfiles() 01244 { 01245 $profiles = array(); 01246 01247 foreach($this->serverGroupList() as $sgid => $sgroup) 01248 { 01249 if($sgroup["type"] != TeamSpeak3::GROUP_DBTYPE_REGULAR) continue; 01250 01251 $profiles[$sgid] = array( 01252 "b_permission_modify_power_ignore" => 0, 01253 "i_group_needed_member_add_power" => 0, 01254 "i_group_member_add_power" => 0, 01255 "i_group_needed_member_remove_power" => 0, 01256 "i_group_member_remove_power" => 0, 01257 "i_needed_modify_power_count" => 0, 01258 "i_needed_modify_power_total" => 0, 01259 "i_permission_modify_power" => 0, 01260 "i_group_needed_modify_power" => 0, 01261 "i_group_modify_power" => 0, 01262 "i_client_needed_modify_power" => 0, 01263 "i_client_modify_power" => 0, 01264 "b_virtualserver_servergroup_create" => 0, 01265 "b_virtualserver_servergroup_delete" => 0, 01266 "b_client_ignore_bans" => 0, 01267 "b_client_ignore_antiflood" => 0, 01268 "b_group_is_permanent" => 0, 01269 "i_client_needed_ban_power" => 0, 01270 "i_client_needed_kick_power" => 0, 01271 "i_client_needed_move_power" => 0, 01272 "i_client_talk_power" => 0, 01273 "__sgid" => $sgid, 01274 "__name" => $sgroup->toString(), 01275 "__node" => $sgroup, 01276 ); 01277 01278 try 01279 { 01280 $perms = $this->serverGroupPermList($sgid, TRUE); 01281 $grant = isset($perms["i_permission_modify_power"]) ? $perms["i_permission_modify_power"]["permvalue"] : null; 01282 } 01283 catch(TeamSpeak3_Adapter_ServerQuery_Exception $e) 01284 { 01285 /* ERROR_database_empty_result */ 01286 if($e->getCode() != 0x501) throw $e; 01287 01288 $perms = array(); 01289 $grant = null; 01290 } 01291 01292 foreach($perms as $permsid => $perm) 01293 { 01294 if(in_array($permsid, array_keys($profiles[$sgid]))) 01295 { 01296 $profiles[$sgid][$permsid] = $perm["permvalue"]; 01297 } 01298 elseif(TeamSpeak3_Helper_String::factory($permsid)->startsWith("i_needed_modify_power_")) 01299 { 01300 if(!$grant || $perm["permvalue"] > $grant) continue; 01301 01302 $profiles[$sgid]["i_needed_modify_power_total"] = $profiles[$sgid]["i_needed_modify_power_total"]+$perm["permvalue"]; 01303 $profiles[$sgid]["i_needed_modify_power_count"]++; 01304 } 01305 } 01306 } 01307 01308 array_multisort($profiles, SORT_DESC); 01309 01310 return $profiles; 01311 } 01312 01313 /** 01314 * Tries to identify the post powerful/weakest server group on the virtual server and returns 01315 * the ID. 01316 * 01317 * @param integer $mode 01318 * @return TeamSpeak3_Node_Servergroup 01319 */ 01320 public function serverGroupIdentify($mode = TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) 01321 { 01322 $profiles = $this->serverGroupGetProfiles(); 01323 01324 $best_guess_profile = ($mode == TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) ? array_shift($profiles) : array_pop($profiles); 01325 01326 return $this->serverGroupGetById($best_guess_profile["__sgid"]); 01327 } 01328 01329 /** 01330 * Returns a list of channel groups available. 01331 * 01332 * @param array $filter 01333 * @return array 01334 */ 01335 public function channelGroupList(array $filter = array()) 01336 { 01337 if($this->cgroupList === null) 01338 { 01339 $this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid"); 01340 01341 foreach($this->cgroupList as $cgid => $group) 01342 { 01343 $this->cgroupList[$cgid] = new TeamSpeak3_Node_Channelgroup($this, $group); 01344 } 01345 01346 uasort($this->cgroupList, array(__CLASS__, "sortGroupList")); 01347 } 01348 01349 return $this->filterList($this->cgroupList, $filter); 01350 } 01351 01352 /** 01353 * Resets the list of channel groups. 01354 * 01355 * @return void 01356 */ 01357 public function channelGroupListReset() 01358 { 01359 $this->cgroupList = null; 01360 } 01361 01362 /** 01363 * Creates a new channel group using the name specified with $name and returns its ID. 01364 * 01365 * @param string $name 01366 * @param integer $type 01367 * @return integer 01368 */ 01369 public function channelGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01370 { 01371 $this->serverGroupListReset(); 01372 01373 $cgid = $this->execute("channelgroupadd", array("name" => $name, "type" => $type))->toList(); 01374 01375 return $cgid["cgid"]; 01376 } 01377 01378 /** 01379 * Creates a copy of an existing channel group specified by $scgid and returns the new groups ID. 01380 * 01381 * @param integer $scgid 01382 * @param string $name 01383 * @param integer $tcgid 01384 * @param integer $type 01385 * @return integer 01386 */ 01387 public function channelGroupCopy($scgid, $name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01388 { 01389 $this->serverGroupListReset(); 01390 01391 $cgid = $this->execute("channelgroupcopy", array("scgid" => $scgid, "tcgid" => $tcgid, "name" => $name, "type" => $type))->toList(); 01392 01393 if($tcgid && $name) 01394 { 01395 $this->channelGroupRename($tcgid, $name); 01396 } 01397 01398 return count($cgid) ? $cgid["cgid"] : intval($tcgid); 01399 } 01400 01401 /** 01402 * Renames the channel group specified with $cgid. 01403 * 01404 * @param integer $cgid 01405 * @param string $name 01406 * @return void 01407 */ 01408 public function channelGroupRename($cgid, $name) 01409 { 01410 $this->serverGroupListReset(); 01411 01412 $this->execute("channelgrouprename", array("cgid" => $cgid, "name" => $name)); 01413 } 01414 01415 /** 01416 * Deletes the channel group specified with $cgid. If $force is set to 1, the channel group 01417 * will be deleted even if there are clients within. 01418 * 01419 * @param integer $sgid 01420 * @param boolean $force 01421 * @return void 01422 */ 01423 public function channelGroupDelete($cgid, $force = FALSE) 01424 { 01425 $this->serverGroupListReset(); 01426 01427 $this->execute("channelgroupdel", array("cgid" => $cgid, "force" => $force)); 01428 } 01429 01430 /** 01431 * Returns the TeamSpeak3_Node_Channelgroup object matching the given ID. 01432 * 01433 * @param integer $cgid 01434 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01435 * @return TeamSpeak3_Node_Channelgroup 01436 */ 01437 public function channelGroupGetById($cgid) 01438 { 01439 if(!array_key_exists((string) $cgid, $this->channelGroupList())) 01440 { 01441 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 01442 } 01443 01444 return $this->cgroupList[intval((string) $cgid)]; 01445 } 01446 01447 /** 01448 * Returns the TeamSpeak3_Node_Channelgroup object matching the given name. 01449 * 01450 * @param string $name 01451 * @param integer $type 01452 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01453 * @return TeamSpeak3_Node_Channelgroup 01454 */ 01455 public function channelGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 01456 { 01457 foreach($this->channelGroupList() as $group) 01458 { 01459 if($group["name"] == $name && $group["type"] == $type) return $group; 01460 } 01461 01462 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00); 01463 } 01464 01465 /** 01466 * Returns a list of permissions assigned to the channel group specified. 01467 * 01468 * @param integer $cgid 01469 * @param boolean $permsid 01470 * @return array 01471 */ 01472 public function channelGroupPermList($cgid, $permsid = FALSE) 01473 { 01474 return $this->execute("channelgrouppermlist", array("cgid" => $cgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid"); 01475 } 01476 01477 /** 01478 * Adds a set of specified permissions to the channel group specified. Multiple permissions 01479 * can be added by providing the two parameters of each permission in separate arrays. 01480 * 01481 * @param integer $cgid 01482 * @param integer $permid 01483 * @param integer $permvalue 01484 * @return void 01485 */ 01486 public function channelGroupPermAssign($cgid, $permid, $permvalue) 01487 { 01488 if(!is_array($permid)) 01489 { 01490 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 01491 } 01492 else 01493 { 01494 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 01495 } 01496 01497 $this->execute("channelgroupaddperm", array("cgid" => $cgid, $permident => $permid, "permvalue" => $permvalue)); 01498 } 01499 01500 /** 01501 * Removes a set of specified permissions from the channel group specified with $cgid. Multiple 01502 * permissions can be removed at once. 01503 * 01504 * @param integer $cgid 01505 * @param integer $permid 01506 * @return void 01507 */ 01508 public function channelGroupPermRemove($cgid, $permid) 01509 { 01510 if(!is_array($permid)) 01511 { 01512 $permident = (is_numeric($permid)) ? "permid" : "permsid"; 01513 } 01514 else 01515 { 01516 $permident = (is_numeric(current($permid))) ? "permid" : "permsid"; 01517 } 01518 01519 $this->execute("channelgroupdelperm", array("cgid" => $cgid, $permident => $permid)); 01520 } 01521 01522 /** 01523 * Returns all the client and/or channel IDs currently assigned to channel groups. All three 01524 * parameters are optional so you're free to choose the most suitable combination for your 01525 * requirements. 01526 * 01527 * @param integer $cgid 01528 * @param integer $cid 01529 * @param integer $cldbid 01530 * @return array 01531 */ 01532 public function channelGroupClientList($cgid = null, $cid = null, $cldbid = null) 01533 { 01534 if($this["virtualserver_default_channel_group"] == $cgid) 01535 { 01536 return array(); 01537 } 01538 01539 return $this->execute("channelgroupclientlist", array("cgid" => $cgid, "cid" => $cid, "cldbid" => $cldbid))->toArray(); 01540 } 01541 01542 /** 01543 * Restores the default permission settings on the virtual server and returns a new initial 01544 * administrator privilege key. 01545 * 01546 * @return TeamSpeak3_Helper_String 01547 */ 01548 public function permReset() 01549 { 01550 $token = $this->request("permreset")->toList(); 01551 01552 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]); 01553 01554 return $token["token"]; 01555 } 01556 01557 /** 01558 * Removes any assignment of the permission specified with $permid on the selected virtual server 01559 * and returns the number of removed assignments on success. 01560 * 01561 * @param integer $permid 01562 * @return integer 01563 */ 01564 public function permRemoveAny($permid) 01565 { 01566 $assignments = $this->permissionFind($permid); 01567 01568 foreach($assignments as $assignment) 01569 { 01570 switch($assignment["t"]) 01571 { 01572 case TeamSpeak3::PERM_TYPE_SERVERGROUP: 01573 $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]); 01574 break; 01575 01576 case TeamSpeak3::PERM_TYPE_CLIENT: 01577 $this->clientPermRemove($assignment["id2"], $assignment["p"]); 01578 break; 01579 01580 case TeamSpeak3::PERM_TYPE_CHANNEL: 01581 $this->channelPermRemove($assignment["id2"], $assignment["p"]); 01582 break; 01583 01584 case TeamSpeak3::PERM_TYPE_CHANNELGROUP: 01585 $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]); 01586 break; 01587 01588 case TeamSpeak3::PERM_TYPE_CHANNELCLIENT: 01589 $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]); 01590 break; 01591 01592 default: 01593 throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604); 01594 } 01595 } 01596 01597 return count($assignments); 01598 } 01599 01600 /** 01601 * Initializes a file transfer upload. $clientftfid is an arbitrary ID to identify the file transfer on client-side. 01602 * 01603 * @todo [SERVER LIMITATION] return real file transfer host address instead of ServerQuery host address 01604 * @param integer $clientftfid 01605 * @param integer $cid 01606 * @param string $name 01607 * @param integer $size 01608 * @param string $cpw 01609 * @param boolean $overwrite 01610 * @param boolean $resume 01611 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01612 * @return array 01613 */ 01614 public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE) 01615 { 01616 $upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList(); 01617 01618 if(array_key_exists("status", $upload) && $upload["status"] != 0x00) 01619 { 01620 throw new TeamSpeak3_Adapter_ServerQuery_Exception($upload["msg"], $upload["status"]); 01621 } 01622 01623 $upload["cid"] = $cid; 01624 $upload["file"] = $name; 01625 01626 if(!array_key_exists("host", $upload)) $upload["host"] = $this->getParent()->getAdapterHost(); 01627 01628 TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload); 01629 01630 return $upload; 01631 } 01632 01633 /** 01634 * Initializes a file transfer download. $clientftfid is an arbitrary ID to identify the file transfer on client-side. 01635 * 01636 * @todo [SERVER LIMITATION] return real file transfer host address instead of ServerQuery host address 01637 * @param integer $clientftfid 01638 * @param integer $cid 01639 * @param string $name 01640 * @param string $cpw 01641 * @param integer $seekpos 01642 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 01643 * @return array 01644 */ 01645 public function transferInitDownload($clientftfid, $cid, $name, $cpw = "", $seekpos = 0) 01646 { 01647 $download = $this->execute("ftinitdownload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "seekpos" => $seekpos))->toList(); 01648 01649 if(array_key_exists("status", $download) && $download["status"] != 0x00) 01650 { 01651 throw new TeamSpeak3_Adapter_ServerQuery_Exception($download["msg"], $download["status"]); 01652 } 01653 01654 $download["cid"] = $cid; 01655 $download["file"] = $name; 01656 01657 if(!array_key_exists("host", $download)) $download["host"] = $this->getParent()->getAdapterHost(); 01658 01659 TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadInit", $download["ftkey"], $download); 01660 01661 return $download; 01662 } 01663 01664 /** 01665 * Displays a list of running file transfers on the selected virtual server. The output contains the path to 01666 * which a file is uploaded to, the current transfer rate in bytes per second, etc. 01667 * 01668 * @return array 01669 */ 01670 public function transferList() 01671 { 01672 return $this->request("ftlist")->toAssocArray("serverftfid"); 01673 } 01674 01675 /** 01676 * Stops the running file transfer with server-side ID $serverftfid. 01677 * 01678 * @param integer $serverftfid 01679 * @param boolean $delete 01680 * @return void 01681 */ 01682 public function transferStop($serverftfid, $delete = FALSE) 01683 { 01684 $this->execute("ftstop", array("serverftfid" => $serverftfid, "delete" => $delete)); 01685 } 01686 01687 /** 01688 * Downloads and returns the servers icon file content. 01689 * 01690 * @return TeamSpeak3_Helper_String 01691 */ 01692 public function iconDownload() 01693 { 01694 if($this->iconIsLocal("virtualserver_icon_id") || $this["virtualserver_icon_id"] == 0) return; 01695 01696 $download = $this->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("virtualserver_icon_id")); 01697 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 01698 01699 return $transfer->download($download["ftkey"], $download["size"]); 01700 } 01701 01702 /** 01703 * Uploads a given icon file content to the server and returns the ID of the icon. 01704 * 01705 * @param string $data 01706 * @return integer 01707 */ 01708 public function iconUpload($data) 01709 { 01710 $crc = crc32($data); 01711 $size = strlen($data); 01712 01713 $upload = $this->transferInitUpload(rand(0x0000, 0xFFFF), 0, "/icon_" . $crc, $size); 01714 $transfer = TeamSpeak3::factory("filetransfer://" . $upload["host"] . ":" . $upload["port"]); 01715 01716 $transfer->upload($upload["ftkey"], $upload["seekpos"], $data); 01717 01718 return $crc; 01719 } 01720 01721 /** 01722 * Changes the virtual server configuration using given properties. 01723 * 01724 * @param array $properties 01725 * @return void 01726 */ 01727 public function modify(array $properties) 01728 { 01729 $this->execute("serveredit", $properties); 01730 $this->resetNodeInfo(); 01731 } 01732 01733 /** 01734 * Sends a text message to all clients on the virtual server. 01735 * 01736 * @param string $msg 01737 * @return void 01738 */ 01739 public function message($msg) 01740 { 01741 $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_SERVER)); 01742 } 01743 01744 /** 01745 * Returns a list of offline messages you've received. The output contains the senders unique identifier, 01746 * the messages subject, etc. 01747 * 01748 * @return array 01749 */ 01750 public function messageList() 01751 { 01752 $this->request("messagelist")->toAssocArray("msgid"); 01753 } 01754 01755 /** 01756 * Sends an offline message to the client specified by $cluid. 01757 * 01758 * @param string $cluid 01759 * @param string $subject 01760 * @param string $message 01761 * @return void 01762 */ 01763 public function messageCreate($cluid, $subject, $message) 01764 { 01765 $this->execute("messageadd", array("cluid" => $cluid, "subject" => $subject, "message" => $message)); 01766 } 01767 01768 /** 01769 * Deletes an existing offline message with ID $msgid from your inbox. 01770 * 01771 * @param integer $msgid 01772 * @return void 01773 */ 01774 public function messageDelete($msgid) 01775 { 01776 $this->execute("messagedel", array("msgid" => $msgid)); 01777 } 01778 01779 /** 01780 * Returns an existing offline message with ID $msgid from your inbox. 01781 * 01782 * @param integer $msgid 01783 * @param boolean $flag_read 01784 * @return array 01785 */ 01786 public function messageRead($msgid, $flag_read = TRUE) 01787 { 01788 $msg = $this->execute("messageget", array("msgid" => $msgid))->toList(); 01789 01790 if($flag_read) 01791 { 01792 $this->execute("messageget", array("msgid" => $msgid, "flag" => $flag_read)); 01793 } 01794 01795 return $msg; 01796 } 01797 01798 /** 01799 * Creates and returns snapshot data for the selected virtual server. 01800 * 01801 * @param string $mode 01802 * @return string 01803 */ 01804 public function snapshotCreate($mode = TeamSpeak3::SNAPSHOT_STRING) 01805 { 01806 $snapshot = $this->request("serversnapshotcreate")->toString(FALSE); 01807 01808 switch($mode) 01809 { 01810 case TeamSpeak3::SNAPSHOT_BASE64: 01811 return $snapshot->toBase64(); 01812 break; 01813 01814 case TeamSpeak3::SNAPSHOT_HEXDEC: 01815 return $snapshot->toHex(); 01816 break; 01817 01818 default: 01819 return (string) $snapshot; 01820 break; 01821 } 01822 } 01823 01824 /** 01825 * Deploys snapshot data on the selected virtual server. If no virtual server is selected (ID 0), 01826 * the data will be used to create a new virtual server from scratch. 01827 * 01828 * @param string $data 01829 * @param string $mode 01830 * @return array 01831 */ 01832 public function snapshotDeploy($data, $mode = TeamSpeak3::SNAPSHOT_STRING) 01833 { 01834 switch($mode) 01835 { 01836 case TeamSpeak3::SNAPSHOT_BASE64: 01837 $data = TeamSpeak3_Helper_String::fromBase64($data); 01838 break; 01839 01840 case TeamSpeak3::SNAPSHOT_HEXDEC: 01841 $data = TeamSpeak3_Helper_String::fromHex($data); 01842 break; 01843 01844 default: 01845 $data = TeamSpeak3_Helper_String::factory($data); 01846 break; 01847 } 01848 01849 $detail = $this->request("serversnapshotdeploy " . $data)->toList(); 01850 01851 if(array_key_exists("sid", $detail)) 01852 { 01853 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail["sid"]); 01854 } 01855 01856 return $detail; 01857 } 01858 01859 /** 01860 * Registers for a specified category of events on a virtual server to receive notification 01861 * messages. Depending on the notifications you've registered for, the server will send you 01862 * a message on every event. 01863 * 01864 * @param string $event 01865 * @param integer $id 01866 * @return void 01867 */ 01868 public function notifyRegister($event, $id = 0) 01869 { 01870 $this->execute("servernotifyregister", array("event" => $event, "id" => $id)); 01871 } 01872 01873 /** 01874 * Unregisters all events previously registered with servernotifyregister so you will no 01875 * longer receive notification messages. 01876 * 01877 * @return void 01878 */ 01879 public function notifyUnregister() 01880 { 01881 $this->request("servernotifyunregister"); 01882 } 01883 01884 /** 01885 * Alias for privilegeKeyList(). 01886 * 01887 * @deprecated 01888 */ 01889 public function tokenList($translate = FALSE) 01890 { 01891 return $this->privilegeKeyList(); 01892 } 01893 01894 /** 01895 * Returns a list of privilege keys (tokens) available. If $resolve is set to TRUE the values 01896 * of token_id1 and token_id2 will be translated into the appropriate group and/or channel 01897 * names. 01898 * 01899 * @param boolean $resolve 01900 * @return array 01901 */ 01902 public function privilegeKeyList($resolve = FALSE) 01903 { 01904 $tokens = $this->request("privilegekeylist")->toAssocArray("token"); 01905 01906 if($resolve) 01907 { 01908 foreach($tokens as $token => $array) 01909 { 01910 $func = $array["token_type"] ? "channelGroupGetById" : "serverGroupGetById"; 01911 01912 try 01913 { 01914 $tokens[$token]["token_id1"] = $this->$func($array["token_id1"])->name; 01915 } 01916 catch(Exception $e) 01917 { 01918 /* ERROR_channel_invalid_id */ 01919 if($e->getCode() != 0xA00) throw $e; 01920 } 01921 01922 try 01923 { 01924 if($array["token_type"]) $tokens[$token]["token_id2"] = $this->channelGetById($array["token_id2"])->getPathway(); 01925 } 01926 catch(Exception $e) 01927 { 01928 /* ERROR_permission_invalid_group_id */ 01929 if($e->getCode() != 0x300) throw $e; 01930 } 01931 } 01932 } 01933 01934 return $tokens; 01935 } 01936 01937 /** 01938 * Alias for privilegeKeyCreate(). 01939 * 01940 * @deprecated 01941 */ 01942 public function tokenCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null) 01943 { 01944 return $this->privilegeKeyCreate($type, $id1, $id2, $description, $customset); 01945 } 01946 01947 /** 01948 * Creates a new privilege key (token) and returns the key. 01949 * 01950 * @param integer $type 01951 * @param integer $id1 01952 * @param integer $id2 01953 * @param string $description 01954 * @param string $customset 01955 * @return TeamSpeak3_Helper_String 01956 */ 01957 public function privilegeKeyCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null) 01958 { 01959 $token = $this->execute("privilegekeyadd", array("tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset))->toList(); 01960 01961 TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]); 01962 01963 return $token["token"]; 01964 } 01965 01966 /** 01967 * Alias for privilegeKeyDelete(). 01968 * 01969 * @deprecated 01970 */ 01971 public function tokenDelete($token) 01972 { 01973 $this->privilegeKeyDelete($token); 01974 } 01975 01976 /** 01977 * Deletes a token specified by key $token. 01978 * 01979 * @param string $token 01980 * @return void 01981 */ 01982 public function privilegeKeyDelete($token) 01983 { 01984 $this->execute("privilegekeydelete", array("token" => $token)); 01985 } 01986 01987 /** 01988 * Alias for privilegeKeyUse(). 01989 * 01990 * @deprecated 01991 */ 01992 public function tokenUse($token) 01993 { 01994 $this->privilegeKeyUse($token); 01995 } 01996 01997 /** 01998 * Use a token key gain access to a server or channel group. Please note that the server will 01999 * automatically delete the token after it has been used. 02000 * 02001 * @param string $token 02002 * @return void 02003 */ 02004 public function privilegeKeyUse($token) 02005 { 02006 $this->execute("privilegekeyuse", array("token" => $token)); 02007 } 02008 02009 /** 02010 * Returns a list of custom client properties specified by $ident. 02011 * 02012 * @param string $ident 02013 * @param string $pattern 02014 * @return array 02015 */ 02016 public function customSearch($ident, $pattern = "%") 02017 { 02018 return $this->execute("customsearch", array("ident" => $ident, "pattern" => $pattern))->toArray(); 02019 } 02020 02021 /** 02022 * Returns a list of custom properties for the client specified by $cldbid. 02023 * 02024 * @param integer $cldbid 02025 * @return array 02026 */ 02027 public function customInfo($cldbid) 02028 { 02029 return $this->execute("custominfo", array("cldbid" => $cldbid))->toArray(); 02030 } 02031 02032 /** 02033 * Returns a list of active bans on the selected virtual server. 02034 * 02035 * @return array 02036 */ 02037 public function banList() 02038 { 02039 return $this->request("banlist")->toAssocArray("banid"); 02040 } 02041 02042 /** 02043 * Deletes all active ban rules from the server. 02044 * 02045 * @return void 02046 */ 02047 public function banListClear() 02048 { 02049 $this->request("bandelall"); 02050 } 02051 02052 /** 02053 * Adds a new ban rule on the selected virtual server. All parameters are optional but at least one 02054 * of the following rules must be set: ip, name, or uid. 02055 * 02056 * @param array $rules 02057 * @param integer $timeseconds 02058 * @param string $reason 02059 * @return integer 02060 */ 02061 public function banCreate(array $rules, $timeseconds = null, $reason = null) 02062 { 02063 $rules["time"] = $timeseconds; 02064 $rules["banreason"] = $reason; 02065 02066 $banid = $this->execute("banadd", $rules)->toList(); 02067 02068 return $banid["banid"]; 02069 } 02070 02071 /** 02072 * Deletes the specified ban rule from the server. 02073 * 02074 * @param integer $banid 02075 * @return void 02076 */ 02077 public function banDelete($banid) 02078 { 02079 $this->execute("bandel", array("banid" => $banid)); 02080 } 02081 02082 /** 02083 * Returns a list of complaints on the selected virtual server. If $tcldbid is specified, only 02084 * complaints about the targeted client will be shown. 02085 * 02086 * @param integer $tcldbid 02087 * @return array 02088 */ 02089 public function complaintList($tcldbid = null) 02090 { 02091 return $this->execute("complainlist", array("tcldbid" => $tcldbid))->toArray(); 02092 } 02093 02094 /** 02095 * Deletes all active complaints about the client with database ID $tcldbid from the server. 02096 * 02097 * @param integer $tcldbid 02098 * @return void 02099 */ 02100 public function complaintListClear($tcldbid) 02101 { 02102 $this->execute("complaindelall", array("tcldbid" => $tcldbid)); 02103 } 02104 02105 /** 02106 * Submits a complaint about the client with database ID $tcldbid to the server. 02107 * 02108 * @param integer $tcldbid 02109 * @param string $message 02110 * @return void 02111 */ 02112 public function complaintCreate($tcldbid, $message) 02113 { 02114 $this->execute("complainadd", array("tcldbid" => $tcldbid, "message" => $message)); 02115 } 02116 02117 /** 02118 * Deletes the complaint about the client with ID $tcldbid submitted by the client with ID $fcldbid from the server. 02119 * 02120 * @param integer $tcldbid 02121 * @param integer $fcldbid 02122 * @return void 02123 */ 02124 public function complaintDelete($tcldbid, $fcldbid) 02125 { 02126 $this->execute("complaindel", array("tcldbid" => $tcldbid, "fcldbid" => $fcldbid)); 02127 } 02128 02129 /** 02130 * Displays a specified number of entries (1-100) from the servers log. 02131 * 02132 * @param integer $lines 02133 * @param integer $begin_pos 02134 * @param boolean $reverse 02135 * @param boolean $instance 02136 * @return array 02137 */ 02138 public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = null) 02139 { 02140 return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray(); 02141 } 02142 02143 /** 02144 * Writes a custom entry into the virtual server log. 02145 * 02146 * @param string $logmsg 02147 * @param integer $loglevel 02148 * @return void 02149 */ 02150 public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO) 02151 { 02152 $this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel)); 02153 } 02154 02155 /** 02156 * Returns detailed connection information of the virtual server. 02157 * 02158 * @return array 02159 */ 02160 public function connectionInfo() 02161 { 02162 return $this->request("serverrequestconnectioninfo")->toList(); 02163 } 02164 02165 /** 02166 * Deletes the virtual server. 02167 * 02168 * @return void 02169 */ 02170 public function delete() 02171 { 02172 $this->getParent()->serverDelete($this->getId()); 02173 02174 unset($this); 02175 } 02176 02177 /** 02178 * Starts the virtual server. 02179 * 02180 * @return void 02181 */ 02182 public function start() 02183 { 02184 $this->getParent()->serverStart($this->getId()); 02185 } 02186 02187 /** 02188 * Stops the virtual server. 02189 * 02190 * @return void 02191 */ 02192 public function stop() 02193 { 02194 $this->getParent()->serverStop($this->getId()); 02195 } 02196 02197 /** 02198 * Changes the properties of your own client connection. 02199 * 02200 * @param array $properties 02201 * @return void 02202 */ 02203 public function selfUpdate(array $properties) 02204 { 02205 $this->execute("clientupdate", $properties); 02206 02207 foreach($properties as $ident => $value) 02208 { 02209 $this->whoamiSet($ident, $value); 02210 } 02211 } 02212 02213 /** 02214 * Updates your own ServerQuery login credentials using a specified username. The password 02215 * will be auto-generated. 02216 * 02217 * @param string $username 02218 * @return TeamSpeak3_Helper_String 02219 */ 02220 public function selfUpdateLogin($username) 02221 { 02222 $password = $this->execute("clientsetserverquerylogin", array("client_login_name" => $username))->toList(); 02223 02224 return $password["client_login_password"]; 02225 } 02226 02227 /** 02228 * Returns an array containing the permission overview of your own client. 02229 * 02230 * @return array 02231 */ 02232 public function selfPermOverview() 02233 { 02234 return $this->execute("permoverview", array("cldbid" => $this->whoamiGet("client_database_id"), "cid" => $this->whoamiGet("client_channel_id"), "permid" => 0))->toArray(); 02235 } 02236 02237 /** 02238 * @ignore 02239 */ 02240 protected function fetchNodeList() 02241 { 02242 $this->nodeList = array(); 02243 02244 foreach($this->channelList() as $channel) 02245 { 02246 if($channel["pid"] == 0) 02247 { 02248 $this->nodeList[] = $channel; 02249 } 02250 } 02251 } 02252 02253 /** 02254 * @ignore 02255 */ 02256 protected function fetchNodeInfo() 02257 { 02258 $this->nodeInfo = array_merge($this->nodeInfo, $this->request("serverinfo")->toList()); 02259 } 02260 02261 /** 02262 * Internal callback funtion for sorting of client objects. 02263 * 02264 * @param TeamSpeak3_Node_Client $a 02265 * @param TeamSpeak3_Node_Client $b 02266 * @return integer 02267 */ 02268 protected static function sortClientList(TeamSpeak3_Node_Client $a, TeamSpeak3_Node_Client $b) 02269 { 02270 if(get_class($a) != get_class($b)) 02271 { 02272 return 0; 02273 02274 /* workaround for PHP bug #50688 */ 02275 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602); 02276 } 02277 02278 if(!$a instanceof TeamSpeak3_Node_Client) 02279 { 02280 return 0; 02281 02282 /* workaround for PHP bug #50688 */ 02283 throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604); 02284 } 02285 02286 if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0)) 02287 { 02288 return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1; 02289 } 02290 02291 if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0)) 02292 { 02293 return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1; 02294 } 02295 02296 return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"])); 02297 } 02298 02299 /** 02300 * Internal callback funtion for sorting of group objects. 02301 * 02302 * @param TeamSpeak3_Node_Abstract $a 02303 * @param TeamSpeak3_Node_Abstract $b 02304 * @return integer 02305 */ 02306 protected static function sortGroupList(TeamSpeak3_Node_Abstract $a, TeamSpeak3_Node_Abstract $b) 02307 { 02308 if(get_class($a) != get_class($b)) 02309 { 02310 return 0; 02311 02312 /* workaround for PHP bug #50688 */ 02313 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602); 02314 } 02315 02316 if(!$a instanceof TeamSpeak3_Node_Servergroup && !$a instanceof TeamSpeak3_Node_Channelgroup) 02317 { 02318 return 0; 02319 02320 /* workaround for PHP bug #50688 */ 02321 throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604); 02322 } 02323 02324 if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0) 02325 { 02326 return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1; 02327 } 02328 02329 return ($a->getId() < $b->getId()) ? -1 : 1; 02330 } 02331 02332 /** 02333 * Internal callback funtion for sorting of file list items. 02334 * 02335 * @param array $a 02336 * @param array $b 02337 * @return integer 02338 */ 02339 protected static function sortFileList(array $a, array $b) 02340 { 02341 if(!array_key_exists("src", $a) || !array_key_exists("src", $b)) 02342 { 02343 return 0; 02344 02345 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602); 02346 } 02347 02348 return strcmp(strtolower($a["src"]), strtolower($b["src"])); 02349 } 02350 02351 /** 02352 * Returns TRUE if the virtual server is online. 02353 * 02354 * @return boolean 02355 */ 02356 public function isOnline() 02357 { 02358 return ($this["virtualserver_status"] == "online") ? TRUE : FALSE; 02359 } 02360 02361 /** 02362 * Returns TRUE if the virtual server is offline. 02363 * 02364 * @return boolean 02365 */ 02366 public function isOffline() 02367 { 02368 return ($this["virtualserver_status"] == "offline") ? TRUE : FALSE; 02369 } 02370 02371 /** 02372 * Returns a unique identifier for the node which can be used as a HTML property. 02373 * 02374 * @return string 02375 */ 02376 public function getUniqueId() 02377 { 02378 return $this->getParent()->getUniqueId() . "_s" . $this->getId(); 02379 } 02380 02381 /** 02382 * Returns the name of a possible icon to display the node object. 02383 * 02384 * @return string 02385 */ 02386 public function getIcon() 02387 { 02388 if($this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"] >= $this["virtualserver_maxclients"]) 02389 { 02390 return "server_full"; 02391 } 02392 elseif($this["virtualserver_flag_password"]) 02393 { 02394 return "server_pass"; 02395 } 02396 else 02397 { 02398 return "server_open"; 02399 } 02400 } 02401 02402 /** 02403 * Returns a symbol representing the node. 02404 * 02405 * @return string 02406 */ 02407 public function getSymbol() 02408 { 02409 return "$"; 02410 } 02411 02412 /** 02413 * Returns a string representation of this node. 02414 * 02415 * @return string 02416 */ 02417 public function __toString() 02418 { 02419 return (string) $this["virtualserver_name"]; 02420 } 02421 }