diff options
author | maride <maride@darknebu.la> | 2019-10-11 14:29:01 +0200 |
---|---|---|
committer | maride <maride@darknebu.la> | 2019-10-11 14:29:01 +0200 |
commit | 92d20710d7cbad0781d04d45ee859a1d66b30b0d (patch) | |
tree | 4361cdc19a54d6026aefc3dff3b8ea5aa2002cc4 | |
parent | 8cb39e5fea15b6401a9a0e9229a8d86c0c3d1601 (diff) |
Add points per challenge and overall scoring
-rw-r--r-- | README.md | 26 | ||||
-rw-r--r-- | hosted/challenges.html | 3 | ||||
-rw-r--r-- | src/challenge.go | 5 | ||||
-rw-r--r-- | src/seed.go | 17 |
4 files changed, 36 insertions, 15 deletions
diff --git a/README.md b/README.md index 61b41ac..4bc8643 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,19 @@ The seed file should be of the following format: ``` { - "challenges": [ - { - "name": "Evil Service", - "description": "A meaningful and funny description", - "flag": "CIRCUS[IS_REALLY_COOL]", - "container": "challenge-evilservice", - "category": "Miscellaneous" - }, - { - "name": "Insecure Stuff", - [...] - ] + "challenges": [ + { + "name": "Evil Service", + "description": "A meaningful and funny description", + "flag": "CIRCUS[IS_REALLY_COOL]", + "container": "challenge-evilservice", + "category": "Miscellaneous", + "points": 100 + }, + { + "name": "Insecure Stuff", + [...] + ] } ``` @@ -76,6 +77,7 @@ The seed file should be of the following format: "name": "ChallengeName", "description": "Some meaningful, interesting and funny description", "category": "Miscellaneous", + "points": 100, "foundFlag": false, // whether the user found the flag "ContainsLaunchable": true, // if set to true: there's a container which can be started/stopped "IPAddress": "1.2.3.4" // contains the IP address if the container is running diff --git a/hosted/challenges.html b/hosted/challenges.html index e899048..6267ab7 100644 --- a/hosted/challenges.html +++ b/hosted/challenges.html @@ -38,6 +38,9 @@ <span class="badge badge-light"> {{ category }} </span> + <span class="badge {{#if foundFlag}}badge-success{{else}}badge-secondary{{/if}}"> + {{ points }} Points + </span> </div> <div class="card-body"> <p> diff --git a/src/challenge.go b/src/challenge.go index 1d0a210..3fb26d7 100644 --- a/src/challenge.go +++ b/src/challenge.go @@ -10,6 +10,7 @@ type Challenge struct { FlagTries uint Container string // this could, but is not required as well Category string + Points int } // TODO: The name "Stripped" is a bit inaccurate now. Rename. @@ -21,12 +22,14 @@ type StrippedChallenge struct { FlagTries uint `json:"flagTries"` ContainsLaunchable bool `json:"ContainsLaunchable"` IPAddress string `json:"IPAddress"` + Points int `json:"points"` } type StatsStrippedChallenge struct { Name string `json:"name"` FoundFlag int64 `json:"foundFlag"` FlagTries uint `json:"flagTries"` + Points int `json:"points"` } func stripChallenge(c Challenge) (StrippedChallenge) { @@ -38,6 +41,7 @@ func stripChallenge(c Challenge) (StrippedChallenge) { FlagTries: c.FlagTries, ContainsLaunchable: c.Container != "", IPAddress: getAddressForChallengeContainer(c.Container), + Points: c.Points, } } @@ -46,5 +50,6 @@ func stripChallengeForStatistics(c Challenge) (StatsStrippedChallenge) { Name: c.Name, FoundFlag: c.FoundFlag.Unix(), FlagTries: c.FlagTries, + Points: c.Points, } } diff --git a/src/seed.go b/src/seed.go index 805ab20..d876940 100644 --- a/src/seed.go +++ b/src/seed.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "log" + "strconv" "time" "github.com/pkg/errors" @@ -51,8 +52,10 @@ func readSeedFile(path string) ([]Challenge, error) { flag, flagOK := challenge["flag"].(string) cont, contOK := challenge["container"].(string) category, categoryOK := challenge["category"].(string) + pointsStr, pointsOK := challenge["points"].(string) + points, _ := strconv.Atoi(pointsStr) - if nameOK && descOK && flagOK && contOK && categoryOK { + if nameOK && descOK && flagOK && contOK && categoryOK && pointsOK { tmpChallenges = append(tmpChallenges, Challenge{ Name: name, Description: desc, @@ -61,9 +64,10 @@ func readSeedFile(path string) ([]Challenge, error) { FlagTries: 0, Container: cont, Category: category, + Points: points, }) } else { - log.Printf("Ignoring challenge at position %d: Not all values are parseable (name: %b, desc: %b, flag: %b, container: %b, category: %b", index, nameOK, descOK, flagOK, contOK, categoryOK) + log.Printf("Ignoring challenge at position %d: Not all values are parseable (name: %b, desc: %b, flag: %b, container: %b, category: %b, points: %b", index, nameOK, descOK, flagOK, contOK, categoryOK, pointsOK) } } @@ -116,18 +120,25 @@ func generateJSONFromChallenges() (string, error) { func generateJSONFromChallengesForStats() (string, error) { // To include only required information for statistics, we need to strip the challenge var strippedChallenges []StatsStrippedChallenge + score := 0 categories := map[string]int{} for _, challenge := range challenges { // Append challenge to list strippedChallenges = append(strippedChallenges, stripChallengeForStatistics(challenge)) - + // Raise category counter categories[challenge.Category]++ + + // Raise score if flag was found + if challenge.FoundFlag.Unix() > 0 { + score = score + challenge.Points + } } marshalled, marshalError := json.Marshal(map[string]interface{}{ "user": user, "challenges": strippedChallenges, + "score": score, }) return string(marshalled), marshalError } |