You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 59 guest(s) and 2 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Teamspeak Block [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
jaj
Corporal
Corporal


Joined: Feb 25, 2004
Posts: 56


PostPosted: Wed Nov 17, 2004 5:30 pm Reply with quoteBack to top

I would have to look into that....
Find all posts by jajView user's profileSend private message
seleleth
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2004
Posts: 5


PostPosted: Thu Nov 18, 2004 9:50 pm Reply with quoteBack to top

jaj,

Thanks for this. It's very simple and does nearly everything I'd like. I tried to finish your testform, but haven't been successful. I don't know html well, and php even less. But I was hoping to enable the option to allow registered users to login with their info. It looks like the only thing lacking (apart from uncommenting the LOGINNAME & PASSWORD areas) is to complete this url:

Code:
$content .= "<input type=\"button\" value=\"-->Submit<--\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value \">";


Can you give me a completed version of that line, including the LOGINNAME & PASSWORD inputs from the forms? I know the proper html url should be this:

Code:
teamspeak://ts.clan-ai.org:8767/nickname=YourNickname?loginname=YourLogin?password=YourPassword


But I don't know how to write the php code to generate that based on the information inputed into the forms above. I thought you might not have finished it because you were worried about sending empty data in the LOGINNAME & PASSWORD fields, should people choose to enter a nickname only. So if it helps I tried entering the following url:

Code:
teamspeak://ts.clan-ai.org:8767/nickname=YourNickname?loginname=?password=


And it seems to login just fine as an anonymous user with the nickname specified. So I think the one complete url will do fine for both registered & anon logins.

Also, if it helps, I modified the entire testform to the following code, which I think appears more clean, concise & self-explanatory:

Code:
$content .= "<form name=\"testform\">";
$content .= "<input type=\"text\" name=\"NICKNAME\"><br> Nickname";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"LOGINNAME\"><br> Login (if registered)";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"PASSWORD\"><br> Password (if registered)";
$content .= "<br>";
$content .= "<br>";
$content .= "<input type=\"button\" value=\"- Join -\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value \">";
$content .= "</form>";


Lastly, on the subject of appearance, I can't seem to find the location of the "quotation marks" that appear around both the channel & nicknames of connected users. I would like to remove them if I can.

You can see the work in progress on a soon-to-be-launched (and moved) site here: http://clan-ai.org:8080 (after move, site will be just clan-ai.org).

Thank you for this much desired block & any future help you can offer.
Find all posts by selelethView user's profileSend private message
Raver
Private
Private


Joined: Oct 03, 2004
Posts: 36


PostPosted: Sat Nov 20, 2004 1:26 am Reply with quoteBack to top

How do i get it right that you can login as a registred user? i dont get the message above

_________________
[b]www.web-corner.net[/b]
Find all posts by RaverView user's profileSend private message
seleleth
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2004
Posts: 5


PostPosted: Sat Nov 20, 2004 10:05 am Reply with quoteBack to top

seleleth wrote:
I tried to finish your testform, but haven't been successful.

I'm still hoping jaj (or anyone else who knows php, for that matter) will fill in the blank described above so that we can allow registered users to login from the site. I wasn't describing how to do it myself.
Find all posts by selelethView user's profileSend private message
jaj
Corporal
Corporal


Joined: Feb 25, 2004
Posts: 56


PostPosted: Sat Nov 20, 2004 8:17 pm Reply with quoteBack to top

I have updated the TS script....you would just need to input your values...Just edit (at the begining) your server address, query port, UDP port and (at the bottom) "img src=" (the location of your button image)...also this script has the quotes removed... and you should have no problems with registerd user login now....and now you can just input the url of an image that you would to use as a button... if you need any help or would like a button image just im me or make a new post....


Code:
<?php




// **** settings - to be edited before first use ****
$serverAddress = "xx.xxx.xx.xxx";  // can be ip address or url
$serverQueryPort = 51234;  // default 51234, must be accessible and usable. check server.ini
$serverUDPPort = 8767;  // default 8767
// **** end of settings ****

if (eregi("block-Teamspeak.php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}


global $user, $cookie;
getusrinfo($user);
cookiedecode($user);
$username = $cookie[1];

// opens a connection to the teamspeak server
function getSocket($host, $port, $errno, $errstr, $timeout) {
   global $errno, $errstr;
   @$socket = fsockopen($host, $port, $errno, $errstr, $timeout);
        if($socket and fread($socket, 4) == "[TS]") {
            fgets($socket, 128);
            return $socket;
        }// end if
        return false;
}// end function getSocket(...)

// sends a query to the teamspeak server
function sendQuery($socket, $query) {
   fputs($socket, $query."\n");
}

// answer OK?
function getOK($socket) {
        $result = fread($socket, 2);
        fgets($socket, 128);
        return($result == "OK");
}

// closes the connection to the teamspeak server
function closeSocket($socket) {
        fputs($socket, "quit");
        fclose($socket);
}

// retrieves the next argument in a tabulator-separated string (PHP scanf function bug workaround)
function getNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, 0, $pos);
        }
        else {
            return $evalString;
        }
}

