#!/usr/bin/perl

# create header for text document to return
print "Content-type: text/html\n\n";

# get data passed in
$get_data = $ENV{'QUERY_STRING'};

# convert escape characters
$get_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C",hex($1))/eg;
$get_data =~ tr/\+/ /;

# get the server time in seconds
$server_time = time();

# take post data and create an array of data
@split_data = split("&",$get_data);
foreach $data_item (@split_data)
  {
  ($key, $value) = split("=",$data_item);
  $info{$key} = $value;
  }

# set filename for highscore database
$filename = "highscore.txt";

# open the database
open(OUTFILE,">>$filename") || exit;

# append the data to the database
print OUTFILE "$info{'score'}&$info{'name'}&$server_time\n";

# close the database
close(OUTFILE);

# signify data written ok
print "resultText=OK\n";

# end this script
exit;
