Alright let’s start with a fun one. Terraria is quite an interesting game, with a pixelart visual style, and a Minecraft esque gameplay style, but 2D and with a clear RPG-esque progression system. It has a multiplayer aspect as well, with an easy “host and play” option in the client.

HOWEVER, who would leave a game open 24/7 to host a server for their friends? Couldn’t be me. So I set up a server myself.

But… Vanilla Terraria isn’t quite enough. Mods exist for a reason, and add such an insane amount of content that it’s very difficult to argue with. Even if you aren’t worried about the content levels, Mods can have a significant amount of quality of life improvements to just make the game overall “better”. To use mods, one must look into tModLoader. It’s both a unique server and client structure, and allows for a vast catalog of mods to be used. They can even be pulled from the hosting server, so the clients don’t even need to know what mods they need anyway.

So let’s start with the goals of the project:

  • 24/7 running tModLoader server
  • QOL mods that are auto downloaded from server
  • 16 players playing in different locations of the map, and the whole operation is smooth
  • Fault tolerance, a crash will restart the server
  • Autosaves, don’t want to lose maps
  • Docker/Kubernetes

Let’s start at the top. 24/7 isn’t really magic in the world of self hosting with a proper server. I’ve got an R620 down in my basement that’s already running 24/7, so check, problem solved there. Now let’s take a quick look into the tModLoader server and how it works.

Currently, it’s an easily downloadable package for Terraria version 1.3 here. However! I want to run a 1.4 dedicated server. I know it’s in beta, I know it may break, but I want to do Vanilla + some QOL mods, don’t need any full rebuilds.

So let’s get started. tModLoader uses Github Actions for their pipeline, which is awesome. It means I can pull a built package ready to go/use here. Find one with a branch attached, and notice a Release Build download button at the bottom. Pull it down, unzip it, and let’s take a look.

(base) ~/terraria/1.4 ❯❯❯ ls
LaunchUtils              serverconfig.txt            start-tModLoader.sh   tModLoader.dll                     tModLoader.xml
Libraries                start-tModLoader.bat        steam_appid.txt       tModLoader.pdb
PlatformVariantLibs      start-tModLoaderServer.bat  tMLMod.targets        tModLoader.runtimeconfig.dev.json
RecentGitHubCommits.txt  start-tModLoaderServer.sh   tModLoader.deps.json  tModLoader.runtimeconfig.json

Interesting, okay. So looks like a few shell scripts, a few utils in one folder (LaunchUtils) and then some other libraries and bits and pieces. Since we’re on Linux, we care about the .sh scripts. So let’s check out what start-tModLoaderServer.sh does.

#!/usr/bin/env bash
cd "$(dirname "$0")"

launch_args="-server -config serverconfig.txt"

read -p "Use Steam Server (y)/(n) " steam

if [ $steam = "y" ]; then
	launch_args="$launch_args -steam"
	
	clear
	read -p "Select Lobby Type (f)riends/(p)rivate " lobby
	
	if [ $lobby == "f" ]; then 
		launch_args="$launch_args -lobby friends"
	else
		launch_args="$launch_args -lobby private"
	fi
fi

launch_args="$launch_args $@"

chmod +x ./LaunchUtils/ScriptCaller.sh
./start-tModLoader.sh $launch_args

Ah nice, great. So it just sets up some args, and runs start-tModLoader.sh. Perfect. What I really wanted was to be able to specify my command line arguments like where my serverconfig lived, where my worlds lived, etc. So I can really just run start-tModLoader.sh with the proper arguments, and be good to go! Alright, let’s see what happens.

You are on platform: "Linux"
Verifying .NET....
This may take a few moments.
Logging to /home/dx/.local/share/Terraria/ModLoader/Beta/Logs/Launch.log
Fixing .NET SDL PATH issues
Success!
Verifying .NET platform specific libraries are correctly deployed
Success!
Parsing .NET version requirements from runtimeconfig.json
Success!
Checking for old .NET versions to remove from folder
Cleanup Complete
Checking dotnet install...
Dotnet should be present in "/opt/1.4/dotnet/6.0.0"
Attempting Launch...
Launched Using Local Dotnet
dlopen failed trying to load:
steamclient.so
with error:
steamclient.so: cannot open shared object file: No such file or directory
dlopen failed trying to load:
/home/dx/.steam/sdk64/steamclient.so
with error:
/home/dx/.steam/sdk64/steamclient.so: cannot open shared object file: No such file or directory
[S_API] SteamAPI_Init(): Sys_LoadModule failed to load: /home/dx/.steam/sdk64/steamclient.so
Permission denied (see server.log for full trace)
Unloading mods...
Finding Mods...
Instantiating Mods...
Initializing: ModLoader v0.12
Setting up...
Loading: ModLoader v0.12
Adding Recipes...
Terraria Server v1.4.3.2 - tModLoader v0.12 1.4 Alpha 6b54a380, built 2/6/2022 6:36 PM

n		New World
d <number>	Delete World
m		Mods Menu
b		Mod Browser

Alright awesome, let’s break it down.

  • Yes, we’re on Linux.
  • Looks like .NET is valid/working, and we’re both logging, and looks like generally things are functional.
  • Hmm, dlopen failed, no steam client library installed, and permission denied. Well things are still progressing, so maybe it’s not important.
  • Finding Mods… only found the “base” mod, okay that’s fine.
  • Terraria 1.4.3.2, with tModLoader .12! Great, that’s functional!

Without pasting it here, a new world gets created with n and a few prompts including map size etc, and I’m presented with a similar prompt, of which I select the world I just created, answer a few questions, and boom, we’re live!

Terraria Server v1.4.3.2

Listening on port 7777
Type 'help' for a list of commands.

Server started

Now time to add mods, let’s see how it goes. For tModLoader v0.12, it looks like the developers moved to using the workshop for mods. That explains the steam client errors above, which means we have a good reason to ignore them for now. However, we still need mods.

For this I’ll write down my steps, but only because screenshots really aren’t gonna help here. Open the tModLoader client in the 1.4 Alpha version on Steam. Once Terraria loads up, go to the Mod Browser, then Download Mods, and pick the mods you’re interested in. I mostly picked few QOL mods, but if you’d like my current list:

AutoTrash v0.6.0.6
BossChecklist v1.2.1
MagicStorage v0.5.3.3
MaxStackExtra v1.4.0.2
RecipeBrowser v0.9.0.6
TeamSpectate v2.1.0.1
WingSlotExtra v1.2.2

So the game sees them, but when I click “open folder”, I get nothing! What gives? Turns out, the mods were stored in the workhop folder instead of the game folder. My tModLoader game is saved in this folder: C:\Program Files (x86)\Steam\steamapps\common\tModLoader, so the workshop mods are saved to C:\Program Files (x86)\Steam\steamapps\workshop\content\1281930. Once you go into that folder, you’ll find a few folders with .tmod files. Zip those up, and rsync them right on over to your server, and put them into the modpath. Now, my 1.4 serverconfig looks like this:

modpath=/opt/1.4/modpath
worldname=vlantime
difficulty=1
maxplayers=16
port=7777
password=vlantime
worldpath=/opt/1.4/worlds`

Wonderful, start it up, follow the prompts, and we’ve got a live 1.4 Terraria tModLoader server.

I’ll add some more to this once I have the lan party on Saturday to speak about how it performed.

See ya then!