home..

Overengineering A Minecraft Server

Sometimes me and my friends like to play minecraft together. For that I selfhost a minecraftserver.
While simply having minecraft installed on my Pc and forwarding the ports works fine it does have two major drawbacks: I need to turn my Pc on everytime someone likes to play minecraft and I have to directly expose my main Pc to the Internet.
The old laptop I use to host all my other services also does not work because it definetly isn’t powerful enough.
I recenty got an old gamingpc from a friend specifically for use as a gameserver. Minecraft works well enough on it. The problem is that I don’t want to run the pc all the time as most of the time noone is actually playing minecraft on the server and I don’t want to waste power.

This is the part where the German overengineering comes into play: writing a matrixbot to control the server

The pc supports wake on lan, a technologie that allows turning on a pc by broadcasting a paket that contains its macaddress. The pc runs a minimal arch install and has the minecraft-server aur package installed. This already provides a systemd unitfile that autostarts the minecraftserver and offers simple commands for controlling the server.

The bot works relativly simply: On my main server I run a simple matrix bot that either sends WOL pakages or sends http reqest to the server running on the minecraft server. The server simply exposes an http api for the following commands:

minecraftd start
minecraftd stop
minecraftd restart
sudo systemctl poweroff

With this my friends are able to issue the following commands to the bot that then turn on the server, power it down(while making shure the world gets saved).

!minecraft start
!minecraft stop
!minecraft restart

I also set up the t2bot.io discord bridge which allows my friends to controll the server from discord. While not provinding the fastest response times it works reasonably well for such a simple bot.

If you also find yourself in need for this unnecceserily complicated soultion to a nonexistend problem the sourcecode is available at github.com/laubersheini/minecraft_controller

© 2022 David Laubersheimer   •  Theme  Moonwalk