ts3phpframework
Loading...
Searching...
No Matches
Server.php
Go to the documentation of this file.
1<?php
2
3namespace PlanetTeamSpeak\TeamSpeak3Framework\Node;
4
5use PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery\Reply;
6use PlanetTeamSpeak\TeamSpeak3Framework\Exception\AdapterException;
7use PlanetTeamSpeak\TeamSpeak3Framework\Exception\HelperException;
8use PlanetTeamSpeak\TeamSpeak3Framework\Exception\NodeException;
9use PlanetTeamSpeak\TeamSpeak3Framework\Exception\ServerQueryException;
10use PlanetTeamSpeak\TeamSpeak3Framework\Helper\Signal;
11use PlanetTeamSpeak\TeamSpeak3Framework\Helper\StringHelper;
12use PlanetTeamSpeak\TeamSpeak3Framework\TeamSpeak3;
13
20class Server extends Node
21{
25 protected array|null $channelList = null;
26
30 protected array|null $clientList = null;
31
35 protected array|null $sgroupList = null;
36
40 protected array|null $cgroupList = null;
41
50 public function __construct(Host $host, array $info, string $index = "virtualserver_id")
51 {
52 $this->parent = $host;
53 $this->nodeInfo = $info;
54
55 if (!array_key_exists($index, $this->nodeInfo)) {
56 throw new ServerQueryException("invalid serverID", 0x400);
57 }
58
59 $this->nodeId = $this->nodeInfo[$index];
60 }
61
71 public function request(string $cmd, bool $throw = true): Reply
72 {
73 if ($this->getId() != $this->getParent()->serverSelectedId()) {
74 $this->getParent()->serverSelect($this->getId());
75 }
76
77 return $this->getParent()->request($cmd, $throw);
78 }
79
88 public function channelList(array $filter = []): array
89 {
90 if ($this->channelList === null) {
91 $channels = $this->request("channellist -topic -flags -voice -limits -icon")->toAssocArray("cid");
92
93 $this->channelList = [];
94
95 foreach ($channels as $cid => $channel) {
96 $this->channelList[$cid] = new Channel($this, $channel);
97 }
98
99 $this->resetNodeList();
100 }
101
102 return $this->filterList($this->channelList, $filter);
103 }
104
110 public function channelListReset(): void
111 {
112 $this->resetNodeList();
113 $this->channelList = null;
114 }
115
123 public function channelGetDefault(): Channel
124 {
125 foreach ($this->channelList() as $channel) {
126 if ($channel["channel_flag_default"]) {
127 return $channel;
128 }
129 }
130
131 throw new ServerQueryException("invalid channelID", 0x300);
132 }
133
142 public function channelCreate(array $properties): int
143 {
144 $cid = $this->execute("channelcreate", $properties)->toList();
145 $this->channelListReset();
146
147 if (!isset($properties["channel_flag_permanent"]) && !isset($properties["channel_flag_semi_permanent"])) {
148 $this->getParent()->whoamiSet("client_channel_id", $cid["cid"]);
149 }
150
151 return $cid["cid"];
152 }
153
163 public function channelDelete(int|Node $cid, bool $force = false): void
164 {
165 $this->execute("channeldelete", ["cid" => $cid, "force" => $force]);
166 $this->channelListReset();
167
168 if (($cid instanceof Node ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id")) {
169 $this->getParent()->whoamiReset();
170 }
171 }
172
183 public function channelMove(int $cid, int $pid, int $order = null): void
184 {
185 $this->execute("channelmove", ["cid" => $cid, "cpid" => $pid, "order" => $order]);
186 $this->channelListReset();
187 }
188
195 public function channelIsSpacer(Channel $channel): bool
196 {
197 return preg_match("/\[[^]]*spacer[^]]*]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"];
198 }
199
213 public function channelSpacerCreate(
214 string $ident,
217 int $order = null,
218 int $maxclients = 0
219 ): int {
220 $properties = [
221 "channel_name_phonetic" => "channel spacer",
222 "channel_codec" => TeamSpeak3::CODEC_OPUS_VOICE,
223 "channel_codec_quality" => 0x00,
224 "channel_flag_permanent" => true,
225 "channel_flag_maxclients_unlimited" => false,
226 "channel_flag_maxfamilyclients_unlimited" => false,
227 "channel_flag_maxfamilyclients_inherited" => false,
228 "channel_maxclients" => $maxclients,
229 "channel_order" => $order,
230 ];
231
232 $properties["channel_name"] = match ($align) {
233 TeamSpeak3::SPACER_ALIGN_REPEAT => "[*spacer" . $ident . "]",
234 TeamSpeak3::SPACER_ALIGN_LEFT => "[lspacer" . $ident . "]",
235 TeamSpeak3::SPACER_ALIGN_RIGHT => "[rspacer" . $ident . "]",
236 TeamSpeak3::SPACER_ALIGN_CENTER => "[cspacer" . $ident . "]",
237 default => throw new ServerQueryException("missing required parameter", 0x606),
238 };
239
240 $properties["channel_name"] .= match ($type) {
241 (string)TeamSpeak3::SPACER_SOLIDLINE => "___",
242 (string)TeamSpeak3::SPACER_DASHLINE => "---",
243 (string)TeamSpeak3::SPACER_DOTLINE => "...",
244 (string)TeamSpeak3::SPACER_DASHDOTLINE => "-.-",
245 (string)TeamSpeak3::SPACER_DASHDOTDOTLINE => "-..",
246 default => strval($type),
247 };
248
249 return $this->channelCreate($properties);
250 }
251
260 public function channelSpacerGetType(int $cid): int
261 {
262 $channel = $this->channelGetById($cid);
263
264 if (!$this->channelIsSpacer($channel)) {
265 throw new ServerQueryException("invalid channel flags", 0x307);
266 }
267
268 return match ($channel["channel_name"]->section("]", 1)) {
274 default => TeamSpeak3::SPACER_CUSTOM,
275 };
276 }
277
286 public function channelSpacerGetAlign(int $cid): int
287 {
288 $channel = $this->channelGetById($cid);
289
290 if (!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*]/", $channel, $matches) || !isset($matches[1])) {
291 throw new ServerQueryException("invalid channel flags", 0x307);
292 }
293
294 return match ($matches[1]) {
299 };
300 }
301
311 public function channelPermList(int $cid, bool $permsid = false): array
312 {
313 return $this->execute("channelpermlist", ["cid" => $cid, $permsid ? "-permsid" : null])
314 ->toAssocArray($permsid ? "permsid" : "permid");
315 }
316
328 public function channelPermAssign(int $cid, int|array $permid, int|array $permvalue): void
329 {
330 if (!is_array($permid)) {
331 $permident = (is_numeric($permid)) ? "permid" : "permsid";
332 } else {
333 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
334 }
335
336 $this->execute("channeladdperm", ["cid" => $cid, $permident => $permid, "permvalue" => $permvalue]);
337 }
338
348 public function channelPermRemove(int $cid, int|array $permid): void
349 {
350 if (!is_array($permid)) {
351 $permident = (is_numeric($permid)) ? "permid" : "permsid";
352 } else {
353 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
354 }
355
356 $this->execute("channeldelperm", ["cid" => $cid, $permident => $permid]);
357 }
358
369 public function channelClientPermList(int $cid, int $cldbid, bool $permsid = false): array
370 {
371 return $this->execute("channelclientpermlist", ["cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null])
372 ->toAssocArray($permsid ? "permsid" : "permid");
373 }
374
387 public function channelClientPermAssign(int $cid, int $cldbid, int|array $permid, int|array $permvalue): void
388 {
389 if (!is_array($permid)) {
390 $permident = (is_numeric($permid)) ? "permid" : "permsid";
391 } else {
392 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
393 }
394
395 $this->execute("channelclientaddperm", ["cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue]);
396 }
397
408 public function channelClientPermRemove(int $cid, int $cldbid, int|array $permid): void
409 {
410 if (!is_array($permid)) {
411 $permident = (is_numeric($permid)) ? "permid" : "permsid";
412 } else {
413 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
414 }
415
416 $this->execute("channelclientdelperm", ["cid" => $cid, "cldbid" => $cldbid, $permident => $permid]);
417 }
418
430 public function channelFileList(int $cid, string $cpw = "", string $path = "/", bool $recursive = false): array
431 {
432 $files = $this->execute("ftgetfilelist", ["cid" => $cid, "cpw" => $cpw, "path" => $path])->toArray();
433 $count = count($files);
434
435 for ($i = 0; $i < $count; $i++) {
436 $files[$i]["sid"] = $this->getId();
437 $files[$i]["cid"] = $files[0]["cid"];
438 $files[$i]["path"] = $files[0]["path"];
439 $files[$i]["src"] = new StringHelper($cid ? $files[$i]["path"] : "/");
440
441 if (!$files[$i]["src"]->endsWith("/")) {
442 $files[$i]["src"]->append("/");
443 }
444
445 $files[$i]["src"]->append($files[$i]["name"]);
446
447 if ($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY) {
448 $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
449 }
450 }
451
452 uasort($files, [__CLASS__, "sortFileList"]);
453
454 return $files;
455 }
456
467 public function channelFileInfo(int $cid, string $cpw = "", string $name = "/"): array
468 {
469 $info = $this->execute("ftgetfileinfo", ["cid" => $cid, "cpw" => $cpw, "name" => $name])->toArray();
470
471 return array_pop($info);
472 }
473
488 public function channelFileRename(int $cid, string $cpw = "", string $oldname = "/", string $newname = "/", int $tcid = null, string $tcpw = null): void
489 {
490 $this->execute("ftrenamefile", ["cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw]);
491 }
492
503 public function channelFileDelete(int $cid, string $cpw = "", string $name = "/"): void
504 {
505 $this->execute("ftdeletefile", ["cid" => $cid, "cpw" => $cpw, "name" => $name]);
506 }
507
518 public function channelDirCreate(int $cid, string $cpw = "", string $dirname = "/"): void
519 {
520 $this->execute("ftcreatedir", ["cid" => $cid, "cpw" => $cpw, "dirname" => $dirname]);
521 }
522
531 public function channelGetLevel(int $cid): int
532 {
533 $channel = $this->channelGetById($cid);
534 $levelno = 0;
535
536 if ($channel["pid"]) {
537 $levelno = $this->channelGetLevel($channel["pid"]) + 1;
538 }
539
540 return $levelno;
541 }
542
551 public function channelGetPathway(int $cid): string
552 {
553 $channel = $this->channelGetById($cid);
554 $pathway = $channel["channel_name"];
555
556 if ($channel["pid"]) {
557 $pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"];
558 }
559
560 return $pathway;
561 }
562
571 public function channelGetById(int $cid): Channel
572 {
573 if (!array_key_exists((string)$cid, $this->channelList())) {
574 throw new ServerQueryException("invalid channelID", 0x300);
575 }
576
577 return $this->channelList[intval((string)$cid)];
578 }
579
588 public function channelGetByName(string $name): Channel
589 {
590 foreach ($this->channelList() as $channel) {
591 if ($channel["channel_name"] == $name) {
592 return $channel;
593 }
594 }
595
596 throw new ServerQueryException("invalid channelID", 0x300);
597 }
598
607 public function clientList(array $filter = []): array
608 {
609 if ($this->clientList === null) {
610 $clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")
611 ->toAssocArray("clid");
612
613 $this->clientList = [];
614
615 foreach ($clients as $clid => $client) {
616 if ($this->getParent()->getExcludeQueryClients() && $client["client_type"]) {
617 continue;
618 }
619
620 $this->clientList[$clid] = new Client($this, $client);
621 }
622
623 uasort($this->clientList, [__CLASS__, "sortClientList"]);
624
625 $this->resetNodeList();
626 }
627
628 return $this->filterList($this->clientList, $filter);
629 }
630
636 public function clientListReset(): void
637 {
638 $this->resetNodeList();
639 $this->clientList = null;
640 }
641
650 public function clientFind(string $pattern): array
651 {
652 return $this->execute("clientfind", ["pattern" => $pattern])->toAssocArray("clid");
653 }
654
665 public function clientListDb(int $offset = null, int $limit = null): array
666 {
667 return $this->execute("clientdblist -count", ["start" => $offset, "duration" => $limit])
668 ->toAssocArray("cldbid");
669 }
670
678 public function clientCountDb(): int
679 {
680 return current($this->execute("clientdblist -count", ["duration" => 1])->toList("count"));
681 }
682
691 public function clientInfoDb(int $cldbid): array
692 {
693 return $this->execute("clientdbinfo", ["cldbid" => $cldbid])->toList();
694 }
695
706 public function clientFindDb(string $pattern, bool $uid = false): array
707 {
708 return array_keys($this->execute("clientdbfind", ["pattern" => $pattern, ($uid) ? "-uid" : null, "-details"])
709 ->toAssocArray("cldbid"));
710 }
711
717 public function clientCount(): int
718 {
719 if ($this->isOffline()) {
720 return 0;
721 }
722
723 return $this["virtualserver_clientsonline"] - $this["virtualserver_queryclientsonline"];
724 }
725
734 public function clientGetById(int $clid): Client
735 {
736 if (!array_key_exists((string)$clid, $this->clientList())) {
737 throw new ServerQueryException("invalid clientID", 0x200);
738 }
739
740 return $this->clientList[intval((string)$clid)];
741 }
742
751 public function clientGetByName(string $name): Client
752 {
753 foreach ($this->clientList() as $client) {
754 if ($client["client_nickname"] == $name) {
755 return $client;
756 }
757 }
758
759 throw new ServerQueryException("invalid clientID", 0x200);
760 }
761
770 public function clientGetByUid(string $uid): Client
771 {
772 foreach ($this->clientList() as $client) {
773 if ($client["client_unique_identifier"] == $uid) {
774 return $client;
775 }
776 }
777
778 throw new ServerQueryException("invalid clientID", 0x200);
779 }
780
789 public function clientGetByDbid(int $dbid): Client
790 {
791 foreach ($this->clientList() as $client) {
792 if ($client["client_database_id"] == $dbid) {
793 return $client;
794 }
795 }
796
797 throw new ServerQueryException("invalid clientID", 0x200);
798 }
799
809 public function clientGetNameByUid(string $cluid): array
810 {
811 return $this->execute("clientgetnamefromuid", ["cluid" => $cluid])->toList();
812 }
813
823 public function clientGetIdsByUid(string $cluid): array
824 {
825 return $this->execute("clientgetids", ["cluid" => $cluid])->toAssocArray("clid");
826 }
827
837 public function clientGetNameByDbid(string $cldbid): array
838 {
839 return $this->execute("clientgetnamefromdbid", ["cldbid" => $cldbid])->toList();
840 }
841
851 public function clientGetServerGroupsByDbid(string $cldbid): array
852 {
853 return $this->execute("servergroupsbyclientid", ["cldbid" => $cldbid])->toAssocArray("sgid");
854 }
855
866 public function clientMove(int|Node $clid, int|Node $cid, $cpw = null): void
867 {
868 $this->clientListReset();
869
870 $this->execute("clientmove", ["clid" => $clid, "cid" => $cid, "cpw" => $cpw]);
871
872 if ($clid instanceof Node) {
873 $clid = $clid->getId();
874 }
875
876 if ($cid instanceof Node) {
877 $cid = $cid->getId();
878 }
879
880 if (!is_array($clid) && $clid == $this->whoamiGet("client_id")) {
881 $this->getParent()->whoamiSet("client_channel_id", $cid);
882 }
883 }
884
895 public function clientKick(int $clid, int $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null): void
896 {
897 $this->clientListReset();
898
899 $this->execute("clientkick", ["clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg]);
900 }
901
911 public function clientPoke(int $clid, string $msg): void
912 {
913 $this->execute("clientpoke", ["clid" => $clid, "msg" => $msg]);
914 }
915
927 public function clientBan(int $clid, int $timeseconds = null, string $reason = null): array
928 {
929 $this->clientListReset();
930
931 $bans = $this->execute("banclient", ["clid" => $clid, "time" => $timeseconds, "banreason" => $reason])
932 ->toAssocArray("banid");
933
934 return array_keys($bans);
935 }
936
946 public function clientModifyDb(string $cldbid, array $properties): void
947 {
948 $properties["cldbid"] = $cldbid;
949
950 $this->execute("clientdbedit", $properties);
951 }
952
961 public function clientDeleteDb(string $cldbid): void
962 {
963 $this->execute("clientdbdelete", ["cldbid" => $cldbid]);
964 }
965
976 public function clientSetChannelGroup(int $cldbid, int $cid, int $cgid): void
977 {
978 $this->execute("setclientchannelgroup", ["cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid]);
979 }
980
990 public function clientPermList(int $cldbid, bool $permsid = false): array
991 {
992 $this->clientListReset();
993
994 return $this->execute("clientpermlist", ["cldbid" => $cldbid, $permsid ? "-permsid" : null])
995 ->toAssocArray($permsid ? "permsid" : "permid");
996 }
997
1010 public function clientPermAssign(int $cldbid, int|array $permid, int|array $permvalue, bool|array $permskip = false): void
1011 {
1012 if (!is_array($permid)) {
1013 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1014 } else {
1015 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1016 }
1017
1018 $this->execute("clientaddperm -continueonerror", ["cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip]);
1019 }
1020
1030 public function clientPermRemove(int $cldbid, int|array $permid): void
1031 {
1032 if (!is_array($permid)) {
1033 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1034 } else {
1035 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1036 }
1037
1038 $this->execute("clientdelperm", ["cldbid" => $cldbid, $permident => $permid]);
1039 }
1040
1050 public function serverGroupList(array $filter = []): array
1051 {
1052 if ($this->sgroupList === null) {
1053 $this->sgroupList = $this->request("servergrouplist")->toAssocArray("sgid");
1054
1055 foreach ($this->sgroupList as $sgid => $group) {
1056 $this->sgroupList[$sgid] = new ServerGroup($this, $group);
1057 }
1058
1059 uasort($this->sgroupList, [__CLASS__, "sortGroupList"]);
1060 }
1061
1062 return $this->filterList($this->sgroupList, $filter);
1063 }
1064
1070 public function serverGroupListReset(): void
1071 {
1072 $this->sgroupList = null;
1073 }
1074
1084 public function serverGroupCreate(string $name, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): int
1085 {
1086 $this->serverGroupListReset();
1087
1088 $sgid = $this->execute("servergroupadd", ["name" => $name, "type" => $type])->toList();
1089
1090 return $sgid["sgid"];
1091 }
1092
1104 public function serverGroupCopy(int $ssgid, string $name = null, int $tsgid = 0, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): int
1105 {
1106 $this->serverGroupListReset();
1107
1108 $sgid = $this->execute("servergroupcopy", ["ssgid" => $ssgid, "tsgid" => $tsgid, "name" => $name, "type" => $type])
1109 ->toList();
1110
1111 if ($tsgid && $name) {
1112 $this->serverGroupRename($tsgid, $name);
1113 }
1114
1115 return count($sgid) ? $sgid["sgid"] : $tsgid;
1116 }
1117
1127 public function serverGroupRename(int $sgid, string $name): void
1128 {
1129 $this->serverGroupListReset();
1130
1131 $this->execute("servergrouprename", ["sgid" => $sgid, "name" => $name]);
1132 }
1133
1144 public function serverGroupDelete(int $sgid, bool $force = false): void
1145 {
1146 $this->serverGroupListReset();
1147
1148 $this->execute("servergroupdel", ["sgid" => $sgid, "force" => $force]);
1149 }
1150
1160 public function serverGroupGetById(int $sgid): ServerGroup
1161 {
1162 if (!array_key_exists((string)$sgid, $this->serverGroupList())) {
1163 throw new ServerQueryException("invalid groupID", 0xA00);
1164 }
1165
1166 return $this->sgroupList[intval((string)$sgid)];
1167 }
1168
1179 public function serverGroupGetByName(string $name, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): ServerGroup
1180 {
1181 foreach ($this->serverGroupList() as $group) {
1182 if ($group["name"] == $name && $group["type"] == $type) {
1183 return $group;
1184 }
1185 }
1186
1187 throw new ServerQueryException("invalid groupID", 0xA00);
1188 }
1189
1199 public function serverGroupPermList(int $sgid, bool $permsid = false): array
1200 {
1201 return $this->execute("servergrouppermlist", ["sgid" => $sgid, $permsid ? "-permsid" : null])
1202 ->toAssocArray($permsid ? "permsid" : "permid");
1203 }
1204
1218 public function serverGroupPermAssign(int $sgid, int|array $permid, int|array $permvalue, int|array $permnegated = 0, bool|array $permskip = false): void
1219 {
1220 if (!is_array($permid)) {
1221 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1222 } else {
1223 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1224 }
1225
1226 $this->execute("servergroupaddperm", ["sgid" => $sgid, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip]);
1227 }
1228
1239 public function serverGroupPermRemove(int $sgid, int|array $permid): void
1240 {
1241 if (!is_array($permid)) {
1242 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1243 } else {
1244 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1245 }
1246
1247 $this->execute("servergroupdelperm", ["sgid" => $sgid, $permident => $permid]);
1248 }
1249
1258 public function serverGroupClientList(int $sgid): array
1259 {
1260 if ($this["virtualserver_default_server_group"] == $sgid) {
1261 return [];
1262 }
1263
1264 return $this->execute("servergroupclientlist", ["sgid" => $sgid, "-names"])->toAssocArray("cldbid");
1265 }
1266
1277 public function serverGroupClientAdd(int $sgid, int $cldbid): void
1278 {
1279 $this->clientListReset();
1280
1281 $this->execute("servergroupaddclient", ["sgid" => $sgid, "cldbid" => $cldbid]);
1282 }
1283
1293 public function serverGroupClientDel(int $sgid, int $cldbid): void
1294 {
1295 $this->execute("servergroupdelclient", ["sgid" => $sgid, "cldbid" => $cldbid]);
1296 }
1297
1309 {
1310 $profiles = [];
1311
1312 foreach ($this->serverGroupList() as $sgid => $sgroup) {
1313 if ($sgroup["type"] != $type) {
1314 continue;
1315 }
1316
1317 $profiles[$sgid] = [
1318 "b_permission_modify_power_ignore" => 0,
1319 "i_group_member_add_power" => 0,
1320 "i_group_member_remove_power" => 0,
1321 "i_needed_modify_power_count" => 0,
1322 "i_needed_modify_power_total" => 0,
1323 "i_permission_modify_power" => 0,
1324 "i_group_modify_power" => 0,
1325 "i_client_modify_power" => 0,
1326 "b_virtualserver_servergroup_create" => 0,
1327 "b_virtualserver_servergroup_delete" => 0,
1328 "b_client_ignore_bans" => 0,
1329 "b_client_ignore_antiflood" => 0,
1330 "b_group_is_permanent" => 0,
1331 "i_client_needed_ban_power" => 0,
1332 "i_client_needed_kick_power" => 0,
1333 "i_client_needed_move_power" => 0,
1334 "i_client_talk_power" => 0,
1335 "__sgid" => $sgid,
1336 "__name" => $sgroup->toString(),
1337 "__node" => $sgroup,
1338 ];
1339
1340 try {
1341 $perms = $this->serverGroupPermList($sgid, true);
1342 $grant = isset($perms["i_permission_modify_power"]) ? $perms["i_permission_modify_power"]["permvalue"] : null;
1343 } catch (ServerQueryException $e) {
1344 /* ERROR_database_empty_result */
1345 if ($e->getCode() != 0x501) {
1346 throw $e;
1347 }
1348
1349 $perms = [];
1350 $grant = null;
1351 }
1352
1353 foreach ($perms as $permsid => $perm) {
1354 if (in_array($permsid, array_keys($profiles[$sgid]))) {
1355 $profiles[$sgid][$permsid] = $perm["permvalue"];
1356 } elseif (StringHelper::factory($permsid)->startsWith("i_needed_modify_power_")) {
1357 if (!$grant || $perm["permvalue"] > $grant) {
1358 continue;
1359 }
1360
1361 $profiles[$sgid]["i_needed_modify_power_total"] = $profiles[$sgid]["i_needed_modify_power_total"] + $perm["permvalue"];
1362 $profiles[$sgid]["i_needed_modify_power_count"]++;
1363 }
1364 }
1365 }
1366
1367 array_multisort($profiles, SORT_DESC);
1368
1369 return $profiles;
1370 }
1371
1383 public function serverGroupIdentify(
1386 ): ServerGroup {
1387 $profiles = $this->serverGroupGetProfiles($type);
1388
1389 $best_guess_profile = ($mode == TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) ? array_shift($profiles) : array_pop($profiles);
1390
1391 return $this->serverGroupGetById($best_guess_profile["__sgid"]);
1392 }
1393
1402 public function channelGroupList(array $filter = []): array
1403 {
1404 if ($this->cgroupList === null) {
1405 $this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
1406
1407 foreach ($this->cgroupList as $cgid => $group) {
1408 $this->cgroupList[$cgid] = new ChannelGroup($this, $group);
1409 }
1410
1411 uasort($this->cgroupList, [__CLASS__, "sortGroupList"]);
1412 }
1413
1414 return $this->filterList($this->cgroupList, $filter);
1415 }
1416
1422 public function channelGroupListReset(): void
1423 {
1424 $this->cgroupList = null;
1425 }
1426
1436 public function channelGroupCreate(string $name, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): int
1437 {
1438 $this->channelGroupListReset();
1439
1440 $cgid = $this->execute("channelgroupadd", ["name" => $name, "type" => $type])->toList();
1441
1442 return $cgid["cgid"];
1443 }
1444
1456 public function channelGroupCopy(int $scgid, string $name = null, int $tcgid = 0, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): int
1457 {
1458 $this->channelGroupListReset();
1459
1460 $cgid = $this->execute("channelgroupcopy", ["scgid" => $scgid, "tcgid" => $tcgid, "name" => $name, "type" => $type])
1461 ->toList();
1462
1463 if ($tcgid && $name) {
1464 $this->channelGroupRename($tcgid, $name);
1465 }
1466
1467 return count($cgid) ? $cgid["cgid"] : $tcgid;
1468 }
1469
1479 public function channelGroupRename(int $cgid, string $name): void
1480 {
1481 $this->channelGroupListReset();
1482
1483 $this->execute("channelgrouprename", ["cgid" => $cgid, "name" => $name]);
1484 }
1485
1496 public function channelGroupDelete(int $cgid, bool $force = false): void
1497 {
1498 $this->channelGroupListReset();
1499
1500 $this->execute("channelgroupdel", ["cgid" => $cgid, "force" => $force]);
1501 }
1502
1511 public function channelGroupGetById(int $cgid): ChannelGroup
1512 {
1513 if (!array_key_exists((string)$cgid, $this->channelGroupList())) {
1514 throw new ServerQueryException("invalid groupID", 0xA00);
1515 }
1516
1517 return $this->cgroupList[intval((string)$cgid)];
1518 }
1519
1529 public function channelGroupGetByName(string $name, int $type = TeamSpeak3::GROUP_DBTYPE_REGULAR): ChannelGroup
1530 {
1531 foreach ($this->channelGroupList() as $group) {
1532 if ($group["name"] == $name && $group["type"] == $type) {
1533 return $group;
1534 }
1535 }
1536
1537 throw new ServerQueryException("invalid groupID", 0xA00);
1538 }
1539
1549 public function channelGroupPermList(int $cgid, bool $permsid = false): array
1550 {
1551 return $this->execute("channelgrouppermlist", ["cgid" => $cgid, $permsid ? "-permsid" : null])
1552 ->toAssocArray($permsid ? "permsid" : "permid");
1553 }
1554
1566 public function channelGroupPermAssign(int $cgid, int|array $permid, int|array $permvalue): void
1567 {
1568 if (!is_array($permid)) {
1569 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1570 } else {
1571 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1572 }
1573
1574 $this->execute("channelgroupaddperm", ["cgid" => $cgid, $permident => $permid, "permvalue" => $permvalue]);
1575 }
1576
1587 public function channelGroupPermRemove(int $cgid, int|array $permid): void
1588 {
1589 if (!is_array($permid)) {
1590 $permident = (is_numeric($permid)) ? "permid" : "permsid";
1591 } else {
1592 $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
1593 }
1594
1595 $this->execute("channelgroupdelperm", ["cgid" => $cgid, $permident => $permid]);
1596 }
1597
1611 public function channelGroupClientList(int $cgid = null, int $cid = null, int $cldbid = null, bool $resolve = false): array
1612 {
1613 if ($this["virtualserver_default_channel_group"] == $cgid) {
1614 return [];
1615 }
1616
1617 try {
1618 $result = $this->execute("channelgroupclientlist", ["cgid" => $cgid, "cid" => $cid, "cldbid" => $cldbid])
1619 ->toArray();
1620 } catch (ServerQueryException $e) {
1621 /* ERROR_database_empty_result */
1622 if ($e->getCode() != 0x501) {
1623 throw $e;
1624 }
1625
1626 $result = [];
1627 }
1628
1629 if ($resolve) {
1630 foreach ($result as $k => $v) {
1631 $result[$k] = array_merge($v, $this->clientInfoDb($v["cldbid"]));
1632 }
1633 }
1634
1635 return $result;
1636 }
1637
1646 public function permReset(): StringHelper
1647 {
1648 $token = $this->request("permreset")->toList();
1649
1650 Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
1651
1652 return $token["token"];
1653 }
1654
1664 public function permRemoveAny(int $permid): int
1665 {
1666 $assignments = $this->permissionFind($permid);
1667
1668 foreach ($assignments as $assignment) {
1669 switch ($assignment["t"]) {
1671 $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
1672 break;
1673
1675 $this->clientPermRemove($assignment["id1"], $assignment["p"]);
1676 break;
1677
1679 $this->channelPermRemove($assignment["id1"], $assignment["p"]);
1680 break;
1681
1683 $this->channelGroupPermRemove($assignment["id2"], $assignment["p"]);
1684 break;
1685
1687 $this->channelClientPermRemove($assignment["id1"], $assignment["id2"], $assignment["p"]);
1688 break;
1689
1690 default:
1691 throw new ServerQueryException("convert error", 0x604);
1692 }
1693 }
1694
1695 return count($assignments);
1696 }
1697
1712 public function transferInitUpload(
1713 int $clientftfid,
1714 int $cid,
1715 string $name,
1716 int $size,
1717 string $cpw = "",
1718 bool $overwrite = false,
1719 bool $resume = false
1720 ): array {
1721 $upload = $this->execute("ftinitupload", ["clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume])
1722 ->toList();
1723
1724 if (array_key_exists("status", $upload) && $upload["status"] != 0x00) {
1725 throw new ServerQueryException($upload["msg"], $upload["status"]);
1726 }
1727
1728 $upload["cid"] = $cid;
1729 $upload["file"] = $name;
1730
1731 if (!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0")) {
1732 $upload["ip"] = $this->getParent()->getAdapterHost();
1733 } else {
1734 $upload["ip"] = $upload["ip"]->section(",");
1735 }
1736 $upload["host"] = $upload["ip"];
1737
1738 Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload);
1739
1740 return $upload;
1741 }
1742
1755 public function transferInitDownload(int $clientftfid, int $cid, string $name, string $cpw = "", int $seekpos = 0): array
1756 {
1757 $download = $this->execute("ftinitdownload", ["clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "seekpos" => $seekpos])
1758 ->toList();
1759
1760 if (array_key_exists("status", $download) && $download["status"] != 0x00) {
1761 throw new ServerQueryException($download["msg"], $download["status"]);
1762 }
1763
1764 $download["cid"] = $cid;
1765 $download["file"] = $name;
1766
1767 if (!array_key_exists("ip", $download) || $download["ip"]->startsWith("0.0.0.0")) {
1768 $download["ip"] = $this->getParent()->getAdapterHost();
1769 } else {
1770 $download["ip"] = $download["ip"]->section(",");
1771 }
1772 $download["host"] = $download["ip"];
1773
1774 Signal::getInstance()->emit("filetransferDownloadInit", $download["ftkey"], $download);
1775
1776 return $download;
1777 }
1778
1787 public function transferList(): array
1788 {
1789 return $this->request("ftlist")->toAssocArray("serverftfid");
1790 }
1791
1801 public function transferStop(int $serverftfid, bool $delete = false): void
1802 {
1803 $this->execute("ftstop", ["serverftfid" => $serverftfid, "delete" => $delete]);
1804 }
1805
1815 public function iconDownload(string $iconname = null)
1816 {
1817 if ($iconname) {
1818 $name = new StringHelper("/" . $iconname);
1819 } else {
1820 $iconid = $this['virtualserver_icon_id'];
1821 if (!is_int($iconid)) {
1822 $iconid = $iconid->toInt();
1823 }
1824
1825 if ($this->iconIsLocal("virtualserver_icon_id") || $iconid == 0) {
1826 return;
1827 }
1828 $name = $this->iconGetName("virtualserver_icon_id");
1829 }
1830
1831 $download = $this->transferInitDownload(rand(0x0000, 0xFFFF), 0, $name);
1832 $transfer = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
1833
1834 return $transfer->download($download["ftkey"], $download["size"]);
1835 }
1836
1846 public function iconUpload(string $data): int
1847 {
1848 $crc = crc32($data);
1849 $size = strlen($data);
1850
1851 $upload = $this->transferInitUpload(rand(0x0000, 0xFFFF), 0, "/icon_" . $crc, $size);
1852 $transfer = TeamSpeak3::factory("filetransfer://" . (str_contains($upload["host"], ":") ? "[" . $upload["host"] . "]" : $upload["host"]) . ":" . $upload["port"]);
1853
1854 $transfer->upload($upload["ftkey"], $upload["seekpos"], $data);
1855
1856 return $crc;
1857 }
1858
1867 public function modify(array $properties): void
1868 {
1869 $this->execute("serveredit", $properties);
1870 $this->resetNodeInfo();
1871 }
1872
1881 public function message(string $msg): void
1882 {
1883 $this->execute("sendtextmessage", ["msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_SERVER]);
1884 }
1885
1894 public function messageList(): array
1895 {
1896 return $this->request("messagelist")->toAssocArray("msgid");
1897 }
1898
1909 public function messageCreate(string $cluid, string $subject, string $message): void
1910 {
1911 $this->execute("messageadd", ["cluid" => $cluid, "subject" => $subject, "message" => $message]);
1912 }
1913
1922 public function messageDelete(int $msgid): void
1923 {
1924 $this->execute("messagedel", ["msgid" => $msgid]);
1925 }
1926
1936 public function messageRead(int $msgid, bool $flag_read = true): array
1937 {
1938 $msg = $this->execute("messageget", ["msgid" => $msgid])->toList();
1939
1940 if ($flag_read) {
1941 $this->execute("messageget", ["msgid" => $msgid, "flag" => $flag_read]);
1942 }
1943
1944 return $msg;
1945 }
1946
1955 public function snapshotCreate(int $mode = TeamSpeak3::SNAPSHOT_STRING): string
1956 {
1957 $snapshot = $this->request("serversnapshotcreate")->toString(false);
1958
1959 return match ($mode) {
1960 TeamSpeak3::SNAPSHOT_BASE64 => $snapshot->toBase64(),
1961 TeamSpeak3::SNAPSHOT_HEXDEC => $snapshot->toHex(),
1962 default => (string)$snapshot,
1963 };
1964 }
1965
1977 public function snapshotDeploy(string $data, int $mode = TeamSpeak3::SNAPSHOT_STRING): array
1978 {
1979 $data = match ($mode) {
1980 TeamSpeak3::SNAPSHOT_BASE64 => StringHelper::fromBase64($data),
1981 TeamSpeak3::SNAPSHOT_HEXDEC => StringHelper::fromHex($data),
1982 default => StringHelper::factory($data),
1983 };
1984
1985 $detail = $this->request("serversnapshotdeploy -mapping " . $data)->toList();
1986
1987 if (isset($detail[0]["sid"])) {
1988 Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail[0]["sid"]);
1989
1990 $server = array_shift($detail);
1991 } else {
1992 $server = [];
1993 }
1994
1995 $server["mapping"] = $detail;
1996
1997 return $server;
1998 }
1999
2011 public function notifyRegister(string $event, int $id = 0): void
2012 {
2013 $this->execute("servernotifyregister", ["event" => $event, "id" => $id]);
2014 }
2015
2024 public function notifyUnregister(): void
2025 {
2026 $this->request("servernotifyunregister");
2027 }
2028
2039 public function tokenList(bool $translate = false): array
2040 {
2041 return $this->privilegeKeyList();
2042 }
2043
2055 public function privilegeKeyList(bool $resolve = false): array
2056 {
2057 $tokens = $this->request("privilegekeylist")->toAssocArray("token");
2058
2059 if ($resolve) {
2060 foreach ($tokens as $token => $array) {
2061 $func = $array["token_type"] ? "channelGroupGetById" : "serverGroupGetById";
2062
2063 try {
2064 $tokens[$token]["token_id1"] = $this->$func($array["token_id1"])->name;
2065 } catch (NodeException $e) {
2066 /* ERROR_channel_invalid_id */
2067 if ($e->getCode() != 0xA00) {
2068 throw $e;
2069 }
2070 }
2071
2072 if ($array["token_type"]) {
2073 $tokens[$token]["token_id2"] = $this->channelGetById($array["token_id2"])->getPathway();
2074 }
2075 }
2076 }
2077
2078 return $tokens;
2079 }
2080
2094 public function tokenCreate(
2095 int $id1,
2096 int $id2 = 0,
2098 string $description = null,
2099 array $customset = null
2100 ): StringHelper {
2101 return $this->privilegeKeyCreate($id1, $id2, $type, $description, $customset);
2102 }
2103
2115 public function privilegeKeyCreate(
2116 int $id1,
2117 int $id2 = 0,
2119 string $description = null,
2120 string $customset = null
2121 ): StringHelper {
2122 $token = $this->execute("privilegekeyadd", ["tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset])
2123 ->toList();
2124
2125 Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
2126
2127 return $token["token"];
2128 }
2129
2138 public function tokenDelete($token)
2139 {
2140 $this->privilegeKeyDelete($token);
2141 }
2142
2151 public function privilegeKeyDelete(string $token): void
2152 {
2153 $this->execute("privilegekeydelete", ["token" => $token]);
2154 }
2155
2164 public function tokenUse($token)
2165 {
2166 $this->privilegeKeyUse($token);
2167 }
2168
2178 public function privilegeKeyUse(string $token): void
2179 {
2180 $this->execute("privilegekeyuse", ["token" => $token]);
2181 }
2182
2192 public function customSearch(string $ident, string $pattern = "%"): array
2193 {
2194 return $this->execute("customsearch", ["ident" => $ident, "pattern" => $pattern])->toArray();
2195 }
2196
2205 public function customInfo(int $cldbid): array
2206 {
2207 return $this->execute("custominfo", ["cldbid" => $cldbid])->toArray();
2208 }
2209
2220 public function customSet(int $cldbid, string $ident, string $value): void
2221 {
2222 $this->execute("customset", ["cldbid" => $cldbid, "ident" => $ident, "value" => $value]);
2223 }
2224
2234 public function customDelete(int $cldbid, string $ident): void
2235 {
2236 $this->execute("customdelete", ["cldbid" => $cldbid, "ident" => $ident]);
2237 }
2238
2248 public function banList($offset = null, $limit = null): array
2249 {
2250 return $this->execute("banlist -count", ["start" => $offset, "duration" => $limit])->toAssocArray("banid");
2251 }
2252
2260 public function banCount(): int
2261 {
2262 return current($this->execute("banlist -count", ["duration" => 1])->toList("count"));
2263 }
2264
2272 public function banListClear(): void
2273 {
2274 $this->request("bandelall");
2275 }
2276
2288 public function banCreate(array $rules, int $timeseconds = null, string $reason = null): int
2289 {
2290 $rules["time"] = $timeseconds;
2291 $rules["banreason"] = $reason;
2292
2293 $banid = $this->execute("banadd", $rules)->toList();
2294
2295 return $banid["banid"];
2296 }
2297
2306 public function banDelete(int $banid): void
2307 {
2308 $this->execute("bandel", ["banid" => $banid]);
2309 }
2310
2320 public function complaintList(int $tcldbid = null): array
2321 {
2322 return $this->execute("complainlist", ["tcldbid" => $tcldbid])->toArray();
2323 }
2324
2333 public function complaintListClear(int $tcldbid): void
2334 {
2335 $this->execute("complaindelall", ["tcldbid" => $tcldbid]);
2336 }
2337
2347 public function complaintCreate(int $tcldbid, string $message): void
2348 {
2349 $this->execute("complainadd", ["tcldbid" => $tcldbid, "message" => $message]);
2350 }
2351
2361 public function complaintDelete(int $tcldbid, int $fcldbid): void
2362 {
2363 $this->execute("complaindel", ["tcldbid" => $tcldbid, "fcldbid" => $fcldbid]);
2364 }
2365
2374 public function tempPasswordList(bool $resolve = false): array
2375 {
2376 $passwords = $this->request("servertemppasswordlist")->toAssocArray("pw_clear");
2377
2378 if ($resolve) {
2379 foreach ($passwords as $password => $array) {
2380 $channel = $this->channelGetById($array["tcid"]);
2381
2382 $passwords[$password]["tcname"] = $channel->toString();
2383 $passwords[$password]["tcpath"] = $channel->getPathway();
2384 }
2385 }
2386
2387 return $passwords;
2388 }
2389
2405 public function tempPasswordCreate(string $pw, int $duration, int $tcid = 0, string $tcpw = "", string $desc = ""): void
2406 {
2407 $this->execute("servertemppasswordadd", ["pw" => $pw, "duration" => $duration, "tcid" => $tcid, "tcpw" => $tcpw, "desc" => $desc]);
2408 }
2409
2418 public function tempPasswordDelete(string $pw): void
2419 {
2420 $this->execute("servertemppassworddel", ["pw" => $pw]);
2421 }
2422
2434 public function logView(int $lines = 30, int $begin_pos = null, bool $reverse = null, bool $instance = null): array
2435 {
2436 return $this->execute("logview", ["lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse])
2437 ->toArray();
2438 }
2439
2449 public function logAdd(string $logmsg, int $loglevel = TeamSpeak3::LOGLEVEL_INFO): void
2450 {
2451 $this->execute("logadd", ["logmsg" => $logmsg, "loglevel" => $loglevel]);
2452 }
2453
2461 public function connectionInfo(): array
2462 {
2463 return $this->request("serverrequestconnectioninfo")->toList();
2464 }
2465
2471 public function delete(): void
2472 {
2473 $this->getParent()->serverDelete($this->getId());
2474 }
2475
2481 public function start(): void
2482 {
2483 $this->getParent()->serverStart($this->getId());
2484 }
2485
2492 public function stop(string $msg = null): void
2493 {
2494 $this->getParent()->serverStop($this->getId(), $msg);
2495 }
2496
2506 public function sendPluginCmd(string $plugin, string $data): void
2507 {
2508 $this->execute("plugincmd", ["name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_SERVER]);
2509 }
2510
2519 public function selfUpdate(array $properties): void
2520 {
2521 $this->execute("clientupdate", $properties);
2522
2523 foreach ($properties as $ident => $value) {
2524 $this->whoamiSet($ident, $value);
2525 }
2526 }
2527
2537 public function selfUpdateLogin(string $username): StringHelper
2538 {
2539 $password = $this->execute("clientsetserverquerylogin", ["client_login_name" => $username])->toList();
2540
2541 return $password["client_login_password"];
2542 }
2543
2551 public function selfPermOverview(): array
2552 {
2553 return $this->execute("permoverview", ["cldbid" => $this->whoamiGet("client_database_id"), "cid" => $this->whoamiGet("client_channel_id"), "permid" => 0])
2554 ->toArray();
2555 }
2556
2562 protected function fetchNodeList()
2563 {
2564 $this->nodeList = [];
2565
2566 foreach ($this->channelList() as $channel) {
2567 if ($channel["pid"] == 0) {
2568 $this->nodeList[] = $channel;
2569 }
2570 }
2571 }
2572
2578 protected function fetchNodeInfo()
2579 {
2580 $this->nodeInfo = array_merge($this->nodeInfo, $this->request("serverinfo")->toList());
2581 }
2582
2590 protected static function sortClientList(Client $a, Client $b): int
2591 {
2592 if (get_class($a) != get_class($b)) {
2593 return 0;
2594 }
2595
2596 if ($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0)) {
2597 return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1;
2598 }
2599
2600 if ($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0)) {
2601 return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1;
2602 }
2603
2604 return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"]));
2605 }
2606
2614 protected static function sortGroupList(Node $a, Node $b): int
2615 {
2616 if (get_class($a) != get_class($b)) {
2617 return 0;
2618 }
2619
2620 if (!$a instanceof ServerGroup && !$a instanceof ChannelGroup) {
2621 return 0;
2622 }
2623
2624 if ($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0) {
2625 return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1;
2626 }
2627
2628 return ($a->getId() < $b->getId()) ? -1 : 1;
2629 }
2630
2638 protected static function sortFileList(array $a, array $b): int
2639 {
2640 if (!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b)) {
2641 return 0;
2642 }
2643
2644 if ($a["type"] != $b["type"]) {
2645 return ($a["type"] < $b["type"]) ? -1 : 1;
2646 }
2647
2648 return strcmp(strtolower($a["src"]), strtolower($b["src"]));
2649 }
2650
2656 public function isOnline(): bool
2657 {
2658 return $this["virtualserver_status"] == "online";
2659 }
2660
2666 public function isOffline(): bool
2667 {
2668 return $this["virtualserver_status"] == "offline";
2669 }
2670
2676 public function getUniqueId(): string
2677 {
2678 return $this->getParent()->getUniqueId() . "_s" . $this->getId();
2679 }
2680
2686 public function getIcon(): string
2687 {
2688 if ($this["virtualserver_clientsonline"] - $this["virtualserver_queryclientsonline"] >= $this["virtualserver_maxclients"]) {
2689 return "server_full";
2690 } elseif ($this["virtualserver_flag_password"]) {
2691 return "server_pass";
2692 } else {
2693 return "server_open";
2694 }
2695 }
2696
2702 public function getSymbol(): string
2703 {
2704 return "$";
2705 }
2706
2712 public function __toString()
2713 {
2714 return (string)$this["virtualserver_name"];
2715 }
2716}
Provides methods to analyze and format a ServerQuery reply.
Definition Reply.php:19
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Node\Node objects.
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery objects.
Class describing a TeamSpeak 3 channel group and all it's parameters.
Class describing a TeamSpeak 3 channel and all it's parameters.
Definition Channel.php:18
Class describing a TeamSpeak 3 client and all it's parameters.
Definition Client.php:18
Class describing a TeamSpeak 3 server instance and all it's parameters.
Definition Host.php:23
filterList(array $nodes=[], array $rules=[])
Definition Node.php:225
getProperty(string $property, mixed $default=null)
Definition Node.php:303
Class describing a TeamSpeak 3 virtual server and all it's parameters.
Definition Server.php:21
clientSetChannelGroup(int $cldbid, int $cid, int $cgid)
Definition Server.php:976
complaintDelete(int $tcldbid, int $fcldbid)
Definition Server.php:2361
channelGroupDelete(int $cgid, bool $force=false)
Definition Server.php:1496
channelSpacerCreate(string $ident, int $type=TeamSpeak3::SPACER_SOLIDLINE, int $align=TeamSpeak3::SPACER_ALIGN_REPEAT, int $order=null, int $maxclients=0)
Definition Server.php:213
serverGroupGetProfiles(int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1308
complaintCreate(int $tcldbid, string $message)
Definition Server.php:2347
clientListDb(int $offset=null, int $limit=null)
Definition Server.php:665
clientPermAssign(int $cldbid, int|array $permid, int|array $permvalue, bool|array $permskip=false)
Definition Server.php:1010
channelGroupCreate(string $name, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1436
snapshotCreate(int $mode=TeamSpeak3::SNAPSHOT_STRING)
Definition Server.php:1955
customSet(int $cldbid, string $ident, string $value)
Definition Server.php:2220
clientPermRemove(int $cldbid, int|array $permid)
Definition Server.php:1030
customDelete(int $cldbid, string $ident)
Definition Server.php:2234
logAdd(string $logmsg, int $loglevel=TeamSpeak3::LOGLEVEL_INFO)
Definition Server.php:2449
serverGroupPermList(int $sgid, bool $permsid=false)
Definition Server.php:1199
channelClientPermList(int $cid, int $cldbid, bool $permsid=false)
Definition Server.php:369
serverGroupIdentify(int $mode=TeamSpeak3::GROUP_IDENTIFIY_STRONGEST, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1383
channelPermAssign(int $cid, int|array $permid, int|array $permvalue)
Definition Server.php:328
static sortFileList(array $a, array $b)
Definition Server.php:2638
clientModifyDb(string $cldbid, array $properties)
Definition Server.php:946
logView(int $lines=30, int $begin_pos=null, bool $reverse=null, bool $instance=null)
Definition Server.php:2434
channelDirCreate(int $cid, string $cpw="", string $dirname="/")
Definition Server.php:518
clientFindDb(string $pattern, bool $uid=false)
Definition Server.php:706
channelClientPermAssign(int $cid, int $cldbid, int|array $permid, int|array $permvalue)
Definition Server.php:387
clientBan(int $clid, int $timeseconds=null, string $reason=null)
Definition Server.php:927
channelPermRemove(int $cid, int|array $permid)
Definition Server.php:348
serverGroupPermAssign(int $sgid, int|array $permid, int|array $permvalue, int|array $permnegated=0, bool|array $permskip=false)
Definition Server.php:1218
tempPasswordCreate(string $pw, int $duration, int $tcid=0, string $tcpw="", string $desc="")
Definition Server.php:2405
channelMove(int $cid, int $pid, int $order=null)
Definition Server.php:183
channelGroupGetByName(string $name, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1529
channelClientPermRemove(int $cid, int $cldbid, int|array $permid)
Definition Server.php:408
serverGroupDelete(int $sgid, bool $force=false)
Definition Server.php:1144
transferInitDownload(int $clientftfid, int $cid, string $name, string $cpw="", int $seekpos=0)
Definition Server.php:1755
sendPluginCmd(string $plugin, string $data)
Definition Server.php:2506
request(string $cmd, bool $throw=true)
Definition Server.php:71
channelGroupClientList(int $cgid=null, int $cid=null, int $cldbid=null, bool $resolve=false)
Definition Server.php:1611
serverGroupGetByName(string $name, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1179
channelGroupPermRemove(int $cgid, int|array $permid)
Definition Server.php:1587
__construct(Host $host, array $info, string $index="virtualserver_id")
Definition Server.php:50
messageRead(int $msgid, bool $flag_read=true)
Definition Server.php:1936
clientPermList(int $cldbid, bool $permsid=false)
Definition Server.php:990
serverGroupCreate(string $name, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1084
channelFileDelete(int $cid, string $cpw="", string $name="/")
Definition Server.php:503
channelPermList(int $cid, bool $permsid=false)
Definition Server.php:311
channelDelete(int|Node $cid, bool $force=false)
Definition Server.php:163
clientKick(int $clid, int $reasonid=TeamSpeak3::KICK_CHANNEL, $reasonmsg=null)
Definition Server.php:895
privilegeKeyCreate(int $id1, int $id2=0, int $type=TeamSpeak3::TOKEN_SERVERGROUP, string $description=null, string $customset=null)
Definition Server.php:2115
channelFileInfo(int $cid, string $cpw="", string $name="/")
Definition Server.php:467
clientMove(int|Node $clid, int|Node $cid, $cpw=null)
Definition Server.php:866
static sortClientList(Client $a, Client $b)
Definition Server.php:2590
channelFileList(int $cid, string $cpw="", string $path="/", bool $recursive=false)
Definition Server.php:430
channelGroupCopy(int $scgid, string $name=null, int $tcgid=0, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1456
transferInitUpload(int $clientftfid, int $cid, string $name, int $size, string $cpw="", bool $overwrite=false, bool $resume=false)
Definition Server.php:1712
serverGroupPermRemove(int $sgid, int|array $permid)
Definition Server.php:1239
channelGroupPermList(int $cgid, bool $permsid=false)
Definition Server.php:1549
transferStop(int $serverftfid, bool $delete=false)
Definition Server.php:1801
banCreate(array $rules, int $timeseconds=null, string $reason=null)
Definition Server.php:2288
messageCreate(string $cluid, string $subject, string $message)
Definition Server.php:1909
customSearch(string $ident, string $pattern="%")
Definition Server.php:2192
snapshotDeploy(string $data, int $mode=TeamSpeak3::SNAPSHOT_STRING)
Definition Server.php:1977
serverGroupCopy(int $ssgid, string $name=null, int $tsgid=0, int $type=TeamSpeak3::GROUP_DBTYPE_REGULAR)
Definition Server.php:1104
channelGroupPermAssign(int $cgid, int|array $permid, int|array $permvalue)
Definition Server.php:1566
channelFileRename(int $cid, string $cpw="", string $oldname="/", string $newname="/", int $tcid=null, string $tcpw=null)
Definition Server.php:488
channelGroupRename(int $cgid, string $name)
Definition Server.php:1479
tokenCreate(int $id1, int $id2=0, int $type=TeamSpeak3::TOKEN_SERVERGROUP, string $description=null, array $customset=null)
Definition Server.php:2094
const PERM_TYPE_CHANNELGROUP
3: channel group permission
const LOGLEVEL_INFO
4: informational output
const PLUGINCMD_SERVER
2: send plugincmd to all clients on server
const PERM_TYPE_CHANNELCLIENT
4: channel-client specific permission
const TOKEN_SERVERGROUP
0: server group token (id1={groupID} id2=0)
const GROUP_IDENTIFIY_STRONGEST
1: identify most powerful group
const FILE_TYPE_DIRECTORY
0: file is directory
const KICK_CHANNEL
4: kick client from channel
const SPACER_ALIGN_REPEAT
3: repeat until the whole line is filled
const PERM_TYPE_CHANNEL
2: channel specific permission
const SPACER_DASHDOTDOTLINE
4: dash dot dot line
const TEXTMSG_SERVER
3: target is a virtual server
const GROUP_DBTYPE_REGULAR
1: regular group (used for regular clients)
const PERM_TYPE_CLIENT
1: client specific permission
const PERM_TYPE_SERVERGROUP
0: server group permission