Client.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: Client.php 06/06/2016 22:27:13 scp@Svens-iMac $
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @package TeamSpeak3
  22. * @version 1.1.24
  23. * @author Sven 'ScP' Paulsen
  24. * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
  25. */
  26. /**
  27. * @class TeamSpeak3_Node_Client
  28. * @brief Class describing a TeamSpeak 3 client and all it's parameters.
  29. */
  30. class TeamSpeak3_Node_Client extends TeamSpeak3_Node_Abstract
  31. {
  32. /**
  33. * The TeamSpeak3_Node_Client constructor.
  34. *
  35. * @param TeamSpeak3_Node_Server $server
  36. * @param array $info
  37. * @param string $index
  38. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  39. * @return TeamSpeak3_Node_Client
  40. */
  41. public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "clid")
  42. {
  43. $this->parent = $server;
  44. $this->nodeInfo = $info;
  45. if(!array_key_exists($index, $this->nodeInfo))
  46. {
  47. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
  48. }
  49. $this->nodeId = $this->nodeInfo[$index];
  50. }
  51. /**
  52. * Changes the clients properties using given properties.
  53. *
  54. * @param array $properties
  55. * @return void
  56. */
  57. public function modify(array $properties)
  58. {
  59. $properties["clid"] = $this->getId();
  60. $this->execute("clientedit", $properties);
  61. $this->resetNodeInfo();
  62. }
  63. /**
  64. * Changes the clients properties using given properties.
  65. *
  66. * @param array $properties
  67. * @return void
  68. */
  69. public function modifyDb(array $properties)
  70. {
  71. $this->getParent()->clientModifyDb($this["client_database_id"], $properties);
  72. }
  73. /**
  74. * Deletes the clients properties from the database.
  75. *
  76. * @return void
  77. */
  78. public function deleteDb()
  79. {
  80. $this->getParent()->clientDeleteDb($this["client_database_id"]);
  81. }
  82. /**
  83. * Returns a list of properties from the database for the client.
  84. *
  85. * @return array
  86. */
  87. public function infoDb()
  88. {
  89. return $this->getParent()->clientInfoDb($this["client_database_id"]);
  90. }
  91. /**
  92. * Sends a text message to the client.
  93. *
  94. * @param string $msg
  95. * @return void
  96. */
  97. public function message($msg)
  98. {
  99. $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
  100. }
  101. /**
  102. * Moves the client to another channel.
  103. *
  104. * @param integer $cid
  105. * @param string $cpw
  106. * @return void
  107. */
  108. public function move($cid, $cpw = null)
  109. {
  110. $this->getParent()->clientMove($this->getId(), $cid, $cpw);
  111. }
  112. /**
  113. * Kicks the client from his currently joined channel or from the server.
  114. *
  115. * @param integer $reasonid
  116. * @param string $reasonmsg
  117. * @return void
  118. */
  119. public function kick($reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
  120. {
  121. $this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg);
  122. }
  123. /**
  124. * Sends a poke message to the client.
  125. *
  126. * @param string $msg
  127. * @return void
  128. */
  129. public function poke($msg)
  130. {
  131. $this->getParent()->clientPoke($this->getId(), $msg);
  132. }
  133. /**
  134. * Bans the client from the server. Please note that this will create two separate
  135. * ban rules for the targeted clients IP address and his unique identifier.
  136. *
  137. * @param integer $timeseconds
  138. * @param string $reason
  139. * @return array
  140. */
  141. public function ban($timeseconds = null, $reason = null)
  142. {
  143. return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason);
  144. }
  145. /**
  146. * Returns a list of custom properties for the client.
  147. *
  148. * @return array
  149. */
  150. public function customInfo()
  151. {
  152. return $this->getParent()->customInfo($this["client_database_id"]);
  153. }
  154. /**
  155. * Returns an array containing the permission overview of the client.
  156. *
  157. * @param integer $cid
  158. * @return array
  159. */
  160. public function permOverview($cid)
  161. {
  162. return $this->execute("permoverview", array("cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0))->toArray();
  163. }
  164. /**
  165. * Returns a list of permissions defined for the client.
  166. *
  167. * @param boolean $permsid
  168. * @return array
  169. */
  170. public function permList($permsid = FALSE)
  171. {
  172. return $this->getParent()->clientPermList($this["client_database_id"], $permsid);
  173. }
  174. /**
  175. * Adds a set of specified permissions to the client. Multiple permissions can be added by providing
  176. * the three parameters of each permission.
  177. *
  178. * @param integer $permid
  179. * @param integer $permvalue
  180. * @param integer $permskip
  181. * @return void
  182. */
  183. public function permAssign($permid, $permvalue, $permskip = FALSE)
  184. {
  185. $this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip);
  186. }
  187. /**
  188. * Alias for permAssign().
  189. *
  190. * @deprecated
  191. */
  192. public function permAssignByName($permname, $permvalue, $permskip = FALSE)
  193. {
  194. $this->permAssign($permname, $permvalue, $permskip);
  195. }
  196. /**
  197. * Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
  198. *
  199. * @param integer $permid
  200. * @return void
  201. */
  202. public function permRemove($permid)
  203. {
  204. $this->getParent()->clientPermRemove($this["client_database_id"], $permid);
  205. }
  206. /**
  207. * Alias for permRemove().
  208. *
  209. * @deprecated
  210. */
  211. public function permRemoveByName($permname)
  212. {
  213. $this->permRemove($permname);
  214. }
  215. /**
  216. * Sets the channel group of a client to the ID specified.
  217. *
  218. * @param integer $cid
  219. * @param integer $cgid
  220. * @return void
  221. */
  222. public function setChannelGroup($cid, $cgid)
  223. {
  224. $this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid);
  225. }
  226. /**
  227. * Adds the client to the server group specified with $sgid.
  228. *
  229. * @param integer $sgid
  230. * @return void
  231. */
  232. public function addServerGroup($sgid)
  233. {
  234. $this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]);
  235. }
  236. /**
  237. * Removes the client from the server group specified with $sgid.
  238. *
  239. * @param integer $sgid
  240. * @return void
  241. */
  242. public function remServerGroup($sgid)
  243. {
  244. $this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]);
  245. }
  246. /**
  247. * Returns the possible name of the clients avatar.
  248. *
  249. * @return TeamSpeak3_Helper_String
  250. */
  251. public function avatarGetName()
  252. {
  253. return new TeamSpeak3_Helper_String("/avatar_" . $this["client_base64HashClientUID"]);
  254. }
  255. /**
  256. * Downloads and returns the clients avatar file content.
  257. *
  258. * @return TeamSpeak3_Helper_String
  259. */
  260. public function avatarDownload()
  261. {
  262. if($this["client_flag_avatar"] == NULL) return;
  263. $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName());
  264. $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
  265. return $transfer->download($download["ftkey"], $download["size"]);
  266. }
  267. /**
  268. * Returns a list of client connections using the same identity as this client.
  269. *
  270. * @return array
  271. */
  272. public function getClones()
  273. {
  274. return $this->execute("clientgetids", array("cluid" => $this["client_unique_identifier"]))->toAssocArray("clid");
  275. }
  276. /**
  277. * Returns the revision/build number from the clients version string.
  278. *
  279. * @return integer
  280. */
  281. public function getRev()
  282. {
  283. return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits();
  284. }
  285. /**
  286. * Returns all server and channel groups the client is currently residing in.
  287. *
  288. * @return array
  289. */
  290. public function memberOf()
  291. {
  292. $groups = array($this->getParent()->channelGroupGetById($this["client_channel_group_id"]));
  293. foreach(explode(",", $this["client_servergroups"]) as $sgid)
  294. {
  295. $groups[] = $this->getParent()->serverGroupGetById($sgid);
  296. }
  297. return $groups;
  298. }
  299. /**
  300. * Downloads and returns the clients icon file content.
  301. *
  302. * @return TeamSpeak3_Helper_String
  303. */
  304. public function iconDownload()
  305. {
  306. if($this->iconIsLocal("client_icon_id") || $this["client_icon_id"] == 0) return;
  307. $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("client_icon_id"));
  308. $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
  309. return $transfer->download($download["ftkey"], $download["size"]);
  310. }
  311. /**
  312. * Sends a plugin command to the client.
  313. *
  314. * @param string $plugin
  315. * @param string $data
  316. * @return void
  317. */
  318. public function sendPluginCmd($plugin, $data)
  319. {
  320. $this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_CLIENT, "target" => $this->getId()));
  321. }
  322. /**
  323. * @ignore
  324. */
  325. protected function fetchNodeInfo()
  326. {
  327. if($this->offsetExists("client_type") && $this["client_type"] == 1) return;
  328. $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("clientinfo", array("clid" => $this->getId()))->toList());
  329. }
  330. /**
  331. * Returns a unique identifier for the node which can be used as a HTML property.
  332. *
  333. * @return string
  334. */
  335. public function getUniqueId()
  336. {
  337. return $this->getParent()->getUniqueId() . "_cl" . $this->getId();
  338. }
  339. /**
  340. * Returns the name of a possible icon to display the node object.
  341. *
  342. * @return string
  343. */
  344. public function getIcon()
  345. {
  346. if($this["client_type"])
  347. {
  348. return "client_query";
  349. }
  350. elseif($this["client_away"])
  351. {
  352. return "client_away";
  353. }
  354. elseif(!$this["client_output_hardware"])
  355. {
  356. return "client_snd_disabled";
  357. }
  358. elseif($this["client_output_muted"])
  359. {
  360. return "client_snd_muted";
  361. }
  362. elseif(!$this["client_input_hardware"])
  363. {
  364. return "client_mic_disabled";
  365. }
  366. elseif($this["client_input_muted"])
  367. {
  368. return "client_mic_muted";
  369. }
  370. elseif($this["client_is_channel_commander"])
  371. {
  372. return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle";
  373. }
  374. else
  375. {
  376. return $this["client_flag_talking"] ? "client_talk" : "client_idle";
  377. }
  378. }
  379. /**
  380. * Returns a symbol representing the node.
  381. *
  382. * @return string
  383. */
  384. public function getSymbol()
  385. {
  386. return "@";
  387. }
  388. /**
  389. * Returns a string representation of this node.
  390. *
  391. * @return string
  392. */
  393. public function __toString()
  394. {
  395. return (string) $this["client_nickname"];
  396. }
  397. }