// removes the first argument in a tabulator-separated string (PHP scanf function bug workaround)
function chopNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, $pos + 1);
        }
        else {
           return "";
        }
}

// MAIN PROGRAM START

// establish connection to teamspeak server
$socket = getSocket($serverAddress, $serverQueryPort, $errno, $errstr, 3);
if($socket == false) {
        $content .= "An error connecting to the TeamSpeak server has occured!<br>\n";
        $content .= "Error number: ".$errno."<br>\n";
        $content .= "Error description: ".$errstr."<br>\n";
        return;
}

// select the one and only running server on port 8767
sendQuery($socket, "sel ".$serverUDPPort);

// retrieve answer "OK"
if(!getOK($socket)) {
   die("Server didn't answer &quot;OK&quot; after last command. Aborting.");
}// end if

// retrieve player list
sendQuery($socket,"pl");

// read player info
$playerList = array();
do {
   $playerinfo = fscanf($socket, "%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s");
        list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
        if($playerid != "OK") {
               $playerList[$playerid] = array("playerid" => $playerid,
                                           "channelid" => $channelid,
                                           "receivedpackets" => $receivedpackets,
                                           "receivedbytes" => $receivedbytes,
                                           "sentpackets" => $sentpackets,
                                           "sentbytes" => $sentbytes,
                                           "totaltime" => $totaltime,
                                           "idletime" => $idletime,
                                           "playername" => str_replace("\"", "", $playername));
        }
} while($playerid != "OK");

// retrieve channel list
sendQuery($socket,"cl");

// read channel info
$channelList = array();
do {
        $channelinfo = "";
        do {
      $input = fread($socket, 1);
      if($input != "\n" && $input != "\r") $channelinfo .= $input;
        } while($input != "\n");

        $channelid = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $codec = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $parent = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $maxplayers = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $channelname = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $topic = getNext($channelinfo);

        if($channelid != "OK") {
      if($isdefault == "Default") $isdefault = 1; else $isdefault = 0;

               // determine number of players in channel
               $playercount = 0;
               foreach($playerList as $playerInfo) {
                   if($playerInfo[channelid] == $channelid) $playercount++;
               }

               $channelList[$channelid] = array("channelid" => $channelid,
                                             "codec" => $codec,
                                             "parent" => $parent,
                                             "maxplayers" => $maxplayers,
                                             "channelname" => $channelname,
                                             "isdefault" => $isdefault,
                                             "topic" => $topic,
                                             "currentplayers" => $playercount);
   }
} while($channelid != "OK");

// display channel list
$content .= "<table width=\"100%\">\n";
$counter = 0;
foreach($channelList as $channelInfo) {
   // default channel?
        if($channelInfo[isdefault] == 1) {
            $channelname = $channelInfo[channelname];
        } else {
            $channelname = $channelInfo[channelname];
        }

      if ($channelInfo[currentplayers] > 0) {
         $content .= "<tr><td><img src=\"images/bullet_channel.gif\" border=\"0\"></td><td colspan=\"1 \">".$channelname." </td></tr>";
      }

        $counter++;
        foreach ($playerList as $playerInfo) {
           if ($channelInfo[channelid] == $playerInfo[channelid]) {
              $content .= "<tr><td></td><td colspan=0><img src=\"images/bullet_0.gif\" border=\"0\" align=left>".$playerInfo[playername]."</td></tr>\n";
           }
        }
    }

    if($counter == 0) $content .= "<tr><td colspan=\"4\" align=\"CENTER\">No channels</td></tr>\n";
    $content .= "</table>\n";

    // close connection to teamspeak server
    closeSocket($socket);



 

