#!/bin/bash
####################################################################
# exoGameCtl - Half-Life Control Panel
# Copyright (c)2002 Symplexity, LLC. [ http://www.symplexity.net ]
####################################################################
#
#       Author: Jeffrey J. Dodge
#        Email: info@exodus.tk
#          Web: http://www.exodus.tk
#     Filename: restartServer
#  Description: Half-Life Restart Script
# File Version: 0.01
#      Release: 1.3
#     Modified: Sun Dec 29 02:02:00 EST 2002
#
####################################################################
# Please direct bug reports, suggestions, or feedback to the member
# forums.  http://www.exodus.tk/members/
# Please see the LICENSE file for the End User License Agreement
####################################################################

clear
echo "exoGameCtl / Restart HLDS"
echo "Copyright (c)2002 Symplexity Development"
echo "http://www.symplexity.net"
echo ""

if [ $# -lt 1 ]
then
    echo "usage: $0 <login>"
    echo ""
    exit 1
fi

hlds_run=`ps xauww | grep $1 | grep hlds_run | awk '{print $2}'`
hlds=`ps xauww | grep $1 | grep "hlds -game" | awk '{print $2}'`


if [ -f "/home/$1/start_hlds.sh" ]
then
   if [ "$hlds" != "" ]
   then
      echo "sudo /bin/kill -9 $hlds_run" > killem.sh
      echo "sudo /bin/kill -9 $hlds" >> killem.sh

      chmod 755 killem.sh
      ./killem.sh
      rm -f killem.sh

      cd /home/$1
      sudo /usr/local/sbin/setuidgid $1 ./start_hlds.sh
      echo "Server Restarted Successfully!"
      echo ""
   else
      echo "error: no servers running, attempting to start"
      echo ""
      cd /home/$1
      sudo /usr/local/sbin/setuidgid $1 ./start_hlds.sh
      echo "Server Started Successfully!"
      echo ""
      exit 1
   fi
else
   echo "error: not a game hosting account"
   echo ""
   exit 1
fi

