Handle optionnal flags
This commit is contained in:
parent
e581630d5e
commit
a414cd22c8
18 changed files with 68 additions and 22 deletions
|
|
@ -735,7 +735,8 @@ type uploadedFlag struct {
|
|||
SortReGroups bool `json:"sort_re_grps"`
|
||||
Flag string
|
||||
Value []byte
|
||||
ChoicesCost int64 `json:"choices_cost"`
|
||||
ChoicesCost int32 `json:"choices_cost"`
|
||||
BonusGain int32 `json:"bonus_gain"`
|
||||
}
|
||||
|
||||
func createExerciceFlag(c *gin.Context) {
|
||||
|
|
@ -758,7 +759,7 @@ func createExerciceFlag(c *gin.Context) {
|
|||
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
|
||||
flag, err := exercice.AddRawFlagKey(uk.Label, uk.Type, uk.Placeholder, uk.IgnoreCase, uk.NoTrim, uk.Multiline, vre, uk.SortReGroups, []byte(uk.Flag), uk.ChoicesCost)
|
||||
flag, err := exercice.AddRawFlagKey(uk.Label, uk.Type, uk.Placeholder, uk.IgnoreCase, uk.NoTrim, uk.Multiline, vre, uk.SortReGroups, []byte(uk.Flag), uk.ChoicesCost, uk.BonusGain)
|
||||
if err != nil {
|
||||
log.Println("Unable to createExerciceFlag:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when trying to create flag."})
|
||||
|
|
@ -839,6 +840,7 @@ func updateExerciceFlag(c *gin.Context) {
|
|||
flag.Checksum = uk.Value
|
||||
}
|
||||
flag.ChoicesCost = uk.ChoicesCost
|
||||
flag.BonusGain = uk.BonusGain
|
||||
|
||||
if uk.ValidatorRe != nil && len(*uk.ValidatorRe) > 0 {
|
||||
flag.ValidatorRegexp = uk.ValidatorRe
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@
|
|||
<div class="col-2">
|
||||
<input type="text" id="kccost{{flag.id}}" ng-model="flag.choices_cost" class="form-control form-control-sm" placeholder="Choices cost" title="Choices cost" integer>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<input type="text" id="kbgain{{flag.id}}" ng-model="flag.bonus_gain" class="form-control form-control-sm" placeholder="Bonus gain" title="Bonus gain" integer>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<input type="text" id="korder{{flag.id}}" ng-model="flag.order" class="form-control form-control-sm" placeholder="Order" title="Order" integer>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<th>Date</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="row in scores | filter: query | orderBy:'time'" ng-class="{'bg-ffound': row.reason == 'First blood', 'bg-wchoices': row.reason == 'Display choices', 'bg-success': row.reason == 'Validation', 'bg-info': row.reason == 'Hint', 'bg-warning': row.reason == 'Tries'}">
|
||||
<tr ng-repeat="row in scores | filter: query | orderBy:'time'" ng-class="{'bg-danger': row.reason == 'Bonus flag', 'bg-ffound': row.reason == 'First blood', 'bg-wchoices': row.reason == 'Display choices', 'bg-success': row.reason == 'Validation', 'bg-info': row.reason == 'Hint', 'bg-warning': row.reason == 'Tries'}">
|
||||
<td>
|
||||
<a ng-repeat="exercice in exercices" ng-if="exercice.id == row.id_exercice" href="exercices/{{ row.id_exercice }}">{{ exercice.title }}</a>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ type ExerciceFlag struct {
|
|||
SortReGroups bool `toml:"sort_validator_regexp_groups,omitempty"`
|
||||
Placeholder string `toml:",omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
ChoicesCost int64 `toml:"choices_cost,omitempty"`
|
||||
BonusGain int32 `toml:"bonus_gain,omitempty"`
|
||||
ChoicesCost int32 `toml:"choices_cost,omitempty"`
|
||||
Choice []ExerciceFlagChoice
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"`
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ func buildKeyFlag(exercice *fic.Exercice, flag ExerciceFlag, flagline int, defau
|
|||
SortReGroups: flag.SortReGroups,
|
||||
Checksum: hashedFlag[:],
|
||||
ChoicesCost: flag.ChoicesCost,
|
||||
BonusGain: flag.BonusGain,
|
||||
})
|
||||
f = &fl
|
||||
|
||||
|
|
|
|||
Reference in a new issue