about summary refs log tree commit diff
path: root/src/challenge.go
blob: 3fb26d78930f5e9d96857e2aa11ee4df3eb92a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main

import "time"

type Challenge struct {
	Name string
	Description string
	Flag string // this should never leave the server
	FoundFlag time.Time
	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.
type StrippedChallenge struct {
	Name string `json:"name"`
	Description string `json:"description"`
	Category string `json:"category"`
	FoundFlag int64 `json:"foundFlag"`
	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) {
	return StrippedChallenge{
		Name: c.Name,
		Description: c.Description,
		Category: c.Category,
		FoundFlag: c.FoundFlag.Unix(),
		FlagTries: c.FlagTries,
		ContainsLaunchable: c.Container != "",
		IPAddress: getAddressForChallengeContainer(c.Container),
		Points: c.Points,
	}
}

func stripChallengeForStatistics(c Challenge) (StatsStrippedChallenge) {
	return StatsStrippedChallenge{
		Name: c.Name,
		FoundFlag: c.FoundFlag.Unix(),
		FlagTries: c.FlagTries,
		Points: c.Points,
	}
}