Dedicated server autopilot (current version: 2.0.4)

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

Moderator: OpenTTD Developers

Post Reply
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Dedicated server autopilot (current version: 2.0.4)

Post by Brianetta »

My nightly server now has an autopilot running the console. It pauses the game when there are no players, and it greets all connecting players with my email address and the URL of the server's house rules. There are no modifications made to OpenTTD - my server runs an unmodified, released build.

This autopilot is written in Expect. In future, it will also be able to page me (as a committed, caring server admin) from within the game by email. It will be able to take messages for other players (once I get that code working) and will pass those messages on when the specified player next joins.

There will hopefully very soon be a modified one for the #OpenTTDCoop sandbox server which will kick and disband anybody connecting as a non-spectator other than in company 1.

If any other server admins have Expect and would like this initial version of the autopilot script, please get in touch.

All players are welcome to join my nightly server (which varies between UK Renewal Set and vanilla Arctic depending on my mood and the mood of players) to see the new autopilot in action.

Windows users can use this product after patching their copy of openttd.exe with this zipped patch utility by glx (attached to page 4 of this thread).

Edit: Added version 2.0.4 to this post
Attachments
autopilot.txt
Version 1.3
(6.35 KiB) Downloaded 1942 times
autopilot-2.0.4.zip
Version 2.0.4

Security update, works with RC4
(33.2 KiB) Downloaded 1256 times
Last edited by Brianetta on 18 Jan 2007 21:32, edited 15 times in total.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
cyclonetwist
Engineer
Engineer
Posts: 86
Joined: 19 Jul 2005 11:33
Location: Inbetween here and there

Post by cyclonetwist »

Sounds good, Where do i get the UK renewal set from?
Image
Image
Image
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

This forum, somewhere. The nightly isn't running the UKRS right this minute, although it will be for the next game.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
WWTBAM
Moderator
Moderator
Posts: 3682
Joined: 02 Apr 2005 07:01
Location: Sydney NSW Antipodea
Contact:

Post by WWTBAM »

specificaly the ttdpatch graphics forum
neonx
Engineer
Engineer
Posts: 11
Joined: 04 Jul 2003 16:06
Location: Norway

Post by neonx »

Could you release the source for this script? It would be neat to have, I'm getting tired of going to bed at night in year 1990 to wake up in year 3000 next day.
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

I'm thinking about it. I want to get the internals presentable and some bugs ironed out first. If I release it I'll probably GPL it because I'm nice like that.

It's a bit fernickety at the moment. It often misses reading join or quite messages, meaning it loses count of the number of clients (which can make it pause when somebody's still there, or stay running when everybody's gone). I've added a command to reset the client count manually, but it's a bit of a naff solution.

I can get it to never miss anything ever by completely ignoring the console user. Unfortunately, this would mean that all server admin must be done by rcon.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

OK, I'm going to release it. The code isn't commented (except a couple of variables at the top) so unless your TCL is good you're going to have to live with that if you want to modify it.

This is released under the GNU General Public License and as such comes with no warranty. If your game runs all night with nobody on it, or you manage to lose a saved game you really liked, or it goes mental and locks up a server to which you have no physical access, all you are entitled to is my sympathy.

Right, you need Expect. This is a TCL extension and can be found here: http://sourceforge.net/projects/expect

It works on Linux. I don't think I did anything platform specific, but you never know - it might also work on Windows or Mac or whatever.

Before you run it, change the motd variables at the start (or be embarrassed when somebody joins your server later). You can change the config file it uses here, or you can set the path to a valid openttd.cfg file in your OTTD_CONFIG environment variable - handy for multiple servers. You can also give a preferred net_frame_freq here. The script hopes that it (and you) are in the installed OpenTTD directory.

The script takes an optional parameter, which loads a saved game of the name "game.sav" from saves/. It can also take an additional optional parameter to load some other game.

./autopilot
./autopilot load
./autopilot load "save/Fundingford Transport.sav"

Windows people will need to either rename autopilot so that it has the extension that Expect expects, or they will need to run it like this:

expect autopilot
expect autopilot load
expect autopilot load "save/Fundingford Transport.sav"

Once you're running, the console might seem laggy. This is because it pays attention to the game for four seconds, then it pays attention to you for four seconds, then the game, etc. It doesn't miss stuff, though.

You have extra commands. The help command is extended, and if you type "save" without giving a filename it saves to game.sav in your save folder (which is the default for loading as mentioned above). Please note that the autopilot cannot be controlled by rcon! You need access to the dedicated console itself to use it. rcon will work as normal for all server functions.

The autopilot will greet people who join the game. It will unpause the server for them, and it will pause the game when they all leave. Once people have all left and the server is paused, it will save the game to save/game.sav, taking advantage of the fact that there's nobody to delay.

