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