Multiplayer Hubs


So you want to host your own hub?


Hub


To get your hub into the Multiplayer Guide, you'll have to contact me on Discord: Assitant#8431. However, make sure you've done everything correctly.

Running a hub can be a little more involved than just launching the executable. You want to make sure that it remains up. You might also want a nice landing page so people can see live statistic.

First you want to make sure you configure the settings correctly, you can find those in Settings.json after you've run the hub at least once, or you can just create it.

If you want your hub to be tracked on the multiplayer guide, you must enable EnableWebSocketServer, and it must run on WSS. This is what's used to track the status of the hubs.

{
  "Server": {
    "Port": 3700,
    "Tickrate": 30,
    "TryUPnP": false,
    "EnableWebSocketServer": true,
    "EnableWebSocketRoomInfo": true,
    "EnableWebSocketRCON": false,
    "RCONPassword": "changeme",
    "WebSocketPort": 3800,
    "ShowTickrateInTitle": false,
    "AllowEventMessages": true,
    "ShowTickEventExceptions": false,
    "SendCrashReports": true
  },
  "Radio": {
    "EnableRadio": false,
    "NextSongPrepareTime": 90.0,
    "ResultsShowTime": 15.0,
    "RadioChannels": [
      {
        "ChannelName": "Radio Channel",
        "ChannelIconUrl": "https://cdn.akaku.org/akaku-radio-icon.png",
        "PreferredDifficulty": "Expert"
      }
    ]
  },
  "Logger": {
    "LogsDir": "Logs/"
  },
  "Access": {
    "Blacklist": [
      "76561201521433077",
      "IGGGAMES",
      "76561199437989403",
      "VALVE"
    ],
    "WhitelistEnabled": false,
    "Whitelist": []
  },
  "TournamentMode": {
    "Enabled": false,
    "RoomNameTemplate": "Tournament Room {0}",
    "Rooms": 4,
    "Password": ""
  }
}

LandingPage


If you want a landing page that shows interactive stats like this one, you can get it from here.

Scripts


I've created a few scripts and systemd service files that will restart the Hub if it ever crashes. Place the following in a script called Hub inside the ServerHub directory.

#!/usr/bin/env bash

port=${1}
ip="localhost"

nc -w 5 -u4z ${ip} ${port}

if [ "${?}" -ne 0 ]; then
  ./ServerHub
else
  (>&2 echo "Port used")
  sleep 5
fi

exit 1

This script will check the health of your hub, and restart it if it's down.

#!/usr/bin/env bash
port=3700

nc -w 5 -u4z localhost ${port}

if [ "${?}" -ne 0 ]; then
    systemctl --user restart ServerHub.service
else
    sleep 5
    (>&2 echo "ServerHub Alive")
fi

This is the systemd service file for the hub, make sure to edit the paths to match yours.

[Unit]
Description=Beat Saber Multiplayer Server Hub
After=network.target

[Service]
WorkingDirectory=/PATH/TO/ServerHub
Type=forking
Restart=always

ExecStart=/usr/bin/screen -dmS HUB /PATH/TO/ServerHub/Hub 3700

ExecStop=/usr/bin/screen -S HUB -X stuff 'quit\n'

[Install]
WantedBy=multi-user.target

This systemd service file will be for your health check, again make sure to edit it accordingly.

[Unit]
Description=Service to keep the ServerHub service alive
After=network.target

[Service]
WorkingDirectory=/PATH/TO/SCRIPT/LOCATION
Type=oneshot

ExecStart=/PATH/TO/SCRIPT/LOCATION/Script

[Install]
WantedBy=multi-user.target

This systemd timer file will run your health check every so often, again make sure to edit it accordingly and name it the same as your service file, except with .timer instead of .service.

[Unit]
Description=Run ServerHubKeepAlive every 1 minute

[Timer]
OnBootSec=6min
OnUnitActiveSec=1min

[Install]