CodeIgniter library to get the status of an SRCDS server
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Initialize Configuration

You can alter the default config values by passing an array of options to the initialize method

$config = array(
	$timeout				= 2;
	$ping_timeout			= 1;
	$enable_cache			= TRUE; // Enable caching
	$cache_bad_responses	= TRUE; // Should we cache invalid reponses (timeouts/errors)
	$cache_time				= 30; // Time to cache server responses for

Pinging a Server

The ping method lets you quickly check to see if a server is responding

// function ping($host, $port = '27015');
$ping = $this->srcds_status->ping('');
echo $ping // Displays the servers ping in milliseconds

Server Status

You can use this method to get all the information available from a server

// function get_status($host, $port = '27015')
$server = $this->srcds_status->get_status('');
echo $server->hostname;
echo $server->mapname;
echo $server->game_dir; // eg. tf
echo $server->game; // eg. Team Fortress
echo $server->app_id;
echo $server->players; // player count
echo $server->max_players;
echo $server->bots;
echo $server->dedicated; // l = Listen, d = Dedicated, p = SourceTV
echo $server->os; // w = Windows, l = Linux
echo $server->password; // 0 or 1
echo $server->secure; // 0 or 1
echo $server->version;

Player List

This method lets you retrieve a list of all players on the server and sort them by kills, name or connection time

// function get_players($host, $port = '27015', $sort_type = NULL, $sort = NULL)
$players = $this->srcds_status->get_players('', '27015', 'kills, 'desc');

foreach($players as $player)
	echo $player->name;
	echo $player->kills;
	echo $player->time; // Connection time in seconds

You can also sort the player list using the sort_players() method

// function sort_players($players, $sort_type = 'kills', $sort = 'desc')
$players = $this->srcds_status->get_players('', '27015');
$sorted_players = $this->srcds_status->sort_players($players, 'kills', 'asc');

You can sort by name, kills or connection time