Aiden Haak

  • About

Moving to GitHub Pages

March 5, 2022

Long time no post!

After having to do an OS reinstall and losing my old deploy script I found myself lamenting the fact this blog did not have an automated deployment. Fortunately Hugo makes it super easy to get up and running with GitHub pages. The fact that GitHub Pages is 100% free is just icing on the cake.

Now where to spend that $1.50 in AWS S3 monthly savings…

Setting Up An OpenTTD Server Part 2

January 29, 2021

I found myself wanting to scratch my OpenTTD itch again but I need to setup another server as I had long ago nuked the server for part one. Turns out that part one is (unsurprisngly) a bit out of date after five years and this time I wanted to dabble in some custom graphics or GRFs for my server.

For the first problem there is a an easy fix thanks to an OpenTTD docker image. As for the custom GRFs - well you’ll just have to keep reading.

For this guide I’m assuming:

  • That you’re running OpenTTD locally on a Windows desktop.
  • You have a Google Cloud account setup and you know your way around it a bit.
  • The OpenTTD server will run on Ubuntu.

Customising the Custom Graphics

I found the easiest way to get the graphics files setup was to do it in game via the New GRF settings

Once you are happy with your custom GRFs (making sure that they are compatible with each other!) it’s time fire up the command prompt and run OpenTTD as a local server using the following command:

openttd.exe -D

This will make OpenTTD generate the config file and GRF files that our server can use. After a brief wait you can stop the OpenTTD server after it has finished generating the map and has started the game.

Next navigate to C:\Users\<username>\Documents\OpenTTD where you should see a openttd.cfg file and a content_download folder. These are the files we will be uploading to a storage bucket. It is a good idea to double check that the new GRFs are correctly included in the config file, you should see something like the following at the end of the openttd.cfg file:

[newgrf]
44440111|9B505....AFB0CA|uk_renewal_set.3.04\pb_ukrs.grf = 
F1250007|997B3....46D7EB|firs_industry_replacement_set_3-3.0.12\firs.grf = 0 0 0 0 0 0 16 150 80 300
4A530117|CA321....D4A501|ecs__firs_vehicle_set-2014.11.26\efrefit.grf = 

Google Cloud Setup

We will be running OpenTTD on the free F1-micro instance but first we have a few things to setup.

Storage

Firstly create a new Storage bucket for your OpenTTD files then upload the openttd.cfg file and content_download folder from the C:\Users\<username>\Documents\OpenTTD folder to a openttd folder in the bucket. Remember to edit the openttd.cfg file to your desired settings before uploading as this is the configuration your server will be using.

After the upload has finished the folder in your bucket should look like the following.

Firewall

We need to add a firewall rule to the VPC network the server will be running in to allow the OpenTTD traffic through. Create a firewall rule that allows TCP and UDP on your desired OpenTTD port – by default this is port 3979.

Putting It All Together

Now it’s time to create a new VM instance but there are a few settings that need to be configured. Firstly, make sure to use a Ubuntu image and then assign a public IP to your instance to ensure that it is reachable over the public internet.

Then copy the following bash script after changing the OPENTTD_BUCKET_NAME in the script to the same name as the bucket you created earlier in this guide.

#!/usr/bin/bash

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

# Use the same bucket name from earlier in the guide here.
OPENTTD_BUCKET_NAME="bucketname"

# Install some prerequisites.
apt-get update -y
apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# Next steps copy pasted from: https://docs.docker.com/engine/install/ubuntu/

# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

# Add the Docker repository.
add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Install docker
apt-get update -y
apt-get install docker-ce docker-ce-cli -y

# Add the openttd group and user.
groupadd openttd -r
useradd openttd -r -g openttd,docker

OPENTTD_GROUP_ID=`id -g openttd`
OPENTTD_USER_ID=`id -u openttd`

# Add firewall exceptions.
apt install ufw -y
ufw allow 3979

OPENTTD_DIR="/etc/openttd"

