#!/usr/sbin/perl
#Tag 0x907F

$ENV{'HOME'} = "/tmp";

$results = `/usr/bin/ps -e | /usr/bin/grep bzfs`;

if ($results) {
	open(CMD, "/usr/bin/X11/xconfirm -header \"Bzflag\" -b \"Stop\" -B \"Continue\"  -t \"You have a bzflag network server running on your system.\"  -t \"Generally, there should only be one server per network. \" -t \" \"  -t \"Click the Stop button to stop this server and join a game on a different bzflag server.\" -t \"Click the Continue button to join a game on your workstation's server.\" -icon info|");
			read(CMD, $out, 100);
			close(CMD);
			if ( $out =~ /Stop/ ) {
				`/sbin/killall bzfs`;
			}
	`/usr/demos/General_Demos/bzflag/bzflag>/dev/null&`;
} else {
		open(CMD, "/usr/bin/X11/xconfirm -header \"Bzflag\" -b \"Server\" -B \"Continue\"  -t \"To run a bzflag network server on your system, click the Server button.\"  -t \"To join a game on a different bzflag server, click the Continue button.\" -icon info|");
			read(CMD, $out, 100);
			close(CMD);
			if ( $out =~ /Server/ ) {
				sleep 1;
				open(CMD, "/usr/demos/General_Demos/bzflag/bzfs>/dev/null&|");
				close(CMD);
			}

	`/usr/demos/General_Demos/bzflag/bzflag>/dev/null&`;

}