$content .= "<form name=\"testform\">";
$content .= "<center><input type=\"text\" name=\"NICKNAME\"  size=\"19\" > ";
$content .= "NICKNAME</center>";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"LOGINNAME\"> LOGIN NAME--For Registered Users";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"PASSWORD\"> PASSWORD--Registered Users";
$content .= "<br>";
$content .= "<center><img src=\"http://www.yoursite.com/?folder/your image name\" alt=\"Join\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value + '?loginname=' + testform.LOGINNAME.value + '?password=' + testform.PASSWORD.value;\"></center>";
$content .= "<br>";

$content .= "</form>";
$content .="<center><a href=\"http://www.goteamspeak.com\"><img src=\"https://sales.tritoncia.com/images/link_to_teamspeak.gif\" border=\"0\" alt=\"Go to Teamspeak.com\"></a></center>"
 ."";






?>
Find all posts by jajView user's profileSend private message
seleleth
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2004
Posts: 5


PostPosted: Sat Nov 20, 2004 9:13 pm Reply with quoteBack to top

You are awesome! There's really nothing more to say--awesome.

(PS How about a simple, centered chat block using the integrated site users now? j/k)
Find all posts by selelethView user's profileSend private message
-Javier-
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2004
Posts: 5


PostPosted: Sat Nov 20, 2004 10:16 pm Reply with quoteBack to top

Great!
Just one thing: The names with a space between...
Thanks,

Javier--
Find all posts by -Javier-View user's profileSend private message
jaj
Corporal
Corporal


Joined: Feb 25, 2004
Posts: 56


PostPosted: Sun Nov 21, 2004 5:19 am Reply with quoteBack to top

I have updated the TS script....you would just need to input your values...Just edit (at the begining) your server address, query port, UDP port and (at the bottom) "img src=" (the location of your button image)...also this script has the quotes removed and will show names with spaces...... and you should have no problems with registerd user login now....and now you can just input the url of an image that you would to use as a button... if you need any help or would like a button image just im me or make a new post....
***************************************************
Just save the other TS block in case there is any issues with this new one...it was just done and has not been field tested....should be fine ..but heh who knows... ***************************************************





Code:
<?php




// **** settings - to be edited before first use ****
$serverAddress = "xx.xxx.xx.xxx";  // can be ip address or url
$serverQueryPort = 51234;  // default 51234, must be accessible and usable. check server.ini
$serverUDPPort = 8767;  // default 8767
// **** end of settings ****

if (eregi("block-Teamspeak.php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}


global $user, $cookie;
getusrinfo($user);
cookiedecode($user);
$username = $cookie[1];

// opens a connection to the teamspeak server
function getSocket($host, $port, $errno, $errstr, $timeout) {
   global $errno, $errstr;
   @$socket = fsockopen($host, $port, $errno, $errstr, $timeout);
        if($socket and fread($socket, 4) == "[TS]") {
            fgets($socket, 128);
            return $socket;
        }// end if
        return false;
}// end function getSocket(...)

// sends a query to the teamspeak server
function sendQuery($socket, $query) {
   fputs($socket, $query."\n");
}

// answer OK?
function getOK($socket) {
        $result = fread($socket, 2);
        fgets($socket, 128);
        return($result == "OK");
}

// closes the connection to the teamspeak server
function closeSocket($socket) {
        fputs($socket, "quit");
        fclose($socket);
}

// retrieves the next argument in a tabulator-separated string (PHP scanf function bug workaround)
function getNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, 0, $pos);
        }
        else {
            return $evalString;
        }
}

// removes the first argument in a tabulator-separated string (PHP scanf function bug workaround)
function chopNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, $pos + 1);
        }
        else {
           return "";
        }
}

// MAIN PROGRAM START

// establish connection to teamspeak server
$socket = getSocket($serverAddress, $serverQueryPort, $errno, $errstr, 3);
if($socket == false) {
        $content .= "An error connecting to the TeamSpeak server has occured!<br>\n";
        $content .= "Error number: ".$errno."<br>\n";
        $content .= "Error description: ".$errstr."<br>\n";
        return;
}

// select the one and only running server on port 8767
sendQuery($socket, "sel ".$serverUDPPort);

// retrieve answer "OK"
if(!getOK($socket)) {
   die("Server didn't answer &quot;OK&quot; after last command. Aborting.");
}// end if

// retrieve player list
sendQuery($socket,"pl");

// read player info
$playerList = array();