# Download the openttd config file and GRFs.
mkdir -p $OPENTTD_DIR
gsutil cp -r "gs://$OPENTTD_BUCKET_NAME/openttd" $OPENTTD_DIR
chown openttd:openttd -R $OPENTTD_DIR

# Finally run the container.
docker run --name openttd -d \
    -e PUID=$OPENTTD_USER_ID \
    -e PGID=$OPENTTD_GROUP_ID \
    -v $OPENTTD_DIR:/home/openttd/.openttd \
    -p 3979:3979/tcp \
    -p 3979:3979/udp \
    bateau/openttd:latest

And paste it into the start-up script section for the VM.

Now create the instance and sit back and wait for the magic to happen 🧙‍♂️

Add the server IP via the in-game browser and you should be able to join!

Troubleshooting

If you can’t connect to your OpenTTD server here are a few basic steps you can try. Firstly, make sure you can ping the server via its public IP. Secondly, verify that the docker container is actually running on the server.

You can do this by running docker ps -a and you should see an bateau/openttd image in the results. If it’s not there it’s likely the startup script failed to run and you can try running the script manually. One easy way to do this is to upload the initialization script to the openttd bucket and run the following commands:

gsutil cp "gs://OPENTTD_BUCKET_NAME/init.sh"
chmod +x init.sh
sudo ./init.sh

After the script has run check the docker container is running – if OpenTTD still isn’t running after this the problem is left as an exercise for reader.

Next Steps

Some next steps to consider for your server:

  • Add a domain for your server.
  • Add cron job to upload save games to storage bucket so you can relive your greatest maps!

Moving To Hugo

June 29, 2019

I have just put the finishing touches on this site’s second migration – this time from Jekyll to Hugo. I’d been planning on doing this migration for a while but the lack of SCSS/SASS support was holding me back. Then in August 2019 Hugo 0.43 happened and with it the introduction of Hugo Pipes and SCSS/SASS. So there was nothing holding me back (except for a lack of free time of course).

The main motivation for this change is two-fold:

  • I remove my dependencies on a bunch of random ruby gems
  • Having a binary file to do the HTML generation is really nice, no setting up a Ruby or Python environment just make sure the Hugo executable is on the path and it’s good to go.

Which means reduced maintenance for keep my theme building and hopefully at least a small increase in my blogging and to start planning yet another migration to the blog platform du jour (probably Gatsby).

OpenVPN and Iptables

July 16, 2016

I recently setup an OpenVPN server, I mostly followed the fantastic Digital Ocean (DO) guide, however I ended up using iptables instead of ufw. Since setting up my iptables configuration correctly was probably the one thing that gave me the most trouble I thought I’d share.

I setup OpenVPN using a TUN adapter for my OpenVPN server because 1: that’s what the DO guide does and 2: I don’t plan to do any bridging. However, if you are using a TAP adapter you can read more about it on the OpenVPN website.

The iptables rules file I ended up using looked something like the following.

*filter

# Allow all loopback (lo0) traffic and reject traffic
# to localhost that does not originate from lo0.
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j REJECT

# Allow ping.
-A INPUT -p icmp -m conntrack --ctstate NEW --icmp-type 8 -j ACCEPT

# Allow SSH connections.
-A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT

# Allow OpenVPN connections.
-A INPUT -p udp --dport 1194 -m conntrack --ctstate NEW -j ACCEPT

# Allow inbound traffic from established connections.
# This includes ICMP error returns.
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# Reject all other inbound.
-A INPUT -j REJECT

# Allow traffic initiated from VPN to access LAN.
-A FORWARD -i tun0 -o eth0 -s 10.8.0.0/24 -d 10.0.0.4/24 -m conntrack --ctstate NEW -j ACCEPT

# Allow established traffic to pass back and forth.
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

# Drop invalid packets.
-A INPUT -m conntrack --ctstate INVALID -j DROP

COMMIT

*nat

# Masquerade all traffic from VPN clients.
-A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE

COMMIT

There’s a few basic non-OpenVPN related items in there - e.g. allow SSH, ping, but overall it’s a pretty barebones iptables configuration since I plan to just run OpenVPN on this server. Also note that this only for IPv4 traffic and NOT IPv6.

