Ok I have looked at the teamspeak module from budabot and have gotten all displayed server settings missing from the bebot teamspeak module I downloaded working except the displaying channels with members in the channel. I keep getting 2 errors whenever I insert the code for the channel list.
The errors show up in my console when I try to run the ts command in game and keep going continuously using up all bandwidth on my pc.
Warning: feof(): supplied argument is not a valid stream resource in Z:\downloads\ign\bebot\custom\modules\teamspeak.php on line 153
Warning: fgets(): supplied argument is not a valid stream resource in Z:\downloads\ign\bebot\custom\modules\teamspeak.php on line 154
And here is my teamspeak script. I marked the area of the non working code I added with a comment. If you remove or comment out that area of the code the script works just fine but no channel list. Lines 142 through 230 in my text editor is the added section.
<?
include_once("_Colors.php");
$ts = new TEAMSPEAK($bot);
$commands["tell"]["ts"] = &$ts;
$commands["gc"]["ts"] = &$ts;
$commands["pgmsg"]["ts"] = &$ts;
class TEAMSPEAK
{
var $bot;
var $ip = "voice.eagled2.net"; //Server IP
var $queryport = "51234"; //Query Port (51234 by default)
var $serverport = "8762"; //Server Port (8767 by default)
var $servername = "Trimmcom Co Voice Server"; // Server name
var $displayhost = "voice.eagled2.net"; //Display ip address
function TEAMSPEAK (&$bot)
{
$this -> bot = &$bot;
$this ->
help['description'] =
'Shows teamspeak server status.';
$this ->
help['command']['ts']="Shows teamspeak server status. Dispalys no server found if server is not up. All server settings are saved directly in the file by the bot owner.";
}
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "ts/i", $msg, $info)) {
$this -> bot -> send_tell($name, $this -> show_tstatus());
}
}
function pgmsg($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "ts/i", $msg, $info)) {
$this -> bot -> send_pgroup($this -> show_tstatus());
}
}
function gc($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "ts/i", $msg, $info)) {
$this -> bot -> send_gc($this -> show_tstatus());
}
}
function show_tstatus()
{
$msg = "TeamSpeak Server Status";
$blob = "";
$infolines="";
$timeToEnd = (time() + 5);
while (!($connection1 = fsockopen($this -> ip, $this -> queryport, $errno, $errstr, 30)) AND (time() < $timeToEnd)) {
if (time() >= $timeToEnd) {
return false;
}
}
if ($connection1) {
fputs($connection1,"sel ".$this -> serverport."\n");
fputs($connection1,"si\n");
fputs($connection1,"quit\n");
while(!feof($connection1)){
$infolines.=fgets($connection1,1024);
}
$infolines = str_replace("[TS]","",$infolines);
$infolines = str_replace("OK","",$infolines);
$infolines = trim($infolines);
// Servername, here but not used, uncomment if you want to use it
$name=substr($infolines,$this -> indexOf($infolines,"server_name="),strlen($infolines));
$name=substr($name,0,$this -> indexOf($name,"server_platform=")-strlen("server_platform="));
//Connected Users
$indexof = strpos($infolines, "server_currentusers=") + strlen("server_currentusers=");
$user = substr($infolines, $indexof, strlen($infolines));
$indexof = strpos($user, "server_currentchannels=") + strlen("server_currentchannels=");
$user = substr($user, 0, $indexof - strlen("server_currentchannels="));
$user = trim($user);
//Server Max Users
$indexof = strpos($infolines, "server_maxusers=") + strlen("server_maxusers=");
$maxusers = substr($infolines, $indexof, strlen($infolines));
$indexof = strpos($maxusers, "server_allow_codec_celp51=") + strlen("server_allow_codec_celp51=");
$maxusers = substr($maxusers, 0, $indexof - strlen("server_allow_codec_celp51="));
$maxusers = trim($maxusers);
//Uptime of the Server
$indexof = strpos($infolines, "server_uptime=") + strlen("server_uptime=");
$uptime = substr($infolines, $indexof, strlen($infolines));
$indexof = strpos($uptime, "server") + strlen("server_currrentusers=");
$uptime = substr($uptime, 0, $indexof - strlen("server_currrentusers="));
$uptime = trim($uptime);
$hours = floor($uptime/3600);
$minutes = floor(($uptime%3600)/60);
$seconds = floor(($uptime%3600)%60);
if($hours>0) $uptime = $hours."h ".$minutes."m ".$seconds."s";
else if($minutes>0) $uptime = $minutes."m ".$seconds."s";
else $uptime = $seconds."s";
//Serverplatform
$indexof = strpos($infolines, "server_platform=") + strlen("server_platform=");
$platform = substr($infolines, $indexof, strlen($infolines));
$indexof = strpos($platform, "server_welcomemessage=") + strlen("server_welcomemessage=");
$platform = substr($platform, 0, $indexof - strlen("server_welcomemessage="));
$platform = trim($platform);
//Number of channels
$indexof = strpos($infolines, "server_currentchannels=") + strlen("server_currentchannels=");
$channels = substr($infolines, $indexof, strlen($infolines));
$indexof = strpos($channels, "server_bwinlastsec=") + strlen("server_bwinlastsec=");
$channels = substr($channels, 0, $indexof - strlen("server_bwinlastsec="));
$channels = trim($channels);
} else {
return "CanĀ“t connect to the TS server. Pls try again later.";
}
$msg = Headertext("::::: Teamspeak Server Info :::::\n\n");
$msg .="Get the client: \"http://www.goteamspeak.com\" \n\n";
$msg .="Note: To connect use ".Highlight($this -> displayhost.":".$this -> serverport)." as the connect address\n";
$msg .="Server Name: ".Highlight($this -> servername)."\n";
$msg .="Server Address: ".Highlight($this -> displayhost)."\n";
$msg .="Server Port: ".Highlight($this -> serverport)."\n\n";
$msg .="Server Platform: ".Highlight($platform)."\n";
$msg .="Server Uptime: ".Highlight($uptime)."\n";
$msg .="Number of Players Currently Connected: ".Highlight($user)."\n";
$msg .="Server Maximum: ".Highlight($maxusers)."\n";
$msg .= "Server Channels: ".Highlight($channels)."\n";
$msg .="Players (Time Connected):\n";
//Begin Non Working code
//Get Players
$player_array = array();
$innerArray = array();
$out = "";
$j = 0;
$k = 0;
$connection = fsockopen($ip, $queryport, $errno, $errstr, 30);
fputs($connection, "pl ".$serverport."\n");
fputs($connection, "quit\n");
while(!feof($connection))
$out .= fgets($connection, 1024);
$out = str_replace("[TS]", "", $out);
$out = str_replace("loginname", "loginname\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i = 0; $i < count($data); $i++) {
$innerArray[$j] = $data[$i];
if($j >= 15) {
$player_array[$k] = $innerArray;
$j = 0;
$k = $k + 1;
} else
$j++;
}
fclose($connection);
//Get Channels
$cArray = array();
$innerArray = array();
$out = "";
$j = 0;
$k = 0;
$connection = fsockopen($ip, $queryport, $errno, $errstr, 30);
fputs($connection, "cl ".$serverport."\n");
fputs($connection, "quit\n");
while(!feof($connection)) {
$out .= fgets($connection, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("\n", "\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i=0;$i<count($data);$i++) {
if($i>=10) {
$innerArray[$j] = $data[$i];
if($j>=8) {
$cArray[$k]=$innerArray;
$j = 0;
$k = $k+1;
} else
$j++;
}
}
fclose($connection);
//Give Channels and their users out
foreach($cArray as $channel) {
$channel[5] = str_replace("\"", "", $channel[5]);
$msg .= "<u>Channel: {$channel[5]}</u>\n";
$c_id = $channel[0];
$num_players = 0;
foreach($player_array as $player) {
if($player[1] == $c_id) {
$num_players++;
$name = $player[14];
$name = str_replace("\"","",$name);
$name = ucfirst($name);
$time = $player[8];
$hours = floor($time/3600);
$minutes = floor(($time%3600)/60);
$seconds = floor(($time%3600)%60);
if($hours>0) $time = $hours."h ".$minutes."m ".$seconds."s";
else if($minutes>0) $time = $minutes."m ".$seconds."s";
else $time = $seconds."s";
$msg .= "<tab>- <highlight>$name<end>($time)\n";
}
}
if($num_players == 0)
$msg .= "<tab>- <highlight>None<end>\n";
}
//end non working code
#t
$player_array = $this -> getTSChannelUsers($this -> ip, $this -> serverport, $this -> queryport);
$count=count($player_array);
if ($count > 1) {
$arraycount=1;
while ($count > 1) {
$player=$player_array[$arraycount][14];
$player=str_replace("\"","",$player);
$player=ucfirst($player);
$time=$player_array[$arraycount][8];
$time=$this -> time_convert($time);
$msg .= Highlight($player)."($time)\n";
$count--;
$arraycount++;
}
} else {
$msg .= Highlight("No Players Connected");
}
return $this -> bot -> make_blob("Teamspeak server status", GroupText($msg));
}
function indexOf($str,$strChar)
{
if(strlen(strchr($str,$strChar))>0) {
$position_num = strpos($str,$strChar) + strlen($strChar);
return $position_num;
} else {
return -1;
}
}
function getTSChannelUsers($ip,$port,$tPort)
{
$uArray = array();
$innerArray = array();
$out = "";
$j = 0;
$k = 0;
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "pl ".$port."\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("loginname", "loginname\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i=0;$i<count($data);$i++) {
$innerArray[$j] = $data[$i];
if($j>=15)
{
$uArray[$k]=$innerArray;
$j = 0;
$k = $k+1;
} else {
$j++;
}
}
fclose($fp);
}
return $uArray;
}
function time_convert($time)
{
$hours = floor($time/3600);
$minutes = floor(($time%3600)/60);
$seconds = floor(($time%3600)%60);
if($hours>0) $time = $hours."h ".$minutes."m ".$seconds."s";
else if($minutes>0) $time = $minutes."m ".$seconds."s";
else $time = $seconds."s";
return $time;
}
}
?>
Can anyone offer any advice?