mr-guard / dayz-server-manager

A server installer and watch-dog for dayz standalone with built-in Discord and RCon bot
MIT License
158 stars 43 forks source link

DayZ Server Manager

Pricing license GitHub Workflow Status CodeCoverage GitHub commits GitHub release Github all releases
Discord

This tool aims to simplify the process of setting up a DayZ Standalone Server on a Windows Server.
The goal was to break down the initial effort to a minimum while providing configuration to nearly all aspects of the server administration process.

Also supports linux server (See Linux Server Usage)

Content

  1. Features
    1. Web UI
  2. Requirements
  3. Usage
  4. Updating
  5. Configuration
    1. Change instance ID
    2. Adding more admins / moderators
    3. Get the Discord Bot Token
    4. Edit the discord channels
    5. Adding local mods
    6. Adding workshop mods
    7. Change Server Name / Password / Admin Password
    8. Change the server port
    9. Add scheduled events
    10. Add Hooks
  6. Linux Server
  7. Steam CMD
  8. TODOs
  9. Default folder layout
  10. Technical details
  11. Security
    1. Discord
    2. Web
  12. Known Issues and Limitations
  13. Development
  14. Disclaimer


Features

Web UI Dashboard

Web UI System

Web UI TypesEditor

Web UI Logs

Web UI Map

Web UI Settings


Installation Requirements


Usage


Updating

This app was written with backwards compatibility in mind.
Sometimes, however, some breaking changes to the server manager config will occur.
The best strategy to update, is to take the config template of the new version and modify it to match your old values.
This way you can not miss out on new properties which might be required.


Configuration

The configuration of the manager is all done in a single config file.

When installing the manager the first time, you will find a configuration template which needs to be renamed to server-manager.json.
You can then go ahead and change the settings inside of this file.
If you do not need anything special (you would probably know by now), then the default values will work out well.

You can also configure serverDZ.cfg manually, but you will have to set the serverCfg to null:

{
  ...
  "serverCfg": null
  ...
}

Otherwise it will be overriden by the settings inside the server-manager.json.

Some important values you probably want to change:
instanceId some unique name of this server instance
admins the admins / moderators who can access the web ui and the discord commands
discordBotToken the token the server manager will use to send messages to your discord server
discordChannels the channels of your discord server to send messages to (make sure the bot has access to them)
rconPassword the server's rcon password !IMPORTANT! change this or others might be able to take control over your server
localMods list of manually install mods which are not auto updated via steam cmd
steamUsername / steamPassword the credentials to use to download the server files and workshop mods
steamWsMods the steam workshop mods to download
events scheduled events for stuff like server restarts, global messages and so on
serverCfg.hostname the name of the server in the server browser
serverCfg.password the password of the game server
serverCfg.passwordAdmin the admin password of the game server !IMPORTANT! change this or others might be able to take control over your server

Below you will find a list of guides on how to edit these values.


Change the instance ID

For later compatibility between multiple installations and identification of different configs a instance id was introduced (currently it is not used)

Set this to some id you like :)
Example:
"instanceId": "main-server"


Adding more admins / moderators

To add/remove admins or moderators, edit the admins list in the config.
Read the description in the template to find out more about the roles.
The example snippet shows how to add an admin, a manager and a moderator.

    ...
    "admins": [
        {
            "userId": "FunkyDude",
            "userLevel": "admin",
            "password": "admin"
        },
        {
            "userId": "the-discord-dude",
            "userLevel": "manage",
            "password": "somecoolpassword"
        },
        {
            "userId": "InternDude",
            "userLevel": "moderate",
            "password": "somoderatormuchwow"
        }
    ],
    ...


Discord Token

To obtain a discord bot token, follow the steps at: https://www.writebots.com/discord-bot-token/#Generating_Your_Token_Step-by-Step

In a nutshell:


Discord Channels

To add/remove discord channels, edit the discordChannels list in the config.
Read the description in the template to find out more about the channel types.
The following example adds a channel for commands and one for rcon messages

