[Release] Online counter (Works for every server)

07/08/2013 14:21 _Emme_#1
A very simple onlinecounter written in C#. Generates a txt-file with the amount of TCP-connections connected on port 5816.

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();
}
Just open config.txt and fill out the settings (Servername, GameIP and Interval - how often it should update)


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.
07/11/2013 13:45 _Emme_#2
Got some PMs about how to implement this, it's pretty straight forward. If you have any questions ask them in the thread.