OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)

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

Moderator: OpenTTD Developers

dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)

Post by dihedral »

OpenTTDLib is a set of php5 classes enableing you to query your game server and retrieve live information, which can then be displayed on your website or stored in a database to build more interesting statistics.

The project is based on work by TrueLight, derived from a file which used to be maintained by the OpenTTD developers, though was removed from the project in March 2007 due to maintainablilty / testing problems.

OpenTTDLib is licensed under the GNU General Public License version 2.0.

To see OpenTTDLib in action, please visit http://openttd.dihedral.de

please refer to docs/ or http://pub.dihedral.de/OpenTTDLib/OpenTTDLib-0.3.2/docs for detailed documentation.

looking forward to your feedback, either posted here or email :-)

UPDATED TO 0.3.2 (2009-04-29)
also to be downloaded from http://pub.dihedral.de/OpenTTDLib or http://www.ohloh.net/p/openttdlib

this version is only required if you are running a version of OpenTTD as of r16175
Attachments
OpenTTDLib-0.3.2.zip
(148.2 KiB) Downloaded 430 times
OpenTTDLib-0.3.2.tar.gz
(88.32 KiB) Downloaded 407 times
Last edited by dihedral on 29 Apr 2009 21:52, edited 14 times in total.
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

A bit more complete than my Tcl code (for which I haven't implemented company details). More useful, too, since Tcl isn't exactly the mainstream language it should be. (-:
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
zlasher
Engineer
Engineer
Posts: 12
Joined: 29 May 2007 11:06
Location: Oslo, Norway

Post by zlasher »

Amazing work guys!!

Thanks a lot! - This is exactly what I've been searching for the last few days..

You guys rock! (I'm including TrueLight in my salute!) :lol:


Steinar / Norway
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

I'm getting this on my webserver: (hosted domain @ hostgo.com)


Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/dutchusa/public_html/openttd/includes/openttd.class.php on line 172

What might that be about?
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Post by dihedral »

maartena wrote:I'm getting this on my webserver: (hosted domain @ hostgo.com)


Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/dutchusa/public_html/openttd/includes/openttd.class.php on line 172

What might that be about?
your webhost does not provide php5 support, only php4, which means that the php5 class structure is unrecognized and therefore fails in line 172 which is
private $fp;
php4 expects this line to be
var $fp;

i shall have a look if i can get the classes converted to php4 class structures for you.

EDIT: see the first post
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

Thanks, I will give it a try later tonight :)

Also, I do have a Linuxbox with Apache 2.0 installed, I can probably get PHP5 working on that..... I'd rather host it on my domain though, and save my own bandwidth for my servers :P
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

Haven't gotten it to work yet. I checked with my hosting provider, and they have both PHP v. 4.4.4 as well as PHP 5.2.0 installed, so I am expecting it should work somehow :)

The PHP4 version you created gave me the same error:


Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/dutchusa/public_html/openttd/includes/openttd.class.php on line 172

Any more suggestions? Do I need to CHMOD any files a certain way? The docs don't really reveal that sort of info :)
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

Found out some more info. Checked with the help/support of my hoster, and their guide said that by default .php files are ran under php4, and if I wanted to change that, I should create a .htaccess file with some stuff in it to have .php files handled by php5.

I did this, and the php's seem to be running now, however I get a new error:


Warning: require_once(HTML/Template/Sigma.php) [function.require-once]: failed to open stream: No such file or directory in /home/dutchusa/public_html/openttd/example2.php on line 6

Fatal error: require_once() [function.require]: Failed opening required 'HTML/Template/Sigma.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dutchusa/public_html/openttd/example2.php on line 6

So it would seem to miss /template/sigma.php..... i'll mess with it some more and let you know :)
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

I think I need something called "PEAR" that may not be installed on my host or something.... :(
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

I'm determined! Heh.

Fixed the Pear issue by using the go-pear installation php, followed by installing the sigma package from my browser window. Got some more info on using the example2.php file:

Warning: Invalid argument supplied for foreach() in /home/dutchusa/public_html/openttd/example2.php on line 33

Somehow i'll figure that out too :D

This is the full path btw:

http://www.dutchusa.com/openttd/example2.php
Last edited by maartena on 26 Jun 2007 21:08, edited 1 time in total.
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Post by Rubidium »

Was it really needed to make five consecutive posts?
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

Rubidium wrote:Was it really needed to make five consecutive posts?
Perhaps not. I will edit this post from now on ;)
I guess it's just easy :P
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Post by dihedral »

personally i do not believe to be responsible for documenting how to get php files to work on a werbserver, there are docs from php for that! + if nothing is stated about chmod'ing the default is assumed, default in this case is the way one gets php files served from a webserver.
but by the looks of it i shall add at least a reference in the docs on where to find information if running into certain issues.

btw: pear is mentioned in the docs as of v. 0.0.1 which is also the version in which example2.php appears.

line 33 is the line in which $detail is looped uppon. there are 3 options why this could happen:
1. i am not catching an error i should be catching and therefore $openttd->queryServer() does not return false
2. you removed the die() statement
3. you did not amend the first few lines of that file.

i believe it's a combination of 1. and 3.!

the $servers array needs changing - perhaps i should point the 'host' section of the example file to 'openttd.dihedral.de' rather than 'localhost'!
As it is only an 'example' (perhaps this does not come out correctly from the filename :-) ) I assume people would look inside and check the code :-)
anyhow - you need to change the contents of the $servers array to point to your games, following the 'example' in that file :-)

