Game Servers – Factorio

Factorio is one of the most unrated game out there as I have covered in my review on the whole game. The game itself is really easy to host and we will be going through how to do so in this How-To. We will be using Ubuntu 18.04 to host our very own Factorio Server.

Factorio is a construction and management simulation game developed by the Czech studio Wube Software. The game was announced via an Indiegogo crowdfunding campaign in 2013 and released for Microsoft Windows, macOS, and Linux on 14 August 2020 following a four-year long early access phase.

Wikipedia

Hosting – VPS

First, you need to find a host which sells Ubuntu Virtual Private Servers. This is often easy to find, but it’s difficult finding the one which the right balance of price and support / usability. For our tutorial, we will be assuming you will be using a host which already does the pre-setup for the user. We will also provide VPS services that we recommend.

Server Space

Pricing
Updated on 26/10/2020

We have used Server Space before, and had a great experience using them. Their prices are cheap and flexible. However, the support may not be as quick as other services. We also have no downtimes with their services and overall had a great experience with them.

Creating The Server

Server Space allows users to create servers within 2 click, follow along

Click on create then create server

After clicking on create, they offer a few options, however, we will stick to these options

Make sure to select the ubuntu 18.04 x64

After creating a server, they should redirect you to their control panel. This step if really up to you, but you can choose to either use PuTTY or use their own web console. i Would recommend using Putty, since it’s easier to copy and paste commands and overall it’s much faster.

Setup & Firewall

Workspace

Before we do anything, let us update the server’s packages by running these commands

apt-get update
apt-get upgrade

It may prompt you a yes or no if its planning on installing or updating new packages, in this case just type Y and ENTER and just let it run and finish.

Now that we are done with that, we can then try to organize our game folders and such by creating a new folder for all your server files. For this tutorial, we will create a new folder under the home directory, if you like to switch this for something else, go for it. You can also make a new user purely for Factorio.

mkdir /home/factorio
cd /home/factorio

We now have a mini workspace for the game’s server.

Firewall

Let us now add a new rule to our firewall to allow others to be able to connect to our Factorio server. Please do note that for hosting services such as Google Cloud Platform this is very different. We will be assuming you are using Server Space for hosting. Factorio will be using Port 34197 using the UDP protocol, so let us allow traffic to flow

ufw allow 34197/udp
ufw enable

Downloading

In this tutorial we will be using the home’s folder like mentioned above, rather than the typical /opt/ folder. You can use that if you like, however to keep this easy, we will just be using the folder created in /home/ above.

While making sure you are still in the new folder created above, let us go to Factorio’s Official Website to find the download link for their server headless file. Make sure to login to their site. Once logged in, follow the below navigation.

Once you find the link, it will be located under the test “If you are running a server, you can use this link to always download the latest stable version.”. You can right click “this link” and click copy link address to get the address. Once done, we will move onto downloading the file using wget on our server

wget https://factorio.com/get-download/latest/headless/linux64 -O factorio_headless.tar.gz
Older Versions

If you like to download an older version of the game to host. then you can go onto their archive and get the link for it.

Once we are done downloading the server file we will then extract the file since we downloaded in a compressed manner. We can do this by running the following command

sudo tar -xzf ./factorio_headless.tar.gz

You should now see a new folder pop up named Factorio. We will change this name to server as this will have all the server files. You can also create a new folder for scripts or other resources inside the /home/factorio folder if you like to save it or use it to store backup saves.

mv /home/factorio/factorio /home/factorio/server

After renaming the folder, we can then remove the compressed file we downloaded by using the rm command

rm ./factorio_headless.tar.gz

Let us now head into the new server folder created.

cd server
ls

After running the ls command, you should see a few files and folder. You should see bin, data and config-path.cfg. The bin folder will house the factorio executable, and the data will host all of its content.

Importing Mods

If you like to import your mods folder, just make a new directory inside the server folder we just made.

mkdir /home/factorio/server/mods

You can then dump all your mods into that folder. We suggest using WinSCP to move the files if you are too lazy to upload it and wget it.

Importing Saves

If you like import existing saves that you have, you can do so by creating a new folder this time, named saves.

mkdir /home/factorio/server/saves

Then moving your save file into the folder

User & Configuation

User

We will not be running Factorio using root, so let us add a new user that we will run Factorio under. Since the new user will only be used to run Factorio, we don’t really need to login into it nor let it have a home folder. We can do this by running the following command

sudo adduser --disabled-login --no-create-home --gecos factorio factorio

Let us take a look at what exactly this is doing

  • Disabled Login – This removes the need to add a password to the user
  • No Create Home – This will not make a home folder for the user
  • Gecos – Adduser will not ask for finger information if this option is given.

Now that we have a new user managing the Factorio server, we will give them the owner of our Factorio folder. We can do this by executing this command

sudo chown -R factorio:factorio /home/factorio

Configuration

The default configuration file will be located under the data folder. We can hop into the folder and view the server settings config. Before doing this, let us copy and paste the file, so that we can have a file that has the default settings and another file that has our settings, just-in-case you would like to backup your configuration file later down the road.

cp /home/factorio/server/data/server-settings.example.json /home/factorio/server/data/server-settings.json

Once you have created a new config file, let us hop into it, you can use your own editor if you like, but we will be using nano

nano /home/factorio/server/data/server-settings.json

The file should look something like this.

{
  "name": "Name of the game as it will appear in the game listing",
  "description": "Description of the game that will appear in the listing",
  "tags": ["game", "tags"],

  "_comment_max_players": "Maximum number of players allowed, admins can join even a full server. 0 means unlimited.",
  "max_players": 0,

  "_comment_visibility": ["public: Game will be published on the official Factorio matching server",
                          "lan: Game will be broadcast on LAN"],
  "visibility":
  {
    "public": true,
    "lan": true
  },

  "_comment_credentials": "Your factorio.com login credentials. Required for games with visibility public",
  "username": "",
  "password": "",

  "_comment_token": "Authentication token. May be used instead of 'password' above.",
  "token": "",

  "game_password": "",

  "_comment_require_user_verification": "When set to true, the server will only allow clients that have a valid Factorio.com account",
  "require_user_verification": true,

  "_comment_max_upload_in_kilobytes_per_second" : "optional, default value is 0. 0 means unlimited.",
  "max_upload_in_kilobytes_per_second": 0,

  "_comment_max_upload_slots" : "optional, default value is 5. 0 means unlimited.",
  "max_upload_slots": 5,

  "_comment_minimum_latency_in_ticks": "optional one tick is 16ms in default speed, default value is 0. 0 means no minimum.",
  "minimum_latency_in_ticks": 0,

  "_comment_ignore_player_limit_for_returning_players": "Players that played on this map already can join even when the max player limit was reached.",
  "ignore_player_limit_for_returning_players": false,

  "_comment_allow_commands": "possible values are, true, false and admins-only",
  "allow_commands": "admins-only",

  "_comment_autosave_interval": "Autosave interval in minutes",
  "autosave_interval": 10,

  "_comment_autosave_slots": "server autosave slots, it is cycled through when the server autosaves.",
  "autosave_slots": 5,

  "_comment_afk_autokick_interval": "How many minutes until someone is kicked when doing nothing, 0 for never.",
  "afk_autokick_interval": 0,

  "_comment_auto_pause": "Whether should the server be paused when no players are present.",
  "auto_pause": true,

  "only_admins_can_pause_the_game": true,

  "_comment_autosave_only_on_server": "Whether autosaves should be saved only on server or also on all connected clients. Default is true.",
  "autosave_only_on_server": true,

  "_comment_non_blocking_saving": "Highly experimental feature, enable only at your own risk of losing your saves. On UNIX systems, server will fork itself to create an autosave. Autosaving on connected Windows clients will be disabled regardless of autosave_only_on_server option.",
  "non_blocking_saving": false,

  "_comment_segment_sizes": "Long network messages are split into segments that are sent over multiple ticks. Their size depends on the number of peers currently connected. Increasing the segment size will increase upload bandwidth requirement for the server and download bandwidth requirement for clients. This setting only affects server outbound messages. Changing these settings can have a negative impact on connection stability for some clients.",
  "minimum_segment_size": 25,
  "minimum_segment_size_peer_count": 20,
  "maximum_segment_size": 100,
  "maximum_segment_size_peer_count": 10
}

Configure it to your liking. The important variables that you can look at is the name, description, tags and the max players. This should be the first thing you set as they will -play a important part in finding your server and limiting how many players can enter it. There is also visibility, which you can change if you are making a private server with your friends. Other than that, there is the username and password, make sure to enter your own account details, if you don’t want to save your password than you can use a token instead.

Starting the Server

Service

We will create a Factorio service, this will make sure the game really never crashes as it will auto restart. The Factorio server will also start up if the server ever reboots. So Use this option if you are planning on using it as a 24/7 dedicated server. If not, move onto the next step.

cd /etc/systemd/system
nano factorio.service

Paste the following in this file

[Unit]
Description=Factorio Server service
After=network.target

[Service]
User=factorio
ExecStart=/home/factorio/server/bin/x64/factorio --server-settings /home/factorio/server/data/server-settings.json --start-server-load-latest --console-log /home/factorio/server/Factorio.log
Restart=always

[Install]
WantedBy=multi-user.target

Then reload the service deamon to make it notice the new service and enable the new service

systemctl daemon-reload
systemctl enable factorio

And that’s it. You now have a dedicated Factorio Server running. You start the service by doing

systemctl start factorio

Manual

Next, let us install screen. Screen basically allows us to detach from terminal sessions while leaving that session running. So we can create a session for our Factorio server while still being able to use the terminal. This makes life much easier, as without screen, when you exit your terminal, the game server will go down with it. Install screen with the following command

sudo apt install screen

Once you have installed screen, make sure to type Y and ENTER, if it askes to install additional packages.

After Installing screen, you can now launch Factorio in a terminal then detach from it, making it run as a different process.

sudo screen -S factorio su factorio
/home/factorio/server/bin/x64/factorio --server-settings /home/factorio/server/data/server-settings.json --start-server-load-latest --console-log /home/factorio/server/Factorio.log

Let me explain what exactly this is doing

  • Screen – Like i mentioned above, we will be using screens to launch a terminal which we can detach from and still leave the game server running in a different process
    • -S factorio– This starts a new terminal session with the name factorio. Make sure you use a name which is easily to memorize, as you might need to hop back into that session to check logs or shutting down the server

When you are ready to log out of your server, be sure to detach from the session with Ctrl + A + D and then log out.

You can then get back into the session running the Minecart server by running the following command

sudo screen -R factorio

Once you are in, you can shut down the server by pressing Ctrl + C

That’s it! You got your very own server, you can now launch Minecraft, boot up the same Client version as your Server version and add the server to your list.

Leave a Reply