ts3phpframework
Loading...
Searching...
No Matches
Client.php
Go to the documentation of this file.
1<?php
2
3namespace PlanetTeamSpeak\TeamSpeak3Framework\Node;
4
5use PlanetTeamSpeak\TeamSpeak3Framework\Exception\AdapterException;
6use PlanetTeamSpeak\TeamSpeak3Framework\Exception\HelperException;
7use PlanetTeamSpeak\TeamSpeak3Framework\Exception\ServerQueryException;
8use PlanetTeamSpeak\TeamSpeak3Framework\Helper\StringHelper;
9use PlanetTeamSpeak\TeamSpeak3Framework\TeamSpeak3;
10
17class Client extends Node
18{
27 public function __construct(Server $server, array $info, string $index = "clid")
28 {
29 $this->parent = $server;
30 $this->nodeInfo = $info;
31
32 if (!array_key_exists($index, $this->nodeInfo)) {
33 throw new ServerQueryException("invalid clientID", 0x200);
34 }
35
36 $this->nodeId = $this->nodeInfo[$index];
37 }
38
47 public function modify(array $properties): void
48 {
49 $properties["clid"] = $this->getId();
50
51 $this->execute("clientedit", $properties);
52 $this->resetNodeInfo();
53 }
54
61 public function modifyDb(array $properties): void
62 {
63 $this->getParent()->clientModifyDb($this["client_database_id"], $properties);
64 }
65
71 public function deleteDb(): void
72 {
73 $this->getParent()->clientDeleteDb($this["client_database_id"]);
74 }
75
81 public function infoDb(): array
82 {
83 return $this->getParent()->clientInfoDb($this["client_database_id"]);
84 }
85
94 public function message(string $msg): void
95 {
96 $this->execute("sendtextmessage", ["msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_CLIENT]);
97 }
98
106 public function move(int $cid, string $cpw = null): void
107 {
108 $this->getParent()->clientMove($this->getId(), $cid, $cpw);
109 }
110
118 public function kick(int $reasonid = TeamSpeak3::KICK_CHANNEL, string $reasonmsg = null): void
119 {
120 $this->getParent()->clientKick($this->getId(), $reasonid, $reasonmsg);
121 }
122
129 public function poke(string $msg): void
130 {
131 $this->getParent()->clientPoke($this->getId(), $msg);
132 }
133
142 public function ban(int $timeseconds = null, string $reason = null): array
143 {
144 return $this->getParent()->clientBan($this->getId(), $timeseconds, $reason);
145 }
146
152 public function customInfo(): array
153 {
154 return $this->getParent()->customInfo($this["client_database_id"]);
155 }
156
164 public function customSet(string $ident, string $value): void
165 {
166 $this->getParent()->customSet($this["client_database_id"], $ident, $value);
167 }
168
175 public function customDelete(string $ident): void
176 {
177 $this->getParent()->customDelete($this["client_database_id"], $ident);
178 }
179
188 public function permOverview(int $cid): array
189 {
190 return $this->execute("permoverview", ["cldbid" => $this["client_database_id"], "cid" => $cid, "permid" => 0])->toArray();
191 }
192
199 public function permList(bool $permsid = false): array
200 {
201 return $this->getParent()->clientPermList($this["client_database_id"], $permsid);
202 }
203
213 public function permAssign(int|array $permid, int|array $permvalue, array|bool $permskip = false): void
214 {
215 $this->getParent()->clientPermAssign($this["client_database_id"], $permid, $permvalue, $permskip);
216 }
217
223 public function permAssignByName($permname, $permvalue, $permskip = false)
224 {
225 $this->permAssign($permname, $permvalue, $permskip);
226 }
227
234 public function permRemove(int $permid): void
235 {
236 $this->getParent()->clientPermRemove($this["client_database_id"], $permid);
237 }
238
244 public function permRemoveByName($permname)
245 {
246 $this->permRemove($permname);
247 }
248
256 public function setChannelGroup(int $cid, int $cgid): void
257 {
258 $this->getParent()->clientSetChannelGroup($this["client_database_id"], $cid, $cgid);
259 }
260
267 public function addServerGroup(int $sgid): void
268 {
269 $this->getParent()->serverGroupClientAdd($sgid, $this["client_database_id"]);
270 }
271
278 public function remServerGroup(int $sgid): void
279 {
280 $this->getParent()->serverGroupClientDel($sgid, $this["client_database_id"]);
281 }
282
288 public function avatarGetName(): StringHelper
289 {
290 return new StringHelper("/avatar_" . $this["client_base64HashClientUID"]);
291 }
292
301 public function avatarDownload()
302 {
303 if ($this["client_flag_avatar"] == null) {
304 return;
305 }
306
307 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName());
308 $transfer = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
309
310 return $transfer->download($download["ftkey"], $download["size"]);
311 }
312
320 public function getClones(): array
321 {
322 return $this->execute("clientgetids", ["cluid" => $this["client_unique_identifier"]])->toAssocArray("clid");
323 }
324
330 public function hasOverwolf(): bool
331 {
332 return str_contains($this["client_badges"], "overwolf=1");
333 }
334
340 public function getBadges(): array
341 {
342 $badges = [];
343
344 foreach (explode(":", $this["client_badges"]) as $set) {
345 if (str_starts_with($set, "badges=")) {
346 $badges[] = array_map("trim", explode(",", substr($set, 7)));
347 }
348 }
349
350 return $badges;
351 }
352
358 public function getRev(): ?int
359 {
360 return $this["client_type"] ? null : $this["client_version"]->section("[", 1)->filterDigits();
361 }
362
368 public function memberOf(): array
369 {
370 $channelGroups = [$this->getParent()->channelGroupGetById($this["client_channel_group_id"])];
371 $serverGroups = [];
372
373 foreach (explode(",", $this["client_servergroups"]) as $sgid) {
374 $serverGroups[] = $this->getParent()->serverGroupGetById($sgid);
375 }
376
377 uasort($serverGroups, [__CLASS__, "sortGroupList"]);
378
379 return array_merge($channelGroups, $serverGroups);
380 }
381
390 public function iconDownload()
391 {
392 $iconid = $this['client_icon_id'];
393 if (!is_int($iconid)) {
394 $iconid = $iconid->toInt();
395 }
396
397 if ($this->iconIsLocal("client_icon_id") || $iconid == 0) {
398 return;
399 }
400
401 $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("client_icon_id"));
402 $transfer = TeamSpeak3::factory("filetransfer://" . (str_contains($download["host"], ":") ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
403
404 return $transfer->download($download["ftkey"], $download["size"]);
405 }
406
416 public function sendPluginCmd(string $plugin, string $data): void
417 {
418 $this->execute("plugincmd", ["name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_CLIENT, "target" => $this->getId()]);
419 }
420
425 protected function fetchNodeInfo()
426 {
427 if ($this->offsetExists("client_type") && $this["client_type"] == 1) {
428 return;
429 }
430
431 $this->nodeInfo = array_merge($this->nodeInfo, $this->execute("clientinfo", ["clid" => $this->getId()])->toList());
432 }
433
439 public function getUniqueId(): string
440 {
441 return $this->getParent()->getUniqueId() . "_cl" . $this->getId();
442 }
443
449 public function getIcon(): string
450 {
451 if ($this["client_type"]) {
452 return "client_query";
453 } elseif ($this["client_away"]) {
454 return "client_away";
455 } elseif (!$this["client_output_hardware"]) {
456 return "client_snd_disabled";
457 } elseif ($this["client_output_muted"]) {
458 return "client_snd_muted";
459 } elseif (!$this["client_input_hardware"]) {
460 return "client_mic_disabled";
461 } elseif ($this["client_input_muted"]) {
462 return "client_mic_muted";
463 } elseif ($this["client_is_channel_commander"]) {
464 return $this["client_flag_talking"] ? "client_cc_talk" : "client_cc_idle";
465 } else {
466 return $this["client_flag_talking"] ? "client_talk" : "client_idle";
467 }
468 }
469
475 public function getSymbol(): string
476 {
477 return "@";
478 }
479
485 public function __toString()
486 {
487 return (string)$this["client_nickname"];
488 }
489}
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery objects.
Class describing a TeamSpeak 3 client and all it's parameters.
Definition Client.php:18
__construct(Server $server, array $info, string $index="clid")
Definition Client.php:27
sendPluginCmd(string $plugin, string $data)
Definition Client.php:416
ban(int $timeseconds=null, string $reason=null)
Definition Client.php:142
customSet(string $ident, string $value)
Definition Client.php:164
permAssign(int|array $permid, int|array $permvalue, array|bool $permskip=false)
Definition Client.php:213
permAssignByName($permname, $permvalue, $permskip=false)
Definition Client.php:223
kick(int $reasonid=TeamSpeak3::KICK_CHANNEL, string $reasonmsg=null)
Definition Client.php:118
Class describing a TeamSpeak 3 virtual server and all it's parameters.
Definition Server.php:21
const PLUGINCMD_CLIENT
3: send plugincmd to all given client ids
const KICK_CHANNEL
4: kick client from channel