#!/usr/sbin/perl

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

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

if ($running) {
    open(CMD, "/usr/bin/X11/xconfirm -header \"Bzflag\" -b \"Stop\" -B \"Ignore\"  -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.\" -t \"Otherwise, click the Ignore button.\" -icon info|");
            read(CMD, $out, 100);
            close(CMD);
            if ( $out =~ /Stop/ ) {
                `/sbin/killall bzfs`;
            }
} else {
        open(CMD, "/usr/bin/X11/xconfirm -header \"Bzflag\" -b \"Server\" -B \"Ignore\"  -t \"To run a bzflag network server on your system, click the Server
button.\"  -t \"Otherwise, click the Ignore 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);
            }

}
