Implement flag type 'text': this is like keys, but on multiple lines
This commit is contained in:
parent
8f998485bb
commit
47ba134b55
9 changed files with 30 additions and 14 deletions
|
|
@ -174,6 +174,7 @@ CREATE TABLE IF NOT EXISTS exercice_flags(
|
|||
type VARCHAR(255) NOT NULL,
|
||||
help VARCHAR(255) NOT NULL,
|
||||
ignorecase BOOLEAN NOT NULL DEFAULT 0,
|
||||
multiline BOOLEAN NOT NULL DEFAULT 0,
|
||||
validator_regexp VARCHAR(255) NULL,
|
||||
cksum BINARY(64) NOT NULL,
|
||||
choices_cost INTEGER NOT NULL,
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ func (f EFile) GetDepends() ([]Flag, error) {
|
|||
if err := rows.Scan(&d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
deps = append(deps, FlagKey{d, f.IdExercice, "", "", false, nil, []byte{}, 0})
|
||||
deps = append(deps, FlagKey{d, f.IdExercice, "", "", false, false, nil, []byte{}, 0})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ type FlagKey struct {
|
|||
Help string `json:"help"`
|
||||
// IgnoreCase indicates if the case is sensitive to case or not
|
||||
IgnoreCase bool `json:"ignorecase"`
|
||||
// Multiline indicates if the flag is stored on multiple lines
|
||||
Multiline bool `json:"multiline"`
|
||||
// ValidatorRegexp extracts a subset of the player's answer, that will be checked.
|
||||
ValidatorRegexp *string `json:"validator_regexp"`
|
||||
// Checksum is the expected hashed flag
|
||||
|
|
@ -31,7 +33,7 @@ type FlagKey struct {
|
|||
|
||||
// GetFlagKeys returns a list of key's flags comming with the challenge.
|
||||
func (e Exercice) GetFlagKeys() ([]FlagKey, error) {
|
||||
if rows, err := DBQuery("SELECT id_flag, id_exercice, type, help, ignorecase, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE id_exercice = ?", e.Id); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_flag, id_exercice, type, help, ignorecase, multiline, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE id_exercice = ?", e.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
|
@ -41,7 +43,7 @@ func (e Exercice) GetFlagKeys() ([]FlagKey, error) {
|
|||
var k FlagKey
|
||||
k.IdExercice = e.Id
|
||||
|
||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost); err != nil {
|
||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.Multiline, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -57,13 +59,13 @@ func (e Exercice) GetFlagKeys() ([]FlagKey, error) {
|
|||
|
||||
// GetFlagKey returns a list of flags comming with the challenge.
|
||||
func GetFlagKey(id int64) (k FlagKey, err error) {
|
||||
err = DBQueryRow("SELECT id_flag, id_exercice, type, help, ignorecase, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE id_flag = ?", id).Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost)
|
||||
err = DBQueryRow("SELECT id_flag, id_exercice, type, help, ignorecase, multiline, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE id_flag = ?", id).Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.Multiline, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost)
|
||||
return
|
||||
}
|
||||
|
||||
// GetFlagKeyByLabel returns a flag matching the given label.
|
||||
func (e Exercice) GetFlagKeyByLabel(label string) (k FlagKey, err error) {
|
||||
err = DBQueryRow("SELECT id_flag, id_exercice, type, help, ignorecase, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE type LIKE ? AND id_exercice = ?", label, e.Id).Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost)
|
||||
err = DBQueryRow("SELECT id_flag, id_exercice, type, help, ignorecase, multiline, validator_regexp, cksum, choices_cost FROM exercice_flags WHERE type LIKE ? AND id_exercice = ?", label, e.Id).Scan(&k.Id, &k.IdExercice, &k.Label, &k.Help, &k.IgnoreCase, &k.Multiline, &k.ValidatorRegexp, &k.Checksum, &k.ChoicesCost)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +105,7 @@ func ExecValidatorRegexp(vre string, val []byte, ignorecase bool) ([]byte, error
|
|||
}
|
||||
|
||||
// AddRawFlagKey creates and fills a new struct FlagKey, from a non-hashed flag, and registers it into the database.
|
||||
func (e Exercice) AddRawFlagKey(name string, help string, ignorecase bool, validator_regexp *string, raw_value []byte, choicescost int64) (f FlagKey, err error) {
|
||||
func (e Exercice) AddRawFlagKey(name string, help string, ignorecase bool, multiline bool, validator_regexp *string, raw_value []byte, choicescost int64) (f FlagKey, err error) {
|
||||
hash, errr := ComputeHashedFlag(raw_value, ignorecase, validator_regexp)
|
||||
if errr != nil {
|
||||
return f, err
|
||||
|
|
@ -113,6 +115,7 @@ func (e Exercice) AddRawFlagKey(name string, help string, ignorecase bool, valid
|
|||
Label: name,
|
||||
Help: help,
|
||||
IgnoreCase: ignorecase,
|
||||
Multiline: multiline,
|
||||
ValidatorRegexp: validator_regexp,
|
||||
Checksum: hash[:],
|
||||
ChoicesCost: choicescost,
|
||||
|
|
@ -145,7 +148,7 @@ func (k FlagKey) Create(e Exercice) (Flag, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if res, err := DBExec("INSERT INTO exercice_flags (id_exercice, type, help, ignorecase, validator_regexp, cksum, choices_cost) VALUES (?, ?, ?, ?, ?, ?, ?)", e.Id, k.Label, k.Help, k.IgnoreCase, k.ValidatorRegexp, k.Checksum, k.ChoicesCost); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercice_flags (id_exercice, type, help, ignorecase, multiline, validator_regexp, cksum, choices_cost) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", e.Id, k.Label, k.Help, k.IgnoreCase, k.Multiline, k.ValidatorRegexp, k.Checksum, k.ChoicesCost); err != nil {
|
||||
return k, err
|
||||
} else if kid, err := res.LastInsertId(); err != nil {
|
||||
return k, err
|
||||
|
|
@ -170,7 +173,7 @@ func (k FlagKey) Update() (int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if res, err := DBExec("UPDATE exercice_flags SET id_exercice = ?, type = ?, help = ?, ignorecase = ?, validator_regexp = ?, cksum = ?, choices_cost = ? WHERE id_flag = ?", k.IdExercice, k.Label, k.Help, k.IgnoreCase, k.ValidatorRegexp, k.Checksum, k.ChoicesCost, k.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercice_flags SET id_exercice = ?, type = ?, help = ?, ignorecase = ?, multiline = ?, validator_regexp = ?, cksum = ?, choices_cost = ? WHERE id_flag = ?", k.IdExercice, k.Label, k.Help, k.IgnoreCase, k.Multiline, k.ValidatorRegexp, k.Checksum, k.ChoicesCost, k.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ type myTeamFlag struct {
|
|||
NbLines uint64 `json:"nb_lines,omitempty"`
|
||||
IgnoreOrder bool `json:"ignore_order,omitempty"`
|
||||
IgnoreCase bool `json:"ignore_case,omitempty"`
|
||||
Multiline bool `json:"multiline,omitempty"`
|
||||
ValidatorRe *string `json:"validator_regexp,omitempty"`
|
||||
Solved *time.Time `json:"found,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
|
|
@ -201,6 +202,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
flag.Solved = t.HasPartiallySolved(k)
|
||||
}
|
||||
|
||||
flag.Multiline = k.Multiline
|
||||
|
||||
var fl FlagLabel
|
||||
if fl, err = k.GetMCQJustification(); err == nil {
|
||||
k.Label = fl.Label
|
||||
|
|
|
|||
Reference in a new issue