Simple web server where players can see a list of available servers, player counts, and request to turn on a server if they have a passcode.
Go to file
Andrew Lalis 91e7f7efed Added a thing to listen for enter key-presses in client key input. 2024-10-15 13:53:34 -04:00
agent Fixed agent auto-shutting down servers. 2024-08-10 14:29:27 -04:00
api Added a thing to listen for enter key-presses in client key input. 2024-10-15 13:53:34 -04:00
shared-utils Improved security by removing hard-coded keys and refactoring agent logic. 2024-08-03 14:15:41 -04:00
.gitignore Added initial api implementation. 2024-06-25 21:01:35 -04:00
README.md Improved security by removing hard-coded keys and refactoring agent logic. 2024-08-03 14:15:41 -04:00
deploy-agent.sh Added agent, refactored API, working version now. 2024-06-27 11:58:40 -04:00
deploy-web.sh Added agent, refactored API, working version now. 2024-06-27 11:58:40 -04:00

README.md

mc-server-manager

Simple web server where players can see a list of available servers, player counts, and request to turn on a server if they have a passcode.

It consists of two components: a web server, and an agent program that runs on the minecraft server hardware itself.

Web Server

The web server's responsibility is to show the latest server status information and provide a way for players to request to turn on a server.

The server is built using handy-http.

In addition to serving the web app from the associated app directory, the following API endpoints are defined:

  • POST /api/servers - for the agent to send the latest server status info.
  • GET /api/servers - for clients to fetch the latest server status.
  • POST /api/servers/:id/requests - for clients to request a server startup.
  • GET /api/server-requests - for the agent to get a list of requested servers.

Deployment

This application is deployed to run under a reverse proxy, like Nginx. Call the deploy-web.sh script to deploy it to Andrew's main server.

Also, create an api-config.properties file in the server's working directory, and populated it with values like so:

agentKey=superSecretAgentKey
clientKey=superSecretClientKey
discordWebhookUrl=https://discord.com/api/webhooks/1234

Agent

The agent will periodically inspect the status of all servers, and send that data to the web server. The agent will also automatically shutdown servers that have been inactive for more than a configured time (see Deployment below for how to configure that).

More precisely, the agent will activate periodically, and each time perform the following activites:

  • Send the latest server status information to the web server.
  • Use an idle-tracker file to determine the amount of time a server has been idle (on, with no players active).
    • If the server is idle, but doesn't yet have a tracker file, one is created.
    • If the server has at least one player, any existing tracker file is removed.
    • If the server is idle and there's a tracker file present, and the tracker file is at least 15 minutes old, then the server is shut down.
  • Get the list of requested servers to start from the web, and start each server.

Deployment

This agent is simply deployed to the physical server where the minecraft servers are installed, and it is linked as a SystemD service (but not enabled), and then a SystemD timer is activated to trigger it to run every so often.

Run deploy-agent.sh to deploy the agent to the server.

You should make sure there's an agent-config.properties file with the following values:

webUrl=https://mc-servers.andrewlalis.com
discordWebhookUrl=https://discord.com/api/webhooks/1234
agentKey=superSecretAgentKey
serverInactivityTimeoutMinutes=30

And additionally, a servers.json file to define the servers that the agent will control, formatted like so:

[
    {
        "name": "survival-server",
        "displayName": "My Survival Server",
        "directory": "/home/andrew/minecraft/servers/survival",
        "description": "My personal survival server."
    },
    {
        "name": "creative-server",
        "displayName": "My Creative Server",
        "directory": "/home/andrew/minecraft/servers/creative",
        "description": "A creative server for me to mess around in."
    }
]