Works better than the netstat tool that some binary servers has been using. Has been tested on a binary server with ~100 online and didn't cause any lag or bugs what so ever.
Note: If you run your server and are NOT using binaries, do not use this. Rather create an online-field in your user table and do a SQL-query from there.
This must be run on the VPS/Dedicated server, in the Appserv/root directory (e.g where your web stuff are).
For you that just wants to see the source, here's the "magic" behind it all.
You can also download the source.
Code:
static void CountConnections(object sender, ElapsedEventArgs e)
{
var connections = from info in
IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()
where info.LocalEndPoint.Port == GAME_IP
select info;
String Count = connections.Count().ToString();
}
To read the result with PHP:
Code:
function OnlinePlayers(){
if ($fp = fopen('http://your_ip/onlineCount.txt', 'r'))
{
$head = array_change_key_case(get_headers("http://your_ip/onlineCount.txt", TRUE));
$filesize = $head['content-length'];
$response = fread($fp, $filesize);
fclose($fp);
return $response;
}
}
Enjoy.






