#!/bin/sh
##
## written by abfackeln@abfackeln.com, based on the original epic code
##
## 2000-10-10 (abfackeln)
##   added a lot of conditions to ensure that the files are actually found
## 2001-06-15 (abfackeln)
##   added "at -b" as per suggestion from Matthew Hall <leareth@angui.sh>
##

INSTALL_DIR=`cat $HOME/.loki/ut/install_dir`

# set three possible locations for the java executable

JAVA1=`which java`
JAVA2="/usr/local/java/bin/java"
JAVA3="/usr/jdk1.2/bin/java"

# set three possible locations for the ngStats directory

NGHOME1="../NetGamesUSA.com/ngStats"
NGHOME2="$INSTALL_DIR/../NetGamesUSA.com/ngStats"
NGHOME3="$HOME/UnrealTournament/NetGamesUSA.com/ngStats"

# try each of the above to see if they work

if [ ! -x "$JAVA1" ]; then
	if [ ! -x "$JAVA2" ]; then
		if [ ! -x "$JAVA3" ]; then
			echo "ngLS: can not exec: $JAVA1"
			echo "ngLS: can not exec: $JAVA2"
			echo "ngLS: can not exec: $JAVA3"
			exit 0
		else
			JAVA="$JAVA3"
		fi
	else
		JAVA="$JAVA2"
	fi
else
	JAVA="$JAVA1"
fi

if [ ! -d "$NGHOME1" ]; then
	if [ ! -d "$NGHOME2" ]; then
		if [ ! -d "$NGHOME3" ]; then
			echo "ngLS: can not find: $NGHOME1"
			echo "ngLS: can not find: $NGHOME2"
			echo "ngLS: can not find: $NGHOME3"
			exit 0
		else
			NGHOME="$NGHOME3"
		fi
	else
		NGHOME="$NGHOME2"
	fi
else
	NGHOME="$NGHOME1"
fi

# export the vars for the java process to use

export CLASSPATH="$NGHOME/ngusa.jar"
export NGCONFIG="$NGHOME/ngStatsUT.cfg"
export NGHOME

# execute java

echo "ngLS: $JAVA ngStatsUT -c $NGCONFIG -j $NGHOME $*"
$JAVA ngStatsUT -c $NGCONFIG -j $NGHOME $* &

