Page 2 of 5
Posted: 28 Jun 2007 02:13
by maartena
rav wrote:just remove any die() statements and/or replace them with print()?
That's "just" something you "just" need to know

I ain't no php coder

Posted: 28 Jun 2007 07:11
by dihedral
not such a good idea rev!
it will just output way more error messages if you do that
if( !$openttd->queryServer( $server['host'], $server['port'] ) ){
print( $openttd->getError() );
}
$info = $openttd->getInfo();
$detail = $openttd->getDetail();
as there is no 'else' section to this ifstatement that wrappes everything following the if statement, a print would show the error message, but then the script would contintue trying to assing data to $info and $detail.
getInfo() and getDetail() should at anytime return an array() to satisfy the foreach loops. Idealy if an error occures (i.e. queryServer() returns false)
the script should skip to the next index in $servers, if there is one.
As i just noticed, the script does not handle this part correctly anyway, so i shall fix that, so the script just skips to the next $server index.
thank you for your idea rev.
EDIT: you cann replace the die() with print() followed by a continue, ie:
print( $openttd->getError() );
continue;
@maartena: well done on the edit

Posted: 28 Jun 2007 08:53
by rav
and if it still doesn't work you can just wrap the whole thing in a try{} catch{}

Posted: 28 Jun 2007 09:26
by dihedral
if the php errors were catchable, yes. usually this is stated along with the error message php outputs, i.e
catchable error foo in file blah on line ##
but it is a nice idea to throw exeptions if something goes wrong, rather than just setting a class internal flag.
i shall try to add that, thank you rev for that idea.
Posted: 28 Jun 2007 16:03
by maartena
the continue; addition works perfectly. Now when I take down a server or it crashes, it simply doesn't display it's information but the information for other servers is still displayed. Perfect solution for me
EDIT: Another suggestion I have:
Can you make the Company #'s on the output HTML correspondent with the actual company/player number? For instance, I have a server with 8 companies and 6 players, nicely listed as 1 through 8. I then decide to delete company 3 and 7 because the players have left and the companies weren't even used. Instead of then displaying 1, 2, 4, 5, 6, and 8 as the companies, it now displays company 1 through 6.
For management purposes, and to see who belongs to what company without having to log on to the server itself, it would be great if the company #'s would match up.

Posted: 29 Jun 2007 15:40
by Bilbo
Just wonder .. will there be querying the master server for server list supported in some future versions, or should I do this myself?
Posted: 29 Jun 2007 15:50
by t2t2
Bilbo wrote:Just wonder .. will there be querying the master server for server list supported in some future versions, or should I do this myself?
Code: Select all
<?
$serverpage = file_get_contents('http://www.openttd.org/servers.php');
$serverpage = explode('<table cellspacing="0" cellpadding="4" border="0" class="fullwidth">', $serverpage);
$serverpage = explode('</table>', $serverpage[1]);
$serverpage = $serverpage[0];
print '<table cellspacing="0" cellpadding="4" border="0" class="fullwidth">'. $serverpage .'</table>';
?>
1. Gets HTML code of
http://www.openttd.org/servers.php
2. Narrows it down to table of servers
3. Prints output with table starting tags.
Posted: 29 Jun 2007 15:56
by dihedral
afaik the master server could be queried with udp packets, fetching a list of ip's and port numbers for games, though i dont think there should ever be a reason anybody needs to fetch data from servers that are not their own

Posted: 29 Jun 2007 16:59
by Bilbo
t2t2 wrote:Bilbo wrote:Just wonder .. will there be querying the master server for server list supported in some future versions, or should I do this myself?
...
1. Gets HTML code of
http://www.openttd.org/servers.php
2. Narrows it down to table of servers
3. Prints output with table starting tags.
I thought of that too. But then I realized one small glitch. The list contain only server addresses and no ports (and ports often differ). And fetching one page from the server for each server just to get port ... that would be silly and waste of server resources, bandwidth, etc ...
Posted: 29 Jun 2007 17:03
by Bilbo
dihedral wrote:afaik the master server could be queried with udp packets, fetching a list of ip's and port numbers for games, though i dont think there should ever be a reason anybody needs to fetch data from servers that are not their own