As people join and leave the game, autopilot will tell you how many people it thinks are connected. If this turns out to be wrong (autopilot has been known to miss the odd join or leave from time to time) then correct it from the console with the 'count' command, eg. 'count 2' will tell autopilot that there are two people connected, regardless of what it thought.

If anybody types "show autopilot version" into the in-game chat, it'll tell everybody the version. The console gives 'version' and 'license' commands, which pertain only to autopilot (although OpenTTD does use the same license, this is coincidental).

Finally, any commands you type into the console that autopilot doesn't recognise, it will relay to the game server.

If anybody has any questions, ask here. Despite what I said about there being no warranty, I'm happy to help out with modifications, etc.

Remember, autopilot is a wrapper. It is agnostic about the version of OpenTTD that it is being run on. As long as the console looks pretty much the same, it will work on any version.

(attachment moved to first post)
Last edited by Brianetta on 17 Jan 2006 00:25, edited 1 time in total.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
neonx
Engineer
Engineer
Posts: 11
Joined: 04 Jul 2003 16:06
Location: Norway

Post by neonx »

Nice! It seems to work quite good.
Thank you very, very much! :D
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

You're quite welcome. (:
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
RMJ
Traffic Manager
Traffic Manager
Posts: 160
Joined: 24 Sep 2005 13:52
Location: Denmark
Contact:

Post by RMJ »

can it be made avalible for us normal persons. :)
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

RMJ wrote:can it be made avalible for us normal persons. :)
Can you be a little more specific? What do you mean by normal, and why isn't autopilot available to said people?
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
neonx
Engineer
Engineer
Posts: 11
Joined: 04 Jul 2003 16:06
Location: Norway

Post by neonx »

If he assumes "normal persons" is windows users he has got it all wrong :wink:
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

There's no real reason why the autopilot shouldn't run on Windows, as long as Expect is installed. Expect is freely available.

If RMJ is hoping for some sort of clickable installer and a Windows executable, he's heading for disappointment. Expect scripts run in Expect, the same as Java classes run in a JVM.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
ljungi
Engineer
Engineer
Posts: 7
Joined: 14 Jan 2006 17:49
Contact:

Post by ljungi »

Hi,

I tried to start autopilot, it works, but after a while I get these errors:
expect: spawn id exp8 not open
while executing
"expect -nobrace -re {
\*\*\* .* has joined the game} {
exp_send "unpause\n"
set output $expect_out(0,string)
set output_sp ..."
invoked from within
"expect {
-re "\n\\\*\\\*\\\* .* has joined the game" {
exp_send "unpause\n"
set output $expect_out(0,string)
set outp..."
("while" body line 2)
invoked from within
"while true {
expect {
-re "\n\\\*\\\*\\\* .* has joined the game" {
exp_send "unpause\n"
set output $expect_out(0,string)
..."
(file "./autopilot" line 72)
//UPDATE!!

I restarted the server and the error is gone...

But another question. Now my Server's calling "Unnamed Server".
Does anybody know the path to the config-file after a Debian-installation?





Greets
ljungi
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

SO everybody knows, the error message "expect: spawn id X not open" means that the dedicated server quit. You'll see this at any assertion failure and any time a player executes rcon exit.

I might make a future version handle this more cleanly (and perhaps restart the server with the last save or something). Depends whether people think it's necessary.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
ljungi
Engineer
Engineer
Posts: 7
Joined: 14 Jan 2006 17:49
Contact:

Post by ljungi »

Hi,

I've got again a Problem...
The autopilot worked... But now he don't anymore!

dbg: [NET][UDP] Advertising to master server
'net_frame_freq' changed to: 2
Game paused.
*** ljungi hat das Spiel betreten
So I joined the game but he doesn't unpause...
When I leave, he doesn't pause.

Thats strange, cause it already worked!
I only restarted the server...

the command to start it was

screen ./autopilot load '/root/.openttd/save/ml.sav'
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Aha - it's a language problem. Unfortunately, autopilot doesn't speak German!
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
neonx
Engineer
Engineer
Posts: 11
Joined: 04 Jul 2003 16:06
Location: Norway

Post by neonx »

It does not speak norwegian either, but it takes you 10 seconds to make it speak it. Just locate "has joined the game" and replace it with your language.
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Don't forget the "has left the game" bit too - or it'll lose count really quickly. (:
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Updated to 1.2 (attached to original post in thread).

It's longer now, but it has an additional feature - it can use the output of the "clients" command to re-count the number of connected clients, on demand (use "recount clients"). It also has a small bug fix - clients with a space in their name are greeted by their whole name, not just the first word.

I found that the autopilot most often lost count when the server got something wrong and all the clients desynced at once. The lines went by too fast for the autopilot, and it ended up with a higher cliuent count than reality. Now, if it sees somebody leave due to a desync, it will instigate a recount.

Also, players can cause a recount on demand by saying "recount clients" into the chat. This is in addition to their being able to see the autopilot version with "show autopilot version".
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: Google Adsense [Bot] and 21 guests