Change exported flags format in my.json
This commit is contained in:
parent
d6ae1551ba
commit
195490484c
5 changed files with 44 additions and 55 deletions
|
|
@ -264,7 +264,7 @@ 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(cksum []byte, respflags map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
|
||||
func (e Exercice) CheckResponse(cksum []byte, respflags map[int64]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 {
|
||||
|
|
@ -298,7 +298,7 @@ func (e Exercice) CheckResponse(cksum []byte, respflags map[string]string, respm
|
|||
|
||||
// Check flags
|
||||
for _, flag := range flags {
|
||||
if res, ok := respflags[flag.Label]; !ok {
|
||||
if res, ok := respflags[flag.Id]; !ok {
|
||||
valid = false
|
||||
} else if !flag.Check([]byte(res)) {
|
||||
if !PartialValidation || t.HasPartiallySolved(flag) == nil {
|
||||
|
|
|
|||
|
|
@ -27,15 +27,19 @@ type myTeamMCQ struct {
|
|||
Choices map[int64]string `json:"choices,omitempty"`
|
||||
Solved *time.Time `json:"solved,omitempty"`
|
||||
}
|
||||
type myTeamFlag struct {
|
||||
Label string `json:"label"`
|
||||
Solved *time.Time `json:"found,omitempty"`
|
||||
Soluce []byte `json:"soluce,omitempty"`
|
||||
}
|
||||
type myTeamExercice struct {
|
||||
ThemeId int `json:"theme_id"`
|
||||
Statement string `json:"statement"`
|
||||
Hints []myTeamHint `json:"hints,omitempty"`
|
||||
Gain int `json:"gain"`
|
||||
Files []myTeamFile `json:"files,omitempty"`
|
||||
Flags []string `json:"keys,omitempty"`
|
||||
SolvedMat []bool `json:"solved_matrix,omitempty"`
|
||||
MCQs []myTeamMCQ `json:"mcqs,omitempty"`
|
||||
Flags map[int64]myTeamFlag `json:"flags,omitempty"`
|
||||
MCQs map[int64]myTeamMCQ `json:"mcqs,omitempty"`
|
||||
SolveDist int64 `json:"solve_dist,omitempty"`
|
||||
SolvedTime time.Time `json:"solved_time,omitempty"`
|
||||
SolvedRank int64 `json:"solved_rank,omitempty"`
|
||||
|
|
@ -150,28 +154,32 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
// Expose exercice flags
|
||||
|
||||
var justifiedMCQ map[string]bool
|
||||
exercice.Flags = []string{}
|
||||
exercice.Flags = map[int64]myTeamFlag{}
|
||||
|
||||
if flags, err := e.GetFlags(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, k := range flags {
|
||||
var flag myTeamFlag
|
||||
|
||||
if k.Label[0] == '%' {
|
||||
justifiedMCQ[k.Label[1:]] = true
|
||||
continue
|
||||
} else if t == nil {
|
||||
exercice.Flags = append(exercice.Flags, fmt.Sprintf("%x", k.Checksum)+k.Label)
|
||||
} else {
|
||||
exercice.Flags = append(exercice.Flags, k.Label)
|
||||
if PartialValidation {
|
||||
exercice.SolvedMat = append(exercice.SolvedMat, t.HasPartiallySolved(k) != nil)
|
||||
}
|
||||
flag.Soluce = k.Checksum
|
||||
} else if PartialValidation {
|
||||
flag.Solved = t.HasPartiallySolved(k)
|
||||
}
|
||||
|
||||
flag.Label = k.Label
|
||||
|
||||
exercice.Flags[k.Id] = flag
|
||||
}
|
||||
}
|
||||
|
||||
// Expose exercice MCQs
|
||||
|
||||
exercice.MCQs = []myTeamMCQ{}
|
||||
exercice.MCQs = map[int64]myTeamMCQ{}
|
||||
|
||||
if mcqs, err := e.GetMCQ(); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -185,11 +193,14 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
justified = true
|
||||
}
|
||||
}
|
||||
if t == nil {
|
||||
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, justified, choices, nil})
|
||||
} else {
|
||||
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, justified, choices, t.HasPartiallyRespond(mcq)})
|
||||
|
||||
m := myTeamMCQ{mcq.Title, justified, choices, nil}
|
||||
|
||||
if t != nil {
|
||||
m.Solved = t.HasPartiallyRespond(mcq)
|
||||
}
|
||||
|
||||
exercice.MCQs[mcq.Id] = m
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue