TeamSpeak 3 PHP Framework  1.1.23
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Server.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Server.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_Server
30  * @brief Class describing a TeamSpeak 3 virtual server and all it's parameters.
31  */
33 {
34  /**
35  * @ignore
36  */
37  protected $channelList = null;
38 
39  /**
40  * @ignore
41  */
42  protected $clientList = null;
43 
44  /**
45  * @ignore
46  */
47  protected $sgroupList = null;
48 
49  /**
50  * @ignore
51  */
52  protected $cgroupList = null;
53 
54  /**
55  * The TeamSpeak3_Node_Server constructor.
56  *
57  * @param TeamSpeak3_Node_Host $host
58  * @param array $info
59  * @param string $index
60  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
61  * @return TeamSpeak3_Node_Server
62  */
63  public function __construct(TeamSpeak3_Node_Host $host, array $info, $index = "virtualserver_id")
64  {
65  $this->parent = $host;
66  $this->nodeInfo = $info;
67 
68  if(!array_key_exists($index, $this->nodeInfo))
69  {
70  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
71  }
72 
73  $this->nodeId = $this->nodeInfo[$index];
74  }
75 
76  /**
77  * Sends a prepared command to the server and returns the result.
78  *
79  * @param string $cmd
80  * @param boolean $throw
81  * @return TeamSpeak3_Adapter_ServerQuery_Reply
82  */
83  public function request($cmd, $throw = TRUE)
84  {
85  if($this->getId() != $this->getParent()->serverSelectedId())
86  {
87  $this->getParent()->serverSelect($this->getId());
88  }
89 
90  return $this->getParent()->request($cmd, $throw);
91  }
92 
93  /**
94  * Returns an array filled with TeamSpeak3_Node_Channel objects.
95  *
96  * @param array $filter
97  * @return array
98  */
99  public function channelList(array $filter = array())
100  {
101  if($this->channelList === null)
102  {
103  $channels = $this->request("channellist -topic -flags -voice -limits -icon")->toAssocArray("cid");
104 
105  $this->channelList = array();
106 
107  foreach($channels as $cid => $channel)
108  {
109  $this->channelList[$cid] = new TeamSpeak3_Node_Channel($this, $channel);
110  }
111 
112  $this->resetNodeList();
113  }
114 
115  return $this->filterList($this->channelList, $filter);
116  }
117 
118  /**
119  * Resets the list of channels online.
120  *
121  * @return void
122  */
123  public function channelListReset()
124  {
125  $this->resetNodeList();
126  $this->channelList = null;
127  }
128 
129  /**
130  * Creates a new channel using given properties and returns the new ID.
131  *
132  * @param array $properties
133  * @return integer
134  */
135  public function channelCreate(array $properties)
136  {
137  $cid = $this->execute("channelcreate", $properties)->toList();
138  $this->channelListReset();
139 
140  if(!isset($properties["client_flag_permanent"]) && !isset($properties["client_flag_semi_permanent"]))
141  {
142  $this->getParent()->whoamiSet("client_channel_id", $cid["cid"]);
143  }
144 
145  return $cid["cid"];
146  }
147 
148  /**
149  * Deletes the channel specified by $cid.
150  *
151  * @param integer $cid
152  * @param boolean $force
153  * @return void
154  */
155  public function channelDelete($cid, $force = FALSE)
156  {
157  $this->execute("channeldelete", array("cid" => $cid, "force" => $force));
158  $this->channelListReset();
159 
160  if(($cid instanceof TeamSpeak3_Node_Abstract ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id"))
161  {
162  $this->getParent()->whoamiReset();
163  }
164  }
165 
166  /**
167  * Moves the channel specified by $cid to the parent channel specified with $pid.
168  *
169  * @param integer $cid
170  * @param integer $pid
171  * @param integer $order
172  * @return void
173  */
174  public function channelMove($cid, $pid, $order = null)
175  {
176  $this->execute("channelmove", array("cid" => $cid, "cpid" => $pid, "order" => $order));
177  $this->channelListReset();
178  }
179 
180  /**
181  * Returns TRUE if the given TeamSpeak3_Node_Channel object is a spacer.
182  *
183  * @param TeamSpeak3_Node_Channel $channel
184  * @return boolean
185  */
186  public function channelIsSpacer(TeamSpeak3_Node_Channel $channel)
187  {
188  return (preg_match("/\[[^\]]*spacer[^\]]*\]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"]) ? TRUE : FALSE;
189  }
190 
191  /**
192  * Creates a new channel spacer and returns the new ID. The first parameter $ident is used to create a
193  * unique spacer name on the virtual server.
194  *
195  * @param string $ident
196  * @param mixed $type
197  * @param integer $align
198  * @param integer $order
199  * @param integer $maxclients
200  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
201  * @return integer
202  */
203  public function channelSpacerCreate($ident, $type = TeamSpeak3::SPACER_SOLIDLINE, $align = TeamSpeak3::SPACER_ALIGN_REPEAT, $order = null, $maxclients = 0)
204  {
205  $properties = array(
206  "channel_name_phonetic" => "channel spacer",
207  "channel_codec" => TeamSpeak3::CODEC_OPUS_VOICE,
208  "channel_codec_quality" => 0x00,
209  "channel_flag_permanent" => TRUE,
210  "channel_flag_maxclients_unlimited" => FALSE,
211  "channel_flag_maxfamilyclients_unlimited" => FALSE,
212  "channel_flag_maxfamilyclients_inherited" => FALSE,
213  "channel_maxclients" => $maxclients,
214  "channel_order" => $order,
215  );
216 
217  switch($align)
218  {
220  $properties["channel_name"] = "[*spacer" . strval($ident) . "]";
221  break;
222 
224  $properties["channel_name"] = "[lspacer" . strval($ident) . "]";
225  break;
226 
228  $properties["channel_name"] = "[rspacer" . strval($ident) . "]";
229  break;
230 
232  $properties["channel_name"] = "[cspacer" . strval($ident) . "]";
233  break;
234 
235  default:
236  throw new TeamSpeak3_Adapter_ServerQuery_Exception("missing required parameter", 0x606);
237  break;
238  }
239 
240  switch($type)
241  {
242  case (string) TeamSpeak3::SPACER_SOLIDLINE:
243  $properties["channel_name"] .= "___";
244  break;
245 
246  case (string) TeamSpeak3::SPACER_DASHLINE:
247  $properties["channel_name"] .= "---";
248  break;
249 
250  case (string) TeamSpeak3::SPACER_DOTLINE:
251  $properties["channel_name"] .= "...";
252  break;
253 
254  case (string) TeamSpeak3::SPACER_DASHDOTLINE:
255  $properties["channel_name"] .= "-.-";
256  break;
257 
258  case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE:
259  $properties["channel_name"] .= "-..";
260  break;
261 
262  default:
263  $properties["channel_name"] .= strval($type);
264  break;
265  }
266 
267  return $this->channelCreate($properties);
268  }
269 
270  /**
271  * Returns the possible type of a channel spacer.
272  *
273  * @param integer $cid
274  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
275  * @return integer
276  */
277  public function channelSpacerGetType($cid)
278  {
279  $channel = $this->channelGetById($cid);
280 
281  if(!$this->channelIsSpacer($channel))
282  {
283  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
284  }
285 
286  switch($channel["channel_name"]->section("]", 1))
287  {
288  case "___":
290 
291  case "---":
293 
294  case "...":
296 
297  case "-.-":
299 
300  case "-..":
302 
303  default:
305  }
306  }
307 
308  /**
309  * Returns the possible alignment of a channel spacer.
310  *
311  * @param integer $cid
312  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
313  * @return integer
314  */
315  public function channelSpacerGetAlign($cid)
316  {
317  $channel = $this->channelGetById($cid);
318 
319  if(!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*\]/", $channel, $matches) || !isset($matches[1]))
320  {
321  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
322  }
323 
324  switch($matches[1])
325  {
326  case "*":
328 
329  case "c":
331 
332  case "r":
334 
335  default:
337  }
338  }
339 
340  /**
341  * Returns a list of permissions defined for a specific channel.
342  *
343  * @param integer $cid
344  * @param boolean $permsid
345  * @return array
346  */
347  public function channelPermList($cid, $permsid = FALSE)
348  {
349  return $this->execute("channelpermlist", array("cid" => $cid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
350  }
351 
352  /**
353  * Adds a set of specified permissions to a channel. Multiple permissions can be added by
354  * providing the two parameters of each permission.
355  *
356  * @param integer $cid
357  * @param integer $permid
358  * @param integer $permvalue
359  * @return void
360  */
361  public function channelPermAssign($cid, $permid, $permvalue)
362  {
363  if(!is_array($permid))
364  {
365  $permident = (is_numeric($permid)) ? "permid" : "permsid";
366  }
367  else
368  {
369  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
370  }
371 
372  $this->execute("channeladdperm", array("cid" => $cid, $permident => $permid, "permvalue" => $permvalue));
373  }
374 
375  /**
376  * Removes a set of specified permissions from a channel. Multiple permissions can be removed at once.
377  *
378  * @param integer $cid
379  * @param integer $permid
380  * @return void
381  */
382  public function channelPermRemove($cid, $permid)
383  {
384  if(!is_array($permid))
385  {
386  $permident = (is_numeric($permid)) ? "permid" : "permsid";
387  }
388  else
389  {
390  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
391  }
392 
393  $this->execute("channeldelperm", array("cid" => $cid, $permident => $permid));
394  }
395 
396  /**
397  * Returns a list of permissions defined for a client in a specific channel.
398  *
399  * @param integer $cid
400  * @param integer $cldbid
401  * @param boolean $permsid
402  * @return array
403  */
404  public function channelClientPermList($cid, $cldbid, $permsid = FALSE)
405  {
406  return $this->execute("channelclientpermlist", array("cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
407  }
408 
409  /**
410  * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by
411  * providing the two parameters of each permission.
412  *
413  * @param integer $cid
414  * @param integer $cldbid
415  * @param integer $permid
416  * @param integer $permvalue
417  * @return void
418  */
419  public function channelClientPermAssign($cid, $cldbid, $permid, $permvalue)
420  {
421  if(!is_array($permid))
422  {
423  $permident = (is_numeric($permid)) ? "permid" : "permsid";
424  }
425  else
426  {
427  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
428  }
429 
430  $this->execute("channelclientaddperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue));
431  }
432 
433  /**
434  * Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once.
435  *
436  * @param integer $cid
437  * @param integer $cldbid
438  * @param integer $permid
439  * @return void
440  */
441  public function channelClientPermRemove($cid, $cldbid, $permid)
442  {
443  if(!is_array($permid))
444  {
445  $permident = (is_numeric($permid)) ? "permid" : "permsid";
446  }
447  else
448  {
449  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
450  }
451 
452  $this->execute("channelclientdelperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid));
453  }
454 
455  /**
456  * Returns a list of files and directories stored in the specified channels file repository.
457  *
458  * @param integer $cid
459  * @param string $cpw
460  * @param string $path
461  * @param boolean $recursive
462  * @return array
463  */
464  public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
465  {
466  $files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
467  $count = count($files);
468 
469  for($i = 0; $i < $count; $i++)
470  {
471  $files[$i]["sid"] = $this->getId();
472  $files[$i]["cid"] = $files[0]["cid"];
473  $files[$i]["path"] = $files[0]["path"];
474  $files[$i]["src"] = new TeamSpeak3_Helper_String($cid ? $files[$i]["path"] : "/");
475 
476  if(!$files[$i]["src"]->endsWith("/"))
477  {
478  $files[$i]["src"]->append("/");
479  }
480 
481  $files[$i]["src"]->append($files[$i]["name"]);
482 
483  if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
484  {
485  $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
486  }
487  }
488 
489  uasort($files, array(__CLASS__, "sortFileList"));
490 
491  return $files;
492  }
493 
494  /**
495  * Returns detailed information about the specified file stored in a channels file repository.
496  *
497  * @param integer $cid
498  * @param string $cpw
499  * @param string $name
500  * @return array
501  */
502  public function channelFileInfo($cid, $cpw = "", $name = "/")
503  {
504  return array_pop($this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray());
505  }
506 
507  /**
508  * Renames a file in a channels file repository. If the two parameters $tcid and $tcpw are specified, the file
509  * will be moved into another channels file repository.
510  *
511  * @param integer $cid
512  * @param string $cpw
513  * @param string $oldname
514  * @param string $newname
515  * @param integer $tcid
516  * @param string $tcpw
517  * @return void
518  */
519  public function channelFileRename($cid, $cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null)
520  {
521  $this->execute("ftrenamefile", array("cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw));
522  }
523 
524  /**
525  * Deletes one or more files stored in a channels file repository.
526  *
527  * @param integer $cid
528  * @param string $cpw
529  * @param string $name
530  * @return void
531  */
532  public function channelFileDelete($cid, $cpw = "", $name = "/")
533  {
534  $this->execute("ftdeletefile", array("cid" => $cid, "cpw" => $cpw, "name" => $name));
535  }
536 
537  /**
538  * Creates new directory in a channels file repository.
539  *
540  * @param integer $cid
541  * @param string $cpw
542  * @param string $dirname
543  * @return void
544  */
545  public function channelDirCreate($cid, $cpw = "", $dirname = "/")
546  {
547  $this->execute("ftcreatedir", array("cid" => $cid, "cpw" => $cpw, "dirname" => $dirname));
548  }
549 
550  /**
551  * Returns the level of a channel.
552  *
553  * @param integer $cid
554  * @return integer
555  */
556  public function channelGetLevel($cid)
557  {
558  $channel = $this->channelGetById($cid);
559  $levelno = 0;
560 
561  if($channel["pid"])
562  {
563  $levelno = $this->channelGetLevel($channel["pid"])+1;
564  }
565 
566  return $levelno;
567  }
568 
569  /**
570  * Returns the pathway of a channel which can be used as a clients default channel.
571  *
572  * @param integer $cid
573  * @return string
574  */
575  public function channelGetPathway($cid)
576  {
577  $channel = $this->channelGetById($cid);
578  $pathway = $channel["channel_name"];
579 
580  if($channel["pid"])
581  {
582  $pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"];
583  }
584 
585  return $pathway;
586  }
587 
588  /**
589  * Returns the TeamSpeak3_Node_Channel object matching the given ID.
590  *
591  * @param integer $cid
592  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
593  * @return TeamSpeak3_Node_Channel
594  */
595  public function channelGetById($cid)
596  {
597  if(!array_key_exists((string) $cid, $this->channelList()))
598  {
599  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
600  }
601 
602  return $this->channelList[intval((string) $cid)];
603  }
604 
605  /**
606  * Returns the TeamSpeak3_Node_Channel object matching the given name.
607  *
608  * @param string $name
609  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
610  * @return TeamSpeak3_Node_Channel
611  */
612  public function channelGetByName($name)
613  {
614  foreach($this->channelList() as $channel)
615  {
616  if($channel["channel_name"] == $name) return $channel;
617  }
618 
619  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
620  }
621 
622  /**
623  * Returns an array filled with TeamSpeak3_Node_Client objects.
624  *
625  * @param array $filter
626  * @return array
627  */
628  public function clientList(array $filter = array())
629  {
630  if($this->clientList === null)
631  {
632  $clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
633 
634  $this->clientList = array();
635 
636  foreach($clients as $clid => $client)
637  {
638  if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
639 
640  $this->clientList[$clid] = new TeamSpeak3_Node_Client($this, $client);
641  }
642 
643  uasort($this->clientList, array(__CLASS__, "sortClientList"));
644 
645  $this->resetNodeList();
646  }
647 
648  return $this->filterList($this->clientList, $filter);
649  }
650 
651  /**
652  * Resets the list of clients online.
653  *
654  * @return void
655  */
656  public function clientListReset()
657  {
658  $this->resetNodeList();
659  $this->clientList = null;
660  }
661 
662  /**
663  * Returns a list of clients matching a given name pattern.
664  *
665  * @param string $pattern
666  * @return array
667  */
668  public function clientFind($pattern)
669  {
670  return $this->execute("clientfind", array("pattern" => $pattern))->toAssocArray("clid");
671  }
672 
673  /**
674  * Returns a list of client identities known by the virtual server. By default, the server spits out 25 entries
675  * at once.
676  *
677  * @param integer $offset
678  * @param integer $limit
679  * @return array
680  */
681  public function clientListDb($offset = null, $limit = null)
682  {
683  return $this->execute("clientdblist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("cldbid");
684  }
685 
686  /**
687  * Returns the number of client identities known by the virtual server.
688  *
689  * @return integer
690  */
691  public function clientCountDb()
692  {
693  return current($this->execute("clientdblist -count", array("duration" => 1))->toList("count"));
694  }
695 
696  /**
697  * Returns a list of properties from the database for the client specified by $cldbid.
698  *
699  * @param integer $cldbid
700  * @return array
701  */
702  public function clientInfoDb($cldbid)
703  {
704  return $this->execute("clientdbinfo", array("cldbid" => $cldbid))->toList();
705  }
706 
707  /**
708  * Returns a list of client database IDs matching a given pattern. You can either search for a clients
709  * last known nickname or his unique identity by using the $uid option.
710  *
711  * @param string $pattern
712  * @param boolean $uid
713  * @return array
714  */
715  public function clientFindDb($pattern, $uid = FALSE)
716  {
717  return array_keys($this->execute("clientdbfind", array("pattern" => $pattern, ($uid) ? "-uid" : null))->toAssocArray("cldbid"));
718  }
719 
720  /**
721  * Returns the number of regular clients online.
722  *
723  * @return integer
724  */
725  public function clientCount()
726  {
727  if($this->isOffline()) return 0;
728 
729  return $this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"];
730  }
731 
732  /**
733  * Returns the TeamSpeak3_Node_Client object matching the given ID.
734  *
735  * @param integer $clid
736  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
737  * @return TeamSpeak3_Node_Client
738  */
739  public function clientGetById($clid)
740  {
741  if(!array_key_exists((string) $clid, $this->clientList()))
742  {
743  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
744  }
745 
746  return $this->clientList[intval((string) $clid)];
747  }
748 
749  /**
750  * Returns the TeamSpeak3_Node_Client object matching the given name.
751  *
752  * @param string $name
753  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
754  * @return TeamSpeak3_Node_Client
755  */
756  public function clientGetByName($name)
757  {
758  foreach($this->clientList() as $client)
759  {
760  if($client["client_nickname"] == $name) return $client;
761  }
762 
763  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
764  }
765 
766  /**
767  * Returns the TeamSpeak3_Node_Client object matching the given unique identifier.
768  *
769  * @param string $uid
770  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
771  * @return TeamSpeak3_Node_Client
772  */
773  public function clientGetByUid($uid)
774  {
775  foreach($this->clientList() as $client)
776  {
777  if($client["client_unique_identifier"] == $uid) return $client;
778  }
779 
780  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
781  }
782 
783  /**
784  * Returns the TeamSpeak3_Node_Client object matching the given database ID.
785  *
786  * @param integer $dbid
787  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
788  * @return TeamSpeak3_Node_Client
789  */
790  public function clientGetByDbid($dbid)
791  {
792  foreach($this->clientList() as $client)
793  {
794  if($client["client_database_id"] == $dbid) return $client;
795  }
796 
797  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
798  }
799 
800  /**
801  * Returns an array containing the last known nickname and the database ID of the client matching
802  * the unique identifier specified with $cluid.
803  *
804  * @param string $cluid
805  * @return array
806  */
807  public function clientGetNameByUid($cluid)
808  {
809  return $this->execute("clientgetnamefromuid", array("cluid" => $cluid))->toList();
810  }
811 
812  /**
813  * Returns an array containing a list of active client connections using the unique identifier
814  * specified with $cluid.
815  *
816  * @param string $cluid
817  * @return array
818  */
819  public function clientGetIdsByUid($cluid)
820  {
821  return $this->execute("clientgetids", array("cluid" => $cluid))->toAssocArray("clid");
822  }
823 
824  /**
825  * Returns an array containing the last known nickname and the unique identifier of the client
826  * matching the database ID specified with $cldbid.
827  *
828  * @param string $cldbid
829  * @return array
830  */
831  public function clientGetNameByDbid($cldbid)
832  {
833  return $this->execute("clientgetnamefromdbid", array("cldbid" => $cldbid))->toList();
834  }
835 
836  /**
837  * Returns an array containing the names and IDs of all server groups the client specified with
838  * $cldbid is is currently residing in.
839  *
840  * @param string $cldbid
841  * @return array
842  */
843  public function clientGetServerGroupsByDbid($cldbid)
844  {
845  return $this->execute("servergroupsbyclientid", array("cldbid" => $cldbid))->toAssocArray("sgid");
846  }
847 
848  /**
849  * Moves a client to another channel.
850  *
851  * @param integer $clid
852  * @param integer $cid
853  * @param string $cpw
854  * @return void
855  */
856  public function clientMove($clid, $cid, $cpw = null)
857  {
858  $this->clientListReset();
859 
860  $this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
861 
862  if($clid instanceof TeamSpeak3_Node_Abstract)
863  {
864  $clid = $clid->getId();
865  }
866 
867  if($cid instanceof TeamSpeak3_Node_Abstract)
868  {
869  $cid = $cid->getId();
870  }
871 
872  if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
873  {
874  $this->getParent()->whoamiSet("client_channel_id", $cid);
875  }
876  }
877 
878  /**
879  * Kicks one or more clients from their currently joined channel or from the server.
880  *
881  * @param integer $clid
882  * @param integer $reasonid
883  * @param string $reasonmsg
884  * @return void
885  */
886  public function clientKick($clid, $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
887  {
888  $this->clientListReset();
889 
890  $this->execute("clientkick", array("clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg));
891  }
892 
893  /**
894  * Sends a poke message to a client.
895  *
896  * @param integer $clid
897  * @param string $msg
898  * @return void
899  */
900  public function clientPoke($clid, $msg)
901  {
902  $this->execute("clientpoke", array("clid" => $clid, "msg" => $msg));
903  }
904 
905  /**
906  * Bans the client specified with ID $clid from the server. Please note that this will create two separate
907  * ban rules for the targeted clients IP address and his unique identifier.
908  *
909  * @param integer $clid
910  * @param integer $timeseconds
911  * @param string $reason
912  * @return array
913  */
914  public function clientBan($clid, $timeseconds = null, $reason = null)
915  {
916  $this->clientListReset();
917 
918  $bans = $this->execute("banclient", array("clid" => $clid, "time" => $timeseconds, "banreason" => $reason))->toAssocArray("banid");
919 
920  return array_keys($bans);
921  }
922 
923  /**
924  * Changes the clients properties using given properties.
925  *
926  * @param string $cldbid
927  * @param array $properties
928  * @return void
929  */
930  public function clientModifyDb($cldbid, array $properties)
931  {
932  $properties["cldbid"] = $cldbid;
933 
934  $this->execute("clientdbedit", $properties);
935  }
936 
937  /**
938  * Deletes a clients properties from the database.
939  *
940  * @param string $cldbid
941  * @return void
942  */
943  public function clientDeleteDb($cldbid)
944  {
945  $this->execute("clientdbdelete", array("cldbid" => $cldbid));
946  }
947 
948  /**
949  * Sets the channel group of a client to the ID specified.
950  *
951  * @param integer $cldbid
952  * @param integer $cid
953  * @param integer $cgid
954  * @return void
955  */
956  public function clientSetChannelGroup($cldbid, $cid, $cgid)
957  {
958  $this->execute("setclientchannelgroup", array("cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid));
959  }
960 
961  /**
962  * Returns a list of permissions defined for a client.
963  *
964  * @param integer $cldbid
965  * @param boolean $permsid
966  * @return array
967  */
968  public function clientPermList($cldbid, $permsid = FALSE)
969  {
970  $this->clientListReset();
971 
972  return $this->execute("clientpermlist", array("cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
973  }
974 
975  /**
976  * Adds a set of specified permissions to a client. Multiple permissions can be added by providing
977  * the three parameters of each permission.
978  *
979  * @param integer $cldbid
980  * @param integer $permid
981  * @param integer $permvalue
982  * @param integer $permskip
983  * @return void
984  */
985  public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE)
986  {
987  if(!is_array($permid))
988  {
989  $permident = (is_numeric($permid)) ? "permid" : "permsid";
990  }
991  else
992  {
993  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
994  }
995 
996  $this->execute("clientaddperm", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
997  }
998 
999  /**
1000  * Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
1001  *
1002  * @param integer $cldbid
1003  * @param integer $permid
1004  * @return void
1005  */
1006  public function clientPermRemove($cldbid, $permid)
1007  {
1008  if(!is_array($permid))
1009  {
1010  $permident = (is_numeric($permid)) ? "permid" : "permsid";
1011  }
1012  else
1013  {
1014  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1015  }
1016 
1017  $this->execute("clientdelperm", array("cldbid" => $cldbid, $permident => $permid));
1018  }
1019 
1020  /**
1021  * Returns a list of server groups available.
1022  *
1023  * @param filter $filter
1024  * @return array
1025  */
1026  public function serverGroupList(array $filter = array())
1027  {
1028  if($this->sgroupList === null)
1029  {
1030  $this->sgroupList = $this->request("servergrouplist")->toAssocArray("sgid");
1031 
1032  foreach($this->sgroupList as $sgid => $group)
1033  {
1034  $this->sgroupList[$sgid] = new TeamSpeak3_Node_Servergroup($this, $group);
1035  }
1036 
1037  uasort($this->sgroupList, array(__CLASS__, "sortGroupList"));
1038  }
1039 
1040  return $this->filterList($this->sgroupList, $filter);
1041  }
1042 
1043  /**
1044  * Resets the list of server groups.
1045  *
1046  * @return void
1047  */
1048  public function serverGroupListReset()
1049  {
1050  $this->sgroupList = null;
1051  }
1052 
1053  /**
1054  * Creates a new server group using the name specified with $name and returns its ID.
1055  *
1056  * @param string $name
1057  * @param integer $type
1058  * @return integer
1059  */
1060  public function serverGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
1061  {
1062  $this->serverGroupListReset();
1063 
1064  $sgid = $this->execute("servergroupadd", array("name" => $name, "type" => $type))->toList();
1065 
1066  return $sgid["sgid"];
1067  }
1068 
1069  /**
1070  * Creates a copy of an existing server group specified by $ssgid and returns the new groups ID.
1071  *
1072  * @param integer $ssgid
1073  * @param string $name
1074  * @param integer $tsgid
1075  * @param integer $type
1076  * @return integer
1077  */
1078  public function serverGroupCopy($ssgid, $name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
1079  {
1080  $this->serverGroupListReset();
1081 
1082  $sgid = $this->execute("servergroupcopy", array("ssgid" => $ssgid, "tsgid" => $tsgid, "name" => $name, "type" => $type))->toList();
1083 
1084  if($tsgid && $name)
1085  {
1086  $this->serverGroupRename($tsgid, $name);
1087  }
1088 
1089  return count($sgid) ? $sgid["sgid"] : intval($tsgid);
1090  }
1091 
1092  /**
1093  * Renames the server group specified with $sgid.
1094  *
1095  * @param integer $sgid
1096  * @param string $name
1097  * @return void
1098  */
1099  public function serverGroupRename($sgid, $name)
1100  {
1101  $this->serverGroupListReset();
1102 
1103  $this->execute("servergrouprename", array("sgid" => $sgid, "name" => $name));
1104  }
1105 
1106  /**
1107  * Deletes the server group specified with $sgid. If $force is set to 1, the server group
1108  * will be deleted even if there are clients within.
1109  *
1110  * @param integer $sgid
1111  * @param boolean $force
1112  * @return void
1113  */
1114  public function serverGroupDelete($sgid, $force = FALSE)
1115  {
1116  $this->serverGroupListReset();
1117 
1118  $this->execute("servergroupdel", array("sgid" => $sgid, "force" => $force));
1119  }
1120 
1121  /**
1122  * Returns the TeamSpeak3_Node_Servergroup object matching the given ID.
1123  *
1124  * @param integer $sgid
1125  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1126  * @return TeamSpeak3_Node_Servergroup
1127  */
1128  public function serverGroupGetById($sgid)
1129  {
1130  if(!array_key_exists((string) $sgid, $this->serverGroupList()))
1131  {
1132  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
1133  }
1134 
1135  return $this->sgroupList[intval((string) $sgid)];
1136  }
1137 
1138  /**
1139  * Returns the TeamSpeak3_Node_Servergroup object matching the given name.
1140  *
1141  * @param string $name
1142  * @param integer $type
1143  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1144  * @return TeamSpeak3_Node_Servergroup
1145  */
1147  {
1148  foreach($this->serverGroupList() as $group)
1149  {
1150  if($group["name"] == $name && $group["type"] == $type) return $group;
1151  }
1152 
1153  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
1154  }
1155 
1156  /**
1157  * Returns a list of permissions assigned to the server group specified.
1158  *
1159  * @param integer $sgid
1160  * @param boolean $permsid
1161  * @return array
1162  */
1163  public function serverGroupPermList($sgid, $permsid = FALSE)
1164  {
1165  return $this->execute("servergrouppermlist", array("sgid" => $sgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
1166  }
1167 
1168  /**
1169  * Adds a set of specified permissions to the server group specified. Multiple permissions
1170  * can be added by providing the four parameters of each permission in separate arrays.
1171  *
1172  * @param integer $sgid
1173  * @param integer $permid
1174  * @param integer $permvalue
1175  * @param integer $permnegated
1176  * @param integer $permskip
1177  * @return void
1178  */
1179  public function serverGroupPermAssign($sgid, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
1180  {
1181  if(!is_array($permid))
1182  {
1183  $permident = (is_numeric($permid)) ? "permid" : "permsid";
1184  }
1185  else
1186  {
1187  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1188  }
1189 
1190  $this->execute("servergroupaddperm", array("sgid" => $sgid, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip));
1191  }
1192 
1193  /**
1194  * Removes a set of specified permissions from the server group specified with $sgid. Multiple
1195  * permissions can be removed at once.
1196  *
1197  * @param integer $sgid
1198  * @param integer $permid
1199  * @return void
1200  */
1201  public function serverGroupPermRemove($sgid, $permid)
1202  {
1203  if(!is_array($permid))
1204  {
1205  $permident = (is_numeric($permid)) ? "permid" : "permsid";
1206  }
1207  else
1208  {
1209  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1210  }
1211 
1212  $this->execute("servergroupdelperm", array("sgid" => $sgid, $permident => $permid));
1213  }
1214 
1215  /**
1216  * Returns a list of clients assigned to the server group specified.
1217  *
1218  * @param integer $sgid
1219  * @return array
1220  */
1221  public function serverGroupClientList($sgid)
1222  {
1223  if($this["virtualserver_default_server_group"] == $sgid)
1224  {
1225  return array();
1226  }
1227 
1228  return $this->execute("servergroupclientlist", array("sgid" => $sgid, "-names"))->toAssocArray("cldbid");
1229  }
1230 
1231  /**
1232  * Adds a client to the server group specified. Please note that a client cannot be
1233  * added to default groups or template groups.
1234  *
1235  * @param integer $sgid
1236  * @param integer $cldbid
1237  * @return void
1238  */
1239  public function serverGroupClientAdd($sgid, $cldbid)
1240  {
1241  $this->clientListReset();
1242 
1243  $this->execute("servergroupaddclient", array("sgid" => $sgid, "cldbid" => $cldbid));
1244  }
1245 
1246  /**
1247  * Removes a client from the server group specified.
1248  *
1249  * @param integer $sgid
1250  * @param integer $cldbid
1251  * @return void
1252  */
1253  public function serverGroupClientDel($sgid, $cldbid)
1254  {
1255  $this->execute("servergroupdelclient", array("sgid" => $sgid, "cldbid" => $cldbid));
1256  }
1257 
1258  /**
1259  * Returns an ordered array of regular server groups available based on a pre-defined
1260  * set of rules.
1261  *
1262  * @return array
1263  */
1264  public function serverGroupGetProfiles()
1265  {
1266  $profiles = array();
1267 
1268  foreach($this->serverGroupList() as $sgid => $sgroup)
1269  {
1270  if($sgroup["type"] != TeamSpeak3::GROUP_DBTYPE_REGULAR) continue;
1271 
1272  $profiles[$sgid] = array(
1273  "b_permission_modify_power_ignore" => 0,
1274  "i_group_needed_member_add_power" => 0,
1275  "i_group_member_add_power" => 0,
1276  "i_group_needed_member_remove_power" => 0,
1277  "i_group_member_remove_power" => 0,
1278  "i_needed_modify_power_count" => 0,
1279  "i_needed_modify_power_total" => 0,
1280  "i_permission_modify_power" => 0,
1281  "i_group_needed_modify_power" => 0,
1282  "i_group_modify_power" => 0,
1283  "i_client_needed_modify_power" => 0,
1284  "i_client_modify_power" => 0,
1285  "b_virtualserver_servergroup_create" => 0,
1286  "b_virtualserver_servergroup_delete" => 0,
1287  "b_client_ignore_bans" => 0,
1288  "b_client_ignore_antiflood" => 0,
1289  "b_group_is_permanent" => 0,
1290  "i_client_needed_ban_power" => 0,
1291  "i_client_needed_kick_power" => 0,
1292  "i_client_needed_move_power" => 0,
1293  "i_client_talk_power" => 0,
1294  "__sgid" => $sgid,
1295  "__name" => $sgroup->toString(),
1296  "__node" => $sgroup,
1297  );
1298 
1299  try
1300  {
1301  $perms = $this->serverGroupPermList($sgid, TRUE);
1302  $grant = isset($perms["i_permission_modify_power"]) ? $perms["i_permission_modify_power"]["permvalue"] : null;
1303  }
1305  {
1306  /* ERROR_database_empty_result */
1307  if($e->getCode() != 0x501) throw $e;
1308 
1309  $perms = array();
1310  $grant = null;
1311  }
1312 
1313  foreach($perms as $permsid => $perm)
1314  {
1315  if(in_array($permsid, array_keys($profiles[$sgid])))
1316  {
1317  $profiles[$sgid][$permsid] = $perm["permvalue"];
1318  }
1319  elseif(TeamSpeak3_Helper_String::factory($permsid)->startsWith("i_needed_modify_power_"))
1320  {
1321  if(!$grant || $perm["permvalue"] > $grant) continue;
1322 
1323  $profiles[$sgid]["i_needed_modify_power_total"] = $profiles[$sgid]["i_needed_modify_power_total"]+$perm["permvalue"];
1324  $profiles[$sgid]["i_needed_modify_power_count"]++;
1325  }
1326  }
1327  }
1328 
1329  array_multisort($profiles, SORT_DESC);
1330 
1331  return $profiles;
1332  }
1333 
1334  /**
1335  * Tries to identify the post powerful/weakest server group on the virtual server and returns
1336  * the ID.
1337  *
1338  * @param integer $mode
1339  * @return TeamSpeak3_Node_Servergroup
1340  */
1342  {
1343  $profiles = $this->serverGroupGetProfiles();
1344 
1345  $best_guess_profile = ($mode == TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) ? array_shift($profiles) : array_pop($profiles);
1346 
1347  return $this->serverGroupGetById($best_guess_profile["__sgid"]);
1348  }
1349 
1350  /**
1351  * Returns a list of channel groups available.
1352  *
1353  * @param array $filter
1354  * @return array
1355  */
1356  public function channelGroupList(array $filter = array())
1357  {
1358  if($this->cgroupList === null)
1359  {
1360  $this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
1361 
1362  foreach($this->cgroupList as $cgid => $group)
1363  {
1364  $this->cgroupList[$cgid] = new TeamSpeak3_Node_Channelgroup($this, $group);
1365  }
1366 
1367  uasort($this->cgroupList, array(__CLASS__, "sortGroupList"));
1368  }
1369 
1370  return $this->filterList($this->cgroupList, $filter);
1371  }
1372 
1373  /**
1374  * Resets the list of channel groups.
1375  *
1376  * @return void
1377  */
1378  public function channelGroupListReset()
1379  {
1380  $this->cgroupList = null;
1381  }
1382 
1383  /**
1384  * Creates a new channel group using the name specified with $name and returns its ID.
1385  *
1386  * @param string $name
1387  * @param integer $type
1388  * @return integer
1389  */
1391  {
1392  $this->channelGroupListReset();
1393 
1394  $cgid = $this->execute("channelgroupadd", array("name" => $name, "type" => $type))->toList();
1395 
1396  return $cgid["cgid"];
1397  }
1398 
1399  /**
1400  * Creates a copy of an existing channel group specified by $scgid and returns the new groups ID.
1401  *
1402  * @param integer $scgid
1403  * @param string $name
1404  * @param integer $tcgid
1405  * @param integer $type
1406  * @return integer
1407  */
1408  public function channelGroupCopy($scgid, $name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
1409  {
1410  $this->channelGroupListReset();
1411 
1412  $cgid = $this->execute("channelgroupcopy", array("scgid" => $scgid, "tcgid" => $tcgid, "name" => $name, "type" => $type))->toList();
1413 
1414  if($tcgid && $name)
1415  {
1416  $this->channelGroupRename($tcgid, $name);
1417  }
1418 
1419  return count($cgid) ? $cgid["cgid"] : intval($tcgid);
1420  }
1421 
1422  /**
1423  * Renames the channel group specified with $cgid.
1424  *
1425  * @param integer $cgid
1426  * @param string $name
1427  * @return void
1428  */
1429  public function channelGroupRename($cgid, $name)
1430  {
1431  $this->channelGroupListReset();
1432 
1433  $this->execute("channelgrouprename", array("cgid" => $cgid, "name" => $name));
1434  }
1435 
1436  /**
1437  * Deletes the channel group specified with $cgid. If $force is set to 1, the channel group
1438  * will be deleted even if there are clients within.
1439  *
1440  * @param integer $sgid
1441  * @param boolean $force
1442  * @return void
1443  */
1444  public function channelGroupDelete($cgid, $force = FALSE)
1445  {
1446  $this->channelGroupListReset();
1447 
1448  $this->execute("channelgroupdel", array("cgid" => $cgid, "force" => $force));
1449  }
1450 
1451  /**
1452  * Returns the TeamSpeak3_Node_Channelgroup object matching the given ID.
1453  *
1454  * @param integer $cgid
1455  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1456  * @return TeamSpeak3_Node_Channelgroup
1457  */
1458  public function channelGroupGetById($cgid)
1459  {
1460  if(!array_key_exists((string) $cgid, $this->channelGroupList()))
1461  {
1462  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
1463  }
1464 
1465  return $this->cgroupList[intval((string) $cgid)];
1466  }
1467 
1468  /**
1469  * Returns the TeamSpeak3_Node_Channelgroup object matching the given name.
1470  *
1471  * @param string $name
1472  * @param integer $type
1473  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1474  * @return TeamSpeak3_Node_Channelgroup
1475  */
1477  {
1478  foreach($this->channelGroupList() as $group)
1479  {
1480  if($group["name"] == $name && $group["type"] == $type) return $group;
1481  }
1482 
1483  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
1484  }
1485 
1486  /**
1487  * Returns a list of permissions assigned to the channel group specified.
1488  *
1489  * @param integer $cgid
1490  * @param boolean $permsid
1491  * @return array
1492  */
1493  public function channelGroupPermList($cgid, $permsid = FALSE)
1494  {
1495  return $this->execute("channelgrouppermlist", array("cgid" => $cgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
1496  }
1497 
1498  /**
1499  * Adds a set of specified permissions to the channel group specified. Multiple permissions
1500  * can be added by providing the two parameters of each permission in separate arrays.
1501  *
1502  * @param integer $cgid
1503  * @param integer $permid
1504  * @param integer $permvalue
1505  * @return void
1506  */
1507  public function channelGroupPermAssign($cgid, $permid, $permvalue)
1508  {
1509  if(!is_array($permid))
1510  {
1511  $permident = (is_numeric($permid)) ? "permid" : "permsid";
1512  }
1513  else
1514  {
1515  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1516  }
1517 
1518  $this->execute("channelgroupaddperm", array("cgid" => $cgid, $permident => $permid, "permvalue" => $permvalue));
1519  }
1520 
1521  /**
1522  * Removes a set of specified permissions from the channel group specified with $cgid. Multiple
1523  * permissions can be removed at once.
1524  *
1525  * @param integer $cgid
1526  * @param integer $permid
1527  * @return void
1528  */
1529  public function channelGroupPermRemove($cgid, $permid)
1530  {
1531  if(!is_array($permid))
1532  {
1533  $permident = (is_numeric($permid)) ? "permid" : "permsid";
1534  }
1535  else
1536  {
1537  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1538  }
1539 
1540  $this->execute("channelgroupdelperm", array("cgid" => $cgid, $permident => $permid));
1541  }
1542 
1543  /**
1544  * Returns all the client and/or channel IDs currently assigned to channel groups. All three
1545  * parameters are optional so you're free to choose the most suitable combination for your
1546  * requirements.
1547  *
1548  * @param integer $cgid
1549  * @param integer $cid
1550  * @param integer $cldbid
1551  * @return array
1552  */
1553  public function channelGroupClientList($cgid = null, $cid = null, $cldbid = null)
1554  {
1555  if($this["virtualserver_default_channel_group"] == $cgid)
1556  {
1557  return array();
1558  }
1559 
1560  return $this->execute("channelgroupclientlist", array("cgid" => $cgid, "cid" => $cid, "cldbid" => $cldbid))->toArray();
1561  }
1562 
1563  /**
1564  * Restores the default permission settings on the virtual server and returns a new initial
1565  * administrator privilege key.
1566  *
1567  * @return TeamSpeak3_Helper_String
1568  */
1569  public function permReset()
1570  {
1571  $token = $this->request("permreset")->toList();
1572 
1573  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
1574 
1575  return $token["token"];
1576  }
1577 
1578  /**
1579  * Removes any assignment of the permission specified with $permid on the selected virtual server
1580  * and returns the number of removed assignments on success.
1581  *
1582  * @param integer $permid
1583  * @return integer
1584  */
1585  public function permRemoveAny($permid)
1586  {
1587  $assignments = $this->permissionFind($permid);
1588 
1589  foreach($assignments as $assignment)
1590  {
1591  switch($assignment["t"])
1592  {
1594  $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
1595  break;
1596 
1598  $this->clientPermRemove($assignment["id2"], $assignment["p"]);
1599  break;
1600 
1602  $this->channelPermRemove($assignment["id2"], $assignment["p"]);
1603  break;
1604 
1606  $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]);
1607  break;
1608 
1610  $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]);
1611  break;
1612 
1613  default:
1614  throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
1615  }
1616  }
1617 
1618  return count($assignments);
1619  }
1620 
1621  /**
1622  * Initializes a file transfer upload. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
1623  *
1624  * @param integer $clientftfid
1625  * @param integer $cid
1626  * @param string $name
1627  * @param integer $size
1628  * @param string $cpw
1629  * @param boolean $overwrite
1630  * @param boolean $resume
1631  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1632  * @return array
1633  */
1634  public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE)
1635  {
1636  $upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList();
1637 
1638  if(array_key_exists("status", $upload) && $upload["status"] != 0x00)
1639  {
1640  throw new TeamSpeak3_Adapter_ServerQuery_Exception($upload["msg"], $upload["status"]);
1641  }
1642 
1643  $upload["cid"] = $cid;
1644  $upload["file"] = $name;
1645 
1646  if(!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0"))
1647  {
1648  $upload["ip"] = $this->getParent()->getAdapterHost();
1649  $upload["host"] = $upload["ip"];
1650  }
1651  else
1652  {
1653  $upload["ip"] = $upload["ip"]->section(",");
1654  $upload["host"] = $upload["ip"];
1655  }
1656 
1657  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload);
1658 
1659  return $upload;
1660  }
1661 
1662  /**
1663  * Initializes a file transfer download. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
1664  *
1665  * @param integer $clientftfid
1666  * @param integer $cid
1667  * @param string $name
1668  * @param string $cpw
1669  * @param integer $seekpos
1670  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
1671  * @return array
1672  */
1673  public function transferInitDownload($clientftfid, $cid, $name, $cpw = "", $seekpos = 0)
1674  {
1675  $download = $this->execute("ftinitdownload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "seekpos" => $seekpos))->toList();
1676 
1677  if(array_key_exists("status", $download) && $download["status"] != 0x00)
1678  {
1679  throw new TeamSpeak3_Adapter_ServerQuery_Exception($download["msg"], $download["status"]);
1680  }
1681 
1682  $download["cid"] = $cid;
1683  $download["file"] = $name;
1684 
1685  if(!array_key_exists("ip", $download) || $download["ip"]->startsWith("0.0.0.0"))
1686  {
1687  $download["ip"] = $this->getParent()->getAdapterHost();
1688  $download["host"] = $download["ip"];
1689  }
1690  else
1691  {
1692  $download["ip"] = $download["ip"]->section(",");
1693  $download["host"] = $download["ip"];
1694  }
1695 
1696  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadInit", $download["ftkey"], $download);
1697 
1698  return $download;
1699  }
1700 
1701  /**
1702  * Displays a list of running file transfers on the selected virtual server. The output contains the path to
1703  * which a file is uploaded to, the current transfer rate in bytes per second, etc.
1704  *
1705  * @return array
1706  */
1707  public function transferList()
1708  {
1709  return $this->request("ftlist")->toAssocArray("serverftfid");
1710  }
1711 
1712  /**
1713  * Stops the running file transfer with server-side ID $serverftfid.
1714  *
1715  * @param integer $serverftfid
1716  * @param boolean $delete
1717  * @return void
1718  */
1719  public function transferStop($serverftfid, $delete = FALSE)
1720  {
1721  $this->execute("ftstop", array("serverftfid" => $serverftfid, "delete" => $delete));
1722  }
1723 
1724  /**
1725  * Downloads and returns the servers icon file content.
1726  *
1727  * @return TeamSpeak3_Helper_String
1728  */
1729  public function iconDownload()
1730  {
1731  if($this->iconIsLocal("virtualserver_icon_id") || $this["virtualserver_icon_id"] == 0) return;
1732 
1733  $download = $this->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("virtualserver_icon_id"));
1734  $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]);
1735 
1736  return $transfer->download($download["ftkey"], $download["size"]);
1737  }
1738 
1739  /**
1740  * Uploads a given icon file content to the server and returns the ID of the icon.
1741  *
1742  * @param string $data
1743  * @return integer
1744  */
1745  public function iconUpload($data)
1746  {
1747  $crc = crc32($data);
1748  $size = strlen($data);
1749 
1750  $upload = $this->transferInitUpload(rand(0x0000, 0xFFFF), 0, "/icon_" . $crc, $size);
1751  $transfer = TeamSpeak3::factory("filetransfer://" . $upload["host"] . ":" . $upload["port"]);
1752 
1753  $transfer->upload($upload["ftkey"], $upload["seekpos"], $data);
1754 
1755  return $crc;
1756  }
1757 
1758  /**
1759  * Changes the virtual server configuration using given properties.
1760  *
1761  * @param array $properties
1762  * @return void
1763  */
1764  public function modify(array $properties)
1765  {
1766  $this->execute("serveredit", $properties);
1767  $this->resetNodeInfo();
1768  }
1769 
1770  /**
1771  * Sends a text message to all clients on the virtual server.
1772  *
1773  * @param string $msg
1774  * @return void
1775  */
1776  public function message($msg)
1777  {
1778  $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_SERVER));
1779  }
1780 
1781  /**
1782  * Returns a list of offline messages you've received. The output contains the senders unique identifier,
1783  * the messages subject, etc.
1784  *
1785  * @return array
1786  */
1787  public function messageList()
1788  {
1789  return $this->request("messagelist")->toAssocArray("msgid");
1790  }
1791 
1792  /**
1793  * Sends an offline message to the client specified by $cluid.
1794  *
1795  * @param string $cluid
1796  * @param string $subject
1797  * @param string $message
1798  * @return void
1799  */
1800  public function messageCreate($cluid, $subject, $message)
1801  {
1802  $this->execute("messageadd", array("cluid" => $cluid, "subject" => $subject, "message" => $message));
1803  }
1804 
1805  /**
1806  * Deletes an existing offline message with ID $msgid from your inbox.
1807  *
1808  * @param integer $msgid
1809  * @return void
1810  */
1811  public function messageDelete($msgid)
1812  {
1813  $this->execute("messagedel", array("msgid" => $msgid));
1814  }
1815 
1816  /**
1817  * Returns an existing offline message with ID $msgid from your inbox.
1818  *
1819  * @param integer $msgid
1820  * @param boolean $flag_read
1821  * @return array
1822  */
1823  public function messageRead($msgid, $flag_read = TRUE)
1824  {
1825  $msg = $this->execute("messageget", array("msgid" => $msgid))->toList();
1826 
1827  if($flag_read)
1828  {
1829  $this->execute("messageget", array("msgid" => $msgid, "flag" => $flag_read));
1830  }
1831 
1832  return $msg;
1833  }
1834 
1835  /**
1836  * Creates and returns snapshot data for the selected virtual server.
1837  *
1838  * @param string $mode
1839  * @return string
1840  */
1842  {
1843  $snapshot = $this->request("serversnapshotcreate")->toString(FALSE);
1844 
1845  switch($mode)
1846  {
1848  return $snapshot->toBase64();
1849  break;
1850 
1852  return $snapshot->toHex();
1853  break;
1854 
1855  default:
1856  return (string) $snapshot;
1857  break;
1858  }
1859  }
1860 
1861  /**
1862  * Deploys snapshot data on the selected virtual server. If no virtual server is selected (ID 0),
1863  * the data will be used to create a new virtual server from scratch.
1864  *
1865  * @param string $data
1866  * @param string $mode
1867  * @return array
1868  */
1869  public function snapshotDeploy($data, $mode = TeamSpeak3::SNAPSHOT_STRING)
1870  {
1871  switch($mode)
1872  {
1874  $data = TeamSpeak3_Helper_String::fromBase64($data);
1875  break;
1876 
1878  $data = TeamSpeak3_Helper_String::fromHex($data);
1879  break;
1880 
1881  default:
1882  $data = TeamSpeak3_Helper_String::factory($data);
1883  break;
1884  }
1885 
1886  $detail = $this->request("serversnapshotdeploy " . $data)->toList();
1887 
1888  if(array_key_exists("sid", $detail))
1889  {
1890  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail["sid"]);
1891  }
1892 
1893  return $detail;
1894  }
1895 
1896  /**
1897  * Registers for a specified category of events on a virtual server to receive notification
1898  * messages. Depending on the notifications you've registered for, the server will send you
1899  * a message on every event.
1900  *
1901  * @param string $event
1902  * @param integer $id
1903  * @return void
1904  */
1905  public function notifyRegister($event, $id = 0)
1906  {
1907  $this->execute("servernotifyregister", array("event" => $event, "id" => $id));
1908  }
1909 
1910  /**
1911  * Unregisters all events previously registered with servernotifyregister so you will no
1912  * longer receive notification messages.
1913  *
1914  * @return void
1915  */
1916  public function notifyUnregister()
1917  {
1918  $this->request("servernotifyunregister");
1919  }
1920 
1921  /**
1922  * Alias for privilegeKeyList().
1923  *
1924  * @deprecated
1925  */
1926  public function tokenList($translate = FALSE)
1927  {
1928  return $this->privilegeKeyList();
1929  }
1930 
1931  /**
1932  * Returns a list of privilege keys (tokens) available. If $resolve is set to TRUE the values
1933  * of token_id1 and token_id2 will be translated into the appropriate group and/or channel
1934  * names.
1935  *
1936  * @param boolean $resolve
1937  * @return array
1938  */
1939  public function privilegeKeyList($resolve = FALSE)
1940  {
1941  $tokens = $this->request("privilegekeylist")->toAssocArray("token");
1942 
1943  if($resolve)
1944  {
1945  foreach($tokens as $token => $array)
1946  {
1947  $func = $array["token_type"] ? "channelGroupGetById" : "serverGroupGetById";
1948 
1949  try
1950  {
1951  $tokens[$token]["token_id1"] = $this->$func($array["token_id1"])->name;
1952  }
1953  catch(Exception $e)
1954  {
1955  /* ERROR_channel_invalid_id */
1956  if($e->getCode() != 0xA00) throw $e;
1957  }
1958 
1959  try
1960  {
1961  if($array["token_type"]) $tokens[$token]["token_id2"] = $this->channelGetById($array["token_id2"])->getPathway();
1962  }
1963  catch(Exception $e)
1964  {
1965  /* ERROR_permission_invalid_group_id */
1966  if($e->getCode() != 0x300) throw $e;
1967  }
1968  }
1969  }
1970 
1971  return $tokens;
1972  }
1973 
1974  /**
1975  * Alias for privilegeKeyCreate().
1976  *
1977  * @deprecated
1978  */
1979  public function tokenCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
1980  {
1981  return $this->privilegeKeyCreate($type, $id1, $id2, $description, $customset);
1982  }
1983 
1984  /**
1985  * Creates a new privilege key (token) and returns the key.
1986  *
1987  * @param integer $type
1988  * @param integer $id1
1989  * @param integer $id2
1990  * @param string $description
1991  * @param string $customset
1992  * @return TeamSpeak3_Helper_String
1993  */
1994  public function privilegeKeyCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
1995  {
1996  $token = $this->execute("privilegekeyadd", array("tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset))->toList();
1997 
1998  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
1999 
2000  return $token["token"];
2001  }
2002 
2003  /**
2004  * Alias for privilegeKeyDelete().
2005  *
2006  * @deprecated
2007  */
2008  public function tokenDelete($token)
2009  {
2010  $this->privilegeKeyDelete($token);
2011  }
2012 
2013  /**
2014  * Deletes a token specified by key $token.
2015  *
2016  * @param string $token
2017  * @return void
2018  */
2019  public function privilegeKeyDelete($token)
2020  {
2021  $this->execute("privilegekeydelete", array("token" => $token));
2022  }
2023 
2024  /**
2025  * Alias for privilegeKeyUse().
2026  *
2027  * @deprecated
2028  */
2029  public function tokenUse($token)
2030  {
2031  $this->privilegeKeyUse($token);
2032  }
2033 
2034  /**
2035  * Use a token key gain access to a server or channel group. Please note that the server will
2036  * automatically delete the token after it has been used.
2037  *
2038  * @param string $token
2039  * @return void
2040  */
2041  public function privilegeKeyUse($token)
2042  {
2043  $this->execute("privilegekeyuse", array("token" => $token));
2044  }
2045 
2046  /**
2047  * Returns a list of custom client properties specified by $ident.
2048  *
2049  * @param string $ident
2050  * @param string $pattern
2051  * @return array
2052  */
2053  public function customSearch($ident, $pattern = "%")
2054  {
2055  return $this->execute("customsearch", array("ident" => $ident, "pattern" => $pattern))->toArray();
2056  }
2057 
2058  /**
2059  * Returns a list of custom properties for the client specified by $cldbid.
2060  *
2061  * @param integer $cldbid
2062  * @return array
2063  */
2064  public function customInfo($cldbid)
2065  {
2066  return $this->execute("custominfo", array("cldbid" => $cldbid))->toArray();
2067  }
2068 
2069  /**
2070  * Returns a list of active bans on the selected virtual server.
2071  *
2072  * @return array
2073  */
2074  public function banList()
2075  {
2076  return $this->request("banlist")->toAssocArray("banid");
2077  }
2078 
2079  /**
2080  * Deletes all active ban rules from the server.
2081  *
2082  * @return void
2083  */
2084  public function banListClear()
2085  {
2086  $this->request("bandelall");
2087  }
2088 
2089  /**
2090  * Adds a new ban rule on the selected virtual server. All parameters are optional but at least one
2091  * of the following rules must be set: ip, name, or uid.
2092  *
2093  * @param array $rules
2094  * @param integer $timeseconds
2095  * @param string $reason
2096  * @return integer
2097  */
2098  public function banCreate(array $rules, $timeseconds = null, $reason = null)
2099  {
2100  $rules["time"] = $timeseconds;
2101  $rules["banreason"] = $reason;
2102 
2103  $banid = $this->execute("banadd", $rules)->toList();
2104 
2105  return $banid["banid"];
2106  }
2107 
2108  /**
2109  * Deletes the specified ban rule from the server.
2110  *
2111  * @param integer $banid
2112  * @return void
2113  */
2114  public function banDelete($banid)
2115  {
2116  $this->execute("bandel", array("banid" => $banid));
2117  }
2118 
2119  /**
2120  * Returns a list of complaints on the selected virtual server. If $tcldbid is specified, only
2121  * complaints about the targeted client will be shown.
2122  *
2123  * @param integer $tcldbid
2124  * @return array
2125  */
2126  public function complaintList($tcldbid = null)
2127  {
2128  return $this->execute("complainlist", array("tcldbid" => $tcldbid))->toArray();
2129  }
2130 
2131  /**
2132  * Deletes all active complaints about the client with database ID $tcldbid from the server.
2133  *
2134  * @param integer $tcldbid
2135  * @return void
2136  */
2137  public function complaintListClear($tcldbid)
2138  {
2139  $this->execute("complaindelall", array("tcldbid" => $tcldbid));
2140  }
2141 
2142  /**
2143  * Submits a complaint about the client with database ID $tcldbid to the server.
2144  *
2145  * @param integer $tcldbid
2146  * @param string $message
2147  * @return void
2148  */
2149  public function complaintCreate($tcldbid, $message)
2150  {
2151  $this->execute("complainadd", array("tcldbid" => $tcldbid, "message" => $message));
2152  }
2153 
2154  /**
2155  * Deletes the complaint about the client with ID $tcldbid submitted by the client with ID $fcldbid from the server.
2156  *
2157  * @param integer $tcldbid
2158  * @param integer $fcldbid
2159  * @return void
2160  */
2161  public function complaintDelete($tcldbid, $fcldbid)
2162  {
2163  $this->execute("complaindel", array("tcldbid" => $tcldbid, "fcldbid" => $fcldbid));
2164  }
2165 
2166  /**
2167  * Returns a list of temporary server passwords.
2168  *
2169  * @param boolean $resolve
2170  * @return array
2171  */
2172  public function tempPasswordList($resolve = FALSE)
2173  {
2174  $passwords = $this->request("servertemppasswordlist")->toAssocArray("pw_clear");
2175 
2176  if($resolve)
2177  {
2178  foreach($passwords as $password => $array)
2179  {
2180  try
2181  {
2182  $channel = $this->channelGetById($array["tcid"]);
2183 
2184  $passwords[$password]["tcname"] = $channel->toString();
2185  $passwords[$password]["tcpath"] = $channel->getPathway();
2186  }
2187  catch(Exception $e)
2188  {
2189  /* ERROR_channel_invalid_id */
2190  if($e->getCode() != 0xA00) throw $e;
2191  }
2192  }
2193  }
2194 
2195  return $passwords;
2196  }
2197 
2198  /**
2199  * Sets a new temporary server password specified with $pw. The temporary password will be
2200  * valid for the number of seconds specified with $duration. The client connecting with this
2201  * password will automatically join the channel specified with $tcid. If tcid is set to 0,
2202  * the client will join the default channel.
2203  *
2204  * @param string $pw
2205  * @param integer $duration
2206  * @param integer $tcid
2207  * @param string $tcpw
2208  * @param string $desc
2209  * @return void
2210  */
2211  public function tempPasswordCreate($pw, $duration, $tcid = 0, $tcpw = "", $desc = "")
2212  {
2213  $this->execute("servertemppasswordadd", array("pw" => $pw, "duration" => $duration, "tcid" => $tcid, "tcpw" => $tcpw, "desc" => $desc));
2214  }
2215 
2216  /**
2217  * Deletes the temporary server password specified with $pw.
2218  *
2219  * @param string $pw
2220  * @return void
2221  */
2222  public function tempPasswordDelete($pw)
2223  {
2224  $this->execute("servertemppassworddel", array("pw" => $pw));
2225  }
2226 
2227  /**
2228  * Displays a specified number of entries (1-100) from the servers log.
2229  *
2230  * @param integer $lines
2231  * @param integer $begin_pos
2232  * @param boolean $reverse
2233  * @param boolean $instance
2234  * @return array
2235  */
2236  public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = null)
2237  {
2238  return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray();
2239  }
2240 
2241  /**
2242  * Writes a custom entry into the virtual server log.
2243  *
2244  * @param string $logmsg
2245  * @param integer $loglevel
2246  * @return void
2247  */
2248  public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO)
2249  {
2250  $this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel));
2251  }
2252 
2253  /**
2254  * Returns detailed connection information of the virtual server.
2255  *
2256  * @return array
2257  */
2258  public function connectionInfo()
2259  {
2260  return $this->request("serverrequestconnectioninfo")->toList();
2261  }
2262 
2263  /**
2264  * Deletes the virtual server.
2265  *
2266  * @return void
2267  */
2268  public function delete()
2269  {
2270  $this->getParent()->serverDelete($this->getId());
2271 
2272  unset($this);
2273  }
2274 
2275  /**
2276  * Starts the virtual server.
2277  *
2278  * @return void
2279  */
2280  public function start()
2281  {
2282  $this->getParent()->serverStart($this->getId());
2283  }
2284 
2285  /**
2286  * Stops the virtual server.
2287  *
2288  * @return void
2289  */
2290  public function stop()
2291  {
2292  $this->getParent()->serverStop($this->getId());
2293  }
2294 
2295  /**
2296  * Sends a plugin command to all clients connected to the server.
2297  *
2298  * @param string $plugin
2299  * @param string $data
2300  * @return void
2301  */
2302  public function sendPluginCmd($plugin, $data)
2303  {
2304  $this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_SERVER));
2305  }
2306 
2307  /**
2308  * Changes the properties of your own client connection.
2309  *
2310  * @param array $properties
2311  * @return void
2312  */
2313  public function selfUpdate(array $properties)
2314  {
2315  $this->execute("clientupdate", $properties);
2316 
2317  foreach($properties as $ident => $value)
2318  {
2319  $this->whoamiSet($ident, $value);
2320  }
2321  }
2322 
2323  /**
2324  * Updates your own ServerQuery login credentials using a specified username. The password
2325  * will be auto-generated.
2326  *
2327  * @param string $username
2328  * @return TeamSpeak3_Helper_String
2329  */
2330  public function selfUpdateLogin($username)
2331  {
2332  $password = $this->execute("clientsetserverquerylogin", array("client_login_name" => $username))->toList();
2333 
2334  return $password["client_login_password"];
2335  }
2336 
2337  /**
2338  * Returns an array containing the permission overview of your own client.
2339  *
2340  * @return array
2341  */
2342  public function selfPermOverview()
2343  {
2344  return $this->execute("permoverview", array("cldbid" => $this->whoamiGet("client_database_id"), "cid" => $this->whoamiGet("client_channel_id"), "permid" => 0))->toArray();
2345  }
2346 
2347  /**
2348  * @ignore
2349  */
2350  protected function fetchNodeList()
2351  {
2352  $this->nodeList = array();
2353 
2354  foreach($this->channelList() as $channel)
2355  {
2356  if($channel["pid"] == 0)
2357  {
2358  $this->nodeList[] = $channel;
2359  }
2360  }
2361  }
2362 
2363  /**
2364  * @ignore
2365  */
2366  protected function fetchNodeInfo()
2367  {
2368  $this->nodeInfo = array_merge($this->nodeInfo, $this->request("serverinfo")->toList());
2369  }
2370 
2371  /**
2372  * Internal callback funtion for sorting of client objects.
2373  *
2374  * @param TeamSpeak3_Node_Client $a
2375  * @param TeamSpeak3_Node_Client $b
2376  * @return integer
2377  */
2379  {
2380  if(get_class($a) != get_class($b))
2381  {
2382  return 0;
2383 
2384  /* workaround for PHP bug #50688 */
2385  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
2386  }
2387 
2388  if(!$a instanceof TeamSpeak3_Node_Client)
2389  {
2390  return 0;
2391 
2392  /* workaround for PHP bug #50688 */
2393  throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
2394  }
2395 
2396  if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0))
2397  {
2398  return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1;
2399  }
2400 
2401  if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0))
2402  {
2403  return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1;
2404  }
2405 
2406  return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"]));
2407  }
2408 
2409  /**
2410  * Internal callback funtion for sorting of group objects.
2411  *
2412  * @param TeamSpeak3_Node_Abstract $a
2413  * @param TeamSpeak3_Node_Abstract $b
2414  * @return integer
2415  */
2417  {
2418  if(get_class($a) != get_class($b))
2419  {
2420  return 0;
2421 
2422  /* workaround for PHP bug #50688 */
2423  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
2424  }
2425 
2426  if(!$a instanceof TeamSpeak3_Node_Servergroup && !$a instanceof TeamSpeak3_Node_Channelgroup)
2427  {
2428  return 0;
2429 
2430  /* workaround for PHP bug #50688 */
2431  throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
2432  }
2433 
2434  if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0)
2435  {
2436  return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1;
2437  }
2438 
2439  return ($a->getId() < $b->getId()) ? -1 : 1;
2440  }
2441 
2442 /**
2443  * Internal callback funtion for sorting of file list items.
2444  *
2445  * @param array $a
2446  * @param array $b
2447  * @return integer
2448  */
2449  protected static function sortFileList(array $a, array $b)
2450  {
2451  if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b))
2452  {
2453  return 0;
2454 
2455  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
2456  }
2457 
2458  if($a["type"] != $b["type"])
2459  {
2460  return ($a["type"] < $b["type"]) ? -1 : 1;
2461  }
2462 
2463  return strcmp(strtolower($a["src"]), strtolower($b["src"]));
2464  }
2465 
2466  /**
2467  * Returns TRUE if the virtual server is online.
2468  *
2469  * @return boolean
2470  */
2471  public function isOnline()
2472  {
2473  return ($this["virtualserver_status"] == "online") ? TRUE : FALSE;
2474  }
2475 
2476  /**
2477  * Returns TRUE if the virtual server is offline.
2478  *
2479  * @return boolean
2480  */
2481  public function isOffline()
2482  {
2483  return ($this["virtualserver_status"] == "offline") ? TRUE : FALSE;
2484  }
2485 
2486  /**
2487  * Returns a unique identifier for the node which can be used as a HTML property.
2488  *
2489  * @return string
2490  */
2491  public function getUniqueId()
2492  {
2493  return $this->getParent()->getUniqueId() . "_s" . $this->getId();
2494  }
2495 
2496  /**
2497  * Returns the name of a possible icon to display the node object.
2498  *
2499  * @return string
2500  */
2501  public function getIcon()
2502  {
2503  if($this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"] >= $this["virtualserver_maxclients"])
2504  {
2505  return "server_full";
2506  }
2507  elseif($this["virtualserver_flag_password"])
2508  {
2509  return "server_pass";
2510  }
2511  else
2512  {
2513  return "server_open";
2514  }
2515  }
2516 
2517  /**
2518  * Returns a symbol representing the node.
2519  *
2520  * @return string
2521  */
2522  public function getSymbol()
2523  {
2524  return "$";
2525  }
2526 
2527  /**
2528  * Returns a string representation of this node.
2529  *
2530  * @return string
2531  */
2532  public function __toString()
2533  {
2534  return (string) $this["virtualserver_name"];
2535  }
2536 }