public function testException() { try { $teamspeak = TeamSpeak3::factory("serverquery://*****:*****@176.57.128.197:10011/?server_port=9987"); $this->fail(); } catch (\Exception $ex) { $this->assertTrue($ex instanceof Ts3Exception); } }
/** * Connect to TeamSpeak3 server */ function __construct($logger, $channel = null) { $cfg = new Config($logger); $this->config = $cfg->get(); $this->logger = $logger; $this->channel = $channel; $TsServerConfig = array($this->config['teamspeak']['user'], $this->config['teamspeak']['password'], $this->config['teamspeak']['host'], $this->config['teamspeak']['server_port']); $serverUri = vsprintf("serverquery://%s:%s@%s/?server_port=%d", $TsServerConfig); try { $this->ts3Server = TeamSpeak3::factory($serverUri); } catch (\Exception $e) { $logger->critical('[slack-teamspeak-integration] Fail to connect to the TeamSpeak server'); } }
/** * EventWorker constructor. * * @param $logger */ public function __construct($logger) { $cfg = new Config($logger); $this->config = $cfg->get(); $this->logger = $logger; $TsServerConfig = array($this->config['teamspeak']['user'], $this->config['teamspeak']['password'], $this->config['teamspeak']['host'], $this->config['teamspeak']['server_port']); $serverUri = vsprintf("serverquery://%s:%s@%s/?server_port=%d&blocking=0", $TsServerConfig); try { $this->ts3Server = TeamSpeak3::factory($serverUri); } catch (\Exception $e) { echo '[slack-teamspeak-integration] Fail to connect to the TeamSpeak server'; exit; } // Listen for user connection / disconnection from the server $this->ts3Server->notifyRegister(self::EVENT_CATEGORY); Signal::getInstance()->subscribe(self::EVENT_CONNECT, array($this, self::EVENT_CONNECT)); Signal::getInstance()->subscribe(self::EVENT_DISCONNECT, array($this, self::EVENT_DISCONNECT)); }
public function init($config) { if (!array_key_exists("username", $config)) { throw new InvalidArgumentException("Username for Teamspeak-Server not set"); } if (!array_key_exists("password", $config)) { throw new InvalidArgumentException("Password for Teamspeak-Server not set"); } if (!array_key_exists("server", $config)) { throw new InvalidArgumentException("Servername for Teamspeak-Server not set"); } if (!array_key_exists("port", $config)) { throw new InvalidArgumentException("Port for Teamspeak-Server not set"); } $username = $config["username"]; $password = $config["password"]; $server = $config["server"]; $port = $config["port"]; $ts = TeamSpeak3::factory("serverquery://{$username}:{$password}@{$server}/?server_port={$port}"); $this->setTeamspeak($ts); }
/** * Uploads a given icon file content to the server and returns the ID of the icon. * * @param string $data * @return integer */ public function iconUpload($data) { $crc = crc32($data); $size = strlen($data); $upload = $this->transferInitUpload(rand(0x0, 0xffff), 0, "/icon_" . $crc, $size); $transfer = TeamSpeak3::factory("filetransfer://" . $upload["host"] . ":" . $upload["port"]); $transfer->upload($upload["ftkey"], $upload["seekpos"], $data); return $crc; }
public function __construct() { $tssettings = TeamspeakSetting::first(); $this->ts3 = TeamSpeak3::factory("serverquery://" . $tssettings->tsuser . ":" . $tssettings->tspass . "@" . $tssettings->tshost . ":" . $tssettings->tsport . "/?server_port=" . $tssettings->tscport); }
/** * Downloads and returns the channel groups icon file content. * * @return TeamSpeak3_Helper_String */ public function iconDownload() { if ($this->iconIsLocal("iconid") || $this["iconid"] == 0) { return; } $download = $this->getParent()->transferInitDownload(rand(0x0, 0xffff), 0, $this->iconGetName("iconid")); $transfer = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"]); return $transfer->download($download["ftkey"], $download["size"]); }
/** * Returns the first Server object matching the given TSDNS hostname. Like the * TeamSpeak 3 Client, this method will start looking for a TSDNS server on the second-level * domain including a fallback to the third-level domain of the specified $tsdns parameter. * * @param string $tsdns * @throws Ts3Exception * @return Server */ public function serverGetByTSDNS($tsdns) { $parts = Uri::getFQDNParts($tsdns); $query = HelperString::factory(array_shift($parts)); while ($part = array_shift($parts)) { $query->prepend($part); try { $port = TeamSpeak3::factory("tsdns://" . $query . "/?timeout=3")->resolve($tsdns)->section(":", 1); return $this->serverGetByPort($port == "" ? 9987 : $port); } catch (Ts3Exception $e) { /* skip "Connection timed out" and "Connection refused" */ if ($e->getCode() != 10060 && $e->getCode() != 10061) { throw $e; } } } throw new Ts3Exception("invalid serverID", 0x400); }
/** * Returns the HTML img tags which can be used to display the various icons for a * TeamSpeak_Node_Client object. * * @return string */ protected function getSuffixIconClient() { $html = ""; if ($this->currObj["client_is_priority_speaker"]) { $html .= $this->getImage("client_priority.png", "Priority Speaker"); } if ($this->currObj["client_is_channel_commander"]) { $html .= $this->getImage("client_cc.png", "Channel Commander"); } if ($this->currObj["client_is_talker"]) { $html .= $this->getImage("client_talker.png", "Talk Power granted"); } elseif ($cntp = $this->currObj->getParent()->channelGetById($this->currObj["cid"])->channel_needed_talk_power) { if ($cntp > $this->currObj["client_talk_power"]) { $html .= $this->getImage("client_mic_muted.png", "Insufficient Talk Power"); } } foreach ($this->currObj->memberOf() as $group) { if (!$group["iconid"]) { continue; } $type = $group instanceof \Teamspeak3\Node\Servergroup ? "Server Group" : "Channel Group"; if (!$group->iconIsLocal("iconid") && $this->ftclient) { if (!isset($this->cacheIcon[$group["iconid"]])) { $download = $group->getParent()->transferInitDownload(rand(0x0, 0xffff), 0, $group->iconGetName("iconid")); if ($this->ftclient == "data:image") { $download = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"])->download($download["ftkey"], $download["size"]); } $this->cacheIcon[$group["iconid"]] = $download; } else { $download = $this->cacheIcon[$group["iconid"]]; } if ($this->ftclient == "data:image") { $html .= $this->getImage("data:" . \TeamSpeak3\Helper\Convert::imageMimeType($download) . ";base64," . base64_encode($download), $group . " [" . $type . "]", null, FALSE); } else { $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), $group . " [" . $type . "]", null, FALSE); } } elseif (in_array($group["iconid"], $this->cachedIcons)) { $html .= $this->getImage("group_icon_" . $group["iconid"] . ".png", $group . " [" . $type . "]"); } } if ($this->currObj["client_icon_id"]) { if (!$this->currObj->iconIsLocal("client_icon_id") && $this->ftclient) { if (!isset($this->cacheIcon[$this->currObj["client_icon_id"]])) { $download = $this->currObj->getParent()->transferInitDownload(rand(0x0, 0xffff), 0, $this->currObj->iconGetName("client_icon_id")); if ($this->ftclient == "data:image") { $download = TeamSpeak3::factory("filetransfer://" . $download["host"] . ":" . $download["port"])->download($download["ftkey"], $download["size"]); } $this->cacheIcon[$this->currObj["client_icon_id"]] = $download; } else { $download = $this->cacheIcon[$this->currObj["client_icon_id"]]; } if ($this->ftclient == "data:image") { $html .= $this->getImage("data:" . \TeamSpeak3\Helper\Convert::imageMimeType($download) . ";base64," . base64_encode($download), "Client Icon", null, FALSE); } else { $html .= $this->getImage($this->ftclient . "?ftdata=" . base64_encode(serialize($download)), "Client Icon", null, FALSE); } } elseif (in_array($this->currObj["client_icon_id"], $this->cachedIcons)) { $html .= $this->getImage("group_icon_" . $this->currObj["client_icon_id"] . ".png", "Client Icon"); } } return $html; }
public function __construct($teamspeack_password) { $this->password = $teamspeack_password; $this->ts3 = TeamSpeak3::factory("serverquery://*****:*****@apologize.ovh:10011/?server_port=9987&nickname=apologize"); }