#
#  Start a xquake server via pipes
#
#  Written by Donovan Young
#

#
#  BEGIN USER MODIFIABLE SECTION
#

HOMEDIR=/usr/quakebbs           # <-- The QuakeBBS HOME directory
DATADIR=/usr/quakebbs/data      # <-- The QuakeBBS DATA directory
LOGSDIR=/usr/quakebbs/logs      # <-- The QuakeBBS LOGS directory
SNAME=quake                     # <-- The quake.servers <shortname> field
PORT=20000                      # <-- The port to run Quake on
NUMPLAYERS=8                    # <-- The maximum number of players to accept

#
#  END OF USER MODIFIABLE SECTION
#

PIPE="${DATADIR}/${SNAME}.in"
LOGFILE="${LOGSDIR}/${SNAME}.log"

if [ ! -d "${DATADIR}" ] ; then
    echo "$DATADIR not a valid directory."
    echo "Please modify the DATADIR value at the top of this script and try again."
    exit 1
fi

if [ ! -d "${LOGSDIR}" ] ; then
    echo "$LOGSDIR not a valid directory."
    echo "Please modify the LOGSDIR value at the top of this script and try again."
    exit 1
fi

if [ ! -p "${PIPE}" ] ; then
    echo "${PIPE} is not a valid FIFO file."
    echo "\nHave you configured your system per the quakebbs.README instructions?"
    echo "If so, you might need to modify the SNAME field at the top of this script"
    echo "to match your system."
    exit 1
fi

> ${LOGFILE}

if [ ! -x ./xquake ] ; then
    echo "You must run this script from the directory where xquake is installed"
    exit 1
fi

./xquake -dedicated $NUMPLAYERS -nojoy -noipx -nomusic -nosound -udpport $PORT $* < ${PIPE} > ${LOGFILE} &
echo status > ${PIPE}

tty > /dev/null
if [ $? ] ; then
    qconsole ${HOMEDIR} ${SNAME}
fi