//Skip the first line. It only contains header labels
fgets($socket);
while (true)
{
   //Read the next line from the socket
   $line = fgets($socket);

   //Break it up on the tab delimiter
   $playerinfo = explode("\t", $line);

   //Bail out if only one element
   if (count($playerinfo) == 1)
   {
      //Only one element means the OK has been encountered.
      //The list is done.
      break;
   }
   
   //Stuff the array values into variables
   list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
   
   $playerList[$playerid] = array("playerid" => $playerid,
               "channelid" => $channelid,
               "receivedpackets" => $receivedpackets,
               "receivedbytes" => $receivedbytes,
               "sentpackets" => $sentpackets,
               "sentbytes" => $sentbytes,
               "totaltime" => $totaltime,
               "idletime" => $idletime,
               "playername" => str_replace("\"", "", $playername));
}



// retrieve channel list
sendQuery($socket,"cl");

// read channel info
$channelList = array();
do {
        $channelinfo = "";
        do {
      $input = fread($socket, 1);
      if($input != "\n" && $input != "\r") $channelinfo .= $input;
        } while($input != "\n");

        $channelid = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $codec = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $parent = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $maxplayers = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $channelname = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $topic = getNext($channelinfo);

        if($channelid != "OK") {
      if($isdefault == "Default") $isdefault = 1; else $isdefault = 0;

               // determine number of players in channel
               $playercount = 0;
               foreach($playerList as $playerInfo) {
                   if($playerInfo[channelid] == $channelid) $playercount++;
               }

               $channelList[$channelid] = array("channelid" => $channelid,
                                             "codec" => $codec,
                                             "parent" => $parent,
                                             "maxplayers" => $maxplayers,
                                             "channelname" => $channelname,
                                             "isdefault" => $isdefault,
                                             "topic" => $topic,
                                             "currentplayers" => $playercount);
   }
} while($channelid != "OK");

// display channel list
$content .= "<table width=\"100%\">\n";
$counter = 0;
foreach($channelList as $channelInfo) {
   // default channel?
        if($channelInfo[isdefault] == 1) {
            $channelname = $channelInfo[channelname];
        } else {
            $channelname = $channelInfo[channelname];
        }

      if ($channelInfo[currentplayers] > 0) {
         $content .= "<tr><td><img src=\"images/bullet_channel.gif\" border=\"0\"></td><td colspan=\"1 \">".$channelname." </td></tr>";
      }

        $counter++;
        foreach ($playerList as $playerInfo) {
           if ($channelInfo[channelid] == $playerInfo[channelid]) {
              $content .= "<tr><td></td><td colspan=0><img src=\"images/bullet_0.gif\" border=\"0\" align=left>".$playerInfo[playername]."</td></tr>\n";
           }
        }
    }

    if($counter == 0) $content .= "<tr><td colspan=\"4\" align=\"CENTER\">No channels</td></tr>\n";
    $content .= "</table>\n";

    // close connection to teamspeak server
    closeSocket($socket);



 

$content .= "<form name=\"testform\">";
$content .= "<center><input type=\"text\" name=\"NICKNAME\"  size=\"19\" > ";
$content .= "NICKNAME</center>";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"LOGINNAME\"> LOGIN NAME--For Registered Users";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"PASSWORD\"> PASSWORD--Registered Users";
$content .= "<br>";
$content .= "<center><img src=\"http://www.yoursite.com/?folder/your image name\" alt=\"Join\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value + '?loginname=' + testform.LOGINNAME.value + '?password=' + testform.PASSWORD.value;\"></center>";
$content .= "<br>";

$content .= "</form>";
$content .="<center><a href=\"http://www.goteamspeak.com\"><img src=\"https://sales.tritoncia.com/images/link_to_teamspeak.gif\" border=\"0\" alt=\"Go to Teamspeak.com\"></a></center>"
 ."";






?>
Find all posts by jajView user's profileSend private message
-Javier-
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2004
Posts: 5


PostPosted: Tue Nov 23, 2004 9:38 am Reply with quoteBack to top

Fantastic!!
Thank you very much!
It's work perfectly.
Find all posts by -Javier-View user's profileSend private message
LordSmack
Nuke Cadet
Nuke Cadet


Joined: Nov 17, 2003
Posts: 6


PostPosted: Fri Dec 17, 2004 11:55 am Reply with quoteBack to top

I have run into a problem with my block if someone can help me I would appreciate it. When you select a channel from the dropdown menu you get a pop up window that says
Quote:
Unable to select database
I think everything has been installed correctly.
our site can be viewed here www.memphisgibfest.com
Find all posts by LordSmackView user's profileSend private message
jaj
Corporal
Corporal


