Skip to content

Commit 991337f

Browse files
committed
update: Container service logic
1 parent dce0428 commit 991337f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

server/router/api/v1/container_service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func CreateChallengeContainer(c echo.Context) error {
5050
return Failed(&c, "You are not in a team.")
5151
}
5252

53+
if challenge.IsSolvedBy(team, ctx.Store) {
54+
return Failed(&c, "You have solved this challenge.")
55+
}
56+
5357
flag := fmt.Sprintf("%s{%s}", challenge.Game.FlagPrefix, util.GenerateFlagContent(challenge.FlagFormat, user.UUID))
5458

5559
if !ctx.Store.CanCreateContainer(user) {

store/challenge.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ func (c *Challenge) Expired() bool {
137137
func (c *Challenge) Ongoing() bool {
138138
return c.StartTime == 0 || c.StartTime < time.Now().UnixMilli() && !c.Expired()
139139
}
140+
141+
func (c *Challenge) IsSolvedBy(team *Team, s *Store) bool {
142+
var count int64
143+
s.db.Model(Flag{}).Where("team_id = ? AND challenge_id = ? AND state >= 1", team.ID, c.ID).Count(&count)
144+
return count > 0
145+
}

0 commit comments

Comments
 (0)