OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
Moderator: OpenTTD Developers
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
if you need any further help: read the docs, if that does not provide enough help, feel free to ask ^^
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
The documentation is pretty clear even for a PHP-newbie like me
One question though:
When I get a return value from OpenTTDLib::getDetail(), the [player][$x][vehicles] array is perfectly reporting the amount of trains on my server etc., but the [allclients] and [player][$x][client] arrays remain empty...
Maybe i'm doing something wrong, but there are 3 clients connected, and [clients_on] from getInfo() IS actually reporting the correct number of clients.
I would love to be able to display client names per company and per server though.
One question though:
When I get a return value from OpenTTDLib::getDetail(), the [player][$x][vehicles] array is perfectly reporting the amount of trains on my server etc., but the [allclients] and [player][$x][client] arrays remain empty...
Maybe i'm doing something wrong, but there are 3 clients connected, and [clients_on] from getInfo() IS actually reporting the correct number of clients.
I would love to be able to display client names per company and per server though.
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
that is because the server no longer provides this information via udp packets
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
Ah, too bad.
Very useful library anyway, im still trying to combine it with some (of course quite unsafe, but its private servers on a LAN) exec() functions on the dedicated server so i'm able to generate, start and stop new servers including the ability to upload scenery and saves to use as a new dedicated server. Lots of problems still, since I use "openttd -D -f" to fork it to a background process so PHP can read the output from a file, but that prevents me from actually interacting with the running server (rcon etc.)
This library gives quite a few cool stats about already running servers though, only need to find a way to create savegames from the server and send&read chat messages.
Very useful library anyway, im still trying to combine it with some (of course quite unsafe, but its private servers on a LAN) exec() functions on the dedicated server so i'm able to generate, start and stop new servers including the ability to upload scenery and saves to use as a new dedicated server. Lots of problems still, since I use "openttd -D -f" to fork it to a background process so PHP can read the output from a file, but that prevents me from actually interacting with the running server (rcon etc.)
This library gives quite a few cool stats about already running servers though, only need to find a way to create savegames from the server and send&read chat messages.
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
i would sugest to make a java webapp instead of using php for that.
perhaps a useful hint would be to use fifo files
and then use those files when starting openttd:
then you can access those fifo files (out and err for reading only, in for writing) and still have access to the console - however, for this you do not have to run openttd as an apache child, it would work perfectly find as long as apache has read/write access to the files accordingly.
note though, when writing to the "in" pipe, to send a \n after a command but no EOF, else "in" will not remain usable after.
perhaps a useful hint would be to use fifo files
Code: Select all
mkfifo in
mkfifo out
mkfifo err
Code: Select all
openttd -D -f 1>out 2>err <in
note though, when writing to the "in" pipe, to send a \n after a command but no EOF, else "in" will not remain usable after.
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
I was trying to use proc_open() with pipes to launch openttd and it seems to work, but the problem seems to be that PHP runs "/dir/dir/openttd -D" as the user www-data, and www-data is not allowed to start programs that listen on ports, openttd needs to be launched with sudo... But, www-data can not execute sudo since it has no password.
Edit: ah, solved by adding www-data with no password option to the sudoers file
Of course, stupid thing to do, but as I said the webserver is only available in a trusted LAN anyway
Edit2: proc_open is not going to work of course, because when I close the browser and reopen it again PHP has no idea where to look for in/output with the server...
The solution with FIFO files doesnt seem to work either, openttd does not start when appending the "-D -f 1>out 2>err <in"
Edit: ah, solved by adding www-data with no password option to the sudoers file
Of course, stupid thing to do, but as I said the webserver is only available in a trusted LAN anyway
Edit2: proc_open is not going to work of course, because when I close the browser and reopen it again PHP has no idea where to look for in/output with the server...
The solution with FIFO files doesnt seem to work either, openttd does not start when appending the "-D -f 1>out 2>err <in"
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
oh, correct, using fifo's does not allow forking to the background - so, basically: start openttd in a screen session (e.g) and use the fifo's, then use php to connect to the fifo's
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
Doesn't matter if I execute it with or without -f, with or without -D, with or without sudo...
As soon as I add "1>out 2>err <in" the console just responds/hangs with a newline and no process is started.
As soon as I add "1>out 2>err <in" the console just responds/hangs with a newline and no process is started.
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
yes it would, as all output is directed to those files, and you need to check them in order to see what's going on!
note: you are redirecting the programs output and input!! what would you expect!
if nothing is found in the out or err file, try
might help. however, generally speaking, all output will be found in "out" and "err"
note: you are redirecting the programs output and input!! what would you expect!
if nothing is found in the out or err file, try
Code: Select all
echo -n "\n" >> in
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
maybe you should try "tee" to print the output into the file and also the console...
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
The process won't even start when using either stdin or stderr, only stdout redirection is accepted, but even if I run:dihedral wrote:yes it would, as all output is directed to those files, and you need to check them in order to see what's going on!
note: you are redirecting the programs output and input!! what would you expect!
if nothing is found in the out or err file, try
echo -n "\n" >> in
might help. however, generally speaking, all output will be found in "out" and "err"
Code: Select all
./openttd -D 1>file.txt
Are you sure openttd can work with stdin/stdout redirection, and the file descriptor numbers are right?
I don't know much about this stuff, so excuse me if i'm doing something stupid, but I would really love to understand more about how openttd works and if/how it can be integrated/wrapped into other systems
Edit:
btw, if I do
"./openttd -D 1>out"
it just puts the cursor on the next line, no process is created and nothing is running, but if I do
"./openttd -D 1>file.txt"
it creates a process, leaves file.txt empty, prints the output in the terminal AND "lsof -p PID" results in:
Code: Select all
openttd PID root 0u CHR 136,2 0t0 5 /dev/pts/2
openttd PID root 1w REG 8,6 0 262319 /dir/to/ottd/file.txt
openttd PID root 2u CHR 136,2 0t0 5 /dev/pts/2
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
that is because a bunch of output goes to the descriptor 2 and not 1!
you can try with a simple ./openttd 2>&1 >file.txt
you can try with a simple ./openttd 2>&1 >file.txt
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
It's been a long time after the last replies.
Would you mind if I ask you a question for OpenTTDLib 0.3.2?
My host server is using PHP 5.2.14 (based on Linux),
And no --enable-bcmath option.
But there's an another PHP class instead of bcmath functions which exactly work like bcmaths.
(I will call it as 'Math' class.)
I found all bcadd(), bcmul(), bcpow() and changed into Math::add(), Math::mul(), Math::pow() in OpenttdLibPacket.php file.
But when I open example.php, it says 'sending packet failed'.
(The server what I setted in source file is 'ottd.iruis.net:3979'.)
http://www.korct.com/php/ottdlib0.3.2/example.php
Could you tell me what should I do or what I missed?
Additional: Here's my PHP Configure Command of phpinfo()
Would you mind if I ask you a question for OpenTTDLib 0.3.2?
My host server is using PHP 5.2.14 (based on Linux),
And no --enable-bcmath option.
But there's an another PHP class instead of bcmath functions which exactly work like bcmaths.
(I will call it as 'Math' class.)
I found all bcadd(), bcmul(), bcpow() and changed into Math::add(), Math::mul(), Math::pow() in OpenttdLibPacket.php file.
But when I open example.php, it says 'sending packet failed'.
(The server what I setted in source file is 'ottd.iruis.net:3979'.)
http://www.korct.com/php/ottdlib0.3.2/example.php
Could you tell me what should I do or what I missed?
Additional: Here's my PHP Configure Command of phpinfo()
Code: Select all
'./configure'
'--with-mysql=/mysql'
'--with-apxs2=/blah/blah/apxs'
'--with-config-file-path=/blah/blah'
'--enable-safe-mode=/blah/blah'
'--enable-ftp'
'--enable-sockets'
'--with-mcrypt'
'--with-gd'
'--with-jpeg-dir=/usr/local/lib/'
'--with-png-dir=/usr/local/lib/'
'--with-freetype-dir=/blah/blah/freetype2/freetype/'
'--with-zlib'
'--with-iconv'
'--enable-exif'
'--enable-mbstring'
'--with-mysqli=/blah/blah/mysql_config'
'--with-openssl'
'--with-libxml-dir=/blah/blah/libxml2/libxml/'
'--enable-soap'
'--with-curl'
'--with-pdo-mysql'
'--with-xmlrpc'
'--enable-zip'
- OpenTTD/OpenRCT2/Parkitect Korean Translator
- TELKLAND site manager, the korean website of OpenRCT2/OpenTTD (https://telk.kr)
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
Code: Select all
test:
bad packet size
#0 /home/01/korct31/www/php/ottdlib0.3.2/includes/OpenTTDLib.php(1630): OpenTTDLib->RecvData()
#1 /home/01/korct31/www/php/ottdlib0.3.2/includes/OpenTTDLib.php(1679): OpenTTDLib->waitForServerResponse()
#2 /home/01/korct31/www/php/ottdlib0.3.2/example.php(19): OpenTTDLib->queryServer('127.0.0.1', 3979, 1)
#3 {main}You are querying localhost according to the error i see
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
Does the charset of my site can be a problem to control packets?
My site uses UTF-8 and now I can use bcmath.
My site uses UTF-8 and now I can use bcmath.
- OpenTTD/OpenRCT2/Parkitect Korean Translator
- TELKLAND site manager, the korean website of OpenRCT2/OpenTTD (https://telk.kr)
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
Either openttd is not running, there is a firewall, possibly selinux is in the way, or you are accessing the wrong host.
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
When I tested by modifying sendPacket() in OpenttdLib.php,dihedral wrote:Either openttd is not running, there is a firewall, possibly selinux is in the way, or you are accessing the wrong host.
It didn't return the byte length from fwrite() when querying ottd.iruis.net:3978.
When querying localhost, fwrite returns an integer more than 0 but errors bad packet.
Do you think it comes from the firewall?
- OpenTTD/OpenRCT2/Parkitect Korean Translator
- TELKLAND site manager, the korean website of OpenRCT2/OpenTTD (https://telk.kr)
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.
Just check what i have mentioned!
-
- Engineer
- Posts: 2
- Joined: 22 Mar 2012 15:18
Re: OpenTTDLib - fetch live game data (UPDATE - VERSION 0.3.2)
I made a simple port to node.js.
It doesn't have all functions the PHP version has.
You can use it with node.js or as a command-line program. Just install it with npm with the --global flag.
It returns a json representation of the data.
nodejs_openttdlib
It doesn't have all functions the PHP version has.
You can use it with node.js or as a command-line program. Just install it with npm with the --global flag.
It returns a json representation of the data.
nodejs_openttdlib
Who is online
Users browsing this forum: Google [Bot] and 8 guests