Server hack, to display status

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Muldy
Engineer
Engineer
Posts: 12
Joined: 16 Apr 2004 17:52
Location: Braga, Portugal

Server hack, to display status

Post 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 :)
Jango
Traffic Manager
Traffic Manager
Posts: 189
Joined: 28 Aug 2004 12:13

Post by Jango »

check out: http://servers.openttd.org/ and you'll find that it's been done already to some extent
User avatar
lucaspiller
Tycoon
Tycoon
Posts: 1228
Joined: 18 Apr 2004 20:27

Post 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.
No longer active here, but you can still reach me via email: luca[at]stackednotion[dot]com
Muldy
Engineer
Engineer
Posts: 12
Joined: 16 Apr 2004 17:52
Location: Braga, Portugal

Post 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 ...
agent
Engineer
Engineer
Posts: 2
Joined: 03 Mar 2005 14:49
Contact:

http://servers.openttd.org/

Post 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
User avatar
orudge
Administrator
Administrator
Posts: 25137
Joined: 26 Jan 2001 20:18
Skype: orudge
Location: Banchory, UK
Contact:

Post by orudge »

You can download the code of the server listing site from the website SVN module.
agent
Engineer
Engineer
Posts: 2
Joined: 03 Mar 2005 14:49
Contact:

Post 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
Image
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post 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.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Taz
Engineer
Engineer
Posts: 7
Joined: 14 Apr 2005 17:18

Post 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?
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 20 guests