]> iEval git - gruntmaster-page.git/blobdiff - lib/Plack/App/Gruntmaster.pm
Add D, OCaml, PHP, Python3
[gruntmaster-page.git] / lib / Plack / App / Gruntmaster.pm
index 77b374894e7a254fa4eb9271b260386c1eb40151..cda45fc04ded26aacac855140c8a0ec42e058928 100644 (file)
@@ -24,15 +24,20 @@ use constant USER_REGEX => qr/^\w{2,20}$/a;
 use constant FORMAT_EXTENSION => {
        C => 'c',
        CPP => 'cpp',
+       D => 'd',
        GCCGO => 'go',
        GOLANG => 'go',
        GOLFSCRIPT => 'gs',
        HASKELL => 'hs',
+       OBERON => 'm',
        MONO => 'cs',
+       OCAML => 'ml',
        JAVA => 'java',
        PASCAL => 'pas',
        PERL => 'pl',
+       PHP => 'php',
        PYTHON => 'py',
+       PYTHON3 => 'py',
        RUBY => 'rb',
        SBCL => 'l',
 };
@@ -80,7 +85,7 @@ sub dispatch_request{
                sub (/robots.txt) { NOT_FOUND },
 
                sub (/src/:job) {
-                       my $job = job_full $_{job};
+                       my $job = db->select(jobs => '*', {id => $_{job}})->hash;
                        return NOT_FOUND if !$job;
                        my $isowner = remote_user && remote_user->{id} eq $job->{owner};
                        my $contest = $job->{contest} && contest_entry $job->{contest};
@@ -105,13 +110,16 @@ sub dispatch_request{
                        },
                },
 
-               sub (/st/:contest) { response st => 'Standings', standings($_{contest}), 10 },
+               sub (/st/:contest) {
+                       my @pb = map { [$_->{id}, $_->{name}] } sort { $a->{value} <=> $b->{value} } @{problem_list contest => $_{contest}};
+                       response st => 'Standings', {problems => \@pb, st => standings $_{contest}}, 10
+               },
 
                sub (/ed/:contest) {
-                       my $contest = contest_full $_{contest};
-                       forbid !$contest->{finished};
+                       my $contest = db->select(contests => '*', {id => $_{contest}})->hash;
+                       forbid time < $contest->{stop};
                        my $pblist = problem_list contest => $_{contest}, solution => 1;
-                       response ed => 'Editorial of ' . $contest->{name}, {%$pblist, editorial => $contest->{editorial}}
+                       response ed => 'Editorial of ' . $contest->{name}, {pb => $pblist, editorial => $contest->{editorial}}
                },
 
                sub (/login) {
@@ -122,16 +130,17 @@ sub dispatch_request{
                sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" },
 
                sub (/us/)                                        { response us => 'Users', {us => user_list} },
-               sub (/ct/  + ?:owner~)                            { response ct => 'Contests', contest_list(%_), 300 },
+               sub (/ct/  + ?:owner~)                            { response ct => 'Contests', {ct => contest_list(%_)}, 300 },
                sub (/log/ + ?:contest~&:owner~&:page~&:problem~&:private~&:result~) {
                        forbid $_{private};
-                       response log => 'Job list', job_list(%_), 5
+                       my ($jobs, $pageinfo) = job_list(%_);
+                       response log => 'Job log', {log => $jobs, %$pageinfo}, 5
                },
                sub (/pb/  + ?:owner~&:contest~&:private~)                  {
                        forbid $_{private};
                        my $pending = $_{contest} && !contest_entry($_{contest})->{started};
                        forbid $pending;
-                       response pb => 'Problems', problem_list %_
+                       response pb => 'Problems', {pb => problem_list %_}
                },
 
                sub (/us/:user)    {
@@ -185,6 +194,11 @@ sub dispatch_request{
                                return reply 'This contest has finished' if $contest->{finished};
                                return reply 'This problem is private' if !admin && $private;
                                return reply 'This problem does not belong to this contest' unless contest_has_problem $_{contest}, $_{problem};
+                               if ($_{contest} =~ /d[12]$/) {
+                                       my $other = $_{contest} =~ y/12/21/r;
+                                       my ($ans) = db->query('SELECT COUNT(*) FROM jobs WHERE owner = ? AND contest = ?', remote_user->{id}, $other)->flat;
+                                       return reply 'You are not allowed to participate in both divisions of a round' if $ans;
+                               }
                        }
                        return reply 'Maximum source size is 10KB' if ($prog ? $prog->size : length $_{source_code}) > 10 * 1024;
                        return reply 'You must wait 30 seconds between jobs' if !admin && time <= remote_user->{lastjob} + 30;
This page took 0.024861 seconds and 4 git commands to generate.