...
"discordChannels": [
  {
      "channel": "main-server-commands",
      "mode": "admin"
  },
  {
      "channel": "main-server-rcon",
      "mode": "rcon"
  }
],
...


Adding local / manually installed mods

Local mods are mods which you manually install and update. The server manager will only add them to the server startup parameters.
Example:

"localMods": [
  "@MyAwesomeMod",
  "path/to/my/@OtherAwesomeMod",
],


Adding workshop mods

Workshop mods will be downloaded and updated everytime the server restarts (if not configured otherwise).
The steamWsMods property specifies a list of workshop mods to download.
There are two possible syntaxes:

"steamWsMods": [
  "1559212036",
  "1565871491"
],

or

"steamWsMods": [
  {
    "workshopId": "1559212036",
    "name": "CF"
  },
  {
    "workshopId": "1565871491",
    "name": "BuilderItems"
  }
],

Hint: The name of the mod is only there to make the config more readable. You can enter whatever you want.
Hint: You can mix the syntaxes


Changing the server name / password / admin password


Changing the server port

You might need to host your server on another port, because you want to host multiple servers on the same machine
or whatever the reason might be.

HowTo:


Adding events

Events are used to do tasks that are occurring at specific points in time.
Typical examples would be regular server restarts and global messages to promote the server's discord.
The following example shows exactly this.
It is scheduling:

The scheduling pattern is the CRON pattern.
There are free websites to generate these peatterns pretty easily:

For more details see the description in the server-manager.json itself.

Example:

...
"events": [
    {
        "name": "Restart every 4 hours",
        "type": "restart",
        "cron": "0 0/4 * * *"
    },
    {
        "name": "Some Message",
        "type": "message",
        "cron": "0/15 * * * *",
        "params": [
            "Hello world"
        ]
    }
],
...


Adding hooks

Hooks can be used to trigger external scripts or programs on certain events.
This can be useful to so manual configuration or other custom stuff.

Possible hook types are:

In the server manager config add a hook object to the hooks array like so:

...
"hooks": [
  {
    "type": "beforeStart",
    "program": "path/to/your/script.bat"
  }
],
...


Linux Server

The manager was tested on Ubuntu 22 (latest). Other up2date debian variants should work as well.
The DayZServer only works on x86 platforms, ARM is NOT supported!
The manager can be run via the binary (recommended) or docker.
The main downside when run with docker:
If the manager crashes or shuts down, your dayz server will also be shut down.

Binary

(the commands below might be needed to be run as root/with sudo)

  1. Install the required libs for dayz and steamcmd

    apt-get install libcap-dev lib32gcc-s1 libcurl4  libcurl4-openssl-dev
  2. Create a user for the server (highly recommended for security reasons) The user should have the home directory set to where the server files will reside Replace /dayz with the directory you want your server to be in, but make sure its already created

    useradd --system -m -d /dayz -s /bin/bash dayz
    chown dayz:dayz /dayz
  3. Download and extract the latest linux release from the releases page

  4. Setup the manager files 4.1. Copy the dayz-server-manager binary to your /dayz directory 4.2. Copy the server-manager-template.json to the /dayz 4.3. Rename the server-manager-template.json to the server-manager.json 4.4. Edit the server-manager.json with a text editor to fit your needs (Make sure its valid json. Its recommended to use VSCode for editing and set the file type to jsonc / json with comments)

  5. Switch to the /dayz dir

    cd /dayz
  6. Make the binary executable and owned by the dayz user

    chown dayz:dayz dayz-server-manager
    chmod +x dayz-server-manager
  7. Switch to the dayz user

    su dayz
  8. Run the manager

    ./dayz-server-manager

Creating a daemon / service

  1. Create the service file /etc/systemd/system/dayz-server-manager.service

    [Unit]
    Description=DayZ Server Manager
    Wants=network-online.target
    After=syslog.target network.target nss-lookup.target network-online.target
    
    [Service]
    ExecStart=/dayz/dayz-server-manager
    WorkingDirectory=/dayz/
    LimitNOFILE=100000
    KillMode=process
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s INT $MAINPID
    User=dayz
    Group=users
    Restart=on-failure
    RestartSec=5s
    
    [Install]
    WantedBy=multi-user.target
  2. Daemon realod and enable the service
    systemctl daemon-reload
    service dayz-server-manager enable
  3. Start the service
    service dayz-server-manager start
  4. Check the service status
    service dayz-server-manager status

