#!/bin/sh

USAGE="Alien Arena server wrapper
This script is Debian specific, it is *NOT* part of the source distribution!
Usage: alien-arena-server [OPTION] [PARAMETERS]...

 -h, --help      Display this help
 -q, --quiet     Disable console output
 -s, --service   Launch server as a service
 -k, --kill      Kill runaway server sessions
 -Q, --query     Query local servers
 -r, --rcon      Sends rcon commands to servers
 [PARAMETERS]    Pass internal parameters for specified script

More information on using this script can be found in the alien-arena-server(6) man page."

QUIET=0
LAUNCH_SERVER_AS_SERVICE=0
KILL_RUNAWAY_CRDED=0
SVSTAT=0
RCON=0

case "$1" in
	-h|--help)
		echo "${USAGE}"
		exit 0
		;;
	-q|--quiet)
		QUIET=1
		shift
		;;
	-s|--service)
		LAUNCH_SERVER_AS_SERVICE=1
		shift
		;;
	-k|--kill)
		KILL_RUNAWAY_CRDED=1
		shift
		;;
	-Q|--query)
		SVSTAT=1
		shift
		;;
	-r|--rcon)
		RCON=1
		shift
		;;
esac

# Ready to rumble!
cd /usr/share/games/alien-arena
export COR_GAME="$HOME/.local/share/cor-games"

if [ ${LAUNCH_SERVER_AS_SERVICE} = 1 ]; then
	exec /usr/lib/games/alien-arena/launch-server "$@"
elif [ ${KILL_RUNAWAY_CRDED} = 1 ]; then
	exec /usr/lib/games/alien-arena/kill-runaway-crded "$@"
elif [ ${SVSTAT} = 1 ]; then
	exec /usr/lib/games/alien-arena/svstat "$@"
elif [ ${RCON} = 1 ]; then
	exec /usr/lib/games/alien-arena/rcon "$@"
elif [ ${QUIET} = 1 ]; then
	exec /usr/lib/games/alien-arena/alienarena-ded "$@" >/dev/null 2>&1
else
	exec /usr/lib/games/alien-arena/alienarena-ded "$@"
fi
