Skip to content

Instantly share code, notes, and snippets.

@koraktor
Created August 16, 2009 10:16
Show Gist options
  • Save koraktor/168595 to your computer and use it in GitHub Desktop.
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
Copy link

mrz944 commented Apr 4, 2011

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
Copy link
Author

koraktor commented Apr 5, 2011

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

@Panties
Copy link

Panties commented Jul 17, 2011

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
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
Copy link

Panties commented Jul 18, 2011

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
Copy link

NPG-Soul commented Sep 2, 2014

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
Copy link

jorea143 commented Feb 6, 2016

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