#/bin/sh
PATH=$PATH:~/halflife
cd ~/halflife

GAME=${1:+-game $1}
PORT=${2:+-port $2}
shift 2
XTRA=$*

failcount=0
while : ; do
        start=`date '+%d%H%M%S'`
        echo "hlds started at $start" >>hlds.log
        rm -f tfc/cust*
        hlds_l $GAME $PORT +exec startup.cfg $XTRA 2>/dev/null >/dev/null
        stop=`date '+%d%H%M%S'`
        t=`expr $stop - $start`
        if test 0 -le $t -a $t -lt 20 ; then
                failcount=`expr $failcount + 1`
        else
                failcount=0
        fi
        if test $failcount -gt 5 ; then
                exit 1
        fi
        sleep 10
done

# EOF