This repository contains two components to have a functional Master Server for the OpenTTD clients.
- a
master_server
component, which runs the actual Master Server and communicates with the OpenTTD clients. - a
web_api
component, which allows HTTP access to the current online servers known by the Master Server.
These are in a single repository, as they share the same database access.
The master_server
and web_api
are written in Python 3.8, and makes strong use of asyncio and aiohttp.
Both make use of the AWS DynamoDB database to store the known servers.
- Python3.8 or higher.
- Docker
To start it, you are advised to first create a virtualenv:
python3 -m venv .env
.env/bin/pip install -r requirements.txt
You need to run a local AWS DynamoDB to experiment with. AWS supplies a version via Docker (you can also run it via Java; this is left as an exercise to the reader):
docker run --rm -p 8000:8000 amazon/dynamodb-local
This will start an empty AWS DynamoDB server on port 8000.
You can start the master_server
by running:
AWS_ACCESS_KEY_ID=1 AWS_SECRET_ACCESS_KEY=1 .env/bin/python -m master_server --app master_server --web-port 8081 --db dynamodb --dynamodb-host http://127.0.0.1:8000
This will start the server on port 3978 (default) for you to work with locally.
The webserver on port 8081 is just to monitor the health of the server.
You can change your /etc/hosts
or C:\Windows\System32\drivers\etc
to map master.openttd.org
to 127.0.0.1
and ::1
for local testing.
You can start the web_api
by running:
AWS_ACCESS_KEY_ID=1 AWS_SECRET_ACCESS_KEY=1 .env/bin/python -m master_server --app web_api --web-port 8080 --db dynamodb --dynamodb-host http://127.0.0.1:8000
This will start the HTTP server on port 8080 for you to work with locally. It does require some servers to be in the database to be useful, so make sure to start a master_server locally and run a (dedicated) server to add an entry.
docker build -t openttd/master-server:local .
docker run --rm --name ms-dynamodb -p 8000:8000 amazon/dynamodb-local
docker run --rm --link ms-dynamodb -p 127.0.0.1:3978:3978/udp -p 127.0.0.1:8081:80 -e AWS_ACCESS_KEY_ID=1 -e AWS_SECRET_ACCESS_KEY=1 openttd/master-server:local --app master_server --bind 0.0.0.0 --db dynamodb --dynamodb-host http://ms-dynamodb:8000
docker run --rm --link ms-dynamodb -p 127.0.0.1:8080:80 -e AWS_ACCESS_KEY_ID=1 -e AWS_SECRET_ACCESS_KEY=1 openttd/master-server:local --app web_api --bind 0.0.0.0 --db dynamodb --dynamodb-host http://ms-dynamodb:8000
This will start an empty AWS DynamoDB, the Master Server listing on UDP 3978 and the Web API on HTTP port 8080.