Utilise a new field to send justifications instead of too complex guessing crap
This commit is contained in:
parent
69a866bbbf
commit
d40922629b
6 changed files with 69 additions and 24 deletions
|
|
@ -52,6 +52,12 @@ func (e Exercice) GetFlags() ([]Flag, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetFlagByLabel returns a flag matching the given label.
|
||||
func (e Exercice) GetFlagByLabel(label string) (k Flag, err error) {
|
||||
err = DBQueryRow("SELECT id_flag, id_exercice, type, help, ignorecase, validator_regexp, cksum FROM exercice_flags WHERE type = ? AND id_exercice = ?", label, e.Id).Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.ValidatorRegexp, &k.Checksum)
|
||||
return
|
||||
}
|
||||
|
||||
// getHashedFlag calculates the expected checksum for the given raw_value.
|
||||
func getHashedFlag(raw_value []byte) [blake2b.Size]byte {
|
||||
hash := blake2b.Sum512(raw_value)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,35 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetMCQbyChoice returns the MCQ corresponding to a choice ID.
|
||||
func GetMCQbyChoice(cid int64) (m MCQ, c MCQ_entry, err error) {
|
||||
if errr := DBQueryRow("SELECT id_mcq, id_exercice, title FROM exercice_mcq WHERE id_mcq = (SELECT id_mcq FROM mcq_entries WHERE id_mcq_entry = ?)", cid).Scan(&m.Id, &m.IdExercice, &m.Title); err != nil {
|
||||
return MCQ{}, MCQ_entry{}, errr
|
||||
}
|
||||
|
||||
if entries_rows, errr := DBQuery("SELECT id_mcq_entry, label, response FROM mcq_entries WHERE id_mcq = ?", m.Id); err != nil {
|
||||
return MCQ{}, MCQ_entry{}, errr
|
||||
} else {
|
||||
defer entries_rows.Close()
|
||||
|
||||
for entries_rows.Next() {
|
||||
var e MCQ_entry
|
||||
|
||||
if err = entries_rows.Scan(&e.Id, &e.Label, &e.Response); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if e.Id == cid {
|
||||
c = e
|
||||
}
|
||||
|
||||
m.Entries = append(m.Entries, e)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddMCQ creates and fills a new struct MCQ and registers it into the database.
|
||||
func (e Exercice) AddMCQ(title string) (MCQ, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title) VALUES (?, ?)", e.Id, title); err != nil {
|
||||
|
|
@ -145,6 +174,11 @@ func (e Exercice) WipeMCQs() (int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetJustifiedFlag searchs for a flag in the scope of the given exercice.
|
||||
func (m MCQ) GetJustifiedFlag(e Exercice, c MCQ_entry) (Flag, error) {
|
||||
return e.GetFlagByLabel("%" + m.Title + "%" + c.Label)
|
||||
}
|
||||
|
||||
// Check if the given vals are the expected ones to validate this flag.
|
||||
func (m MCQ) Check(vals map[int64]bool) int {
|
||||
diff := 0
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type myTeamHint struct {
|
|||
}
|
||||
type myTeamMCQ struct {
|
||||
Title string `json:"title"`
|
||||
Justify []int64 `json:"justify,omitempty"`
|
||||
Justify bool `json:"justify,omitempty"`
|
||||
Choices map[int64]string `json:"choices,omitempty"`
|
||||
Solved *time.Time `json:"solved,omitempty"`
|
||||
PSolved map[int64]int `json:"checks_solved,omitempty"`
|
||||
|
|
@ -211,8 +211,6 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
soluce := ""
|
||||
solved_justify := true
|
||||
var nb_gen_justify_id int64
|
||||
var max_justify_id int64
|
||||
|
||||
for _, e := range mcq.Entries {
|
||||
m.Choices[e.Id] = e.Label
|
||||
|
|
@ -222,31 +220,18 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
soluce += "f"
|
||||
}
|
||||
if v, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
if m.Justify == nil {
|
||||
m.Justify = []int64{}
|
||||
}
|
||||
m.Justify = true
|
||||
|
||||
if t == nil {
|
||||
soluce += hex.EncodeToString(v)
|
||||
}
|
||||
|
||||
if v, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; ok {
|
||||
if _, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; ok {
|
||||
solved_justify = false
|
||||
m.Justify = append(m.Justify, v)
|
||||
if v > max_justify_id {
|
||||
max_justify_id = v
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nb_gen_justify_id += 1
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the rest of the array with factice values in order to hide number of valid choices
|
||||
for i := int64(0); i < nb_gen_justify_id; i++ {
|
||||
m.Justify = append(m.Justify, max_justify_id + 1 + i)
|
||||
}
|
||||
|
||||
if t != nil {
|
||||
if solved_justify {
|
||||
m.Solved = t.HasPartiallyRespond(mcq)
|
||||
|
|
|
|||
Reference in a new issue