Skip to content
koraktor edited this page Aug 5, 2012 · 7 revisions

Querying game servers

Querying a Source game server listening on IP 192.168.0.114 and port 27015

<?php
$server = new SourceServer('192.168.0.114', 27015);
$server->initialize();
print_r($server->getPlayers());
?>

Querying a GoldSrc game server listening on IP 192.168.0.114 and port 27016

<?php
$server = new GoldSrcServer('192.168.0.114', 27016);
$server->initialize();
print_r($server->getPlayers());
?>

Querying master servers

Querying the GoldSrc master server and getting a random GoldSrc server

<?php
$master = new MasterServer(MasterServer::GOLDSRC_MASTER_SERVER);
$servers = $master->getServers();
$randomServer = $servers[array_rand($servers)];
$server = new GoldSrcServer($randomServer[0], $randomServer[1]);
?>

Controlling game servers using RCON

Executing the command status on a local Source server and displaying the output

<?php
$server = new SourceServer('127.0.0.1');
try {
  $server->rconAuth('passw0rd');
  echo $server->rconExec('status');
}
catch(RCONNoAuthException $e) {
  trigger_error('Could not authenticate with the game server.',
    E_USER_ERROR);
}
?>

Getting information from the Steam Community

Getting the Steam Community profile of Valve's Adrian Finol and his TF2 achievements

<?php
$id = SteamId::create('demomenz');
$stats = $id->getGameStats('tf2');
$achievements = $stats->getAchievements();
?>
Clone this wiki locally