diff --git a/bans.php b/bans.php index d3fb33c..7d775d9 100644 --- a/bans.php +++ b/bans.php @@ -54,7 +54,7 @@ function getBanlist() { global $lang; try { - $tsAdmin = TeamSpeak3::factory(getTeamspeakURI() . "#no_query_clients"); + $tsAdmin = getTeamspeakConnection("#no_query_clients"); $bans = $tsAdmin->banList(); diff --git a/include/adminlist.php b/include/adminlist.php index 34ea1f9..841d520 100644 --- a/include/adminlist.php +++ b/include/adminlist.php @@ -20,7 +20,7 @@ function getAdminList() { $localIcons = array(100, 200, 300, 400, 500, 600); try { - $tsAdmin = TeamSpeak3::factory(getTeamspeakURI()); + $tsAdmin = getTeamspeakConnection(); $output = ""; diff --git a/include/tsutils.php b/include/tsutils.php index 07ffb23..7e9a735 100644 --- a/include/tsutils.php +++ b/include/tsutils.php @@ -4,29 +4,35 @@ require_once __DIR__ . '/../config/config.php'; require_once __DIR__ . "/../lib/ts3phpframework/libraries/TeamSpeak3/TeamSpeak3.php"; function pingTeamspeakServerFromConfig() { - return pingTeamspeakServer(getTeamspeakURI() . "&use_offline_as_virtual=1&no_query_clients=1"); + return pingTeamspeakServer(getTeamspeakConnection("?use_offline_as_virtual=1&no_query_clients=1")); } -function pingTeamspeakServer($uri) { +function pingTeamspeakServer() { try { - $tsAdmin = TeamSpeak3::factory($uri); + $tsAdmin = getTeamspeakConnection(); - if (!$tsAdmin->getProperty("virtualserver_status")) + if ($tsAdmin->isOffline()) throw new Exception("Server is offline"); return $tsAdmin->getInfo(); } catch (TeamSpeak3_Exception $e) { return false; } - } -function getTeamspeakURI() { - global $config; - $host = $config['teamspeak']['host']; - $login = $config['teamspeak']['login']; - $passwd = $config['teamspeak']['password']; - $sport = $config['teamspeak']['server_port']; - $qport = $config['teamspeak']['query_port']; - return "serverquery://$login:$passwd@$host:$qport/?server_port=$sport"; +function getTeamspeakConnection($arguments = '') { + try { + global $config; + $host = $config['teamspeak']['host']; + $login = $config['teamspeak']['login']; + $passwd = $config['teamspeak']['password']; + $sport = $config['teamspeak']['server_port']; + $qport = $config['teamspeak']['query_port']; + + $tsNodeHost = TeamSpeak3::factory("serverquery://$host:$qport/$arguments"); + $tsNodeHost->login($login, $passwd); + return $tsNodeHost->serverGetByPort($sport); + } catch (Exception $e) { + throw $e; + } } diff --git a/viewer.php b/viewer.php index 3bd90df..72d892c 100644 --- a/viewer.php +++ b/viewer.php @@ -17,8 +17,9 @@ function getViewer() { global $lang; try { - $tsAdmin = TeamSpeak3::factory(getTeamspeakURI() . "#no_query_clients"); - return $tsAdmin->getViewer(new TeamSpeak3_Viewer_Html("lib/ts3phpframework/images/viewer/", "lib/ts3phpframework/images/flags/", "data:image")); + $tsAdmin = getTeamspeakConnection("#no_query_clients"); + $base = "lib/ts3phpframework/images"; + return $tsAdmin->getViewer(new TeamSpeak3_Viewer_Html("$base/viewer/", "$base/flags/", "data:image")); } catch (TeamSpeak3_Exception $e) { return '

' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '

'; }