#! /bin/csh -f
# Written by Furey.
# With additions from Tony.
# Adapted by SledgeHam

#check if we are running already ...
#the first below line no longer works, since the OTHER nimud uses a
#startmerc script too...
#set num=`ps ax | grep startup | grep -v grep | wc -l`
# the `a' switch not allowed in envy for non-staff accounts, so removed
set num=`ps x | grep "mud 2000" | grep -v grep | wc -l`

# had to change this to a 0, cuz mud hasn't been run yet.
#if ( "$num" != "1" ) exit 0
if ( "$num" != "0" ) exit 0

#set a limit on coredumpsize ... so we have a coredump  ..
limit coredumpsize 10000

date > /home/theisles/restarted

# Set the port number.
set port = 2000
#always run on 2000, since we can no longer uniquely look for 'startup'
#if ( "$1" != "" ) set port="$1"

# Change to area directory.
cd /home/theisles/isles/area

# Set limits.
nohup
nice
limit stack 1024k
if ( -e shutdown.txt ) rm -f shutdown.txt

while ( 1 )
    # copy the last commands ...
#    if ( -e commands.txt ) then
#      cp commands.txt commands/`date +"%m:%d-%T"`
#    endif
# Reset the guest char
      cp /home/theisles/isles/player/_Onlooker /home/theisles/isles/player/Onlooker

    # Run Nim.
#    /home/theisles/isles/src/mud $port >>&! /home/theisles/isles/log/current.log
#    cat /home/theisles/isles/log/current.log >>&! logfile
    ../src/mud >>&! $logfile

    if ( -e shutdown.txt ) then
	rm -f shutdown.txt
	exit 0
    endif
    sleep 10
end
