PDA

View Full Version : Display users at channel (PHP)


saigh
25-01-2007, 23:40
Dear sirs,
At first - sorry for my English, cuz it's foreign language for me.
I have list of my friends.
By script I want to get list of users who are logged now at TS server on channel named "Shoutbox", and if name of user == name of my friend at my list - display some image near his name.
I'm a newbie at PHP. So... Can you help me with script via PHP?:rolleyes:
Thanks.

ScP
26-01-2007, 06:43
Which version of PHP do you currently use?

saigh
26-01-2007, 15:56
Is that important? PHP 4

ScP
26-01-2007, 22:07
Basically, there are two very good PHP libraries available which can be used to interact with your TeamSpeak 2 server:
CyTS (http://www.planetteamspeak.com/component/option,com_docman/task,doc_details/gid,41/Itemid,70/) (PHP 4 required)
libacts2 (http://www.planetteamspeak.com/component/option,com_docman/task,doc_details/gid,57/Itemid,70/) (PHP 5 required)Since you're running PHP 4, you'll have to use the CyTS library. The following example should fulfill your needs:

/* init CyTS library */
$cyts = new cyts();

/* connect to TeamSpeak server */
$cyts->connect('localhost', 51234, 8767);

/* find a channel named Shoutbox */
$channel = $cyts->info_getChannelByName('Shoutbox');

/* create a new array containing players in channel Shoutbox */
$players = array();
foreach($cyts->info_playerList() as $player) {
if($player['c_id'] == $channel['id']) $players[] = $player;
}

saigh
26-01-2007, 23:43
ScP,thanks a lot - it's a very useful,thanks you, you help me so much!!

Read my post completely please, i have a question at the end...

It's an one error in your code.
function info_getChannelByName return channel ID or name or -1 if no name exist.
So condition
if($player['c_id'] == $channel['id']) //
Must be
if($player['c_id'] == $channel) // (without ['id']

I have some questions for you: Does this script display users at subchannels in Shoutbox?

Code to display users at our channel is
<?
include 'cyts.class.php';
/* init CyTS library */
$cyts = new cyts();

/* connect to TeamSpeak server */
$cyts->connect('localhost', 51234, 8767);

/* find a channel named Shoutbox */
$channel = $cyts->info_getChannelByName('Shoutbox'); //it's retur ID without get ['id]

/* create a new array containing players in channel Shoutbox */
$players = array();
foreach($cyts->info_playerList() as $player)
{
if($player['c_id'] == $channel)
{
$players[] = $player;
echo $player[15];
echo "<br>";
}
}
?>

Now my question: The script doesn't display users at subchannels in channel "Shoutbox". What I can do to display their names?

ScP
27-01-2007, 09:20
Sorry, I haven't tested my code example before posting.

:)

To display all users from the 'Shoutbox' tree, you'll have to find all sub-channels of 'Shoutbox' in the servers channellist. You can use the info_channelList() method to get a list of channels. After that you'll have to compare every channels parent ID with the ID you've got from info_getChannelByName().

Please note, that you should always use functions like htmlentities() when displaying a clients nickname on a website.

echo htmlentities($player['nick']);

crazyandy
27-01-2007, 13:51
HI is it possible to adapt this script so that it will show all the users in the teamspeak server.
Basicly I would like it to show all the regestered users of the server and then say wheither they are online of offline.
Thanks Andy

saigh
27-01-2007, 15:54
Please note, that you should always use functions like htmlentities() when displaying a clients nickname on a website.

echo htmlentities($player['nick']);
Is it for security... Because user name may content HTML/JS code. Am I right?

HI is it possible to adapt this script so that it will show all the users in the teamspeak server.
Basicly I would like it to show all the regestered users of the server and then say wheither they are online of offline.
Thanks Andy

Just comment some conditions, like that

// if($player['c_id'] == $channel)
// {
// .....
// }
In array $player are
[15], [nick] => Nickname
[16], [loginname] => Loginname (empty if user is not registered).
You must display list of all players registred in TeamSpeak by cycle... I don't know where it placed, may be in MySQL or somethink else, where $name will be equal name of current player.
After that you're put condition in this cycle

echo htmlentities($name);
$player_id=$cyts->info_getPlayerByName($name); //it return -1 if can't find on TS server player called $name
if ($player_id>=0)
{
echo "&nbsp; Player is online";
}
else
{
echo "&nbsp; Player is offline";
}

crazyandy
31-01-2007, 14:54
I dont quite understand what you have said above saigh. Could you maybe lay it out a bit better.
Thanks very much, Andy