6 use CGI::Carp qw(fatalsToBrowser);
7 require '../foosball.pm';
11 my $username1 = $cgi->param('username1');
12 $username1 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 1";
15 my $username2 = $cgi->param('username2');
16 $username2 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 2";
19 my $score1 = $cgi->param('score1');
20 $score1 =~ /^([0-9]|10)$/ or die "Invalid score 1";
23 my $score2 = $cgi->param('score2');
24 $score2 =~ /^([0-9]|10)$/ or die "Invalid score 2";
27 my $dbh = foosball::db_connect();
28 $dbh->{AutoCommit} = 0;
30 foosball::create_user_if_not_exists($dbh, $username1);
31 foosball::create_user_if_not_exists($dbh, $username2);
34 # fetch the previous single ratings
35 my ($rating1, $rd1) = foosball::find_single_rating($dbh, $username1);
36 my ($rating2, $rd2) = foosball::find_single_rating($dbh, $username2);
40 my ($newr1, $newrd1) = foosball::calc_rating($rating1, $rd1, $rating2, $rd2, $score1, $score2);
41 my ($newr2, $newrd2) = foosball::calc_rating($rating2, $rd2, $rating1, $rd1, $score2, $score1);
43 $dbh->do('INSERT INTO single_results (gametime,username1,username2,score1,score2) VALUES (CURRENT_TIMESTAMP,?,?,?,?)',
44 undef, $username1, $username2, $score1, $score2);
45 $dbh->do('INSERT INTO single_rating (username,ratetime,rating,rd) VALUES (?,CURRENT_TIMESTAMP,?,?)',
46 undef, $username1, $newr1, $newrd1);
47 $dbh->do('INSERT INTO single_rating (username,ratetime,rating,rd) VALUES (?,CURRENT_TIMESTAMP,?,?)',
48 undef, $username2, $newr2, $newrd2);
52 print $cgi->header(-status=>'303 See Other',
53 -location=>'http://foosball.sesse.net/');