about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-10-11 14:23:30 +0200
committerEmile <hanemile@protonmail.com>2019-10-11 14:23:30 +0200
commitf590b4cc106db53cab22832b5f4a6089d1d0f420 (patch)
tree6297cfdf5f8956ac2a016019ed90a0da42e98e48 /src
parentd03f2e1d0d1c1f3f09047f5e17cad24119bfd4d2 (diff)
expose user score
Diffstat (limited to 'src')
-rw-r--r--src/docker.go18
-rw-r--r--src/http.go6
2 files changed, 10 insertions, 14 deletions
diff --git a/src/docker.go b/src/docker.go
index 236580f..79cf67d 100644
--- a/src/docker.go
+++ b/src/docker.go
@@ -23,7 +23,7 @@ var (
 	dockerCLI *client.Client
 
 	// store the amount of flags each user has found
-	userFlags map[string]int
+	userScore map[string]int
 	users     []string // list of users
 )
 
@@ -34,7 +34,8 @@ type Statistics struct {
 		FoundFlag int64  `json:"foundFlag"`
 		FlagTries uint   `json:"flagTries"`
 	} `json:"challenges"`
-	User string `json:"user"`
+	User  string `json:"user"`
+	Score int    `json:"score"`
 }
 
 func setupContext() {
@@ -135,17 +136,12 @@ func listDockerContainers() {
 				users = append(users, statsGoStruct.User)
 			}
 
-			if userFlags == nil {
-				userFlags = make(map[string]int)
+			if userScore == nil {
+				userScore = make(map[string]int)
 			}
 
-			// count the amount of flags each user has found
-			userFlags[statsGoStruct.User] = 0
-			for _, chall := range statsGoStruct.Challenges {
-				if chall.FoundFlag > 1 {
-					userFlags[statsGoStruct.User]++
-				}
-			}
+			// update the score if the individual user
+			userScore[statsGoStruct.User] = statsGoStruct.Score
 		}
 	}
 }
diff --git a/src/http.go b/src/http.go
index a08845e..72815b5 100644
--- a/src/http.go
+++ b/src/http.go
@@ -27,15 +27,15 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
 
 // metricsHandler handles the "/metrics" endpoint
 func metricsHandler(w http.ResponseWriter, r *http.Request) {
-	if userFlags == nil {
-		userFlags = make(map[string]int)
+	if userScore == nil {
+		userScore = make(map[string]int)
 	}
 
 	fmt.Fprintf(w, "%s\n", "scoreboard_up 1")
 
 	for _, user := range users {
 		if user != "" {
-			fmt.Fprintf(w, "challengesSolves{name=\"%s\"} %d\n", user, userFlags[user])
+			fmt.Fprintf(w, "score{name=\"%s\"} %d\n", user, userScore[user])
 		}
 	}
 }