#!/usr/bin/perl

# Retrieves the CGI env. variable "SERVER_NAME", and passes it as a
# parameter to bkgo_applet.class

#    bkgo_applet.pl?port=30000

# Set these variables to narrow the range of ports to which BKGo clients
# can connect (big security issue here!):

$portstart = 30000;
$portend   = 30004;

# Set this variable to the URL of the bkgo classes (assuming that
# your web-server's DNS name is already prepended to the front):

$code_location = "/bkgo/classes";


#-----------------------------------------------------------


# The applet's first field automatically has the Web-server's name filled in:
$servername = $ENV{'SERVER_NAME'};

# And the port number is passed in as an argument:
$query_string = $ENV{'QUERY_STRING'};
($fieldname, $port) = split(/=/, $query_string);

if (($port < $portstart) || ($port > $portend)) {
    print "Content-type: text/html", "\n\n";
    print "<h2>Security Violation</h2>\n";
    print "A BKGo client cannot connect to port ".$port."!\n";
    exit(0);
}

print "Content-type: text/html", "\n\n";

print "<title>BKGo Web System</title>";
print "<center><h1>BKGo Client </h1></center>";

print <<print_end;

<b>Please wait for the BKGo client applet to load!</b>
<p>
The client applet below will allow you to connect to the specified BKGo
Server.  Please keep in mind that you will <b>not</b> be able to:
<p>
<ul>
    <li> Access your disk to load or save games; </li>
    <li> Print a game; </li>
    <li> Connect to any machine except this web server</li>
</ul>
<p>

If you want to do any of those things, you'll need to download the
full-application version of BKGo.
<hr>

print_end

print "<applet code=\"bkgo_applet.class\" codebase=\"",
    $code_location, "\" width=500 height=500>";

print "<param name=\"servername\" value=\"", $servername, "\"> </param>";
print "<param name=\"portnum\" value=\"", $port, "\"> </param>";

print "</applet>";

print "</html>";
