package main import ( "encoding/json" "io/ioutil" "log" "os" "srs.epita.fr/fic-server/libfic" ) type wantChoices struct { FlagId int64 `json:"id"` } func treatWantChoices(pathname string, team fic.Team) { var ask wantChoices if cnt_raw, err := ioutil.ReadFile(pathname); err != nil { log.Println("[ERR]", err) } else if err = json.Unmarshal(cnt_raw, &ask); err != nil { log.Println("[ERR]", err) } else if ask.FlagId == 0 { log.Println("[WRN] Invalid content in wantChoices file: ", pathname) os.Remove(pathname) } else if flag, err := fic.GetFlagKey(ask.FlagId); err != nil { log.Println("[ERR]", err) } else if !team.CanSeeFlag(flag) { log.Println("[!!!] The team asks to display choices whereas it doesn't have access to the flag") } else if exercice, err := flag.GetExercice(); err != nil { log.Println("[ERR] Unable to retrieve the flag's underlying exercice:", err) } else if !team.HasAccess(exercice) { log.Println("[!!!] The team asks to display choices whereas it doesn't have access to the exercice") } else if err = team.DisplayChoices(flag); err != nil { log.Println("[ERR]", err) } else { genTeamQueue <- &team if err = os.Remove(pathname); err != nil { log.Println("[ERR]", err) } } }