Page 1 of 1

Server hack, to display status

Posted: 10 Feb 2005 02:32
by Muldy
Hi!

I'm trying a little server hack to make server report status to a site, so i can parse it with php, and make a little box on my site with the server status.

I don't know if there is already a cleaver way to do this, i hope not.....


Here it goes: (from net_server.c function NetworkServerMonthlyLoop)

Code: Select all

void NetworkServerMonthlyLoop(void)
{
        FILE *f1;
        char tmp[256];
        int year;

        f1 = fopen("status.txt","w+");
        sprintf(tmp,"Server revision = %s\n",_network_game_info.server_revision);
        fputs(tmp,f1);
        year = ConvertDateInt(_network_game_info.game_date);
        sprintf(tmp,"Current year = %i\n",year);
        fputs(tmp,f1);
        sprintf(tmp,"Game start = %i\n",_network_game_info.start_date);
        fputs(tmp,f1);
        sprintf(tmp,"Clients on = %i\n",_network_game_info.clients_on);
        fputs(tmp,f1);
        sprintf(tmp,"Max Clients = %i\n",_network_game_info.clients_max);
        fputs(tmp,f1);
        sprintf(tmp,"Spectators = %i\n",_network_game_info.spectators_on);
        fputs(tmp,f1);
        fclose(f1);
        NetworkCheckRestartMap();
        NetworkAutoCleanCompanies();
}

Im having trouble with start_date and game_date, i don't know all the globals and their specific types... it will take me some time to get this info to make this work...

So can someone save me the trouble? thanks in advance!

P.S.-Some loops to display player/companies status would be apreciated too :)

Posted: 10 Feb 2005 07:47
by Jango
check out: http://servers.openttd.org/ and you'll find that it's been done already to some extent

Posted: 11 Feb 2005 17:54
by lucaspiller
I tried making a thing last week that put copies of the small maps into image files for this very reason - unfortunately it wouldn't work, at all. I know why it went wrong but I am still trying to thing of a good way to overcome the problem.

Posted: 11 Feb 2005 19:55
by Muldy
Well, i think i will be able to do it... but it will take longuer for me to decode the vars...

If someone knew where to get the right values would be faster ...

http://servers.openttd.org/

Posted: 03 Mar 2005 14:59
by agent
Jango wrote:check out: http://servers.openttd.org/ and you'll find that it's been done already to some extent
Hi all,

I'am a member of a former Counterstrike-Clan that nowadays loves playing TTD.
We've even got your own linux server running, from time to time,
but we'd love to integrate some sort of server-stats on our web-page as it was possible with CSs rcon.

So do you know where I can get the PHP-sources for the above page?
Or if that's not possible - where can I get a specification of the interface to OpenTTDs rcon or something similar?

Greetings,
Agent

Posted: 03 Mar 2005 16:39
by orudge
You can download the code of the server listing site from the website SVN module.

Posted: 02 Apr 2005 01:33
by agent
In case anyone would like to take a look at the result of the Clan-Site Integration, which I happened to have time for just today: http://www.kriech.org/ (the lower left).

But my next question is, if there is any way to send RCON-commands to the OTTD-Server while it is running in forked mode?

So I could integrate a way to reset the server or kick players from the OTTD-Server into the protected pages for clan-members. That would be real neat, I guess.

Regards,
Agent

Posted: 02 Apr 2005 12:16
by Darkvater
@Muldy: start_date and dates in general are counted in days with a starting point of 1-1-1920. You have functions like ConvertDayToYMD() ConvertYMDToDay() and ConvertIntDate() in misc.c to handle the conversions.

@agent: OpenTTD has master.openttd.org hardcoded (in network.h) into the code so that it only reports its status there. For rcon to work you need to start up another copy of OTTD, connect to the server and give out your rcon commands...that is so far the only way to do it.

Posted: 14 Apr 2005 17:22
by Taz
Maybe it is possible to use some sort of webscript to send rcon commands? since the php part (servers.openttd.com) to make the server list uses direct udp connections to the server?