backend: save the checksum of each try, to be able to detect duplicates after
This commit is contained in:
parent
44d335bc9f
commit
333bb408e1
@ -11,6 +11,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/crypto/blake2b"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
@ -54,6 +56,13 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Save checksum to treat duplicates
|
||||
cksum := blake2b.Sum512(cnt_raw)
|
||||
if err != nil {
|
||||
log.Println(id, "[ERR] JSON parsing error:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Parse it
|
||||
var responses ResponsesUpload
|
||||
err = json.Unmarshal(cnt_raw, &responses)
|
||||
@ -70,7 +79,7 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
||||
}
|
||||
|
||||
// Check given answers
|
||||
solved, err := exercice.CheckResponse(responses.Keys, responses.MCQs, team)
|
||||
solved, err := exercice.CheckResponse(cksum[:], responses.Keys, responses.MCQs, team)
|
||||
if err != nil {
|
||||
log.Println(id, "[ERR] Unable to CheckResponse:", err)
|
||||
genTeamMyFile(team)
|
||||
|
@ -244,6 +244,7 @@ CREATE TABLE IF NOT EXISTS exercice_tries(
|
||||
id_exercice INTEGER NOT NULL,
|
||||
id_team INTEGER NOT NULL,
|
||||
time TIMESTAMP NOT NULL,
|
||||
cksum BINARY(64) NOT NULL,
|
||||
nbdiff INTEGER NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
|
||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||
|
@ -205,8 +205,8 @@ func (e Exercice) GetLevel() (int, error) {
|
||||
}
|
||||
|
||||
// NewTry registers a solving attempt for the given Team.
|
||||
func (e Exercice) NewTry(t Team) error {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time) VALUES (?, ?, ?)", e.Id, t.Id, time.Now()); err != nil {
|
||||
func (e Exercice) NewTry(t Team, cksum []byte) error {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time, cksum) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), cksum); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
@ -264,8 +264,8 @@ func (e Exercice) TriedCount() int64 {
|
||||
|
||||
// CheckResponse, given both flags and MCQ responses, figures out if thoses are correct (or if they are previously solved).
|
||||
// In the meanwhile, CheckResponse registers good answers given (but it does not mark the challenge as solved at the end).
|
||||
func (e Exercice) CheckResponse(respflags map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
|
||||
if err := e.NewTry(t); err != nil {
|
||||
func (e Exercice) CheckResponse(cksum []byte, respflags map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
|
||||
if err := e.NewTry(t, cksum); err != nil {
|
||||
return false, err
|
||||
} else if flags, err := e.GetFlags(); err != nil {
|
||||
return false, err
|
||||
|
Loading…
Reference in New Issue
Block a user