Joined: Feb 25, 2004
Posts: 56


PostPosted: Sat Dec 18, 2004 4:10 pm Reply with quoteBack to top

Post the script for the block...so that it can be looked at...
Find all posts by jajView user's profileSend private message
ridersofthewind.com
Nuke Cadet
Nuke Cadet


Joined: Dec 19, 2004
Posts: 4


PostPosted: Tue Dec 21, 2004 11:26 am Reply with quoteBack to top

saved the script in my blocks section on my nuke site, and it does not appear under blocks administration for activation
Find all posts by ridersofthewind.comView user's profileSend private message
jaj
Corporal
Corporal


Joined: Feb 25, 2004
Posts: 56


PostPosted: Tue Dec 21, 2004 3:15 pm Reply with quoteBack to top

you have to name the script....
block-whatever and save it as a php file and put in your blocks folder...

then look for it in your administartion page under blocks then go down the page some in "add new block" and you find it under file name
Find all posts by jajView user's profileSend private message
CaptDD
Corporal
Corporal


Joined: Jan 02, 2005
Posts: 51

Location: Manistee, MI, USA

PostPosted: Sun Jan 02, 2005 6:54 am Reply with quoteBack to top

jaj,

I hope you don't mind but I have tweaked your code listed above. I gave you credit in the code as the creator. The tweak allows for registered users to enter thier Teamspeak server login information and includes a submit button. It was generated using your codes listed here. My new code is as follows.
Code:
<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/************************************************************************/
/* block-Teamspeak3.php                                                */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2004 by jaj (jaj@nukecops.com)          */
/* http://nukecops.com                                             */
/************************************************************************/
/* Cosmetic changes by CaptDD at webmaster@rapidfireclan.com            */
/* http://rapidfireclan.com                                              */
/************************************************************************/



// **** settings - to be edited before first use ****

$serverAddress = "xxx.xxx.xxx.xxx";  // can be ip address or url

$serverQueryPort = 51234;  // default 51234, must be accessible and usable. check server.ini

$serverUDPPort = 8767;  // default 8767

// **** end of settings ****

if (eregi("block-Teamspeak3.php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}


global $user, $cookie;
getusrinfo($user);
cookiedecode($user);
$username = $cookie[1];

// opens a connection to the teamspeak server
function getSocket($host, $port, $errno, $errstr, $timeout) {
   global $errno, $errstr;
   @$socket = fsockopen($host, $port, $errno, $errstr, $timeout);
        if($socket and fread($socket, 4) == "[TS]") {
            fgets($socket, 128);
            return $socket;
        }// end if
        return false;
}// end function getSocket(...)

// sends a query to the teamspeak server
function sendQuery($socket, $query) {
   fputs($socket, $query."\n");
}

// answer OK?
function getOK($socket) {
        $result = fread($socket, 2);
        fgets($socket, 128);
        return($result == "OK");
}

// closes the connection to the teamspeak server
function closeSocket($socket) {
        fputs($socket, "quit");
        fclose($socket);
}

// retrieves the next argument in a tabulator-separated string (PHP scanf function bug workaround)
function getNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, 0, $pos);
        }
        else {
            return $evalString;
        }
}

// removes the first argument in a tabulator-separated string (PHP scanf function bug workaround)
function chopNext($evalString) {
        $pos = strpos($evalString, "\t");
        if(is_integer($pos)) {
      return substr($evalString, $pos + 1);
        }
        else {
           return "";
        }
}

// MAIN PROGRAM START

// establish connection to teamspeak server
$socket = getSocket($serverAddress, $serverQueryPort, $errno, $errstr, 3);
if($socket == false) {
        $content .= "An error connecting to the TeamSpeak server has occured!<br>\n";
        $content .= "Error number: ".$errno."<br>\n";
        $content .= "Error description: ".$errstr."<br>\n";
        return;
}

// select the one and only running server on port 8767
sendQuery($socket, "sel ".$serverUDPPort);

// retrieve answer "OK"
if(!getOK($socket)) {
   die("Server didn't answer &quot;OK&quot; after last command. Aborting.");
}// end if

// retrieve player list
sendQuery($socket,"pl");

// read player info
$playerList = array();

