ts3phpframework
Loading...
Searching...
No Matches
Channel.php
Go to the documentation of this file.
1<?php
2
4
10
17class Channel extends Node
18{
19 private array|null $clientList = null;
20 private array $channelList = [];
21
30 public function __construct(Server $server, array $info, string $index = "cid")
31 {
32 $this->parent = $server;
33 $this->nodeInfo = $info;
34
35 if (!array_key_exists($index, $this->nodeInfo)) {
36 throw new ServerQueryException("invalid channelID", 0x300);
37 }
38
39 $this->nodeId = $this->nodeInfo[$index];
40 }
41
48 public function subChannelList(array $filter = []): array
49 {
50 $channels = [];
51
52 foreach ($this->getParent()->channelList() as $channel) {
53 if ($channel["pid"] == $this->getId()) {
54 $channels[$channel->getId()] = $channel;
55 }
56 }
57
58 return $this->filterList($channels, $filter);
59 }
60
68 public function subChannelGetById(int $cid): Channel
69 {
70 if (!array_key_exists($cid, $this->subChannelList())) {
71 throw new ServerQueryException("invalid channelID", 0x300);
72 }
73
74 return $this->channelList[$cid];
75 }
76
84 public function subChannelGetByName(int $name): Channel
85 {
86 foreach ($this->subChannelList() as $channel) {
87 if ($channel["channel_name"] == $name) {
88 return $channel;
89 }
90 }
91
92 throw new ServerQueryException("invalid channelID", 0x300);
93 }
94
101 public function clientList(array $filter = []): array
102 {
103 $clients = [];
104
105 foreach ($this->getParent()->clientList() as $client) {
106 if ($client["cid"] == $this->getId()) {
107 $clients[$client->getId()] = $client;
108 }
109 }
110
111 return $this->filterList($clients, $filter);
112 }
113
121 public function clientGetById(int $clid): Client
122 {
123 if (!array_key_exists($clid, $this->clientList())) {
124 throw new ServerQueryException("invalid clientID", 0x200);
125 }
126
127 return $this->clientList[$clid];
128 }
129
137 public function clientGetByName(int $name): Client
138 {
139 foreach ($this->clientList() as $client) {
140 if ($client["client_nickname"] == $name) {
141 return $client;
142 }
143 }
144
145 throw new ServerQueryException("invalid clientID", 0x200);
146 }
147
155 public function clientPermList(int $cldbid, bool $permsid = false): array
156 {
157 return $this->getParent()->channelClientPermList($this->getId(), $cldbid, $permsid);
158 }
159
169 public function clientPermAssign(int $cldbid, int|array $permid, int|array $permvalue): void
170 {
171 $this->getParent()->channelClientPermAssign($this->getId(), $cldbid, $permid, $permvalue);
172 }
173
179 public function clientPermAssignByName($cldbid, $permname, $permvalue)
180 {
181 $this->clientPermAssign($cldbid, $permname, $permvalue);
182 }
183
191 public function clientPermRemove(int $cldbid, int|array $permid): void
192 {
193 $this->getParent()->channelClientPermRemove($this->getId(), $cldbid, $permid);
194 }
195
201 public function clientPermRemoveByName($cldbid, $permname)
202 {
203 $this->clientPermRemove($cldbid, $permname);
204 }
205
212 public function permList(bool $permsid = false): array
213 {
214 return $this->getParent()->channelPermList($this->getId(), $permsid);
215 }
216
225 public function permAssign(int|array $permid, int|array $permvalue): void
226 {
227 $this->getParent()->channelPermAssign($this->getId(), $permid, $permvalue);
228 }
229
235 public function permAssignByName($permname, $permvalue)
236 {
237 $this->permAssign($permname, $permvalue);
238 }
239
246 public function permRemove(int|array $permid): void
247 {
248 $this->getParent()->channelPermRemove($this->getId(), $permid);
249 }
250
256 public function permRemoveByName($permname)
257 {
258 $this->permRemove($permname);
259 }
260
269 public function fileList(string $cpw = "", string $path = "/", bool $recursive = false): array
270 {
271 return $this->getParent()->channelFileList($this->getId(), $cpw, $path, $recursive);
272 }
273
281 public function fileInfo(string $cpw = "", string $name = "/"): array
282 {
283 return $this->getParent()->channelFileInfo($this->getId(), $cpw, $name);
284 }
285
297 public function fileRename(string $cpw = "", string $oldname = "/", string $newname = "/", int $tcid = null, string $tcpw = null): void
298 {
299 $this->getParent()->channelFileRename($this->getId(), $cpw, $oldname, $newname, $tcid, $tcpw);
300 }
301
309 public function fileDelete(string $cpw = "", string $name = "/"): void
310 {
311 $this->getParent()->channelFileDelete($this->getId(), $cpw, $name);
312 }
313
321 public function dirCreate(string $cpw = "", string $dirname = "/"): void
322 {
323 $this->getParent()->channelDirCreate($this->getId(), $cpw, $dirname);
324 }
325
331 public function getLevel(): int
332 {
333 return $this->getParent()->channelGetLevel($this->getId());
334 }
335
341 public function getPathway(): string
342 {
343 return $this->getParent()->channelGetPathway($this->getId());
344 }
345
351 public function spacerGetType(): int
352 {
353 return $this->getParent()->channelSpacerGetType($this->getId());
354 }
355
361 public function spacerGetAlign(): int
362 {
363 return $this->getParent()->channelSpacerGetAlign($this->getId());
364 }
365
371 public function isSpacer(): bool
372 {
373 return $this->getParent()->channelIsSpacer($this);
374 }
375
384 public function iconDownload()
385 {
386 $iconid = $this['channel_icon_id'];
387 if (!is_int($iconid)) {
388 $iconid = $iconid->toInt();
389 }
390
391 if ($this->iconIsLocal("channel_icon_id") || $iconid == 0) {
392 return;
393 }
394
395 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("channel_icon_id"));
396 $transfer = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
397
398 return $transfer->download($download["ftkey"], $download["size"]);
399 }
400
409 public function modify(array $properties): void
410 {
411 $properties["cid"] = $this->getId();
412
413 $this->execute("channeledit", $properties);
414 $this->resetNodeInfo();
415 }
416
426 public function message(string $msg, string $cpw = null): void
427 {
428 if ($this->getId() != $this->getParent()->whoamiGet("client_channel_id")) {
429 $this->getParent()->clientMove($this->getParent()->whoamiGet("client_id"), $this->getId(), $cpw);
430 }
431
432 $this->execute("sendtextmessage", ["msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CHANNEL]);
433 }
434
441 public function delete(bool $force = false): void
442 {
443 $this->getParent()->channelDelete($this->getId(), $force);
444 }
445
453 public function move(int $pid, int $order = null): void
454 {
455 $this->getParent()->channelMove($this->getId(), $pid, $order);
456 }
457
469 public function sendPluginCmd(string $plugin, string $data, string $cpw = null, bool $subscribed = false): void
470 {
471 if ($this->getId() != $this->getParent()->whoamiGet("client_channel_id")) {
472 $this->getParent()->clientMove($this->getParent()->whoamiGet("client_id"), $this->getId(), $cpw);
473 }
474
475 $this->execute("plugincmd", ["name" => $plugin, "data" => $data, "targetmode" => $subscribed ? TeamSpeak3::PLUGINCMD_CHANNEL_SUBSCRIBED : TeamSpeak3::PLUGINCMD_CHANNEL]);
476 }
477
481 protected function fetchNodeList()
482 {
483 $this->nodeList = [];
484
485 if ($this->getParent()->getLoadClientlistFirst()) {
486 foreach ($this->clientList() as $client) {
487 if ($client["cid"] == $this->getId()) {
488 $this->nodeList[] = $client;
489 }
490 }
491
492 foreach ($this->subChannelList() as $channel) {
493 if ($channel["pid"] == $this->getId()) {
494 $this->nodeList[] = $channel;
495 }
496 }
497 } else {
498 foreach ($this->subChannelList() as $channel) {
499 if ($channel["pid"] == $this->getId()) {
500 $this->nodeList[] = $channel;
501 }
502 }
503
504 foreach ($this->clientList() as $client) {
505 if ($client["cid"] == $this->getId()) {
506 $this->nodeList[] = $client;
507 }
508 }
509 }
510 }
511
517 protected function fetchNodeInfo()
518 {
519 $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("channelinfo", ["cid" => $this->getId()])->toList());
520 }
521
527 public function getUniqueId(): string
528 {
529 return $this->getParent()->getUniqueId() . "_ch" . $this->getId();
530 }
531
537 public function getIcon(): string
538 {
539 if (!$this["channel_maxclients"] || ($this["channel_maxclients"] != -1 && $this["channel_maxclients"] <= $this["total_clients"])) {
540 return "channel_full";
541 } elseif ($this["channel_flag_password"]) {
542 return "channel_pass";
543 } else {
544 return "channel_open";
545 }
546 }
547
553 public function getSymbol(): string
554 {
555 return "#";
556 }
557
563 public function __toString()
564 {
565 return (string)$this["channel_name"];
566 }
567}
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\Adapter objects.
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Helper* objects.
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery objects.
Class describing a TeamSpeak 3 channel and all it's parameters.
Definition Channel.php:18
fileList(string $cpw="", string $path="/", bool $recursive=false)
Definition Channel.php:269
fileRename(string $cpw="", string $oldname="/", string $newname="/", int $tcid=null, string $tcpw=null)
Definition Channel.php:297
clientPermRemove(int $cldbid, int|array $permid)
Definition Channel.php:191
clientPermList(int $cldbid, bool $permsid=false)
Definition Channel.php:155
message(string $msg, string $cpw=null)
Definition Channel.php:426
__construct(Server $server, array $info, string $index="cid")
Definition Channel.php:30
permAssign(int|array $permid, int|array $permvalue)
Definition Channel.php:225
clientPermAssignByName($cldbid, $permname, $permvalue)
Definition Channel.php:179
dirCreate(string $cpw="", string $dirname="/")
Definition Channel.php:321
sendPluginCmd(string $plugin, string $data, string $cpw=null, bool $subscribed=false)
Definition Channel.php:469
fileDelete(string $cpw="", string $name="/")
Definition Channel.php:309
clientPermAssign(int $cldbid, int|array $permid, int|array $permvalue)
Definition Channel.php:169
fileInfo(string $cpw="", string $name="/")
Definition Channel.php:281
Class describing a TeamSpeak 3 client and all it's parameters.
Definition Client.php:18
filterList(array $nodes=[], array $rules=[])
Definition Node.php:225
Class describing a TeamSpeak 3 virtual server and all it's parameters.
Definition Server.php:21
Factory class all for TeamSpeak 3 PHP Framework objects.
const PLUGINCMD_CHANNEL
1: send plugincmd to all clients in current channel
const PLUGINCMD_CHANNEL_SUBSCRIBED
4: send plugincmd to all subscribed clients in current channel
const TEXTMSG_CHANNEL
2: target is a channel