implement choices_cost
This commit is contained in:
parent
f9abdd23c6
commit
476f0f553c
18 changed files with 180 additions and 24 deletions
38
backend/choices.go
Normal file
38
backend/choices.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"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.GetFlag(ask.FlagId); err != nil {
|
||||
log.Println("[ERR]", err)
|
||||
} else if err := team.DisplayChoices(flag); err != nil {
|
||||
log.Println("[ERR]", err)
|
||||
} else {
|
||||
if err := genTeamMyFile(team); err != nil {
|
||||
log.Println("my-", team.Id, ".json generation error: ", err)
|
||||
}
|
||||
if err := os.Remove(pathname); err != nil {
|
||||
log.Println("[ERR]", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,6 +169,8 @@ func treat(raw_path string) {
|
|||
treatRename(raw_path, team)
|
||||
case "hint":
|
||||
treatOpeningHint(raw_path, team)
|
||||
case "choices":
|
||||
treatWantChoices(raw_path, team)
|
||||
default:
|
||||
treatSubmission(raw_path, team, spath[2])
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue