]> mj.ucw.cz Git - eval.git/commitdiff
Added checking of contest time.
authorMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 21:23:48 +0000 (23:23 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 21:23:48 +0000 (23:23 +0200)
TODO
submit/commands.c
submit/config
submit/tasks.c

diff --git a/TODO b/TODO
index f31fbe38cd8b01f9d112898b76f99d47aa8c1fc7..b2c726b9d830c4cc23a0cc2c13e6f5a7252832b9 100644 (file)
--- a/TODO
+++ b/TODO
@@ -17,7 +17,6 @@ Installer:
 - quotas
 
 New submitter:
-- Checking of contest time (and per-contestant exceptions)
 - contest: override failed check
 - contest: local history
 - contest: task status cache
index bee9549d24f04b3c3675f0ae2aafbeca66dab851..7ecd7810ed1a0c7a940feb04116a3fcc29b9d2c3 100644 (file)
@@ -8,9 +8,11 @@
 #include "lib/mempool.h"
 #include "lib/simple-lists.h"
 #include "lib/stkstring.h"
+#include "lib/fastbuf.h"
 #include "sherlock/object.h"
 #include "sherlock/objread.h"
 
+#include <fcntl.h>
 #include <time.h>
 
 #include "submitd.h"
@@ -128,6 +130,43 @@ cmd_status(struct conn *c)
     }
 }
 
+/*** Contest timeout checks ***/
+
+static int
+load_time_limit(char *name)
+{
+  struct fastbuf *f = bopen_try(name, O_RDONLY, 1024);
+  if (!f)
+    return -1;
+  char buf[256];
+  int h, m;
+  if (bgets_nodie(f, buf, sizeof(buf)) < 0 ||
+      sscanf(buf, "%d:%d", &h, &m) != 2 ||
+      h < 0 || h > 23 || m < 0 || m > 59)
+    {
+      msg(L_ERROR, "Invalid timeout in %s", name);
+      bclose(f);
+      return -1;
+    }
+  bclose(f);
+  return 100*h + m;
+}
+
+static int
+contest_over(struct conn *c)
+{
+  time_t now = time(NULL);
+  struct tm *tm = localtime(&now);
+  int tstamp = tm->tm_hour*100 + tm->tm_min;
+  int local_limit = load_time_limit(stk_printf("solutions/%s/TIMEOUT", c->user));
+  int global_limit = load_time_limit("solutions/TIMEOUT");
+  if (trace_commands > 1)
+    msg(L_DEBUG, "Time check: current %d, global limit %d, user limit %d", tstamp, global_limit, local_limit);
+  if (local_limit >= 0)
+    return (tstamp >= local_limit);
+  return (global_limit >= 0 && tstamp >= global_limit);
+}
+
 /*** SUBMIT ***/
 
 static struct fastbuf *
@@ -165,6 +204,12 @@ read_attachment(struct conn *c, uns max_size)
 static void
 cmd_submit(struct conn *c)
 {
+  if (contest_over(c))
+    {
+      err(c, "The contest is over, no more submits allowed");
+      return;
+    }
+
   byte *tname = obj_find_aval(c->request, 'T');
   if (!tname)
     {
index 578c856390b6eff9910a1ecdee1788d6d73834db..85d266981f5e732ea738b32b978b59d0433563f6 100644 (file)
@@ -66,7 +66,7 @@ Access {
 TraceTLS               1
 
 # Trace command and their results
-TraceCommands          1
+TraceCommands          2
 
 }
 
index 243cd907f0ee32c0adf12d1a56172125bc0ab014..e60b40c3d6bb2c362f457a07b0c4e6f487651b40 100644 (file)
@@ -194,7 +194,8 @@ task_status_find_part(struct odes *to, byte *part, uns create)
   return o;
 }
 
-static void task_record_history(byte *user, byte *task, byte *part, byte *ext, uns version, byte *submitted_name)
+static void
+task_record_history(byte *user, byte *task, byte *part, byte *ext, uns version, byte *submitted_name)
 {
   if (!history_format)
     return;
@@ -216,7 +217,8 @@ static void task_record_history(byte *user, byte *task, byte *part, byte *ext, u
   bclose(orig);
 }
 
-void task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version, struct fastbuf *fb)
+void
+task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version, struct fastbuf *fb)
 {
   byte *dir = stk_printf("solutions/%s/%s", user, task);
   byte *name = stk_printf("%s/%s.%s", dir, part, ext);
@@ -232,7 +234,8 @@ void task_submit_part(byte *user, byte *task, byte *part, byte *ext, uns version
   task_record_history(user, task, part, ext, version, name);
 }
 
-void task_delete_part(byte *user, byte *task, byte *part, byte *ext, uns version UNUSED)
+void
+task_delete_part(byte *user, byte *task, byte *part, byte *ext, uns version UNUSED)
 {
   byte *dir = stk_printf("solutions/%s/%s", user, task);
   byte *name = stk_printf("%s/%s.%s", dir, part, ext);