Finally, to load the rules so that your server is using them it’s a matter of running a simple one line command.

sudo iptables-restore openvpniptable.rules

And that’s it! Assuming you followed the rest of the DO guide you should now have a shiny new OpenVPN server using iptables up and running. Happy VPNing.

Setting Up An OpenTTD Server

November 8, 2015

Update: Check out part two for a more up to date guide.

I recently setup an OpenTTD server and I thought I might document the steps I took to do so.

I choose to use a Digital Ocean (DO) to host my server since I’ve been wanting to try them out for some time. It also helps that their cheapest hosting option is rather cheap - only $5 per month. And since I don’t think OpenTTD will be particularily memory intensive I am fairly certain that the extra 512MB of RAM for the $10 per month DO droplet will be needed.

After creating my $5 per month droplet running Ubuntu 14.04 LTS I followed DO’s handy initial server setup to get my server ready for installing OpenTTD.

Installing OpenTTD

The first step to installing OpenTTD is downloading it:

wget https://binaries.openttd.org/releases/1.5.2/openttd-1.5.2-linux-ubuntu-trusty-amd64.deb

Then to install OpenTTD and it’s dependencies:

sudo dpkg -i openttd-1.5.2-linux-ubuntu-trusty-amd64.deb
sudo apt-get -f install

Installing Graphics

Before you can kick off your OpenTTD server you need to install some graphics. If you don’t have your original Transport Tycoon Deluxe CDs handy the bare minimum for this is to download OpenGFX which provides free replacements for the game’s graphics. To install it:

wget https://binaries.openttd.org/extra/opengfx/0.5.2/opengfx-0.5.2-all.zip
unzip opengfx-0.5.2-all.zip
tar -xvf opengfx-0.5.2.tar
mv opengfx-0.5.2 ~/.openttd/baseset

Adding An OpenTTD Service

With OpenTTD installed one of the last steps is to setup an OpenTTD service. Luckily for us, Frodus has kindly created an OpenTTD init script available here.

First we need to download and unzip it:

wget https://bitbucket.org/frodus/openttd-init/downloads/openttd-init-1.1.1.zip
unzip openttd-init-1.1.1.zip -d openttd-init

Then we need to add a symlink of the openttd file to /etc/init.d, update its permissions and add the OpenTTD service to the Ubuntu startup scripts.

sudo ln -s ~/openttd-init/openttd /etc/init.d/openttd
chmod 755  ~/openttd-init/openttd
sudo update-rc.d openttd defaults

Finally rename ~/openttd-init/config.example to config and edit the variables to suitable values.

OpenTTD Configuration

The last step before starting to play is setting up the openttd.cfg file - a list of the available options is on the OpenTTD wiki. A good overview of what options to change is also available on the OpenTTD Coop Wiki.

One setting of great importance is the sever_port (default value 3979) setting. Whatever option you choose, make sure to add a firewall rule. If you are using the default Ubuntu firewall ufw it is as simple as:

sudo ufw allow 3979/tcp
sudo ufw reload

iptables configuration is left as an exercise to the reader.

Some of the other settings I like to change are:

  • min_active_clients set this to 1 so the game is paused when noone is connected.
  • inflation set this to false since after a while money is no object.
  • forbid_90_deg set this to false as 90 degree turns are ugly.
  • train_acceleration_model set this to realistic otherwise slopes will seriously slow your trains down.
  • vehicle_breakdowns breakdowns are annoying so no breakdowns please.
  • no_servicing_if_no_breakdowns no servicing when there are no breakdowns.

Joining Your Server

Once you have setup your config it’s finally time to fire up your OpenTTD server:

sudo service openttd start

To join your server in the Multiplayer settings window click the Add Server button and add your server with the port number like so:

And after joining you should be greeted with your shiny new OpenTTD game. Happy network building!

  • 1
  • 2
  • 3
  • ...
  • Next ›
  • Last »

© 2013-2022 Aiden Haak – Powered by Hugo