//Skip the first line. It only contains header labels
fgets($socket);
while (true)
{
   //Read the next line from the socket
   $line = fgets($socket);

   //Break it up on the tab delimiter
   $playerinfo = explode("\t", $line);

   //Bail out if only one element
   if (count($playerinfo) == 1)
   {
      //Only one element means the OK has been encountered.
      //The list is done.
      break;
   }
   
   //Stuff the array values into variables
   list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
   
   $playerList[$playerid] = array("playerid" => $playerid,
               "channelid" => $channelid,
               "receivedpackets" => $receivedpackets,
               "receivedbytes" => $receivedbytes,
               "sentpackets" => $sentpackets,
               "sentbytes" => $sentbytes,
               "totaltime" => $totaltime,
               "idletime" => $idletime,
               "playername" => str_replace("\"", "", $playername));
}



// retrieve channel list
sendQuery($socket,"cl");

// read channel info
$channelList = array();
do {
        $channelinfo = "";
        do {
      $input = fread($socket, 1);
      if($input != "\n" && $input != "\r") $channelinfo .= $input;
        } while($input != "\n");

        $channelid = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $codec = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $parent = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $maxplayers = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $channelname = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $d = getNext($channelinfo);
        $channelinfo = chopNext($channelinfo);
        $topic = getNext($channelinfo);

        if($channelid != "OK") {
      if($isdefault == "Default") $isdefault = 1; else $isdefault = 0;

               // determine number of players in channel
               $playercount = 0;
               foreach($playerList as $playerInfo) {
                   if($playerInfo[channelid] == $channelid) $playercount++;
               }

               $channelList[$channelid] = array("channelid" => $channelid,
                                             "codec" => $codec,
                                             "parent" => $parent,
                                             "maxplayers" => $maxplayers,
                                             "channelname" => $channelname,
                                             "isdefault" => $isdefault,
                                             "topic" => $topic,
                                             "currentplayers" => $playercount);
   }
} while($channelid != "OK");

// display channel list
$content .= "<table width=\"100%\">\n";
$counter = 0;
foreach($channelList as $channelInfo) {
   // default channel?
        if($channelInfo[isdefault] == 1) {
            $channelname = $channelInfo[channelname];
        } else {
            $channelname = $channelInfo[channelname];
        }

      if ($channelInfo[currentplayers] > 0) {
         $content .= "<tr><td><img src=\"images/bullet_channel.gif\" border=\"0\"></td><td colspan=\"1 \">".$channelname." </td></tr>";
      }

        $counter++;
        foreach ($playerList as $playerInfo) {
           if ($channelInfo[channelid] == $playerInfo[channelid]) {
              $content .= "<tr><td></td><td colspan=0><img src=\"images/bullet_0.gif\" border=\"0\" align=left>".$playerInfo[playername]."</td></tr>\n";
           }
        }
    }

    if($counter == 0) $content .= "<tr><td colspan=\"4\" align=\"CENTER\">No channels</td></tr>\n";
    $content .= "</table>\n";

    // close connection to teamspeak server
    closeSocket($socket);



 

$content .= "<form name=\"testform\">";
$content .= "<input type=\"text\" name=\"NICKNAME\"> NICKNAME--Registered Users";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"LOGINNAME\"> LOGIN NAME--For Registered Users";
$content .= "<br>";
$content .= "<input type=\"text\" name=\"PASSWORD\"> PASSWORD--Registered Users";
$content .= "<br>";
$content .= "<input type=\"button\" value=\"-->Submit<--\" onClick=\"location.href='teamspeak://$serverAddress: $serverUDPPort/nickname=' + testform.NICKNAME.value + '?loginname=' + testform.LOGINNAME.value + '?password=' + testform.PASSWORD.value;\"></center>";
$content .= "<br>";

$content .= "</form>";
$content .="<center><a href=\"http://www.goteamspeak.com\"><img src=\"https://sales.tritoncia.com/images/link_to_teamspeak.gif\" border=\"0\" alt=\"Go to Teamspeak.com\"></a></center>"
 ."";






?>
 

_________________
Image
Find all posts by CaptDDView user's profileSend private messageVisit poster's websiteAIM AddressMSN Messenger
BYTES
Nuke Cadet
Nuke Cadet


Joined: Jan 14, 2005
Posts: 2


PostPosted: Thu Jan 13, 2005 9:54 pm Reply with quoteBack to top

I would like to thank jaj and CaptDD for their excellent posts. My other webadmin, Aleister, edited the code to fit inside of a narrower block. The alignment is set to the left, and there are no images which offers a much cleaner look IMHO. He also set the max number of characters to 15, but you can modify the number, as well as the colors, to fit you needs. You are welcome to see it in action on our website http://www.dcw