#!/bin/csh -f

onintr leave
set imserver = 0;
zctl sub message hunt \*

if ("$1" == "-z") then
shift
else
zwrite -n -q $USER -m \
"Subscribe to Zephyr instance  hunt  to be notified of ongoing games.\
You are temporarily subscribed to this instance now.\
If you wish to unsubscribe, type  zctl unsub message hunt '*'.\
The subscription can be made permanent by\
adding  message,hunt,*  to your .zephyr.subs file.\
\
Type   more /mit/games/man/cat6/hunt.6\
for instructions on how to play.\
\
Give  -z  as the FIRST argument if you do not wish to see this message."
endif

zwrite -n -q -i hunt -m "There is a hunt game in progress. \
User  $USER  has entered hunt, from host  `hostname` , type `machtype -c`.\
Hunt arguments:  $* \
\
Play instructions: The first person to start the game types  hunt\
Wait about 60 seconds for the game to start.\
Everyone else then types  hunt host\
where  host  is the machine of the first person."

/mit/games/`machtype`bin/hunt.real $*

if ($status) then
echo "No game found on the local net. Starting one ..."
set imserver = 1;
/mit/games/`machtype`bin/hunt.real $*
endif

if ($imserver && -e /usr/tmp/hunt.stats) then
zwrite -n -q -i hunt -s "Game Post-Mortem Statistics" < /usr/tmp/hunt.stats
endif

leave:
zwrite -n -q -i hunt -m \
"User  $USER  has departed the hunting ground."