Well, there are reason, like:
I have nicks of my friends. List servers on which they are playing.
Or to filter the list based on some more advanced criteria. The in-game server browser have no filtering options and the window is pretty small ... maybe best will be to fix it in the code, but making some extra PHP thingy is much easier for me

Posted: 29 Jun 2007 18:34
by dihedral
it would be better if the master server provided such features, rather than OpenTTDLib fetching details from the master server, then fetching details from each of those servers. this would take way too long to process as well.
so rather than everybody having their own copy of OpenTTDLib that does this kind of trick, it would be a much cleaner job if the master server did this.
i might add the query to the master server, but only after discussing it with TrueLight.
again: personally i do not think that everybody needs to query other peoples servers with OpenTTDLib, just to find a nick name of a player... ignoring the fact for now that a nick name can appear more than once.
the todo list currently includes following:
- query server for new grf data
- send methods for OpenTTDLibPacket class (required for fetching new grf data )
- moving all packet related methods to OpenTTDLibPacket, and making it more like src/network/core/packet.cpp
- xml webservice (though may never become public; primary use for sandra-bullock.co.uk games)
Edit: just so people read this: there is a php bug under windows, currently tested on a 64bit system, with IIS6. problem lies in the usage of the php function stream_select()
Posted: 29 Jun 2007 20:36
by VPN-User
There is another bug: Quotations are being escaped which results in company names like 'Foo \"bar\" and stupid' etc.
Posted: 29 Jun 2007 21:07
by dihedral
thanks - yes, it's a just a simple function call in openttd.class.php
it will be removed for the next release
Posted: 29 Jun 2007 21:16
by VPN-User
I also have a feature request: What about a possibility to get the "restart_date" of the server?
Posted: 29 Jun 2007 21:24
by dihedral
currently this is not included in the info packet the server returns. it the devs should decide to upgrade this info packet (which i am hoping for) they might also add the restart date, though at the moment there is no way for me to fetch these details.
the only currently available data that OpenTTDLib does not fetch at the moment is details on loaded new grf's.
i am working on getting this included
Posted: 29 Jun 2007 21:27
by VPN-User
Anyway, if anyone is interested in how I used OpenTTDLib:
http://tot.kik-server.de/ 
Posted: 03 Jul 2007 20:14
by dihedral
thanks - i like seeing it in use elsewhere

v 0.2 released
Posted: 19 Sep 2007 18:04
by dihedral
just finished work on v 0.2
this release is mainly getting me a step closser to adding new GRF support
though a few things have changed:
- OpenTTDLib now throws an exception (OpenTTDLibException) rather than returning false
- added images for station and vehicle types (see
http://openttdlib.dihedral.de/wiki/LiveDemo)
- removed escaping from company and player names (the disturbing backslash '\')
- more dynamic option setting (e.g. timeout, conversion of netlang, mapset, etc)
...
when upgrading from v. 0.1.1 please pay close attention to the docs and example.php and example2.php
NOTE: there is no backwards compatibility!
downloads available at http://openttdlib.dihedral.de/wiki/Download
or from the first post of this thread:
http://www.tt-forums.net/viewtopic.php? ... 40#p599640
Re: OpenTTDLib - fetch live game data (UPDATE - v 0.2)
Posted: 09 Nov 2007 10:48
by dihedral
release of version 0.3
changelog:
Code: Select all
change $info $detail and $newgrf are now handled as objects
can be retreived as arrays if need be (see documentation)
added caching, currently only newgrf data is cached, minimizing the
amount of newgrf requests sent to the server
added support for fetching newgrf data, packet types:
UDP_CLIENT_GET_NEWGRFS and UDP_SERVER_NEWGRFS
fixed conversion of vehicle and station types was brocken
download at the
first post of this topic or at
http://openttdlib.dihedral.de
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3)
Posted: 10 Nov 2007 22:43
by maartena
Hey
I just happen to have reinstalled my linux box. I installed OpenSUSE 10.3, got apache running, installed php5, installed PEAR and used the pear command from a terminal to install the sigma.php in the right spot.... but when you click on the link in my sig it doesn't work. My guess is that I need to put an include somewhere for php to know PEAR is there or something, bu i haven't been able to figure it out yet. Any ideas?