From 4b1b5445f7a62ce5228de68f3fd7236f65469045 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 8 Jun 2022 16:38:00 +0200 Subject: [PATCH] backend: Don't consider non error in MCQ as good response --- libfic/exercice.go | 5 +++-- libfic/flag.go | 2 +- libfic/flag_key.go | 5 +++-- libfic/flag_label.go | 3 ++- libfic/mcq.go | 5 +++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libfic/exercice.go b/libfic/exercice.go index e5c4e241..d675381d 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -463,8 +463,9 @@ func (e *Exercice) CheckResponse(cksum []byte, respflags map[int]string, respmcq // Validate MCQs if no error if valid { for _, mcq := range mcqs { - mcq.FoundBy(t) - goodResponses += 1 + if mcq.FoundBy(t) == nil { + goodResponses += 1 + } } } diff --git a/libfic/flag.go b/libfic/flag.go index 29fd3f0d..06373495 100644 --- a/libfic/flag.go +++ b/libfic/flag.go @@ -13,7 +13,7 @@ type Flag interface { GetOrder() int8 Check(val interface{}) int IsOptionnal() bool - FoundBy(t *Team) + FoundBy(t *Team) error } // GetFlag returns a list of flags comming with the challenge. diff --git a/libfic/flag_key.go b/libfic/flag_key.go index a7f300bd..98c50ed5 100644 --- a/libfic/flag_key.go +++ b/libfic/flag_key.go @@ -335,8 +335,9 @@ func (k *FlagKey) Check(v interface{}) int { } // FoundBy registers in the database that the given Team solved the flag. -func (k *FlagKey) FoundBy(t *Team) { - DBExec("INSERT INTO flag_found (id_flag, id_team, time) VALUES (?, ?, ?)", k.Id, t.Id, time.Now()) +func (k *FlagKey) FoundBy(t *Team) (err error) { + _, err = DBExec("INSERT INTO flag_found (id_flag, id_team, time) VALUES (?, ?, ?)", k.Id, t.Id, time.Now()) + return } // GetExercice returns the parent Exercice where this flag can be found. diff --git a/libfic/flag_label.go b/libfic/flag_label.go index 17472286..6d103f7f 100644 --- a/libfic/flag_label.go +++ b/libfic/flag_label.go @@ -178,7 +178,8 @@ func (k *FlagLabel) Check(v interface{}) int { } // FoundBy registers in the database that the given Team solved the flag. -func (k *FlagLabel) FoundBy(t *Team) { +func (k *FlagLabel) FoundBy(t *Team) error { + return nil } // GetExercice returns the parent Exercice where this flag can be found. diff --git a/libfic/mcq.go b/libfic/mcq.go index 9d8bc92c..82315479 100644 --- a/libfic/mcq.go +++ b/libfic/mcq.go @@ -341,6 +341,7 @@ func (m *MCQ) Check(v interface{}) int { } // FoundBy registers in the database that the given Team solved the MCQ. -func (m *MCQ) FoundBy(t *Team) { - DBExec("INSERT INTO mcq_found (id_mcq, id_team, time) VALUES (?, ?, ?)", m.Id, t.Id, time.Now()) +func (m *MCQ) FoundBy(t *Team) (err error) { + _, err = DBExec("INSERT INTO mcq_found (id_mcq, id_team, time) VALUES (?, ?, ?)", m.Id, t.Id, time.Now()) + return }