Theme can be optional: exercices can be standalone
This commit is contained in:
parent
3519f7416d
commit
a0bc832910
8 changed files with 81 additions and 39 deletions
|
|
@ -47,13 +47,19 @@ func treatOpeningHint(pathname string, team *fic.Team) {
|
|||
} else if err = team.OpenHint(hint); err != nil && !fic.DBIsDuplicateKeyError(err) { // Skip DUPLICATE KEY errors
|
||||
log.Printf("%s [ERR] Unable to open hint: %s\n", id, err)
|
||||
} else {
|
||||
// Write event
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Printf("%s [WRN] %s\n", id, err)
|
||||
} else if theme, err := fic.GetTheme(exercice.IdTheme); err != nil {
|
||||
log.Printf("%s [WRN] %s\n", id, err)
|
||||
} else if _, err = fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "info"); err != nil {
|
||||
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
|
||||
if exercice.IdTheme == nil {
|
||||
if _, err = fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le défi %s !", html.EscapeString(team.Name), exercice.Title), "info"); err != nil {
|
||||
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
|
||||
}
|
||||
} else {
|
||||
// Write event
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Printf("%s [WRN] %s\n", id, err)
|
||||
} else if theme, err := fic.GetTheme(*exercice.IdTheme); err != nil {
|
||||
log.Printf("%s [WRN] %s\n", id, err)
|
||||
} else if _, err = fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "info"); err != nil {
|
||||
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
||||
|
|
|
|||
|
|
@ -65,16 +65,19 @@ func treatSubmission(pathname string, team *fic.Team, exercice_id string) {
|
|||
}
|
||||
|
||||
// Find the corresponding theme
|
||||
theme, err := fic.GetTheme(exercice.IdTheme)
|
||||
if err != nil {
|
||||
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, eid, err)
|
||||
return
|
||||
}
|
||||
var theme *fic.Theme
|
||||
if exercice.IdTheme != nil {
|
||||
theme, err = fic.GetTheme(*exercice.IdTheme)
|
||||
if err != nil {
|
||||
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, eid, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Theme should not be locked
|
||||
if theme.Locked {
|
||||
log.Printf("%s [!!!] Submission received for locked theme %d (eid=%d): %s\n", id, exercice.IdTheme, eid, theme.Name)
|
||||
return
|
||||
// Theme should not be locked
|
||||
if theme.Locked {
|
||||
log.Printf("%s [!!!] Submission received for locked theme %d (eid=%d): %s\n", id, exercice.IdTheme, eid, theme.Name)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Read received file
|
||||
|
|
@ -102,7 +105,11 @@ func treatSubmission(pathname string, team *fic.Team, exercice_id string) {
|
|||
// Ensure the team didn't already solve this exercice
|
||||
tm := team.HasSolved(exercice)
|
||||
if tm != nil {
|
||||
log.Printf("%s [WRN] Team %d ALREADY solved exercice %d (%s : %s), continuing for eventual bonus flags\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
if theme == nil {
|
||||
log.Printf("%s [WRN] Team %d ALREADY solved standalone exercice %d (%s), continuing for eventual bonus flags\n", id, team.Id, exercice.Id, exercice.Title)
|
||||
} else {
|
||||
log.Printf("%s [WRN] Team %d ALREADY solved exercice %d (%s : %s), continuing for eventual bonus flags\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle MCQ justifications: convert to expected keyid
|
||||
|
|
@ -141,29 +148,50 @@ func treatSubmission(pathname string, team *fic.Team, exercice_id string) {
|
|||
if tm != nil {
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
||||
} else if solved {
|
||||
log.Printf("%s Team %d SOLVED exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
if theme == nil {
|
||||
log.Printf("%s Team %d SOLVED exercice %d (%s)\n", id, team.Id, exercice.Id, exercice.Title)
|
||||
} else {
|
||||
log.Printf("%s Team %d SOLVED exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
|
||||
}
|
||||
if err := exercice.Solved(team); err != nil {
|
||||
log.Println(id, "[ERR] Unable to mark the challenge as solved:", err)
|
||||
}
|
||||
|
||||
// Write event
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Println(id, "[ERR] Unable to get exercice level:", err)
|
||||
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a résolu le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "success"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
if theme == nil {
|
||||
if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a résolu le défi %s !", html.EscapeString(team.Name), exercice.Title), "success"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
}
|
||||
} else {
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Println(id, "[ERR] Unable to get exercice level:", err)
|
||||
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a résolu le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "success"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
}
|
||||
}
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenThemes})
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeams})
|
||||
} else {
|
||||
log.Printf("%s Team %d submit an invalid solution for exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
if theme == nil {
|
||||
log.Printf("%s Team %d submit an invalid solution for exercice %d (%s : %s)\n", id, team.Id, exercice.Id, theme.Name, exercice.Title)
|
||||
} else {
|
||||
log.Printf("%s Team %d submit an invalid solution for exercice %d (%s)\n", id, team.Id, exercice.Id, exercice.Title)
|
||||
}
|
||||
|
||||
// Write event (only on first try)
|
||||
if tm == nil {
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Println(id, "[ERR] Unable to get exercice level:", err)
|
||||
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s tente le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "warning"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
if theme == nil {
|
||||
if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s tente le défi %s !", html.EscapeString(team.Name), exercice.Title), "warning"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
}
|
||||
} else {
|
||||
if lvl, err := exercice.GetLevel(); err != nil {
|
||||
log.Println(id, "[ERR] Unable to get exercice level:", err)
|
||||
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s tente le <strong>%d<sup>e</sup></strong> défi %s !", html.EscapeString(team.Name), lvl, theme.Name), "warning"); err != nil {
|
||||
log.Println(id, "[WRN] Unable to create event:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
||||
|
|
|
|||
Reference in a new issue