#! /bin/sh
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>
#		Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>
#

### BEGIN INIT INFO
# Provides:          pvpgn
# Required-Start:    $local_fs $remote_fs $syslog $network $time
# Required-Stop:     $local_fs $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Gaming server that emulates Battle.net(R)
### END INIT INFO


# checks for the pvpgn support files
check_support() 
{
	FILES="IX86ver1.mpq  XMACver1.mpq       bnserver-WAR3.ini  icons.bni                     
	       matchmaking-war3-enUS.dat       PMACver1.mpq  bnserver-D2DV.ini  
               bnserver.ini icons_STAR.bni     WAR3IX86.mpq  bnserver-D2XP.ini  
	       icons-WAR3.bni     	       matchmaking-war3-default.dat"
	
	START=1
	for i in $FILES; do
		if [ ! -f "/var/lib/pvpgn/files/$i" ]; then
			START=0;
		fi
	done

	if [ "$START" = "0" ]; then
		echo -e "\nYou are missing the pvpgn support files and daemon will not start without them."
		echo "Run pvpgn-support-installer or read /usr/share/doc/pvpgn/README.Debian"		      
		exit 0
	fi

}

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/bnetd
NAME=bnetd
DESC="bnetd daemon"

test -x $DAEMON || exit 0

set -e
case "$1" in
  start)
	check_support
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
	check_support
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --exec $DAEMON
	sleep 1
	start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
