diff options
-rw-r--r-- | .SRCINFO | 4 | ||||
-rw-r--r-- | PKGBUILD | 4 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | dom4 | 110 | ||||
-rw-r--r-- | dom4-server.install | 1 |
5 files changed, 90 insertions, 37 deletions
@@ -1,6 +1,6 @@ pkgbase = dom4-server pkgdesc = Configure and run Dominions 4 as a headless server - pkgver = 1.0.4 + pkgver = 1.0.5 pkgrel = 1 url = http://www.illwinter.com/dom4/ install = dom4-server.install @@ -16,7 +16,7 @@ pkgbase = dom4-server md5sums = 7e51badb10054709bbec60bfcbf424ee md5sums = e9772a237cc540558e74235b98df8a7f md5sums = 338b8462868ecf6cc56c4a520cea6bac - md5sums = 17d227cbd6c5b620b7cf2c07aba37b31 + md5sums = 48350dc0c90ea1c611e6ceeeae71811a md5sums = 22bdb16a296d12c51988c43c3218201b pkgname = dom4-server @@ -1,7 +1,7 @@ # Dominions 4 Server Configuration # Maintainer: Dian Fay <dian.m.fay@gmail.com> pkgname=dom4-server -pkgver=1.0.4 +pkgver=1.0.5 pkgrel=1 pkgdesc="Configure and run Dominions 4 as a headless server" arch=('x86_64') @@ -32,5 +32,5 @@ md5sums=('d8e3011dfa108d3f1574c57aefcecb32' '7e51badb10054709bbec60bfcbf424ee' 'e9772a237cc540558e74235b98df8a7f' '338b8462868ecf6cc56c4a520cea6bac' - '17d227cbd6c5b620b7cf2c07aba37b31' + '48350dc0c90ea1c611e6ceeeae71811a' '22bdb16a296d12c51988c43c3218201b') diff --git a/README.md b/README.md index cdcb54b4a2e2..d1f3a2f8ef2b 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Your game configuration is stored in key=value format in a properties file. Copy 1. `sudo dom4 config mygame.properties` loads your config into the server and sets the current game name. 1. `sudo systemctl start dom4-server` starts the server in pretender upload mode. -1. If `uploadmaxp` or `uploadtime` are set in your configuration, you're done: the game will start automatically when the appropriate limit is reached. If not, wait for everyone to upload their pretenders and then bring the server down with `sudo systemctl stop dom4-server`. -1. `sudo dom4 ready` sets the server up to host the last configured game, or you can pass in the name of another properties file (without the extension) after all pretenders have been uploaded. -1. Restart the server using `sudo systemctl start dom4-server` again to begin the game. +1. If `uploadmaxp` or `uploadtime` are set in your configuration, you're done: the game will start automatically when the appropriate limit is reached. +1. Once everyone has uploaded their pretenders, `sudo dom4 ready` sets the game start flag. You can `sudo dom4 ready mygame` to specify a game to host regardless of what was last configured. +1. Restart the server using `sudo systemctl restart dom4-server` to begin the game. You may also want to `sudo systemctl enable dom4-server` in order to start the server automatically after reboots. -Note that only one game may be served at a time. If you run `dom4 config` with a config file when a game has already been set up, it will ask if you want to overwrite the existing game. +Note that only one game may be served at a time. If you run `dom4 config` with a config file when a game has already been set up, it will ask if you want to host the new game instead. The previous config file will be preserved, unless the new one has the same name. ### Deleting Games @@ -1,18 +1,49 @@ #!/bin/bash +# Change the current hosted game by editing /usr/share/dom4/current. +# Params: +# $1 game name +function change { + if [[ -s /usr/share/dom4/current ]]; then + game=$(</usr/share/dom4/current) + + if [[ $1 != $game ]]; then + read -r -n 2 -p "Currently hosting $game. Set up to host $1 instead? [Y/n] " ovr + if [[ $ovr != Y ]]; then + exit 0 + fi + echo + fi + fi + + echo "Setting $1 up for hosting." + echo "$1" > /usr/share/dom4/current +} + +# Load a properties file. +# Params: +# $1 path to properties file function config { + if [[ -z $1 ]]; then + cat <<EOF +Usage: + + sudo dom4 config path/to/mygame.properties +EOF + exit 1 + fi + if [[ ! -s $1 ]]; then - echo "Specify a valid properties file." + echo "$1 does not exist. Specify a valid properties file." exit 1 fi - if [[ -s /usr/share/dom4/current ]]; then - game=$(</usr/share/dom4/current) - new=$(basename $1 .properties) - read -r -n 2 -p "A game named $game already exists. Set up to host $new instead? [Y/n] " ovr + if [[ -s "/usr/share/dom4/config/$1" ]]; then + read -r -n 2 -p "$1 is already configured. Overwrite? [Y/n] " ovr if [[ $ovr != Y ]]; then exit 0 fi + echo fi echo "Copying properties file..." @@ -23,22 +54,20 @@ function config { mapname=$(basename $mapfile .map) confdir=$(dirname $1) - echo "Looking for $mapname map files..." - mkdir -p /usr/share/dom4/maps USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6) if [[ -s "$mapname.map" ]]; then - echo "Copying $mapname map files" + echo "Copying $mapname map files..." cp "$mapname".* /usr/share/dom4/maps elif [[ -s "$confdir/$mapname".map ]]; then - echo "Copying $mapname map files from $confdir" + echo "Copying $mapname map files from $confdir..." cp "$confdir/$mapname".* /usr/share/dom4/maps elif [[ -s "$USER_HOME/dominions4/maps/$mapname".map ]]; then - echo "Copying $mapname map files from $USER_HOME/dominions4/maps" + echo "Copying $mapname map files from $USER_HOME/dominions4/maps..." cp "$USER_HOME/dominions4/maps/$mapname".* /usr/share/dom4/maps else @@ -47,8 +76,9 @@ function config { exit 1; fi - # Set name as current hosted game - echo $(basename $1 .properties) > /usr/share/dom4/current + echo + + change "$(basename $1 .properties)" cat <<EOF @@ -62,21 +92,45 @@ Once all pretenders have been uploaded, stop the service and set the game to rea EOF } +# Set game start flag in properties file. +# Params: +# $1 game name (optional; uses whatever's in current if not supplied) function ready { if [[ ! -z $1 ]]; then - echo $1 > /usr/share/dom4/current + if [[ ! -s "/usr/share/dom4/config/$1.properties" ]]; then + echo "No game named '$1' found. Use dom4 config $1.properties to upload it." + + exit 1 + fi + + change $1 fi if [[ ! -s /usr/share/dom4/current ]]; then echo "No current game found. Use dom4 config to load game configuration." + exit 1 fi game=$(</usr/share/dom4/current) - players=$(ls -1 /usr/share/dom4/savedgames/$game | wc -l) + + if [[ ! -d "/usr/share/dom4/savedgames/$game" ]]; then + echo "No pretenders uploaded for $game. Start the service with systemctl to let players upload." + + exit 1 + fi + + if [[ -s "/usr/share/dom4/savedgames/$game/ftherlnd" ]]; then + echo "$game has already been started. If the service is not running, start it with systemctl." + + exit 1 + fi + + players=$(ls -1 /usr/share/dom4/savedgames/$game/*.2h | wc -l) if grep -qE "uploadtime|uploadmaxp" /usr/share/dom4/config/$game.properties ; then - echo "Upload flag already set. Start the service with systemctl." + echo "Upload flag already set for $game. Start the service with systemctl." + exit 1 fi @@ -122,20 +176,21 @@ function delete { } if [[ $EUID -ne 0 && ! -z $1 ]]; then - echo "This script must be run as root or via sudo." + echo "Use sudo to run this script." + exit 1 fi case $1 in - config) + "config" | "configure") config "${@:2}" ;; - ready) + "ready") ready "${@:2}" ;; - delete) + "delete") delete "${@:2}" ;; @@ -145,7 +200,7 @@ Get an example template to modify in your editor of choice: cp /usr/share/dom4/config/default.properties mygame.properties -Load a properties file into the server and set it as the current game: +Load a properties file into the server and set it as the current hosted game: sudo dom4 config path/to/mygame.properties @@ -153,22 +208,19 @@ Set start flag for current game after all pretenders have been uploaded, prior t sudo dom4 ready +Set start flag for mygame after pretenders have been uploaded and set it as current hosted game: + + sudo dom4 ready mygame + Delete a game: sudo dom4 delete mygame -Start the service: +Service commands: sudo systemctl start dom4-server.service - -Stop the service: - sudo systemctl stop dom4-server.service - -Troubleshooting: - -If the service isn't running, figure out what's going wrong: - + sudo systemctl restart dom4-server.service systemctl status dom4-server.service EOF ;; diff --git a/dom4-server.install b/dom4-server.install index ab6418d87ae2..3c82daec748a 100644 --- a/dom4-server.install +++ b/dom4-server.install @@ -14,6 +14,7 @@ post_upgrade() { fi cat <<EOF + Post-install tasks: Ensure Dominions 4 is installed to /opt/Dominions4. If you installed it from the Steam GUI with the default library path, use: |