TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Client.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_Client 00030 * @brief Class describing a TeamSpeak 3 client and all it's parameters. 00031 */ 00032 class TeamSpeak3_Node_Client extends TeamSpeak3_Node_Abstract 00033 { 00034 /** 00035 * The TeamSpeak3_Node_Client constructor. 00036 * 00037 * @param TeamSpeak3_Node_Server $server 00038 * @param array $info 00039 * @param string $index 00040 * @throws TeamSpeak3_Adapter_ServerQuery_Exception 00041 * @return TeamSpeak3_Node_Client 00042 */ 00043 public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "clid") 00044 { 00045 $this->parent = $server; 00046 $this->nodeInfo = $info; 00047 00048 if(!array_key_exists($index, $this->nodeInfo)) 00049 { 00050 throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200); 00051 } 00052 00053 $this->nodeId = $this->nodeInfo[$index]; 00054 } 00055 00056 /** 00057 * Changes the clients properties using given properties. 00058 * 00059 * @param array $properties 00060 * @return void 00061 */ 00062 public function modify(array $properties) 00063 { 00064 $properties["clid"] = $this->getId(); 00065 00066 $this->execute("clientedit", $properties); 00067 $this->resetNodeInfo(); 00068 } 00069 00070 /** 00071 * Changes the clients properties using given properties. 00072 * 00073 * @param array $properties 00074 * @return void 00075 */ 00076 public function modifyDb(array $properties) 00077 { 00078 return $this->getParent()->clientModifyDb($this["client_database_id"], $properties); 00079 } 00080 00081 /** 00082 * Deletes the clients properties from the database. 00083 * 00084 * @return void 00085 */ 00086 public function deleteDb() 00087 { 00088 return $this->getParent()->clientDeleteDb($this["client_database_id"]); 00089 } 00090 00091 /** 00092 * Returns a list of properties from the database for the client. 00093 * 00094 * @return array 00095 */ 00096 public function infoDb() 00097 { 00098 return $this->getParent()->clientInfoDb($this["client_database_id"]); 00099 } 00100 00101 /** 00102 * Sends a text message to the client. 00103 * 00104 * @param string $msg 00105 * @return void 00106 */ 00107 public function message($msg) 00108 { 00109 $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT)); 00110 } 00111 00112 /** 00113 * Moves the client to another channel. 00114 * 00115 * @param integer $cid 00116 * @param string $cpw 00117 * @return void 00118 */ 00119 public function move($cid, $cpw = null) 00120 { 00121 return $this->getParent()->clientMove($this->getId(), $cid, $cpw); 00122 } 00123 00124 /** 00125 * Kicks the client from his currently joined channel or from the server. 00126 * 00127 * @param integer $reasonid 00128 * @param string $reasonmsg 00129 * @return void 00130 */ 00131 public function kick($reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null) 00132 { 00133 return $this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg); 00134 } 00135 00136 /** 00137 * Sends a poke message to the client. 00138 * 00139 * @param string $msg 00140 * @return void 00141 */ 00142 public function poke($msg) 00143 { 00144 return $this->getParent()->clientPoke($this->getId(), $msg); 00145 } 00146 00147 /** 00148 * Bans the client from the server. Please note that this will create two separate 00149 * ban rules for the targeted clients IP address and his unique identifier. 00150 * 00151 * @param integer $timeseconds 00152 * @param string $reason 00153 * @return array 00154 */ 00155 public function ban($timeseconds = null, $reason = null) 00156 { 00157 return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason); 00158 } 00159 00160 /** 00161 * Returns a list of custom properties for the client. 00162 * 00163 * @return array 00164 */ 00165 public function customInfo() 00166 { 00167 return $this->getParent()->customInfo($this["client_database_id"]); 00168 } 00169 00170 /** 00171 * Returns an array containing the permission overview of the client. 00172 * 00173 * @param integer $cid 00174 * @return array 00175 */ 00176 public function permOverview($cid) 00177 { 00178 return $this->execute("permoverview", array("cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0))->toArray(); 00179 } 00180 00181 /** 00182 * Returns a list of permissions defined for the client. 00183 * 00184 * @param boolean $permsid 00185 * @return array 00186 */ 00187 public function permList($permsid = FALSE) 00188 { 00189 return $this->getParent()->clientPermList($this["client_database_id"], $permsid); 00190 } 00191 00192 /** 00193 * Adds a set of specified permissions to the client. Multiple permissions can be added by providing 00194 * the three parameters of each permission. 00195 * 00196 * @param integer $permid 00197 * @param integer $permvalue 00198 * @param integer $permskip 00199 * @return void 00200 */ 00201 public function permAssign($permid, $permvalue, $permskip = FALSE) 00202 { 00203 return $this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip); 00204 } 00205 00206 /** 00207 * Alias for permAssign(). 00208 * 00209 * @deprecated 00210 */ 00211 public function permAssignByName($permname, $permvalue, $permskip = FALSE) 00212 { 00213 return $this->permAssign($permname, $permvalue, $permskip); 00214 } 00215 00216 /** 00217 * Removes a set of specified permissions from a client. Multiple permissions can be removed at once. 00218 * 00219 * @param integer $permid 00220 * @return void 00221 */ 00222 public function permRemove($permid) 00223 { 00224 return $this->getParent()->clientPermRemove($this["client_database_id"], $permid); 00225 } 00226 00227 /** 00228 * Alias for permRemove(). 00229 * 00230 * @deprecated 00231 */ 00232 public function permRemoveByName($permname) 00233 { 00234 return $this->permRemove($permname); 00235 } 00236 00237 /** 00238 * Sets the channel group of a client to the ID specified. 00239 * 00240 * @param integer $cid 00241 * @param integer $cgid 00242 * @return void 00243 */ 00244 public function setChannelGroup($cid, $cgid) 00245 { 00246 return $this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid); 00247 } 00248 00249 /** 00250 * Adds the client to the server group specified with $sgid. 00251 * 00252 * @param integer $sgid 00253 * @return void 00254 */ 00255 public function addServerGroup($sgid) 00256 { 00257 return $this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]); 00258 } 00259 00260 /** 00261 * Removes the client from the server group specified with $sgid. 00262 * 00263 * @param integer $sgid 00264 * @return void 00265 */ 00266 public function remServerGroup($sgid) 00267 { 00268 return $this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]); 00269 } 00270 00271 /** 00272 * Returns the possible name of the clients avatar. 00273 * 00274 * @return TeamSpeak3_Helper_String 00275 */ 00276 public function avatarGetName() 00277 { 00278 return new TeamSpeak3_Helper_String("/avatar_" . $this["client_base64HashClientUID"]); 00279 } 00280 00281 /** 00282 * Downloads and returns the clients avatar file content. 00283 * 00284 * @return TeamSpeak3_Helper_String 00285 */ 00286 public function avatarDownload() 00287 { 00288 if($this["client_flag_avatar"] == 0) return; 00289 00290 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName()); 00291 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 00292 00293 return $transfer->download($download["ftkey"], $download["size"]); 00294 } 00295 00296 /** 00297 * Returns a list of client connections using the same identity as this client. 00298 * 00299 * @return array 00300 */ 00301 public function getClones() 00302 { 00303 return $this->execute("clientgetids", array("cluid" => $this["client_unique_identifier"]))->toAssocArray("clid"); 00304 } 00305 00306 /** 00307 * Returns the revision/build number from the clients version string. 00308 * 00309 * @return integer 00310 */ 00311 public function getRev() 00312 { 00313 return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits(); 00314 } 00315 00316 /** 00317 * Returns all server and channel groups the client is currently residing in. 00318 * 00319 * @return array 00320 */ 00321 public function memberOf() 00322 { 00323 $groups = array($this->getParent()->channelGroupGetById($this["client_channel_group_id"])); 00324 00325 foreach(explode(",", $this["client_servergroups"]) as $sgid) 00326 { 00327 $groups[] = $this->getParent()->serverGroupGetById($sgid); 00328 } 00329 00330 return $groups; 00331 } 00332 00333 /** 00334 * Downloads and returns the clients icon file content. 00335 * 00336 * @return TeamSpeak3_Helper_String 00337 */ 00338 public function iconDownload() 00339 { 00340 if($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) return; 00341 00342 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("client_icon_id")); 00343 $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); 00344 00345 return $transfer->download($download["ftkey"], $download["size"]); 00346 } 00347 00348 /** 00349 * @ignore 00350 */ 00351 protected function fetchNodeInfo() 00352 { 00353 if($this["client_type"] == 1) return; 00354 00355 $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("clientinfo", array("clid" => $this->getId()))->toList()); 00356 } 00357 00358 /** 00359 * Returns a unique identifier for the node which can be used as a HTML property. 00360 * 00361 * @return string 00362 */ 00363 public function getUniqueId() 00364 { 00365 return $this->getParent()->getUniqueId() . "_cl" . $this->getId(); 00366 } 00367 00368 /** 00369 * Returns the name of a possible icon to display the node object. 00370 * 00371 * @return string 00372 */ 00373 public function getIcon() 00374 { 00375 if($this["client_type"]) 00376 { 00377 return "client_query"; 00378 } 00379 elseif($this["client_away"]) 00380 { 00381 return "client_away"; 00382 } 00383 elseif(!$this["client_output_hardware"]) 00384 { 00385 return "client_snd_disabled"; 00386 } 00387 elseif($this["client_output_muted"]) 00388 { 00389 return "client_snd_muted"; 00390 } 00391 elseif(!$this["client_input_hardware"]) 00392 { 00393 return "client_mic_disabled"; 00394 } 00395 elseif($this["client_input_muted"]) 00396 { 00397 return "client_mic_muted"; 00398 } 00399 elseif($this["client_is_channel_commander"]) 00400 { 00401 return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle"; 00402 } 00403 else 00404 { 00405 return $this["client_flag_talking"] ? "client_talk" : "client_idle"; 00406 } 00407 } 00408 00409 /** 00410 * Returns a symbol representing the node. 00411 * 00412 * @return string 00413 */ 00414 public function getSymbol() 00415 { 00416 return "@"; 00417 } 00418 00419 /** 00420 * Returns a string representation of this node. 00421 * 00422 * @return string 00423 */ 00424 public function __toString() 00425 { 00426 return (string) $this["client_nickname"]; 00427 } 00428 } 00429