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