/
Server.php
2612 lines (2281 loc) · 69.8 KB
/
Server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* TeamSpeak 3 PHP Framework
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TeamSpeak3
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Node_Server
* @brief Class describing a TeamSpeak 3 virtual server and all it's parameters.
*/
class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
{
/**
* @ignore
*/
protected $channelList = null;
/**
* @ignore
*/
protected $clientList = null;
/**
* @ignore
*/
protected $sgroupList = null;
/**
* @ignore
*/
protected $cgroupList = null;
/**
* The TeamSpeak3_Node_Server constructor.
*
* @param TeamSpeak3_Node_Host $host
* @param array $info
* @param string $index
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Server
*/
public function __construct(TeamSpeak3_Node_Host $host, array $info, $index = "virtualserver_id")
{
$this->parent = $host;
$this->nodeInfo = $info;
if(!array_key_exists($index, $this->nodeInfo))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
}
$this->nodeId = $this->nodeInfo[$index];
}
/**
* Sends a prepared command to the server and returns the result.
*
* @param string $cmd
* @param boolean $throw
* @return TeamSpeak3_Adapter_ServerQuery_Reply
*/
public function request($cmd, $throw = TRUE)
{
if($this->getId() != $this->getParent()->serverSelectedId())
{
$this->getParent()->serverSelect($this->getId());
}
return $this->getParent()->request($cmd, $throw);
}
/**
* Returns an array filled with TeamSpeak3_Node_Channel objects.
*
* @param array $filter
* @return array|TeamSpeak3_Node_Channel[]
*/
public function channelList(array $filter = array())
{
if($this->channelList === null)
{
$channels = $this->request("channellist -topic -flags -voice -limits -icon -banners")->toAssocArray("cid");
$this->channelList = array();
foreach($channels as $cid => $channel)
{
$this->channelList[$cid] = new TeamSpeak3_Node_Channel($this, $channel);
}
$this->resetNodeList();
}
return $this->filterList($this->channelList, $filter);
}
/**
* Resets the list of channels online.
*
* @return void
*/
public function channelListReset()
{
$this->resetNodeList();
$this->channelList = null;
}
/**
* Returns the TeamSpeak3_Node_Channel object representing the default channel.
*
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function channelGetDefault()
{
foreach($this->channelList() as $channel)
{
if($channel["channel_flag_default"]) return $channel;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
/**
* Creates a new channel using given properties and returns the new ID.
*
* @param array $properties
* @return integer
*/
public function channelCreate(array $properties)
{
$cid = $this->execute("channelcreate", $properties)->toList();
$this->channelListReset();
if(!isset($properties["channel_flag_permanent"]) && !isset($properties["channel_flag_semi_permanent"]))
{
$this->getParent()->whoamiSet("client_channel_id", $cid["cid"]);
}
return $cid["cid"];
}
/**
* Deletes the channel specified by $cid.
*
* @param integer $cid
* @param boolean $force
* @return void
*/
public function channelDelete($cid, $force = FALSE)
{
$this->execute("channeldelete", array("cid" => $cid, "force" => $force));
$this->channelListReset();
if(($cid instanceof TeamSpeak3_Node_Abstract ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id"))
{
$this->getParent()->whoamiReset();
}
}
/**
* Moves the channel specified by $cid to the parent channel specified with $pid.
*
* @param integer $cid
* @param integer $pid
* @param integer $order
* @return void
*/
public function channelMove($cid, $pid, $order = null)
{
$this->execute("channelmove", array("cid" => $cid, "cpid" => $pid, "order" => $order));
$this->channelListReset();
}
/**
* Returns TRUE if the given TeamSpeak3_Node_Channel object is a spacer.
*
* @param TeamSpeak3_Node_Channel $channel
* @return boolean
*/
public function channelIsSpacer(TeamSpeak3_Node_Channel $channel)
{
return (preg_match("/\[[^\]]*spacer[^\]]*\]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"]) ? TRUE : FALSE;
}
/**
* Creates a new channel spacer and returns the new ID. The first parameter $ident is used to create a
* unique spacer name on the virtual server.
*
* @param string $ident
* @param mixed $type
* @param integer $align
* @param integer $order
* @param integer $maxclients
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerCreate($ident, $type = TeamSpeak3::SPACER_SOLIDLINE, $align = TeamSpeak3::SPACER_ALIGN_REPEAT, $order = null, $maxclients = 0)
{
$properties = array(
"channel_name_phonetic" => "channel spacer",
"channel_codec" => TeamSpeak3::CODEC_OPUS_VOICE,
"channel_codec_quality" => 0x00,
"channel_flag_permanent" => TRUE,
"channel_flag_maxclients_unlimited" => FALSE,
"channel_flag_maxfamilyclients_unlimited" => FALSE,
"channel_flag_maxfamilyclients_inherited" => FALSE,
"channel_maxclients" => $maxclients,
"channel_order" => $order,
);
switch($align)
{
case TeamSpeak3::SPACER_ALIGN_REPEAT:
$properties["channel_name"] = "[*spacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_LEFT:
$properties["channel_name"] = "[lspacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_RIGHT:
$properties["channel_name"] = "[rspacer" . strval($ident) . "]";
break;
case TeamSpeak3::SPACER_ALIGN_CENTER:
$properties["channel_name"] = "[cspacer" . strval($ident) . "]";
break;
default:
throw new TeamSpeak3_Adapter_ServerQuery_Exception("missing required parameter", 0x606);
break;
}
switch($type)
{
case (string) TeamSpeak3::SPACER_SOLIDLINE:
$properties["channel_name"] .= "___";
break;
case (string) TeamSpeak3::SPACER_DASHLINE:
$properties["channel_name"] .= "---";
break;
case (string) TeamSpeak3::SPACER_DOTLINE:
$properties["channel_name"] .= "...";
break;
case (string) TeamSpeak3::SPACER_DASHDOTLINE:
$properties["channel_name"] .= "-.-";
break;
case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE:
$properties["channel_name"] .= "-..";
break;
default:
$properties["channel_name"] .= strval($type);
break;
}
return $this->channelCreate($properties);
}
/**
* Returns the possible type of a channel spacer.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerGetType($cid)
{
$channel = $this->channelGetById($cid);
if(!$this->channelIsSpacer($channel))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
}
switch($channel["channel_name"]->section("]", 1))
{
case "___":
return TeamSpeak3::SPACER_SOLIDLINE;
case "---":
return TeamSpeak3::SPACER_DASHLINE;
case "...":
return TeamSpeak3::SPACER_DOTLINE;
case "-.-":
return TeamSpeak3::SPACER_DASHDOTLINE;
case "-..":
return TeamSpeak3::SPACER_DASHDOTDOTLINE;
default:
return TeamSpeak3::SPACER_CUSTOM;
}
}
/**
* Returns the possible alignment of a channel spacer.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return integer
*/
public function channelSpacerGetAlign($cid)
{
$channel = $this->channelGetById($cid);
if(!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*\]/", $channel, $matches) || !isset($matches[1]))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
}
switch($matches[1])
{
case "*":
return TeamSpeak3::SPACER_ALIGN_REPEAT;
case "c":
return TeamSpeak3::SPACER_ALIGN_CENTER;
case "r":
return TeamSpeak3::SPACER_ALIGN_RIGHT;
default:
return TeamSpeak3::SPACER_ALIGN_LEFT;
}
}
/**
* Returns a list of permissions defined for a specific channel.
*
* @param integer $cid
* @param boolean $permsid
* @return array
*/
public function channelPermList($cid, $permsid = FALSE)
{
return $this->execute("channelpermlist", array("cid" => $cid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $cid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function channelPermAssign($cid, $permid, $permvalue)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channeladdperm", array("cid" => $cid, $permident => $permid, "permvalue" => $permvalue));
}
/**
* Removes a set of specified permissions from a channel. Multiple permissions can be removed at once.
*
* @param integer $cid
* @param integer $permid
* @return void
*/
public function channelPermRemove($cid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channeldelperm", array("cid" => $cid, $permident => $permid));
}
/**
* Returns a list of permissions defined for a client in a specific channel.
*
* @param integer $cid
* @param integer $cldbid
* @param boolean $permsid
* @return array
*/
public function channelClientPermList($cid, $cldbid, $permsid = FALSE)
{
return $this->execute("channelclientpermlist", array("cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by
* providing the two parameters of each permission.
*
* @param integer $cid
* @param integer $cldbid
* @param integer $permid
* @param integer $permvalue
* @return void
*/
public function channelClientPermAssign($cid, $cldbid, $permid, $permvalue)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelclientaddperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue));
}
/**
* Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once.
*
* @param integer $cid
* @param integer $cldbid
* @param integer $permid
* @return void
*/
public function channelClientPermRemove($cid, $cldbid, $permid)
{
if(!is_array($permid))
{
$permident = (is_numeric($permid)) ? "permid" : "permsid";
}
else
{
$permident = (is_numeric(current($permid))) ? "permid" : "permsid";
}
$this->execute("channelclientdelperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid));
}
/**
* Returns a list of files and directories stored in the specified channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $path
* @param boolean $recursive
* @return array
*/
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
{
$files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
$count = count($files);
for($i = 0; $i < $count; $i++)
{
$files[$i]["sid"] = $this->getId();
$files[$i]["cid"] = $files[0]["cid"];
$files[$i]["path"] = $files[0]["path"];
$files[$i]["src"] = new TeamSpeak3_Helper_String($cid ? $files[$i]["path"] : "/");
if(!$files[$i]["src"]->endsWith("/"))
{
$files[$i]["src"]->append("/");
}
$files[$i]["src"]->append($files[$i]["name"]);
if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
{
$files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
}
}
uasort($files, array(__CLASS__, "sortFileList"));
return $files;
}
/**
* Returns detailed information about the specified file stored in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $name
* @return array
*/
public function channelFileInfo($cid, $cpw = "", $name = "/")
{
$info = $this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray();
return array_pop($info);
}
/**
* Renames a file in a channels file repository. If the two parameters $tcid and $tcpw are specified, the file
* will be moved into another channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $oldname
* @param string $newname
* @param integer $tcid
* @param string $tcpw
* @return void
*/
public function channelFileRename($cid, $cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null)
{
$this->execute("ftrenamefile", array("cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw));
}
/**
* Deletes one or more files stored in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $name
* @return void
*/
public function channelFileDelete($cid, $cpw = "", $name = "/")
{
$this->execute("ftdeletefile", array("cid" => $cid, "cpw" => $cpw, "name" => $name));
}
/**
* Creates new directory in a channels file repository.
*
* @param integer $cid
* @param string $cpw
* @param string $dirname
* @return void
*/
public function channelDirCreate($cid, $cpw = "", $dirname = "/")
{
$this->execute("ftcreatedir", array("cid" => $cid, "cpw" => $cpw, "dirname" => $dirname));
}
/**
* Returns the level of a channel.
*
* @param integer $cid
* @return integer
*/
public function channelGetLevel($cid)
{
$channel = $this->channelGetById($cid);
$levelno = 0;
if($channel["pid"])
{
$levelno = $this->channelGetLevel($channel["pid"])+1;
}
return $levelno;
}
/**
* Returns the pathway of a channel which can be used as a clients default channel.
*
* @param integer $cid
* @return string
*/
public function channelGetPathway($cid)
{
$channel = $this->channelGetById($cid);
$pathway = $channel["channel_name"];
if($channel["pid"])
{
$pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"];
}
return $pathway;
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given ID.
*
* @param integer $cid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function channelGetById($cid)
{
if(!array_key_exists((string) $cid, $this->channelList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
return $this->channelList[intval((string) $cid)];
}
/**
* Returns the TeamSpeak3_Node_Channel object matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Channel
*/
public function channelGetByName($name)
{
foreach($this->channelList() as $channel)
{
if($channel["channel_name"] == $name) return $channel;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
}
/**
* Returns an array filled with TeamSpeak3_Node_Client objects.
*
* @param array $filter
* @return array|TeamSpeak3_Node_Client[]
*/
public function clientList(array $filter = array())
{
if($this->clientList === null)
{
$clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
$this->clientList = array();
foreach($clients as $clid => $client)
{
if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
$this->clientList[$clid] = new TeamSpeak3_Node_Client($this, $client);
}
uasort($this->clientList, array(__CLASS__, "sortClientList"));
$this->resetNodeList();
}
return $this->filterList($this->clientList, $filter);
}
/**
* Resets the list of clients online.
*
* @return void
*/
public function clientListReset()
{
$this->resetNodeList();
$this->clientList = null;
}
/**
* Returns a list of clients matching a given name pattern.
*
* @param string $pattern
* @return array
*/
public function clientFind($pattern)
{
return $this->execute("clientfind", array("pattern" => $pattern))->toAssocArray("clid");
}
/**
* Returns a list of client identities known by the virtual server. By default, the server spits out 25 entries
* at once.
*
* @param integer $offset
* @param integer $limit
* @return array
*/
public function clientListDb($offset = null, $limit = null)
{
return $this->execute("clientdblist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("cldbid");
}
/**
* Returns the number of client identities known by the virtual server.
*
* @return integer
*/
public function clientCountDb()
{
return current($this->execute("clientdblist -count", array("duration" => 1))->toList("count"));
}
/**
* Returns a list of properties from the database for the client specified by $cldbid.
*
* @param integer $cldbid
* @return array
*/
public function clientInfoDb($cldbid)
{
return $this->execute("clientdbinfo", array("cldbid" => $cldbid))->toList();
}
/**
* Returns a list of client database information matching a given pattern. You can either search for a clients
* last known nickname or his unique identity by using the $uid option.
*
* @param string $pattern
* @param boolean $uid
* @return array
*/
public function clientFindDb($pattern, $uid = FALSE)
{
return array_keys($this->execute("clientdbfind", array("pattern" => $pattern, ($uid) ? "-uid" : null, "-details"))->toAssocArray("cldbid"));
}
/**
* Returns the number of regular clients online.
*
* @return integer
*/
public function clientCount()
{
if($this->isOffline()) return 0;
return $this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"];
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given ID.
*
* @param integer $clid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetById($clid)
{
if(!array_key_exists((string) $clid, $this->clientList()))
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
return $this->clientList[intval((string) $clid)];
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given name.
*
* @param string $name
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByName($name)
{
foreach($this->clientList() as $client)
{
if($client["client_nickname"] == $name) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given unique identifier.
*
* @param string $uid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByUid($uid)
{
foreach($this->clientList() as $client)
{
if($client["client_unique_identifier"] == $uid) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns the TeamSpeak3_Node_Client object matching the given database ID.
*
* @param integer $dbid
* @throws TeamSpeak3_Adapter_ServerQuery_Exception
* @return TeamSpeak3_Node_Client
*/
public function clientGetByDbid($dbid)
{
foreach($this->clientList() as $client)
{
if($client["client_database_id"] == $dbid) return $client;
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
}
/**
* Returns an array containing the last known nickname and the database ID of the client matching
* the unique identifier specified with $cluid.
*
* @param string $cluid
* @return array
*/
public function clientGetNameByUid($cluid)
{
return $this->execute("clientgetnamefromuid", array("cluid" => $cluid))->toList();
}
/**
* Returns an array containing a list of active client connections using the unique identifier
* specified with $cluid.
*
* @param string $cluid
* @return array
*/
public function clientGetIdsByUid($cluid)
{
return $this->execute("clientgetids", array("cluid" => $cluid))->toAssocArray("clid");
}
/**
* Returns an array containing the last known nickname and the unique identifier of the client
* matching the database ID specified with $cldbid.
*
* @param string $cldbid
* @return array
*/
public function clientGetNameByDbid($cldbid)
{
return $this->execute("clientgetnamefromdbid", array("cldbid" => $cldbid))->toList();
}
/**
* Returns an array containing the names and IDs of all server groups the client specified with
* $cldbid is is currently residing in.
*
* @param string $cldbid
* @return array
*/
public function clientGetServerGroupsByDbid($cldbid)
{
return $this->execute("servergroupsbyclientid", array("cldbid" => $cldbid))->toAssocArray("sgid");
}
/**
* Moves a client to another channel.
*
* @param integer $clid
* @param integer $cid
* @param string $cpw
* @return void
*/
public function clientMove($clid, $cid, $cpw = null)
{
$this->clientListReset();
$this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
if($clid instanceof TeamSpeak3_Node_Abstract)
{
$clid = $clid->getId();
}
if($cid instanceof TeamSpeak3_Node_Abstract)
{
$cid = $cid->getId();
}
if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
{
$this->getParent()->whoamiSet("client_channel_id", $cid);
}
}
/**
* Kicks one or more clients from their currently joined channel or from the server.
*
* @param integer $clid
* @param integer $reasonid
* @param string $reasonmsg
* @return void
*/
public function clientKick($clid, $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
{
$this->clientListReset();
$this->execute("clientkick", array("clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg));
}
/**
* Sends a poke message to a client.
*
* @param integer $clid
* @param string $msg
* @return void
*/
public function clientPoke($clid, $msg)
{
$this->execute("clientpoke", array("clid" => $clid, "msg" => $msg));
}
/**
* Bans the client specified with ID $clid from the server. Please note that this will create three separate
* ban rules for the targeted clients IP address, the unique identifier and the myTeamSpeak ID (if available).
*
* @param integer $clid
* @param integer $timeseconds
* @param string $reason
* @return array
*/
public function clientBan($clid, $timeseconds = null, $reason = null)
{
$this->clientListReset();
$bans = $this->execute("banclient", array("clid" => $clid, "time" => $timeseconds, "banreason" => $reason))->toAssocArray("banid");
return array_keys($bans);
}
/**
* Changes the clients properties using given properties.
*
* @param string $cldbid
* @param array $properties
* @return void
*/
public function clientModifyDb($cldbid, array $properties)
{
$properties["cldbid"] = $cldbid;
$this->execute("clientdbedit", $properties);
}
/**
* Deletes a clients properties from the database.
*
* @param string $cldbid
* @return void
*/
public function clientDeleteDb($cldbid)
{
$this->execute("clientdbdelete", array("cldbid" => $cldbid));
}
/**
* Sets the channel group of a client to the ID specified.
*
* @param integer $cldbid
* @param integer $cid
* @param integer $cgid
* @return void
*/
public function clientSetChannelGroup($cldbid, $cid, $cgid)
{
$this->execute("setclientchannelgroup", array("cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid));
}
/**
* Returns a list of permissions defined for a client.
*
* @param integer $cldbid
* @param boolean $permsid
* @return array
*/
public function clientPermList($cldbid, $permsid = FALSE)
{
$this->clientListReset();
return $this->execute("clientpermlist", array("cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
}
/**
* Adds a set of specified permissions to a client. Multiple permissions can be added by providing
* the three parameters of each permission.
*
* @param integer $cldbid
* @param integer $permid
* @param integer $permvalue
* @param integer $permskip
* @return void
*/
public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE)