Skip to content

Instantly share code, notes, and snippets.

@koraktor
Created August 16, 2009 10:16
Show Gist options
  • Select an option

  • Save koraktor/168595 to your computer and use it in GitHub Desktop.

Select an option

Save koraktor/168595 to your computer and use it in GitHub Desktop.
Generating a HTML table for player data aquired using Steam Condenser
<?php
// Be sure that the path is correct
require_once "/path/to/steam-condenser/lib/steam-condenser.php";
// Add your server's IP address here ...
$ipAddress = new InetAddress("x.x.x.x");
// ... and port number here
$portNumber = yyyyy;
$server = new GoldSrcServer($ipAddress, $portNumber);
$players = $server->getPlayers("passw0rd"); // Player pings are only available if the RCON password is provided
echo "<table>";
echo "<tr><th>Name</th><th>Score</th><th>Ping</th></tr>";
foreach($players as $player) {
echo "<tr>";
echo "<td>{$player->getName()}</td>";
echo "<td>{$player->getScore()}</td>";
echo "<td>{$player->getPing()}</td>";
echo "</tr>";
}
echo "</table>";
?>
@mrz944

mrz944 commented Apr 3, 2011

Copy link
Copy Markdown

Hi,

when I'm trying to use this script I'm getting an error:

Warning: require_once(STEAM_CONDENSER_PATHInetAddress.php) [function.require-once]: failed to open stream: No such file or directory in /home/epplus/ftp/123/cs/lib/steam/servers/GoldSrcServer.php on line 14

Fatal error: require_once() [function.require]: Failed opening required 'STEAM_CONDENSER_PATHInetAddress.php' (include_path='lib/') in /home/epplus/ftp/123/cs/lib/steam/servers/GoldSrcServer.php on line 14

I'm usung version 0.12.0 of Steam Condenser.
Can you help? Thanks in advance.

@koraktor

koraktor commented Apr 3, 2011

Copy link
Copy Markdown
Author

This example is pretty old. The easiest way to load Steam Condenser would be

// Modify Steam Condenser's path here if needed
require_once './steam-condenser/lib/steam-condenser.php';

Another way would be to define STEAM_CONDENSER_PATH yourself and require individual files like the example above does:

define('STEAM_CONDENSER_PATH', '/path/to/steam-condenser/');
require_once STEAM_CONDENSER_PATH . 'lib/InetAddress.php';
require_once STEAM_CONDENSER_PATH . 'lib/steam/servers/GoldSrcServer.php';

@mrz944

mrz944 commented Apr 3, 2011

Copy link
Copy Markdown

Thanks for fast reply. But I'm still getting errors. Can you give me any working example?

@koraktor

koraktor commented Apr 3, 2011

Copy link
Copy Markdown
Author

I just updated the example to use the new method. This will work.

@mrz944

mrz944 commented Apr 3, 2011

Copy link
Copy Markdown

And now...

Notice: Sending packet of type "A2S_PLAYER_Packet"... in /home/epplus/ftp/123/cs/lib/steam/sockets/SteamSocket.php on line 105

Notice: Expected S2A_PLAYER_Packet, but timed out. The server is probably offline. in /home/epplus/ftp/123/cs/lib/steam/servers/GameServer.php on line 182

Warning: Invalid argument supplied for foreach() in /home/epplus/ftp/123/cs/testowy.php on line 14

I've tested with few Counter-Strike 1.6 servers and I always got the same error.

@koraktor

koraktor commented Apr 3, 2011

Copy link
Copy Markdown
Author

Maybe you should add print_r($players); after the line defining $players to see what you really got.

Please note, that you can only get all information if you provide the RCON password of the server.

@mrz944

mrz944 commented Apr 4, 2011

Copy link
Copy Markdown

Here's my code:

<?php
// Be sure that the path is correct
require_once "lib/steam-condenser.php";

// Add your server's IP address here ...
$ipAddress = new InetAddress("80.54.133.14");
// ... and port number here
$portNumber = 27059;
$server = new GoldSrcServer($ipAddress, $portNumber);

$players = $server->getPlayers("******");
print_r($players);

echo "<table>";
echo "<tr><th>Name</th><th>Score</th><th>Ping</th></tr>";
foreach($players as $player) {
    echo "<tr>";
    echo "<td>{$player->getName()}</td>";
    echo "<td>{$player->getScore()}</td>";
    echo "<td>{$player->getPing()}</td>";
    echo "</tr>";
}
echo "</table>";
?>

And here, what I've got:

Notice: Sending packet of type "A2S_PLAYER_Packet"... in /home/epplus/ftp/123/cs/lib/steam/sockets/SteamSocket.php on line 105

Notice: Expected S2A_PLAYER_Packet, but timed out. The server is probably offline. in   /home/epplus/ftp/123/cs/lib/steam/servers/GameServer.php on line 182

Warning: Invalid argument supplied for foreach() in /home/epplus/ftp/123/cs/testowy.php on line 16
Name    Score   Ping

IP, port and RCON are 100% correct.

@koraktor

koraktor commented Apr 4, 2011

Copy link
Copy Markdown
Author

Oh, sorry. Didn't really look at the messages. :o
The error suggests your server isn't reachable from the host your running the script.

The output should look more like the following (as long as notices aren't disabled):

Notice: Sending packet of type "A2S_PLAYER_Packet"... in /Users/koraktor/open-source/steam-condenser.git/php/lib/steam/sockets/SteamSocket.php on line 118

Notice: Received packet of type "S2C_CHALLENGE_Packet" in /Users/koraktor/open-source/steam-condenser.git/php/lib/steam/sockets/GoldSrcSocket.php on line 86

Notice: Expected S2A_PLAYER_Packet, got S2C_CHALLENGE_Packet. in /Users/koraktor/open-source/steam-condenser.git/php/lib/steam/servers/GameServer.php on line 174

Notice: Sending packet of type "A2S_PLAYER_Packet"... in /Users/koraktor/open-source/steam-condenser.git/php/lib/steam/sockets/SteamSocket.php on line 118

Notice: Received packet of type "S2A_PLAYER_Packet" in /Users/koraktor/open-source/steam-condenser.git/php/lib/steam/sockets/GoldSrcSocket.php on line 86

@mrz944

mrz944 commented Apr 4, 2011

Copy link
Copy Markdown

I've bought new hosting and now everything is working correctly. THANK YOU for your help.
But what can be wrong with previous host?

@koraktor

koraktor commented Apr 5, 2011

Copy link
Copy Markdown
Author

Probably port restrictions or something similar. Not all web hosts like it when you use raw socket connections to arbitrary ports.

@Panties

Panties commented Jul 17, 2011

Copy link
Copy Markdown

Hey, I'm also running into some trouble with this script, I'm getting these errors

Notice: Sending packet of type "A2S_PLAYER_Packet"... in /home/kickasse/public_html/rules/alt/lib/steam/sockets/SteamSocket.php on line 116
Warning: socket_send() [function.socket-send]: unable to write to socket [1]: Operation not permitted in /home/kickasse/public_html/rules/alt/lib/Socket.php on line 157
Fatal error: Uncaught exception 'Exception' with message 'Could not send data.' in /home/kickasse/public_html/rules/alt/lib/Socket.php:166 
Stack trace: #0 /home/kickasse/public_html/rules/alt/lib/steam/sockets/SteamSocket.php(118): Socket->send('????U????')
 #1 /home/kickasse/public_html/rules/alt/lib/steam/servers/GameServer.php(355): SteamSocket->send(Object(A2S_PLAYER_Packet))
 #2 /home/kickasse/public_html/rules/alt/lib/steam/servers/GameServer.php(290): GameServer->sendRequest(Object(A2S_PLAYER_Packet)) 
#3 /home/kickasse/public_html/rules/alt/lib/steam/servers/GameServer.php(409): GameServer->handleResponseForRequest(2) 
#4 /home/kickasse/public_html/rules/alt/lib/steam/servers/GameServer.php(183): GameServer->updatePlayers(NULL) 
#5 /home/kickasse/public_html/rules/alt/index.php(35): GameServer->getPlayers() 
#6 {main} thrown in /home/kickasse/public_html/rules/alt/lib/Socket.php on line 166

and the code I'm using

<?php
// Be sure that the path is correct
require_once "lib/steam-condenser.php";

$server = new SourceServer("202.130.32.154", 27019);

$players = $server->getPlayers();
print_r($players);
?>

I have no idea what codes to use and < code> didnt work, sorry
The IP and Port are definitely correct, the path to steam-condenser is correct also. I've removed the echo'ing for simplicity's sake, sorry for the messyness

Thanks

@koraktor

Copy link
Copy Markdown
Author

@Panties: My guess is that you're probably running your code in an restricted environment (like a shared PHP host) that doesn't allow you to open socket connections. That is a common restriction on standard web hosts. So you're probably unable to use Steam Condenser on your current web host.

PS: The right syntax for code blocks here on GitHub is '''php and ''', but with backticks instead of single quotes. I updated your post above so you may see how I used it there.

@Panties

Panties commented Jul 18, 2011

Copy link
Copy Markdown

Yea had a feeling that would be the reason, probably should have looked into that more before signing up, oh well :(

Thanks anyway.

@NPG-Soul

NPG-Soul commented Sep 2, 2014

Copy link
Copy Markdown

koraktor, could you add the ability to specify a secondary port for games that have a seperate port for rcon purposes such as Arma2. It does not use the steamquery port but the gameport wich is different then the steamqueryport, effectivly making it impossible to use the rcon for arma2 bases servers atm with this library...

@jorea143

jorea143 commented Feb 6, 2016

Copy link
Copy Markdown

Could you update this? I don't know how to code so it be a great help if you can update this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment