TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Host.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Host.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_Host
30  * @brief Class describing a TeamSpeak 3 server instance and all it's parameters.
31  */
33 {
34  /**
35  * @ignore
36  */
37  protected $whoami = null;
38 
39  /**
40  * @ignore
41  */
42  protected $version = null;
43 
44  /**
45  * @ignore
46  */
47  protected $serverList = null;
48 
49  /**
50  * @ignore
51  */
52  protected $permissionList = null;
53 
54  /**
55  * @ignore
56  */
57  protected $predefined_query_name = null;
58 
59  /**
60  * @ignore
61  */
62  protected $exclude_query_clients = FALSE;
63 
64  /**
65  * @ignore
66  */
67  protected $start_offline_virtual = FALSE;
68 
69  /**
70  * @ignore
71  */
72  protected $sort_clients_channels = FALSE;
73 
74  /**
75  * The TeamSpeak3_Node_Host constructor.
76  *
77  * @param TeamSpeak3_Adapter_ServerQuery $squery
78  * @return TeamSpeak3_Node_Host
79  */
81  {
82  $this->parent = $squery;
83  }
84 
85  /**
86  * Returns the primary ID of the selected virtual server.
87  *
88  * @return integer
89  */
90  public function serverSelectedId()
91  {
92  return $this->whoamiGet("virtualserver_id", 0);
93  }
94 
95  /**
96  * Returns the primary UDP port of the selected virtual server.
97  *
98  * @return integer
99  */
100  public function serverSelectedPort()
101  {
102  return $this->whoamiGet("virtualserver_port", 0);
103  }
104 
105  /**
106  * Returns the servers version information including platform and build number.
107  *
108  * @param string $ident
109  * @return mixed
110  */
111  public function version($ident = null)
112  {
113  if($this->version === null)
114  {
115  $this->version = $this->request("version")->toList();
116  }
117 
118  return ($ident && array_key_exists($ident, $this->version)) ? $this->version[$ident] : $this->version;
119  }
120 
121  /**
122  * Selects a virtual server by ID to allow further interaction.
123  *
124  * @param integer $sid
125  * @param boolean $virtual
126  * @return void
127  */
128  public function serverSelect($sid, $virtual = null)
129  {
130  if($this->whoami !== null && $this->serverSelectedId() == $sid) return;
131 
132  $virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual;
133  $getargs = func_get_args();
134 
135  $this->execute("use", array("sid" => $sid, $virtual ? "-virtual" : null));
136 
137  if($sid != 0 && $this->predefined_query_name !== null)
138  {
139  $this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name));
140  }
141 
142  $this->whoamiReset();
143 
144  $this->setStorage("_server_use", array(__FUNCTION__, $getargs));
145 
146  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this);
147  }
148 
149  /**
150  * Alias for serverSelect().
151  *
152  * @param integer $sid
153  * @param boolean $virtual
154  * @return void
155  */
156  public function serverSelectById($sid, $virtual = null)
157  {
158  $this->serverSelect($sid, $virtual);
159  }
160 
161  /**
162  * Selects a virtual server by UDP port to allow further interaction.
163  *
164  * @param integer $port
165  * @param boolean $virtual
166  * @return void
167  */
168  public function serverSelectByPort($port, $virtual = null)
169  {
170  if($this->whoami !== null && $this->serverSelectedPort() == $port) return;
171 
172  $virtual = ($virtual !== null) ? $virtual : $this->start_offline_virtual;
173  $getargs = func_get_args();
174 
175  $this->execute("use", array("port" => $port, $virtual ? "-virtual" : null));
176 
177  if($port != 0 && $this->predefined_query_name !== null)
178  {
179  $this->execute("clientupdate", array("client_nickname" => (string) $this->predefined_query_name));
180  }
181 
182  $this->whoamiReset();
183 
184  $this->setStorage("_server_use", array(__FUNCTION__, $getargs));
185 
186  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerselected", $this);
187  }
188 
189  /**
190  * Deselects the active virtual server.
191  *
192  * @return void
193  */
194  public function serverDeselect()
195  {
196  $this->serverSelect(0);
197 
198  $this->delStorage("_server_use");
199  }
200 
201  /**
202  * Returns the ID of a virtual server matching the given port.
203  *
204  * @param integer $port
205  * @return integer
206  */
207  public function serverIdGetByPort($port)
208  {
209  $sid = $this->execute("serveridgetbyport", array("virtualserver_port" => $port))->toList();
210 
211  return $sid["server_id"];
212  }
213 
214  /**
215  * Returns the port of a virtual server matching the given ID.
216  *
217  * @param integer $sid
218  * @return integer
219  */
220  public function serverGetPortById($sid)
221  {
222  if(!array_key_exists((string) $sid, $this->serverList()))
223  {
224  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
225  }
226 
227  return $this->serverList[intval((string) $sid)]["virtualserver_port"];
228  }
229 
230  /**
231  * Returns the TeamSpeak3_Node_Server object matching the currently selected ID.
232  *
233  * @return TeamSpeak3_Node_Server
234  */
235  public function serverGetSelected()
236  {
237  return $this->serverGetById($this->serverSelectedId());
238  }
239 
240  /**
241  * Returns the TeamSpeak3_Node_Server object matching the given ID.
242  *
243  * @param integer $sid
244  * @return TeamSpeak3_Node_Server
245  */
246  public function serverGetById($sid)
247  {
248  $this->serverSelectById($sid);
249 
250  return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($sid)));
251  }
252 
253  /**
254  * Returns the TeamSpeak3_Node_Server object matching the given port number.
255  *
256  * @param integer $port
257  * @return TeamSpeak3_Node_Server
258  */
259  public function serverGetByPort($port)
260  {
261  $this->serverSelectByPort($port);
262 
263  return new TeamSpeak3_Node_Server($this, array("virtualserver_id" => $this->serverSelectedId()));
264  }
265 
266  /**
267  * Returns the first TeamSpeak3_Node_Server object matching the given name.
268  *
269  * @param string $name
270  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
271  * @return TeamSpeak3_Node_Server
272  */
273  public function serverGetByName($name)
274  {
275  foreach($this->serverList() as $server)
276  {
277  if($server["virtualserver_name"] == $name) return $server;
278  }
279 
280  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
281  }
282 
283  /**
284  * Returns the first TeamSpeak3_Node_Server object matching the given unique identifier.
285  *
286  * @param string $uid
287  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
288  * @return TeamSpeak3_Node_Server
289  */
290  public function serverGetByUid($uid)
291  {
292  foreach($this->serverList() as $server)
293  {
294  if($server["virtualserver_unique_identifier"] == $uid) return $server;
295  }
296 
297  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
298  }
299 
300  /**
301  * Returns the first TeamSpeak3_Node_Server object matching the given TSDNS hostname. Like the
302  * TeamSpeak 3 Client, this method will start looking for a TSDNS server on the second-level
303  * domain including a fallback to the third-level domain of the specified $tsdns parameter.
304  *
305  * @param string $tsdns
306  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
307  * @return TeamSpeak3_Node_Server
308  */
309  public function serverGetByTSDNS($tsdns)
310  {
311  $parts = TeamSpeak3_Helper_Uri::getFQDNParts($tsdns);
312  $query = TeamSpeak3_Helper_String::factory(array_shift($parts));
313 
314  while($part = array_shift($parts))
315  {
316  $query->prepend($part);
317 
318  try
319  {
320  $port = TeamSpeak3::factory("tsdns://" . $query . "/?timeout=3")->resolve($tsdns)->section(":", 1);
321 
322  return $this->serverGetByPort($port == "" ? 9987 : $port);
323  }
325  {
326  /* skip "Connection timed out" and "Connection refused" */
327  if($e->getCode() != 10060 && $e->getCode() != 10061) throw $e;
328  }
329  }
330 
331  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
332  }
333 
334  /**
335  * Creates a new virtual server using given properties and returns an assoc
336  * array containing the new ID and initial admin token.
337  *
338  * @param array $properties
339  * @return array
340  */
341  public function serverCreate(array $properties = array())
342  {
343  $this->serverListReset();
344 
345  $detail = $this->execute("servercreate", $properties)->toList();
346  $server = new TeamSpeak3_Node_Server($this, array("virtualserver_id" => intval($detail["sid"])));
347 
348  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this, $detail["sid"]);
349  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $server, $detail["token"]);
350 
351  return $detail;
352  }
353 
354  /**
355  * Deletes the virtual server specified by ID.
356  *
357  * @param integer $sid
358  * @return void
359  */
360  public function serverDelete($sid)
361  {
362  $this->serverListReset();
363 
364  $this->execute("serverdelete", array("sid" => $sid));
365 
366  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerdeleted", $this, $sid);
367  }
368 
369  /**
370  * Starts the virtual server specified by ID.
371  *
372  * @param integer $sid
373  * @return void
374  */
375  public function serverStart($sid)
376  {
377  if($sid == $this->serverSelectedId())
378  {
379  $this->serverDeselect();
380  }
381 
382  $this->execute("serverstart", array("sid" => $sid));
383  $this->serverListReset();
384 
385  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstarted", $this, $sid);
386  }
387 
388  /**
389  * Stops the virtual server specified by ID.
390  *
391  * @param integer $sid
392  * @return void
393  */
394  public function serverStop($sid)
395  {
396  if($sid == $this->serverSelectedId())
397  {
398  $this->serverDeselect();
399  }
400 
401  $this->execute("serverstop", array("sid" => $sid));
402  $this->serverListReset();
403 
404  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServerstopped", $this, $sid);
405  }
406 
407  /**
408  * Stops the entire TeamSpeak 3 Server instance by shutting down the process.
409  *
410  * @return void
411  */
412  public function serverStopProcess()
413  {
414  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServershutdown", $this);
415 
416  $this->execute("serverprocessstop");
417  }
418 
419  /**
420  * Returns an array filled with TeamSpeak3_Node_Server objects.
421  *
422  * @param array $filter
423  * @return array
424  */
425  public function serverList(array $filter = array())
426  {
427  if($this->serverList === null)
428  {
429  $servers = $this->request("serverlist -uid")->toAssocArray("virtualserver_id");
430 
431  $this->serverList = array();
432 
433  foreach($servers as $sid => $server)
434  {
435  $this->serverList[$sid] = new TeamSpeak3_Node_Server($this, $server);
436  }
437 
438  $this->resetNodeList();
439  }
440 
441  return $this->filterList($this->serverList, $filter);
442  }
443 
444  /**
445  * Resets the list of virtual servers.
446  *
447  * @return void
448  */
449  public function serverListReset()
450  {
451  $this->resetNodeList();
452  $this->serverList = null;
453  }
454 
455  /**
456  * Returns a list of IP addresses used by the server instance on multi-homed machines.
457  *
458  * @return array
459  */
460  public function bindingList()
461  {
462  return $this->request("bindinglist")->toArray();
463  }
464 
465  /**
466  * Returns a list of permissions available on the server instance.
467  *
468  * @return array
469  */
470  public function permissionList()
471  {
472  if($this->permissionList === null)
473  {
474  $this->permissionList = $this->request("permissionlist")->toAssocArray("permname");
475 
476  foreach($this->permissionList as $permname => $permdata)
477  {
478  $this->permissionList[$permname]["permcatid"] = $this->permissionGetCategoryById($permdata["permid"]);
479  $this->permissionList[$permname]["permgrant"] = $this->permissionGetGrantById($permdata["permid"]);
480  }
481  }
482 
483  return $this->permissionList;
484  }
485 
486  /**
487  * Returns an array filled with all permission categories known to the server including
488  * their ID, name and parent.
489  *
490  * @return array
491  */
492  public function permissionTree()
493  {
494  $permtree = array();
495  $reflects = new ReflectionClass("TeamSpeak3");
496 
497  foreach($reflects->getConstants() as $key => $val)
498  {
499  if(!TeamSpeak3_Helper_String::factory($key)->startsWith("PERM_CAT") || $val == 0xFF)
500  {
501  continue;
502  }
503 
504  $permtree[$val]["permcatid"] = $val;
505  $permtree[$val]["permcathex"] = "0x" . dechex($val);
507  $permtree[$val]["permcatparent"] = $permtree[$val]["permcathex"]{3} == 0 ? 0 : hexdec($permtree[$val]["permcathex"]{2} . 0);
508  $permtree[$val]["permcatchilren"] = 0;
509  $permtree[$val]["permcatcount"] = 0;
510 
511  if(isset($permtree[$permtree[$val]["permcatparent"]]))
512  {
513  $permtree[$permtree[$val]["permcatparent"]]["permcatchilren"]++;
514  }
515 
516  if($permtree[$val]["permcatname"]->contains("/"))
517  {
518  $permtree[$val]["permcatname"] = $permtree[$val]["permcatname"]->section("/", 1)->trim();
519  }
520 
521  foreach($this->permissionList() as $permission)
522  {
523  if($this->permissionGetCategoryById($permission["permid"]) == $val)
524  {
525  $permtree[$val]["permcatcount"]++;
526  }
527  }
528  }
529 
530  return $permtree;
531  }
532 
533  /**
534  * Returns the IDs of all clients, channels or groups using the permission with the
535  * specified ID.
536  *
537  * @param integer $permid
538  * @return array
539  */
540  public function permissionFind($permid)
541  {
542  if(!is_array($permid))
543  {
544  $permident = (is_numeric($permid)) ? "permid" : "permsid";
545  }
546  else
547  {
548  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
549  }
550 
551  return $this->execute("permfind", array($permident => $permid))->toArray();
552  }
553 
554  /**
555  * Returns the ID of the permission matching the given name.
556  *
557  * @param string $name
558  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
559  * @return integer
560  */
561  public function permissionGetIdByName($name)
562  {
563  if(!array_key_exists((string) $name, $this->permissionList()))
564  {
565  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
566  }
567 
568  return $this->permissionList[(string) $name]["permid"];
569  }
570 
571  /**
572  * Returns the name of the permission matching the given ID.
573  *
574  * @param integer $permid
575  * @throws TeamSpeak3_Adapter_ServerQuery_Exception
576  * @return TeamSpeak3_Helper_String
577  */
578  public function permissionGetNameById($permid)
579  {
580  foreach($this->permissionList() as $name => $perm)
581  {
582  if($perm["permid"] == $permid) return new TeamSpeak3_Helper_String($name);
583  }
584 
585  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
586  }
587 
588  /**
589  * Returns the internal category of the permission matching the given ID.
590  *
591  * All permission IDs are are 2 bytes wide. The first byte identifies the category while the second
592  * byte is the permission count within that group.
593  *
594  * @param integer $permid
595  * @return integer
596  */
597  public function permissionGetCategoryById($permid)
598  {
599  if(!is_numeric($permid))
600  {
601  $permid = $this->permissionGetIdByName($permid);
602  }
603 
604  return (int) $permid >> 8;
605  }
606 
607  /**
608  * Returns the internal ID of the i_needed_modify_power_* or grant permission.
609  *
610  * Every permission has an associated i_needed_modify_power_* permission, for example b_client_ban_create has an
611  * associated permission called i_needed_modify_power_client_ban_create.
612  *
613  * @param integer $permid
614  * @return integer
615  */
616  public function permissionGetGrantById($permid)
617  {
618  if(!is_numeric($permid))
619  {
620  $permid = $this->permissionGetIdByName($permid);
621  }
622 
623  return (int) bindec(substr(decbin($permid), -8))+0xFF00;
624  }
625 
626  /**
627  * Adds a set of specified permissions to all regular server groups on all virtual servers. The target groups will
628  * be identified by the value of their i_group_auto_update_type permission specified with $sgtype.
629  *
630  * @param integer $sgtype
631  * @param integer $permid
632  * @param integer $permvalue
633  * @param integer $permnegated
634  * @param integer $permskip
635  * @return void
636  */
637  public function serverGroupPermAutoAssign($sgtype, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
638  {
639  if(!is_array($permid))
640  {
641  $permident = (is_numeric($permid)) ? "permid" : "permsid";
642  }
643  else
644  {
645  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
646  }
647 
648  $this->execute("servergroupautoaddperm", array("sgtype" => $sgtype, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip));
649  }
650 
651  /**
652  * Removes a set of specified permissions from all regular server groups on all virtual servers. The target groups
653  * will be identified by the value of their i_group_auto_update_type permission specified with $sgtype.
654  *
655  * @param integer $sgtype
656  * @param integer $permid
657  * @return void
658  */
659  public function serverGroupPermAutoRemove($sgtype, $permid)
660  {
661  if(!is_array($permid))
662  {
663  $permident = (is_numeric($permid)) ? "permid" : "permsid";
664  }
665  else
666  {
667  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
668  }
669 
670  $this->execute("servergroupautodelperm", array("sgtype" => $sgtype, $permident => $permid));
671  }
672 
673  /**
674  * Returns an array containing the value of a specified permission for your own client.
675  *
676  * @param integer $permid
677  * @return array
678  */
679  public function selfPermCheck($permid)
680  {
681  if(!is_array($permid))
682  {
683  $permident = (is_numeric($permid)) ? "permid" : "permsid";
684  }
685  else
686  {
687  $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
688  }
689 
690  return $this->execute("permget", array($permident => $permid))->toAssocArray("permsid");
691  }
692 
693  /**
694  * Changes the server instance configuration using given properties.
695  *
696  * @param array $properties
697  * @return void
698  */
699  public function modify(array $properties)
700  {
701  $this->execute("instanceedit", $properties);
702  $this->resetNodeInfo();
703  }
704 
705  /**
706  * Sends a text message to all clients on all virtual servers in the TeamSpeak 3 Server instance.
707  *
708  * @param string $msg
709  * @return void
710  */
711  public function message($msg)
712  {
713  $this->execute("gm", array("msg" => $msg));
714  }
715 
716  /**
717  * Displays a specified number of entries (1-100) from the servers log.
718  *
719  * @param integer $lines
720  * @param integer $begin_pos
721  * @param boolean $reverse
722  * @param boolean $instance
723  * @return array
724  */
725  public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = TRUE)
726  {
727  return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray();
728  }
729 
730  /**
731  * Writes a custom entry into the server instance log.
732  *
733  * @param string $logmsg
734  * @param integer $loglevel
735  * @return void
736  */
737  public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO)
738  {
739  $sid = $this->serverSelectedId();
740 
741  $this->serverDeselect();
742  $this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel));
743  $this->serverSelect($sid);
744  }
745 
746  /**
747  * Authenticates with the TeamSpeak 3 Server instance using given ServerQuery login credentials.
748  *
749  * @param string $username
750  * @param string $password
751  * @return void
752  */
753  public function login($username, $password)
754  {
755  $this->execute("login", array("client_login_name" => $username, "client_login_password" => $password));
756  $this->whoamiReset();
757 
758  $crypt = new TeamSpeak3_Helper_Crypt($username);
759 
760  $this->setStorage("_login_user", $username);
761  $this->setStorage("_login_pass", $crypt->encrypt($password));
762 
763  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogin", $this);
764  }
765 
766  /**
767  * Deselects the active virtual server and logs out from the server instance.
768  *
769  * @return void
770  */
771  public function logout()
772  {
773  $this->request("logout");
774  $this->whoamiReset();
775 
776  $this->delStorage("_login_user");
777  $this->delStorage("_login_pass");
778 
779  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogout", $this);
780  }
781 
782  /**
783  * Returns information about your current ServerQuery connection.
784  *
785  * @return array
786  */
787  public function whoami()
788  {
789  if($this->whoami === null)
790  {
791  $this->whoami = $this->request("whoami")->toList();
792  }
793 
794  return $this->whoami;
795  }
796 
797  /**
798  * Returns a single value from the current ServerQuery connection info.
799  *
800  * @param string $ident
801  * @param mixed $default
802  * @return mixed
803  */
804  public function whoamiGet($ident, $default = null)
805  {
806  if(array_key_exists($ident, $this->whoami()))
807  {
808  return $this->whoami[$ident];
809  }
810 
811  return $default;
812  }
813 
814  /**
815  * Sets a single value in the current ServerQuery connection info.
816  *
817  * @param string $ident
818  * @param mixed $value
819  * @return mixed
820  */
821  public function whoamiSet($ident, $value = null)
822  {
823  $this->whoami();
824 
825  $this->whoami[$ident] = (is_numeric($value)) ? intval($value) : TeamSpeak3_Helper_String::factory($value);
826  }
827 
828  /**
829  * Resets the current ServerQuery connection info.
830  *
831  * @return void
832  */
833  public function whoamiReset()
834  {
835  $this->whoami = null;
836  }
837 
838  /**
839  * Returns the hostname or IPv4 address the adapter is connected to.
840  *
841  * @return string
842  */
843  public function getAdapterHost()
844  {
845  return $this->getParent()->getTransportHost();
846  }
847 
848  /**
849  * Returns the network port the adapter is connected to.
850  *
851  * @return string
852  */
853  public function getAdapterPort()
854  {
855  return $this->getParent()->getTransportPort();
856  }
857 
858  /**
859  * @ignore
860  */
861  protected function fetchNodeList()
862  {
863  $servers = $this->serverList();
864 
865  foreach($servers as $server)
866  {
867  $this->nodeList[] = $server;
868  }
869  }
870 
871  /**
872  * @ignore
873  */
874  protected function fetchNodeInfo()
875  {
876  $info1 = $this->request("hostinfo")->toList();
877  $info2 = $this->request("instanceinfo")->toList();
878 
879  $this->nodeInfo = array_merge($this->nodeInfo, $info1, $info2);
880  }
881 
882  /**
883  * Sets a pre-defined nickname for ServerQuery clients which will be used automatically
884  * after selecting a virtual server.
885  *
886  * @param string $name
887  * @return void
888  */
889  public function setPredefinedQueryName($name = null)
890  {
891  $this->setStorage("_query_nick", $name);
892 
893  $this->predefined_query_name = $name;
894  }
895 
896  /**
897  * Returns the pre-defined nickname for ServerQuery clients which will be used automatically
898  * after selecting a virtual server.
899  *
900  * @return string
901  */
902  public function getPredefinedQueryName()
903  {
905  }
906 
907  /**
908  * Sets the option to decide whether ServerQuery clients should be excluded from node
909  * lists or not.
910  *
911  * @param boolean $exclude
912  * @return void
913  */
914  public function setExcludeQueryClients($exclude = FALSE)
915  {
916  $this->setStorage("_query_hide", $exclude);
917 
918  $this->exclude_query_clients = $exclude;
919  }
920 
921  /**
922  * Returns the option to decide whether ServerQuery clients should be excluded from node
923  * lists or not.
924  *
925  * @return boolean
926  */
927  public function getExcludeQueryClients()
928  {
930  }
931 
932  /**
933  * Sets the option to decide whether offline servers will be started in virtual mode
934  * by default or not.
935  *
936  * @param boolean $virtual
937  * @return void
938  */
939  public function setUseOfflineAsVirtual($virtual = FALSE)
940  {
941  $this->setStorage("_do_virtual", $virtual);
942 
943  $this->start_offline_virtual = $virtual;
944  }
945 
946  /**
947  * Returns the option to decide whether offline servers will be started in virtual mode
948  * by default or not.
949  *
950  * @return boolean
951  */
952  public function getUseOfflineAsVirtual()
953  {
955  }
956 
957  /**
958  * Sets the option to decide whether clients should be sorted before sub-channels to support
959  * the new TeamSpeak 3 Client display mode or not.
960  *
961  * @param boolean $first
962  * @return void
963  */
964  public function setLoadClientlistFirst($first = FALSE)
965  {
966  $this->setStorage("_client_top", $first);
967 
968  $this->sort_clients_channels = $first;
969  }
970 
971  /**
972  * Returns the option to decide whether offline servers will be started in virtual mode
973  * by default or not.
974  *
975  * @return boolean
976  */
977  public function getLoadClientlistFirst()
978  {
980  }
981 
982  /**
983  * Returns the underlying TeamSpeak3_Adapter_ServerQuery object.
984  *
985  * @return TeamSpeak3_Adapter_ServerQuery
986  */
987  public function getAdapter()
988  {
989  return $this->getParent();
990  }
991 
992  /**
993  * Returns a unique identifier for the node which can be used as a HTML property.
994  *
995  * @return string
996  */
997  public function getUniqueId()
998  {
999  return "ts3_h";
1000  }
1001 
1002  /**
1003  * Returns the name of a possible icon to display the node object.
1004  *
1005  * @return string
1006  */
1007  public function getIcon()
1008  {
1009  return "host";
1010  }
1011 
1012  /**
1013  * Returns a symbol representing the node.
1014  *
1015  * @return string
1016  */
1017  public function getSymbol()
1018  {
1019  return "+";
1020  }
1021 
1022  /**
1023  * Re-authenticates with the TeamSpeak 3 Server instance using given ServerQuery login
1024  * credentials and re-selects a previously selected virtual server.
1025  *
1026  * @return void
1027  */
1028  public function __wakeup()
1029  {
1030  $username = $this->getStorage("_login_user");
1031  $password = $this->getStorage("_login_pass");
1032 
1033  if($username && $password)
1034  {
1035  $crypt = new TeamSpeak3_Helper_Crypt($username);
1036 
1037  $this->login($username, $crypt->decrypt($password));
1038  }
1039 
1040  $this->predefined_query_name = $this->getStorage("_query_nick");
1041  $this->exclude_query_clients = $this->getStorage("_query_hide", FALSE);
1042  $this->start_offline_virtual = $this->getStorage("_do_virtual", FALSE);
1043  $this->sort_clients_channels = $this->getStorage("_client_top", FALSE);
1044 
1045  if($server = $this->getStorage("_server_use"))
1046  {
1047  $func = array_shift($server);
1048  $args = array_shift($server);
1049 
1050  call_user_func_array(array($this, $func), $args);
1051  }
1052  }
1053 
1054  /**
1055  * Returns a string representation of this node.
1056  *
1057  * @return string
1058  */
1059  public function __toString()
1060  {
1061  return (string) $this->getAdapterHost();
1062  }
1063 }
1064