Skip to content

Commit

Permalink
Sensible dedicated server guide #286 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jun 18, 2024
1 parent d7f91f4 commit 5168d6b
Showing 1 changed file with 60 additions and 81 deletions.
141 changes: 60 additions & 81 deletions README_SERVER.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,82 @@
# Hypersomnia dedicated server guide (Ubuntu 22.04)
# Hypersomnia dedicated server guide

First you'll have to buy a VPS, e.g. you can buy a cheap one here:
The dedicated server is known to work on Ubuntu 20.04 or later.

https://contabo.com/
You should easily be able to run it on other distributions like Arch Linux.

This guide is written for **Ubuntu 22.04,** but you should easily be able to run the server on other distributions.
**Make sure to check out the [Dockerfile](https://github.com/TeamHypersomnia/Hypersomnia/blob/master/Dockerfile) for an up-to-date working server setup.**

If you already have a working VPS with configured SSH access, skip to [Download AppImage step.](#download-appimage)
- [Basic setup](#basic-setup)
* [(Optional) Download all community maps (<100 MB)](#optional-download-all-community-maps-100-mb)
* [libfuse](#libfuse)
- [Configuration](#configuration)
* [Ports](#ports)
* [Setup folders for many server instances](#setup-folders-for-many-server-instances)

## Add an unprivileged user

You'll likely start with a clean VPS with just a root account.
In this case, first add an unprivileged user:

```sh
# This will ask you for password, choose whatever as it won't be used anyway
adduser ubuntu
passwd -d ubuntu
usermod -aG sudo ubuntu
su - ubuntu
```

## Setup SSH

Now we'll setup SSH access.
First generate your SSH keypair, I recommend using ``ssh-ed25519`` algorithm.
Then do this:
# Basic setup

```sh
MY_KEY='PUT YOUR PUBLIC KEY HERE'
wget https://hypersomnia.xyz/builds/latest/Hypersomnia-Headless.AppImage
chmod +x Hypersomnia-Headless.AppImage
nohup ./Hypersomnia-Headless.AppImage --appimage-extract-and-run --daily-autoupdate > /dev/null 2>&1 &
```

For example (this public key is mine, don't add it unless you want to give me access to your VPS):

```sh
MY_KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFpBAHe/KyfrmzWcx5LxbAytckcJj2ssIJYAfNdkg318 [email protected]'
```
This will run the server in the background.

To authorize this key, do this:
## (Optional) Download all community maps (<100 MB)

```sh
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo $MY_KEY >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
./Hypersomnia-Headless.AppImage --appimage-extract-and-run --sync-external-arenas-and-quit
```

### Disable password login
The maps will be saved to ``~/.config/Hypersomnia/user/downloads/arenas``.
Anyone who connects will be able to play them - the server will send the player any custom map currently played on the server.

We want SSH to be the only way to log in to your server.
Backup your ``/etc/ssh/sshd_config`` just in case:
## libfuse

```sh
cp /etc/ssh/sshd_config ./sshd_config.bak
```
Note you can skip the ``--appimage-extract-and-run`` flag if you have [fuse](https://packages.ubuntu.com/focal/fuse) installed. It's ``fuse2`` on Arch.

The following script will automatically modify the config to disable all options that would enable password logins (so you don't have to edit it manually with ``nano``):
``--appimage-extract-and-run`` will work out-of-the-box but involves an extraction step into ``/tmp``.

```sh
sudo sed -i '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i '/^ChallengeResponseAuthentication/s/^.*$/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
sudo sed -i '/^UsePAM/s/^.*$/UsePAM no/' /etc/ssh/sshd_config
Not a big deal as the ``Hypersomnia-Headless.AppImage`` is rather small (< 30 MB) but it's something to keep in mind.

if ! grep -q "^PasswordAuthentication" /etc/ssh/sshd_config; then
echo "PasswordAuthentication no" | sudo tee -a /etc/ssh/sshd_config
fi
# Configuration

if ! grep -q "^ChallengeResponseAuthentication" /etc/ssh/sshd_config; then
echo "ChallengeResponseAuthentication no" | sudo tee -a /etc/ssh/sshd_config
fi
To be able to manage your server, remember to set the ``master_rcon_password`` in ``~/.config/Hypersomnia/user/config.force.lua`` - see ``default_config.lua`` for reference. Open your game client. Setup your RCON password in ``Settings -> Client``. Then, press ``Esc`` when you're on your server to open the administration panel.

if ! grep -q "^UsePAM" /etc/ssh/sshd_config; then
echo "UsePAM no" | sudo tee -a /etc/ssh/sshd_config
fi
``--daily-autoupdate`` flag causes the server to update itself every 24 hours at 03:00 AM (your local time), if a newer game version is available. This flag is highly recommended so you don't have to keep up with frequent game updates (the game is in active development). You can also set the flag in RCON settings (press F8 and go to Vars tab).

sudo systemctl restart sshd
```
## Ports

## Download AppImage
You'll need:
- One UDP port for native clients (``8412`` is recommended).
- One or more UDP ports for [Web clients](https://hypersomnia.io).
- ``9000-9020`` by default, but you can use just a single port with *UDP multiplexing*.

Now download the dedicated server.
For example:

```sh
wget https://hypersomnia.xyz/builds/latest/Hypersomnia.AppImage
chmod +x Hypersomnia.AppImage
```lua
server = {
webrtc_udp_mux = true,
webrtc_port_range_begin = 9000
-- , webrtc_port_range_begin = 9020 -- only matters if webrtc_udp_mux = false
},
server_start = {
port = 8412
}
```

## Install libraries
With these values, you will only need to expose UDP ports ``8412`` and ``9000``.

Install libraries required by the dedicated server's AppImage:

```sh
sudo apt install -y libgl1 libsm6 fuse
```

## Download all community maps

Run this command once, the app will quit once the download is complete:

```sh
./Hypersomnia.AppImage --sync-external-arenas-and-quit
```

The downloaded maps will go to ``~/.config/Hypersomnia/user/downloads/arenas``.

## Setup folders for all server instances
## Setup folders for many server instances

Let's create appdata folders for every server instance we want to run.
I recommend no more than 2 servers per vCore, with no more than 10 slots per server.

```sh
make_server_dir() {
name="server$1"
mkdir $name
name="servers/$1"
mkdir -p $name

ln -s ~/.config/Hypersomnia/user/downloads/arenas $name/user/downloads/arenas
}
Expand All @@ -122,3 +86,18 @@ make_server_dir "2"
make_server_dir "3"
make_server_dir "4"
```

You can then run several server instances like this:

```sh
nohup ./Hypersomnia-Headless.AppImage --apply-config ./config.common.lua --appdata-dir ./servers/1 --daily-autoupdate > /dev/null 2>&1 &
nohup ./Hypersomnia-Headless.AppImage --apply-config ./config.common.lua --appdata-dir ./servers/2 --daily-autoupdate > /dev/null 2>&1 &
nohup ./Hypersomnia-Headless.AppImage --apply-config ./config.common.lua --appdata-dir ./servers/3 --daily-autoupdate > /dev/null 2>&1 &
nohup ./Hypersomnia-Headless.AppImage --apply-config ./config.common.lua --appdata-dir ./servers/4 --daily-autoupdate > /dev/null 2>&1 &
```

The servers will share ``config.common.lua`` and *later* apply their server-specific config in e.g. ``./servers/2/user/config.force.lua``.

They will also share the community maps so as to not have to download them again.

**Make sure ./servers/2/user/config.force.lua, ./servers/3/user/config.force.lua etc. specify different ports!**

0 comments on commit 5168d6b

Please sign in to comment.