backend: Don't consider non error in MCQ as good response

This commit is contained in:
nemunaire 2022-06-08 16:38:00 +02:00
parent 0a8d0dad30
commit 4b1b5445f7
5 changed files with 12 additions and 8 deletions

View File

@ -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
}
}
}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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
}