Skip to content

DavidMacDonald11/msw-backend

Repository files navigation

Minecraft Server Website Backend

The Minecraft Server Website Toolkit

This is part of a three-part system designed to automate a minecraft server using a website. Also see:

This was developed for my own personal use. The system I’ve designed is very unique to my scenario, so it may not be easy to directly replicate. I also have no intention of implementing features that I will never actaully use. That said, it may still be worth asking for features, as I may find use in them.

Otherwise, feel free to edit this project however you need to for it to suit your needs. If you would like pointers to help you do so, feel free to ask.

System Structure

  1. The Frontend Server

    1. This is the website users will actually interact with.

    2. It will send http requests to the backend for authentication and data management.

  2. The Backend Server

    1. Handles website authentication and remotely controls the host.

    2. The server uses SSH to access a raspberry pi to use WoL to wake up the host machine. This is to save power. Compared to a complete host machine, a raspberry pi uses far less power. Using a raspberry pi allows WoL from outside of the local network.

    3. The server uses SSH to interact with the local API on the host.

  3. The Local API

    1. Shuts down the host machine after 15 minutes of inactivity.

    2. Starts the Minecraft servers.

    3. Uses local-network only RCON to send commands to the server. Allows the local api to keep track of players and time left.

  4. The Idle Timeout Datapack

    1. Each server will have this datapack installed.

    2. If no one is online, the server will shutdown after 30 minutes.

    3. Allows the local api to keep track of players online.

Instructions

  1. Start by studying this system and seeing if it can fit your needs.

  2. Install the local API onto your host machine and make sure it works as expected.

  3. You will need to publically expose the host machine’s SSH port.

  4. Create an SSH key and add the public key to the host machine. Careful to not overwite your existing SSH keys.

  5. Create a free account on Vercel.

    1. Fork this project and create a new Vercel project using that repo, or install the Vercel command-line tool, download this repo, and run vercel.

    2. Add the following environment variables:

      • PATH_TO_LOCAL_APP - the absolute location of the local api on the host machine.

      • PATH_TO_PI_WOL - the absolute location of the raspberry pi’s WoL script

      • PI_WOL - the command to run the script inside of PATH_TO_PI_WOL

      • SSH_HOST - the public IP of your host and raspberry pi

      • SSH_LOCAL_IP - the local IP of your host

      • SSH_PORT - the host’s public SSH port

      • SSH_PI_PORT - the raspberry pi’s public SSH port

      • SSH_USER - the host’s username to SSH into

      • SSH_PI_USER - the rasberry pi’s username to SSH into

      • SECRET_KEY - a secure password for encrypting authentication

      • SSH_PRIVATE_KEY - the SSH private key

      • SSH_PASS - the SSH password you set

  6. Create a free account on MongoDB and create a free cluster.

    1. Go to this page to integrate MongoDB with the backend on Vercel.

Local Development

You will need to create a .env file with the above environment variables. Run npm install and run the development server with node -r dotenv/config app.js. I recommend using nodemon.