Refactor flags
Both QCM and Key are Flag
This commit is contained in:
parent
e029ec5414
commit
a66d6885e7
13 changed files with 318 additions and 249 deletions
|
@ -179,14 +179,14 @@ func (t Team) OpenHint(h EHint) (error) {
|
|||
}
|
||||
|
||||
// SeeChoices checks if the Team has revealed the given choices.
|
||||
func (t Team) SeeChoices(k Flag) (bool) {
|
||||
func (t Team) SeeChoices(k FlagKey) (bool) {
|
||||
var tm *time.Time
|
||||
DBQueryRow("SELECT MIN(time) FROM team_wchoices WHERE id_team = ? AND id_flag = ?", t.Id, k.Id).Scan(&tm)
|
||||
return tm != nil
|
||||
}
|
||||
|
||||
// DisplayChoices registers to the database that the Team has now revealed.
|
||||
func (t Team) DisplayChoices(k Flag) (error) {
|
||||
func (t Team) DisplayChoices(k FlagKey) (error) {
|
||||
_, err := DBExec("INSERT INTO team_wchoices (id_team, id_flag, time) VALUES (?, ?, ?)", t.Id, k.Id, time.Now())
|
||||
return err
|
||||
}
|
||||
|
@ -248,12 +248,12 @@ func (t Team) GetSolvedRank(e Exercice) (nb int64, err error) {
|
|||
|
||||
// HasPartiallySolved checks if the Team already has unlocked the given flag and returns the validation's timestamp.
|
||||
func (t Team) HasPartiallySolved(f Flag) (tm *time.Time) {
|
||||
DBQueryRow("SELECT MIN(time) FROM flag_found WHERE id_team = ? AND id_flag = ?", t.Id, f.Id).Scan(&tm)
|
||||
return
|
||||
}
|
||||
|
||||
// HasPartiallyRespond checks if the Team already has unlocked the given MCQ and returns the validation's timestamp.
|
||||
func (t Team) HasPartiallyRespond(m MCQ) (tm *time.Time) {
|
||||
DBQueryRow("SELECT MIN(time) FROM mcq_found WHERE id_team = ? AND id_mcq = ?", t.Id, m.Id).Scan(&tm)
|
||||
if k, ok := f.(FlagKey); ok {
|
||||
DBQueryRow("SELECT MIN(time) FROM flag_found WHERE id_team = ? AND id_flag = ?", t.Id, k.Id).Scan(&tm)
|
||||
} else if m, ok := f.(MCQ); ok {
|
||||
DBQueryRow("SELECT MIN(time) FROM mcq_found WHERE id_team = ? AND id_mcq = ?", t.Id, m.Id).Scan(&tm)
|
||||
} else {
|
||||
log.Fatal("Unknown flag type")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Reference in a new issue