Multiplayer-Linux

From Necesse Wiki
Jump to navigation Jump to search

Linux Dedicated Server Setup Instructions[edit]

Instructions for setting up a dedicated Multiplayer server on a Debian based distribution.

We will be using SteamCMD to install and update the server.

Install steamCMD dependencies using the commands below, either as root or a user with sudo privileges.

sudo dpkg --add-architecture i386 \
sudo apt update \
sudo apt install -y lib32gcc1 \
sudo apt install -y lib32gcc-s1

Create the user who will run the server.

sudo useradd --create-home necesse


Change to the necesse user and go to it's home directory, where we will be installing steam and the server files.

su - necesse ; cd /home/necesse

Then download and unzip SteamCMD

curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -


Create the configuration file that will manage steamCMD

cat >$HOME/update_necesse.txt <<'EOL'
@ShutdownOnFailedCommand 1 //Set to 0 if updating more than one server.
@NoPromptForPassword 1
force_install_dir /home/necesse/
login anonymous  // Necesse dedicated server is available as anonymous. Thank you Fair!
app_update 1169370 validate
quit
EOL

Run steamCMD and point it at the config file to install and update the server.

./home/necesse/steamcmd.sh +runscript $HOME/update_necesse.txt

This will take a few minutes. SteamCMD will first update itself, then download the server files.

This command will also update the server files. Either run it as a cron job or manually as needed.


You can now start the Necesse server with

./StartServer-nogui.sh

You will have to answer a few questions each time the server launches.

To start the server with no interaction, use the -world [Save name] Argument.

Example: ./StartServer-nogui.sh -world SaveGame1

Ports[edit]

Default port is, 14159

You will need to do port forwarding and find your IP address to give to friends. There is already a write-up about this on the wiki.

Start Server with boot[edit]

If you want your server to recover after your machine turns on or reboots, having it start as a service in Linux is the way to go!

In your text editor create a service file. Recommend using nano. sudo nano /etc/systemd/system/necesse.service

[Unit]
Description=Necesse Dedicated Server
After=network.target

[Service]
PrivateTmp=true
Type=simple
User=necesse
WorkingDirectory=/home/necesse/Steam/steamapps/common/Necesse Dedicated Server/
ExecStart=/bin/sh -c "exec /home/necesse/Steam/steamapps/common/Necesse\ Dedicated\ Server/StartServer-nogui.sh -world YourWorldNamehere"


[Install]
WantedBy=multi-user.target

When this is written, run the following commands from the command line.

sudo systemctl enable necesse.service

sudo systemctl start necesse.service

This will make it run in the background while you use the machine also!

To see what the server is doing, or to verify that it is running run - sudo systemctl status necesse.service

When running it should look like -

● necesse.service - Necesse Dedicated Server
     Loaded: loaded (/etc/systemd/system/necesse.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-05-01 11:31:53 BST; 44s ago
   Main PID: 3457231 (StartServer-nog)
      Tasks: 62 (limit: 57655)
     Memory: 1.0G
        CPU: 1min 7.003s
     CGroup: /system.slice/necesse.service
             ├─3457231 /bin/bash "/home/necesse/Steam/steamapps/common/Necesse Dedicated Server/StartServer-nogui.sh" -world BirdLand
             └─3457234 ./jre/bin/java -jar Server.jar -nogui -world

File Locations[edit]

By default

The server configuration file is named "server.cfg" and is located at ~/.config/Necesse/cfg

The world configuration file is named "worldSettings.cfg" and is located at ~/.config/Necesse/saves/YourWorldNamehere.zip

The save data is the .zip named according to the world name, and is located at ~/.config/Necesse/saves

The server logs are found at ~/.config/Necesse/logs

You can also force configs to the game directory with the -localdir parameter in the shell script file.

Example: ./StartServer-nogui.sh -localdir

Docker Instructions[edit]

Running Necesse using Docker is also possible.

Create a Dockerfile in an empty directory:

# Use a base image
FROM debian:bullseye-slim

# Add user 'necesse', don't run stuff as root!!
ARG user=necesse
ARG group=necesse
ARG uid=1000
ARG gid=1000

RUN groupadd -g ${gid} ${group}
RUN useradd -u ${uid} -g ${group} -s /bin/bash -m ${user}

RUN dpkg --add-architecture i386
RUN apt update; apt install -y ca-certificates-java
RUN apt update; apt install -y lib32gcc-s1 curl openjdk-17-jre-headless

# Download and extract SteamCMD
RUN mkdir -p /steamapps
RUN curl -sqL https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz | tar zxvf - -C /steamapps
WORKDIR /steamapps

# Create the update_necesse.txt file
RUN echo '@ShutdownOnFailedCommand 1' >> update_necesse.txt \
    && echo '@NoPromptForPassword 1' >> update_necesse.txt \
    && echo 'force_install_dir /app/' >> update_necesse.txt \
    && echo 'login anonymous' >> update_necesse.txt \
    && echo 'app_update 1169370 validate' >> update_necesse.txt \
    && echo 'quit' >> update_necesse.txt

RUN echo $(date) && ./steamcmd.sh +runscript update_necesse.txt

# Saves will be available under /root/.config/Necesse/saves
RUN chown -R 1000:1000 /app
RUN mkdir -p /home/necesse/.config/Necesse
RUN chown -R 1000:1000 /home/necesse

USER ${uid}:${gid}

# Set the working directory and create entrypoint.sh
WORKDIR /app
RUN echo '#!/bin/sh' > entrypoint.sh && \
    echo 'java -jar Server.jar -nogui -world "$WORLD_NAME"' >> entrypoint.sh && \
    chmod +x entrypoint.sh

# Set the entry point for the container
CMD ["./entrypoint.sh"]

Build the image:

docker build -t necesse .

Now run the container interactively once to create a world:

docker run --rm -it -v necesse_data:/home/necesse.config/Necesse necesse java -jar Server.jar -nogui

Please remember the world name!

Now you can run the docker forever, create a file called start_necesse.sh and make it executable by running chmod +x start_necesse.sh:

docker stop necesse
docker rm necesse
docker build -t necesse .
docker run -d --name necesse \
  -e WORLD_NAME=my_world\
  -p 14159:14159/udp \
  -v ./data:/home/necesse/.config/Necesse \
  --restart always \
  necesse

If there is an update you can run start_necesse.sh again and it will update to the latest version available on Steam and automatically start.