checker: Refactor + ensure theme is not disabled
This commit is contained in:
parent
b9ded53920
commit
6e5fd70156
@ -25,29 +25,73 @@ func treatWantChoices(pathname string, team *fic.Team) {
|
|||||||
|
|
||||||
var ask wantChoices
|
var ask wantChoices
|
||||||
|
|
||||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
cnt_raw, err := ioutil.ReadFile(pathname)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
} else if err = json.Unmarshal(cnt_raw, &ask); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(cnt_raw, &ask)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
} else if ask.FlagId == 0 {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ask.FlagId == 0 {
|
||||||
log.Printf("%s [WRN] Invalid content in wantChoices file: %s\n", id, pathname)
|
log.Printf("%s [WRN] Invalid content in wantChoices file: %s\n", id, pathname)
|
||||||
os.Remove(pathname)
|
os.Remove(pathname)
|
||||||
} else if flag, err := fic.GetFlagKey(ask.FlagId); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
flag, err := fic.GetFlagKey(ask.FlagId)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
} else if !team.CanSeeFlag(flag) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !team.CanSeeFlag(flag) {
|
||||||
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the flag\n", id)
|
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the flag\n", id)
|
||||||
} else if exercice, err := flag.GetExercice(); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exercice, err := flag.GetExercice()
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] Unable to retrieve the flag's underlying exercice: %s\n", id, err)
|
log.Printf("%s [ERR] Unable to retrieve the flag's underlying exercice: %s\n", id, err)
|
||||||
} else if !team.HasAccess(exercice) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !team.HasAccess(exercice) {
|
||||||
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the exercice\n", id)
|
log.Printf("%s [!!!] The team asks to display choices whereas it doesn't have access to the exercice\n", id)
|
||||||
} else if exercice.Disabled {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if exercice.Disabled {
|
||||||
log.Println("[!!!] The team submits something for a disabled exercice")
|
log.Println("[!!!] The team submits something for a disabled exercice")
|
||||||
} else if err = team.DisplayChoices(flag); err != nil {
|
return
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
}
|
||||||
} else {
|
|
||||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
if exercice.IdTheme != nil {
|
||||||
if err = os.Remove(pathname); err != nil {
|
theme, err := fic.GetTheme(*exercice.IdTheme)
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
if err != nil {
|
||||||
|
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, exercice.Id, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theme should not be locked
|
||||||
|
if theme.Locked {
|
||||||
|
log.Printf("%s [!!!] Want choice received for locked theme %d (fid=%d): %s\n", id, exercice.IdTheme, ask.FlagId, theme.Name)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = team.DisplayChoices(flag)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenTeam, TeamId: team.Id})
|
||||||
|
if err = os.Remove(pathname); err != nil {
|
||||||
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,45 +27,88 @@ func treatOpeningHint(pathname string, team *fic.Team) {
|
|||||||
|
|
||||||
var ask askOpenHint
|
var ask askOpenHint
|
||||||
|
|
||||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
cnt_raw, err := ioutil.ReadFile(pathname)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
} else if err = json.Unmarshal(cnt_raw, &ask); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(cnt_raw, &ask)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
} else if ask.HintId == 0 {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ask.HintId == 0 {
|
||||||
log.Printf("%s [WRN] Invalid content in hint file: %s\n", id, pathname)
|
log.Printf("%s [WRN] Invalid content in hint file: %s\n", id, pathname)
|
||||||
os.Remove(pathname)
|
os.Remove(pathname)
|
||||||
} else if hint, err := fic.GetHint(ask.HintId); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hint, err := fic.GetHint(ask.HintId)
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] Unable to retrieve the given hint: %s\n", id, err)
|
log.Printf("%s [ERR] Unable to retrieve the given hint: %s\n", id, err)
|
||||||
} else if exercice, err := hint.GetExercice(); err != nil {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exercice, err := hint.GetExercice()
|
||||||
|
if err != nil {
|
||||||
log.Printf("%s [ERR] Unable to retrieve the hint's underlying exercice: %s\n", id, err)
|
log.Printf("%s [ERR] Unable to retrieve the hint's underlying exercice: %s\n", id, err)
|
||||||
} else if exercice.Disabled {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if exercice.Disabled {
|
||||||
log.Println("[!!!] The team submits something for a disabled exercice")
|
log.Println("[!!!] The team submits something for a disabled exercice")
|
||||||
} else if !team.HasAccess(exercice) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !team.HasAccess(exercice) {
|
||||||
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to the exercice\n", id)
|
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to the exercice\n", id)
|
||||||
} else if !team.CanSeeHint(hint) {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !team.CanSeeHint(hint) {
|
||||||
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to it due to hint dependencies\n", id)
|
log.Printf("%s [!!!] The team asks to open an hint whereas it doesn't have access to it due to hint dependencies\n", id)
|
||||||
} else if err = team.OpenHint(hint); err != nil && !fic.DBIsDuplicateKeyError(err) { // Skip DUPLICATE KEY errors
|
return
|
||||||
log.Printf("%s [ERR] Unable to open hint: %s\n", id, err)
|
}
|
||||||
} else {
|
|
||||||
if exercice.IdTheme == nil {
|
// Find the corresponding theme
|
||||||
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 {
|
var theme *fic.Theme
|
||||||
log.Printf("%s [WRN] Unable to create event: %s\n", id, err)
|
if exercice.IdTheme != nil {
|
||||||
}
|
theme, err = fic.GetTheme(*exercice.IdTheme)
|
||||||
} else {
|
if err != nil {
|
||||||
// Write event
|
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, exercice.Id, err)
|
||||||
if lvl, err := exercice.GetLevel(); err != nil {
|
return
|
||||||
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})
|
// Theme should not be locked
|
||||||
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenEvents})
|
if theme.Locked {
|
||||||
if err = os.Remove(pathname); err != nil {
|
log.Printf("%s [!!!] Open hint received for locked theme %d (hid=%d): %s\n", id, exercice.IdTheme, ask.HintId, theme.Name)
|
||||||
log.Printf("%s [ERR] %s\n", id, err)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if theme == 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 _, 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})
|
||||||
|
appendGenQueue(fic.GenStruct{Id: id, Type: fic.GenEvents})
|
||||||
|
if err = os.Remove(pathname); err != nil {
|
||||||
|
log.Printf("%s [ERR] %s\n", id, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user