zqsd: Update to 2024 revision

This commit is contained in:
nemunaire 2024-03-03 00:23:28 +01:00
parent 177c87eeb7
commit a4fe5bbedd

View file

@ -2,32 +2,45 @@ package fic
import ( import (
"fmt" "fmt"
"time"
"srs.epita.fr/fic-server/settings" "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 { type ChallengeZQDS struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Category string `json:"category"` Category string `json:"category"`
Points int64 `json:"points"` Points int64 `json:"points"`
State string `json:"state"`
LockedBy []int64 `json:"locked_by,omitempty"`
FirstBloodBonus []float64 `json:"first_blood_bonus,omitempty"` FirstBloodBonus []float64 `json:"first_blood_bonus,omitempty"`
Description string `json:"description"` Description string `json:"description"`
Flags []string `json:"flags,omitempty"` Flags []string `json:"flags,omitempty"`
Requirements *ChallengeRequirementsZQDS `json:"requirements,omitempty"`
} }
type SessionZQDS struct { type SessionZQDS struct {
Name string `json:"name"` Name string `json:"name"`
BackgroundURL string `json:"background_url,omitempty"`
Description string `json:"description"` Description string `json:"description"`
Scenario string `json:"scenario,omitempty"` Scenario string `json:"scenario,omitempty"`
YourMission string `json:"your_mission"` YourMission string `json:"your_mission"`
Rules string `json:"rules"` Rules string `json:"rules"`
Start time.Time `json:"start"` Duration string `json:"duration"`
End time.Time `json:"end"` WorkZones []WorkZoneZQDS `json:"work_zones,omitempty"`
Challenges []*ChallengeZQDS `json:"challenges"` Challenges []*ChallengeZQDS `json:"challenges"`
} }
@ -50,26 +63,28 @@ func GenZQDSSessionFile(c *settings.ChallengeInfo, s *settings.Settings) (*Sessi
} }
for _, ex := range exos { for _, ex := range exos {
state := "visible" var requirements *ChallengeRequirementsZQDS
lockedby := []int64{}
if ex.Depend != nil { if ex.Depend != nil {
state = "locked" exdep, err := GetExercice(*ex.Depend)
lockedby = append(lockedby, *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{ challenges = append(challenges, &ChallengeZQDS{
ID: ex.Id,
Name: ex.Title, Name: ex.Title,
Type: "first_blood", Type: "first_blood",
Category: th.Name, Category: th.Name,
Points: ex.Gain, Points: ex.Gain,
State: state,
LockedBy: lockedby,
FirstBloodBonus: []float64{ FirstBloodBonus: []float64{
float64(ex.Gain) * (1 + s.FirstBlood), 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, Description: c.Description,
Rules: c.Rules, Rules: c.Rules,
YourMission: c.YourMission, YourMission: c.YourMission,
Start: s.Start, Duration: fmt.Sprintf("%d:%d:00", c.ExpectedDuration/60, c.ExpectedDuration%60),
End: *s.End,
Challenges: challenges, Challenges: challenges,
}, nil }, nil
} }