thanks for the feedback, i shall include some more stuff in the next docs to cover some questions that might arise (like in your case).

greets

diheddral
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

dihedral wrote:1. i am not catching an error i should be catching and therefore $openttd->queryServer() does not return false
2. you removed the die() statement
3. you did not amend the first few lines of that file.

i believe it's a combination of 1. and 3.!

the $servers array needs changing - perhaps i should point the 'host' section of the example file to 'openttd.dihedral.de' rather than 'localhost'!
As it is only an 'example' (perhaps this does not come out correctly from the filename :-) ) I assume people would look inside and check the code :-)
anyhow - you need to change the contents of the $servers array to point to your games, following the 'example' in that file :-)
Some more info:

I get a query timeout when I use this:

$servers[0]['host'] = 'nl.mine.nu';
$servers[0]['port'] = 3979;

And the previously mentioned error on line 33 when I use this:

$servers[0]['host'] = nl.mine.nu;
$servers[0]['port'] = 3979;

I think it NEEDS the quotes for it to work properly, so my problem would be finding out why it times out.

To verify that, I also tried it using your openttd.dihedral.de address and had the same results: timeouts using quotes, errors not using quotes.

So now I am wondering what it is that I am still doing wrong, as obviously both our game servers are up and running. ;)
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

Well, I gave up on getting it to work on my host.

Instead, I installed apache2 and php5 on my linuxbox, along with pear, followed by the openttdlib packages, and sure enough..... it works like a charm!

I then proceeded to edit the css stylesheet it created in the /templates folder, and changed it so it would have a background and different colors, and this is the result:

http://nl.mine.nu/openttd/
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Post by dihedral »

1. you have the ability to edit posts :-) please use that ability if no one has answered to your post, you can mark additions to your one post preceeding your message with 'EDIT: '!

2. of course you need the quotes!! they would not be there in the first place if they were not needed!!!
please refer to http://www.php.net for such stuff! this is not php forum, and it is not purpose of this thread to teach how one assigns variables in php.

it could be that your webhost does not allow outgoing traffic with destination port 3979, and in no way are they obligated to.

I am happy you finally got it to work, and thank you for posting a link.
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Post by Mchl »

dihedral wrote:this is not php forum, and it is not purpose of this thread to teach how one assigns variables in php.
On the other hand it is the forum, where other people having problems with your library will look for information. I suppose you should be glad, that marteena took an effort to install your library, even though he's not familiar with php (I agree though, that he could have edited his posts ;) ). This only proves, it is possible for such a person.
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Post by dihedral »

true true, i will agree with you 100%

@marteena: thx for your feedback, it will most likely be helpful to others.
and like i said in another post, i shall add some more detail to the docs.
maartena
Route Supervisor
Route Supervisor
Posts: 470
Joined: 11 Jul 2003 04:53
Location: California, U.S.A.

Post by maartena »

A note to programmers: Do not EVER expect people to "look inside and check the code". ;) I'm not a coder indeed, and although I can easily look inside code and figure out what goes where, most people on this forum are absolute php newbies, and most people will not know what to look for in code.

I figured it all out no problem - it went smoooth as soon as I started working with my own linux box - but not everyone is a computer nerd like me :P

Thanks though, it's working like a charm now! :D :D

EDIT: (I want recognition for using edit, heh, heh!)

I noticed an annoying bug. I monitor 5 servers, and I actually just launched a 6th one to experiment with nightlies. So I changed the code to monitor all 6 servers.

The problem however is when I take down 1 of the 6 servers for maintenance or whatever other reason. When you do that, the php script no longer works and displays the following error:

object(OpenTTDLibPacket)#3 (3) { ["data:private"]=> string(0) "" ["size:private"]=> int(0) ["pos:private"]=> int(3) } unknown packet received

As soon as I launch the server again, the php script works again. In a next version, the script should still display the information for all running servers, and just display a "this server is down or unreachable" message when it cannot get any information from it, instead of simply erroring out.

Sometimes it happens that a server crashed due to e.g. a segmentation fault when I am sleeping, working, or otherwise not near my PC. With the current version, that would mean the php script will also not work until the server is either launched again, or removed from the phpfile.

Just a thought :)
Guess what! I got a fever! And the only prescription...... is MORE COWBELL!
User avatar
rav
Traffic Manager
Traffic Manager
Posts: 253
Joined: 17 May 2007 13:36
Location: Netherlands
Contact:

Post by rav »

just remove any die() statements and/or replace them with print()?
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 17 guests