Docker

The manager is also published as a docker image:
ghcr.io/mr-guard/dayz-server-manager:latest
If you run the manager inside docker, the dayz server will also start in the same container. If you stop the manager, the dayz server will stop as well.

How-To:

  1. Create a directory for your server and make sure its accessible

    mkdir /dayz
    chmod 777 /dayz
  2. Copy your server-manager.json inside that dir

  3. Copy the docker-compose.yml from the repository to that dir.

  4. Start the server manager:

    docker compose up -d

You can run the image without compose, but you will need to figure that out on your own...


SteamCMD

The server manager tries to automate every required installation step of the server.
However, the DayZ Server and the DayZ Workshop Mods cannot be installed without an account which owns (only for workshop mods) DayZ (the full game).
In order to login to your account, you have to provide your steam credentials in the configuration file.
This is only needed ONCE, since SteamCMD caches your session. (If the cache is invalidated, you will need to provide it again)
Your password will not be used for anything else. In fact, it is even hidden in the logs.
Still, it is recommended that you create an account which owns only DayZ.

If you are really paranoid about pasting your password somewhere, or you use steam guard:


Planned features / TODOs


Default Folder Layout

-- server-manager.json
-- DayZServer // contains the server installation
----- profiles // contains the server logs (rpt, ADM, ...) and battleye folder
----- serverDZ.cfg // server name, password, player count, ...
----- .. // other files, workshop mods will also be linked to this folder
-- SteamCMD
----- steamcmd.exe
----- ..
-- Workshop // contains the actual workshop mods
-- STEAM_GUARD_CODE // Optional text file. Containing only your steam guard code. will be deleted after usage. See Known Issues / Limitations for more details.
-- SERVER_LOCK // Optional file. If exists server restarts will be skipped

You can, however, change these paths to fit your needs


Technical Details

The server manager is a self contained NodeJS-App written in TypeScript and packaged with pkg.
You DON'T need to install NodeJS or anything else.
Everything you need is contained in the single executable (exe).
However, due to that the exe is around 90MB in size.
This tool makes use of the windows commandline tools (namely netsh and wmic) or the linux cli tools and procfs to determine installation requirements and the state of the server.
It is recommended NOT to use an elevated user for running it.


Security


Discord

The security model of the discord bot is based on the fact that discord gamer tags (name#number) ARE unique.
We do not need to know/check actual account ids.
If a user is able to post messages with a authorized gamer tag,
it means that the user is actually logged in to the authorized account.


WebUI and REST API Security

The UI and API are secured by basic auth.
This should be "good enough" for this use case.
However, be advised that if the UI or API are served to the (public) internet,
the login info is not encrypted because the manager is served via HTTP.

To protect the UI and API from being intercepted/tampered with,
you should consider using a reverse proxy (such as nginx) with a valid SSL Certificate on the same server
(this might already be the case if you host a website).
This way the traffic is handled securely until terminated at the reverse proxy.


Known Issues / Limitations









Development

To work on the server manager, the nodejs runtime (v14) must be installed and the node extensions must be compiled locally.
To do this, you will need a C++ compiler:

Windows:

choco install python python2 -y
choco install visualstudio2019buildtools -y
choco install visualstudio2019-workload-vctools -y

Linux:

apt-get install -y make python3 python2 build-essential

When the tools are installed, clone the repository and run npm ci.

When everything is installed, you can start the manager by running:

CLI mode:

npm run start

Packed mode:

npm run startPacked


Disclaimer

NO WARRANTY / GUARANTEE RESPONSIBILITY

By using the software and/or thw source code you agree that the authors CAN NOT be held responsible for any damages caused by the software and/or the source code.