#!/usr/bin/perl

use CGI qw(:standard);
if (param('name')) {
  $username=param('name');
  $filecheck=(-e "C:/mazeperm/$username.txt");
  if ($filecheck){
    print header(),start_html('Name already taken');
    print p("$username is already in use.  Please <A HREF='entry.pl'>choose</A> a different name.");
    print end_html();
  } else {
    $username=param('name');
    open (COOKLIST, ">C:/mazeperm/$username.txt") || die "open: $!";
    print COOKLIST "$username,1,0,0,0,0,0,0,0,0";
    close (COOKLIST);
    $cookie = cookie(-name=>'MazeID',
			-value=>$username,
			-expires=>'+1y',
                        -path=>'/');
    print header(-cookie=>$cookie);
    print start_html('Welcome to the Maze');
    print h1('Welcome to the maze!');
    print p("Welcome, $username");
    print p(($zippo));
    print p("Please <A HREF='maze1.pl'>enter</A>.");
    print end_html();
  }
} else {
  if (cookie('MazeID')) {
  $username=cookie('MazeID');
  print header();
  print start_html('Welcome to the Maze');
  print h1('Welcome to the maze!');
  print p("Welcome, $username");
  print p("Please <A HREF='maze1.pl'>enter</A>.");
  print end_html();
  }
  else {
  print redirect('http://127.0.0.1/cgi-bin/maze/entry.pl');
  }
}