TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Servergroup.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_Servergroup 00030 * @brief Class describing a TeamSpeak 3 server group and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Servergroup extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * The TeamSpeak3_Node_Servergroup constructor. 00036 * 00037 * @param TeamSpeak3_Node_Server $server 00038 * @param array $info 00039 * @param string $index 00040 * @throws TeamSpeak3_Node_Exception 00041 * @return TeamSpeak3_Node_Servergroup 00042 */ 00043 public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "sgid") 00044 { 00045 $this->parent = $server; 00046 $this->nodeInfo = $info; 00047 00048 if(!array_key_exists($index, $this->nodeInfo)) 00049 { 00050 throw new TeamSpeak3_Node_Exception("invalid groupID", 0xA00); 00051 } 00052 00053 $this->nodeId = $this->nodeInfo[$index]; 00054 } 00055 00056 /** 00057 * Renames the server group specified. 00058 * 00059 * @param string $name 00060 * @return void 00061 */ 00062 public function rename($name) 00063 { 00064 return $this->getParent()->serverGroupRename($this->getId(), $name); 00065 } 00066 00067 /** 00068 * Deletes the server group. If $force is set to 1, the server group will be 00069 * deleted even if there are clients within. 00070 * 00071 * @param boolean $force 00072 * @return void 00073 */ 00074 public function delete($force = FALSE) 00075 { 00076 $this->getParent()->serverGroupDelete($this->getId(), $force); 00077 00078 unset($this); 00079 } 00080 00081 /** 00082 * Creates a copy of the server group and returns the new groups ID. 00083 * 00084 * @param string $name 00085 * @param integer $tsgid 00086 * @param integer $type 00087 * @return integer 00088 */ 00089 public function copy($name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR) 00090 { 00091 return $this->getParent()->serverGroupCopy($this->getId(), $name, $tsgid, $type); 00092 } 00093 00094 /** 00095 * Returns a list of permissions assigned to the server group. 00096 * 00097 * @param boolean $permsid 00098 * @return array 00099 */ 00100 public function permList($permsid = FALSE) 00101 { 00102 return $this->getParent()->serverGroupPermList($this->getId(), $permsid); 00103 } 00104 00105 /** 00106 * Adds a set of specified permissions to the server group. Multiple permissions 00107 * can be added by providing the four parameters of each permission in separate arrays. 00108 * 00109 * @param integer $permid 00110 * @param integer $permvalue 00111 * @param integer $permnegated 00112 * @param integer $permskip 00113 * @return void 00114 */ 00115 public function permAssign($permid, $permvalue, $permnegated = FALSE, $permskip = FALSE) 00116 { 00117 return $this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip); 00118 } 00119 00120 /** 00121 * Alias for permAssign(). 00122 * 00123 * @deprecated 00124 */ 00125 public function permAssignByName($permname, $permvalue, $permnegated = FALSE, $permskip = FALSE) 00126 { 00127 return $this->permAssign($permname, $permvalue, $permnegated, $permskip); 00128 } 00129 00130 /** 00131 * Removes a set of specified permissions from the server group. Multiple 00132 * permissions can be removed at once. 00133 * 00134 * @param integer $permid 00135 * @return void 00136 */ 00137 public function permRemove($permid) 00138 { 00139 return $this->getParent()->serverGroupPermRemove($this->getId(), $permid); 00140 } 00141 00142 /** 00143 * Alias for permRemove(). 00144 * 00145 * @deprecated 00146 */ 00147 public function permRemoveByName($permname) 00148 { 00149 return $this->permRemove($permname); 00150 } 00151 00152 /** 00153 * Returns a list of clients assigned to the server group specified. 00154 * 00155 * @return array 00156 */ 00157 public function clientList() 00158 { 00159 return $this->getParent()->serverGroupClientList($this->getId()); 00160 } 00161 00162 /** 00163 * Adds a client to the server group specified. Please note that a client cannot be 00164 * added to default groups or template groups. 00165 * 00166 * @param integer $cldbid 00167 * @return void 00168 */ 00169 public function clientAdd($cldbid) 00170 { 00171 return $this->getParent()->serverGroupClientAdd($this->getId(), $cldbid); 00172 } 00173 00174 /** 00175 * Removes a client from the server group. 00176 * 00177 * @param integer $cldbid 00178 * @return void 00179 */ 00180 public function clientDel($cldbid) 00181 { 00182 return $this->getParent()->serverGroupClientDel($this->getId(), $cldbid); 00183 } 00184 00185 /** 00186 * Alias for privilegeKeyCreate(). 00187 * 00188 * @deprecated 00189 */ 00190 public function tokenCreate($description = null, $customset = null) 00191 { 00192 return $this->privilegeKeyCreate($description, $customset); 00193 } 00194 00195 /** 00196 * Creates a new privilege key (token) for the server group and returns the key. 00197 * 00198 * @param string $description 00199 * @param string $customset 00200 * @return TeamSpeak3_Helper_String 00201 */ 00202 public function privilegeKeyCreate($description = null, $customset = null) 00203 { 00204 return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_SERVERGROUP, $this->getId(), 0, $description, $customset); 00205 } 00206 00207 /** 00208 * Sends a text message to all clients residing in the server group on the virtual server. 00209 * 00210 * @param string $msg 00211 * @return void 00212 */ 00213 public function message($msg) 00214 { 00215 foreach($this as $client) 00216 { 00217 try 00218 { 00219 $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 00220 } 00221 catch(TeamSpeak3_Adapter_ServerQuery_Exception $e) 00222 { 00223 /* ERROR_client_invalid_id */ 00224 if($e->getCode() != 0x0200) throw $e; 00225 } 00226 } 00227 } 00228 00229 /** 00230 * Downloads and returns the server groups icon file content. 00231 * 00232 * @return TeamSpeak3_Helper_String 00233 */ 00234 public function iconDownload() 00235 { 00236 if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return; 00237 00238 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid")); 00239 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 00240 00241 return $transfer->download($download["ftkey"], $download["size"]); 00242 } 00243 00244 /** 00245 * @ignore 00246 */ 00247 protected function fetchNodeList() 00248 { 00249 $this->nodeList = array(); 00250 00251 foreach($this->getParent()->clientList() as $client) 00252 { 00253 if(in_array($this->getId(), explode(",", $client["client_servergroups"]))) 00254 { 00255 $this->nodeList[] = $client; 00256 } 00257 } 00258 } 00259 00260 /** 00261 * Returns a unique identifier for the node which can be used as a HTML property. 00262 * 00263 * @return string 00264 */ 00265 public function getUniqueId() 00266 { 00267 return $this->getParent()->getUniqueId() . "_sg" . $this->getId(); 00268 } 00269 00270 /** 00271 * Returns the name of a possible icon to display the node object. 00272 * 00273 * @return string 00274 */ 00275 public function getIcon() 00276 { 00277 return "group_server"; 00278 } 00279 00280 /** 00281 * Returns a symbol representing the node. 00282 * 00283 * @return string 00284 */ 00285 public function getSymbol() 00286 { 00287 return "%"; 00288 } 00289 00290 /** 00291 * Returns a string representation of this node. 00292 * 00293 * @return string 00294 */ 00295 public function __toString() 00296 { 00297 return (string) $this["name"]; 00298 } 00299 } 00300