From 51e6d3494735a2f5ab576731d7c14ae535550573 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 28 Jun 2007 23:23:48 +0200 Subject: [PATCH] Added checking of contest time. --- TODO | 1 - submit/commands.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ submit/config | 2 +- submit/tasks.c | 9 ++++++--- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index f31fbe3..b2c726b 100644 --- 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 diff --git a/submit/commands.c b/submit/commands.c index bee9549..7ecd781 100644 --- a/submit/commands.c +++ b/submit/commands.c @@ -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 #include #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) { diff --git a/submit/config b/submit/config index 578c856..85d2669 100644 --- a/submit/config +++ b/submit/config @@ -66,7 +66,7 @@ Access { TraceTLS 1 # Trace command and their results -TraceCommands 1 +TraceCommands 2 } diff --git a/submit/tasks.c b/submit/tasks.c index 243cd90..e60b40c 100644 --- a/submit/tasks.c +++ b/submit/tasks.c @@ -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); -- 2.39.2