#! /usr/bin/perl
use CGI;
$CgiObj = CGI::new();
print $CgiObj->header;

@lines = split(';', LoadScore());

my $nick=$CgiObj->param('nick');
my $score=$CgiObj->param('score');
my $hash=$CgiObj->param('hash');
#check hash
my $index = -1;
for (my $i=2; $i>=0; $i--) {
	my @val = split('=', @lines[$i]);
	if (@val[1]<$score) {
		$index = $i;
	}
}
if ($index != -1) {
	splice(@lines, $index, 0, "$nick=$score");
	$#lines = 2;
	SaveScore();
}


print join(';', @lines);

sub LoadScore {
	my $filename = 'score.txt';
	open(fileh, $filename) || return "ONNI=200;ONNI=150;ONNI=100";
	chomp(my @tmp=<fileh>);
	close(fileh);
	return join("\r\n", @tmp);
}

sub SaveScore {
	my $filename = 'score.txt';
	open(fileh, ">$filename") || return;
	print fileh join(';', @lines);
	close fileh;
}
