2022-05-01 20:05:26 +00:00
|
|
|
package fic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"srs.epita.fr/fic-server/settings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ChallengeZQDS struct {
|
2022-05-02 10:08:05 +00:00
|
|
|
ID int64 `json:"id,omitempty"`
|
2022-05-01 20:05:26 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Category string `json:"category"`
|
|
|
|
Points int64 `json:"points"`
|
|
|
|
State string `json:"state"`
|
2022-05-02 10:08:05 +00:00
|
|
|
LockedBy []int64 `json:"locked_by,omitempty"`
|
2022-05-01 20:05:26 +00:00
|
|
|
FirstBloodBonus []float64 `json:"first_blood_bonus,omitempty"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Flags []string `json:"flags,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SessionZQDS struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
2022-05-01 20:33:59 +00:00
|
|
|
Scenario string `json:"scenario,omitempty"`
|
2022-05-01 20:05:26 +00:00
|
|
|
YourMission string `json:"your_mission"`
|
|
|
|
Rules string `json:"rules"`
|
|
|
|
Start time.Time `json:"start"`
|
|
|
|
End time.Time `json:"end"`
|
|
|
|
Challenges []*ChallengeZQDS `json:"challenges"`
|
|
|
|
}
|
|
|
|
|
2022-05-01 20:33:59 +00:00
|
|
|
func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*SessionZQDS, error) {
|
2022-05-01 20:05:26 +00:00
|
|
|
themes, err := GetThemes()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var challenges []*ChallengeZQDS
|
|
|
|
|
|
|
|
for _, th := range themes {
|
|
|
|
exos, err := th.GetExercices()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ex := range exos {
|
2022-05-02 10:08:05 +00:00
|
|
|
state := "visible"
|
|
|
|
lockedby := []int64{}
|
|
|
|
|
|
|
|
if ex.Depend != nil {
|
|
|
|
state = "locked"
|
|
|
|
lockedby = append(lockedby, *ex.Depend)
|
|
|
|
}
|
|
|
|
|
2022-05-01 20:05:26 +00:00
|
|
|
challenges = append(challenges, &ChallengeZQDS{
|
2022-05-02 10:08:05 +00:00
|
|
|
ID: ex.Id,
|
2022-05-01 20:05:26 +00:00
|
|
|
Name: ex.Title,
|
|
|
|
Type: "first_blood",
|
|
|
|
Category: th.Name,
|
|
|
|
Points: ex.Gain,
|
2022-05-02 10:08:05 +00:00
|
|
|
State: state,
|
|
|
|
LockedBy: lockedby,
|
2022-05-01 20:05:26 +00:00
|
|
|
FirstBloodBonus: []float64{
|
|
|
|
float64(ex.Gain) * (1 + s.FirstBlood),
|
|
|
|
},
|
|
|
|
Description: ex.Overview,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &SessionZQDS{
|
2022-05-01 20:33:59 +00:00
|
|
|
Name: c.Title,
|
|
|
|
Description: c.Description,
|
|
|
|
Rules: c.Rules,
|
|
|
|
YourMission: c.YourMission,
|
2022-05-01 20:05:26 +00:00
|
|
|
Start: s.Start,
|
|
|
|
End: s.End,
|
|
|
|
Challenges: challenges,
|
|
|
|
}, nil
|
|
|
|
}
|