Dedicated server with highscore?

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Tycooner82
Engineer
Engineer
Posts: 2
Joined: 03 Feb 2007 19:01

Dedicated server with highscore?

Post by Tycooner82 »

Hi

I have a couple questions about OpenTTD when running as dedicated server.


1. Is it possible to dump all the companies finances/results in a file(.txt) after x amount of years? or when the game is ending?

2. If not. Is it possible to somehow make the server take a screenshot of all the companies final finances when the game ends?

I want my server to automaticly take screens or dump highscores to a file when a openttd game ends, so im asking if t here is a easy way to do this?
Connum
Engineer
Engineer
Posts: 127
Joined: 25 Dec 2006 17:05

Post by Connum »

That would really be a nice thing to extend my server settings & stats page!
I like that idea!!
English is not my native language, so please excuse me if I sometimes might appear a bit harsh or if I make a spelling or grammar mistake!
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2567
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

1. Autopilot could, but not without extensive work. Finances would be limited to company value.

2. No.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
Ailure
Route Supervisor
Route Supervisor
Posts: 435
Joined: 26 Apr 2005 19:06
Location: Sweden

Post by Ailure »

I would rather see openTTD connecting to a database and dump the economy data there. :P

But then, I would like to see the economy statics somewhat redone, such as being able to backtrack stats since the start of the game, and not just limited to a few years. :/
Tycooner82
Engineer
Engineer
Posts: 2
Joined: 03 Feb 2007 19:01

Post by Tycooner82 »

Thanks for the answer.

Connecting to a database would have been great :)
I totally agree with you about the economy statistics should have been redone, Ailure.
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

I really think that this would be possible..

With a bit of work and a 'kludge' of a few different ideas I really this that this
could be done...
I have been looking for some ideas to 'Sink My Teath' into and this is something
that i am going to take on..

With the Help of people like 'Brianetta' and others from the community this
shouldn't be to hard..

I will report back as soon as I have something, even if it is to say, "ITS IMPOSSIBLE & it is making me want to pull out all of my Hair !!!"
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2567
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

DaGeek wrote:With the Help of people like 'Brianetta' and others from the community this
shouldn't be to hard..
Yuck... please don't stick my name in quotes like that. It makes me feel like a fraud or something.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

:oops: Sorry Again
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

right...
Brianetta in post 540872 @ http://www.tt-forums.net/viewtopic.php?p=540872#540872
you posted the code of your Banner Script...

With this script you used TCL to send a UDP query to the server and then
annotate that info onto a png...
Can we not just use this info and output it to 1.) a txt file or 2.) a MySQL DB...

The main info needed would be the Company Info... ie Company Value and so on...
Would that work ?

Comments/Suggestions/Flames anything Welcome...
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2567
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Yes, it's trivial to write it to a text file. I use something very similar to generate the dynamic content on the web page that the graphic in my signature links to. Also writing to a database is simple enough; the openttd server list works exactly like that, except that it's written in PHP, not Tcl.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

What comment would you have to send to the Server (via UDP) to
ask about the info that is shown when you get to the Join Screen in OpenTTD ?

like in the Picture below:-
Image

I have tried to 'sniff the packets' but i just cant find the command to send
to the server...
Is this info inside the 'PACKET_SERVER_GAME_INFO' command ?

It must be there somewhere, or how would the Client get it ?
This info is 110% what we are looking for. If we could get this we could make
a High Score system without any problem...

Maybe and OpenTTD Developer can help...
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Post by Rubidium »

Part of that information is acquired via UDP (you send PACKET_UDP_CLIENT_FIND_SERVER and get a PACKET_UDP_SERVER_RESPONSE back).

The other part is acquired via TCP (you send PACKET_CLIENT_COMPANY_INFO and get a PACKET_SERVER_COMPANY_INFO back).

Those are respectively NetworkUDPQueryServer and NetworkTCPQueryServer in the trunk code.
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

"By Joe, I Think I Have Done It !!"

Post by DaGeek »

I think I've done it...

My servers now all Output the 'player' command to a txt file on the www server.
This data is then ready to be read by a script to 'collate' the information.

and example of the files can be seen @ http://openttd.dageek.co.uk/DaGeek_Serv ... xample.txt
(this is not a dynamic updating example, This is just to show an example of the data)

