diff --git a/libfic/zqsd.go b/libfic/zqsd.go index 0fe73815..e585aaf1 100644 --- a/libfic/zqsd.go +++ b/libfic/zqsd.go @@ -2,33 +2,46 @@ package fic import ( "fmt" - "time" "srs.epita.fr/fic-server/settings" ) +type WorkZoneRoleZQDS struct { + Name string `json:"name"` + Accesses []interface{} `json:"acceses"` +} + +type WorkZoneZQDS struct { + Name string `json:"name"` + Duplicable bool `json:"duplicable"` + Roles []WorkZoneRoleZQDS `json:"roles"` +} + +type ChallengeRequirementsZQDS struct { + Challenges []string `json:"challenges"` +} + type ChallengeZQDS struct { - ID int64 `json:"id,omitempty"` - Name string `json:"name"` - Type string `json:"type,omitempty"` - Category string `json:"category"` - Points int64 `json:"points"` - State string `json:"state"` - LockedBy []int64 `json:"locked_by,omitempty"` - FirstBloodBonus []float64 `json:"first_blood_bonus,omitempty"` - Description string `json:"description"` - Flags []string `json:"flags,omitempty"` + Name string `json:"name"` + Type string `json:"type,omitempty"` + Category string `json:"category"` + Points int64 `json:"points"` + FirstBloodBonus []float64 `json:"first_blood_bonus,omitempty"` + Description string `json:"description"` + Flags []string `json:"flags,omitempty"` + Requirements *ChallengeRequirementsZQDS `json:"requirements,omitempty"` } type SessionZQDS struct { - Name string `json:"name"` - Description string `json:"description"` - Scenario string `json:"scenario,omitempty"` - YourMission string `json:"your_mission"` - Rules string `json:"rules"` - Start time.Time `json:"start"` - End time.Time `json:"end"` - Challenges []*ChallengeZQDS `json:"challenges"` + Name string `json:"name"` + BackgroundURL string `json:"background_url,omitempty"` + Description string `json:"description"` + Scenario string `json:"scenario,omitempty"` + YourMission string `json:"your_mission"` + Rules string `json:"rules"` + Duration string `json:"duration"` + WorkZones []WorkZoneZQDS `json:"work_zones,omitempty"` + Challenges []*ChallengeZQDS `json:"challenges"` } func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*SessionZQDS, error) { @@ -50,26 +63,28 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi } for _, ex := range exos { - state := "visible" - lockedby := []int64{} + var requirements *ChallengeRequirementsZQDS if ex.Depend != nil { - state = "locked" - lockedby = append(lockedby, *ex.Depend) + exdep, err := GetExercice(*ex.Depend) + if err != nil { + return nil, fmt.Errorf("unable to find dependancy: %w", err) + } + + requirements = &ChallengeRequirementsZQDS{} + requirements.Challenges = append(requirements.Challenges, exdep.Title) } challenges = append(challenges, &ChallengeZQDS{ - ID: ex.Id, Name: ex.Title, Type: "first_blood", Category: th.Name, Points: ex.Gain, - State: state, - LockedBy: lockedby, FirstBloodBonus: []float64{ float64(ex.Gain) * (1 + s.FirstBlood), }, - Description: ex.Overview, + Description: ex.Overview, + Requirements: requirements, }) } } @@ -79,8 +94,7 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi Description: c.Description, Rules: c.Rules, YourMission: c.YourMission, - Start: s.Start, - End: *s.End, + Duration: fmt.Sprintf("%d:%d:00", c.ExpectedDuration/60, c.ExpectedDuration%60), Challenges: challenges, }, nil }