Now all we/I have to do is make the PHP end of things to show these details
in a nicer way to the end user, and then also make some kind of 'Score History' page as well....
If I can get these values into a MySQL DB we can even start to make some nice pretty graphs..
"wow" I hear you say...
Well O.K. maybe not, but I can dream... :D
william wm
Engineer
Engineer
Posts: 2
Joined: 11 Feb 2007 00:22
Contact:

Post by william wm »

Looking forward to use your solution when it is finished on our server at work.
Connum
Engineer
Engineer
Posts: 127
Joined: 25 Dec 2006 17:05

Post by Connum »

Hmm I tried to get something via PHP... But I never had to use such connections in PHP before... How do I send the packets to the server and how do I read out the answer then?
I guess I need fsockopen or something..

\\edit:
okay I got it plotting something from the UDP port...
http://shadowdrinker.no-ip.com/OTTD/udp.php

but that is quite few information... and it doesn't work with tcp:// at all!
English is not my native language, so please excuse me if I sometimes might appear a bit harsh or if I make a spelling or grammar mistake!
thistle
Engineer
Engineer
Posts: 27
Joined: 31 Aug 2006 20:35

Post by thistle »

Connum wrote:but that is quite few information... and it doesn't work with tcp:// at all!
do you need to specify the tcp:// ? can't you just use the IP address in fscockopen?

I've just tried sending and reading a UDP query but can't get it to do anything on my setup.
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

thistle wrote: do you need to specify the tcp:// ? can't you just use the IP address in fscockopen?

I've just tried sending and reading a UDP query but can't get it to do anything on my setup.
This UDP example is from the PHP.net site...

Code: Select all

<?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
   echo "ERROR: $errno - $errstr<br />\n";
} else {
   fwrite($fp, "\n");
   echo fread($fp, 26);
   fclose($fp);
}
?> 
The TCP example from the same page is...

Code: Select all

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: www.example.com\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp, $out);
   while (!feof($fp)) {
       echo fgets($fp, 128);
   }
   fclose($fp);
}
?> 
So TCP is the default option with 'fsockopen' so you do not need to issue tcp://
User avatar
DaGeek
Engineer
Engineer
Posts: 24
Joined: 01 Mar 2006 16:49
Skype: gspurgeon
Location: London, UK
Contact:

Post by DaGeek »

I have almost finished my Add-On to autopilot that will pull game stats from
a running server.

Is is a very very simple (but some will say messy) way of getting the stats,
The Add-On will pull the data strait from the Console of the running server
and output it to some txt files.. (This bit alrealy works fine, examples @
http://openttd.dageek.co.uk/DaGeek_Server99_score.txt
&
http://openttd.dageek.co.uk/DaGeek_Server99_stats.txt
)
The other parts of the Add-On are for the Auto Screenshots that you can see
@ http://openttd.dageek.co.uk (Major thanks goes out to Brianetta
who has pointed me in the right direction on this bit)

The last thing I'm working on @ the mo is the www interface to show all these
details in a nice way...
thistle
Engineer
Engineer
Posts: 27
Joined: 31 Aug 2006 20:35

Post by thistle »

Ok this is a total noob question because I've never really played with this sort of stuff before:

How do I send a packet to the server in PHP?

I've opened a (TCP) socket with fsockopen and then fwrote "PACKET_CLIENT_COMPANY_INFO" to the socket.
In the dedicated server console window the connection shows up, but when I try to fread a reply, I don't get anything.

If I do something similar with UDP and write "PACKET_UDP_CLIENT_FIND_SERVER" to the socket then the console window shows:

Code: Select all

Recieved Invalid packet type 67 from 192.168.1.101:1300
Do I need to so some magic encoding with the packet to get a reply?

My entire code is below, and it works fine when sending a HTTP request to a local web server:

Code: Select all

<?PHP

//script for querying an openttd server and displaying the response

$server = "192.168.1.101";
$port = 3979;

$packet = "PACKET_CLIENT_COMPANY_INFO";

$socket = fsockopen($server, $port, $errno, $error, 30);

fwrite($socket, $packet);

while (!feof($socket)) {
	echo fread($socket, 64);
}

fclose($socket);


?>
Last edited by thistle on 15 Feb 2007 16:27, edited 1 time in total.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Post by Rubidium »

You are not sending the correct information to the server; PACKET_UDP_CLIENT_FIND_SERVER is a name for the packet, but it is not send in the packet, it is the name of a constant within the OpenTTD source code. You'll have to look up the correct numeric value in the network code.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 2 guests