about summary refs log tree commit diff
path: root/src/challenge.go
blob: 1d0a2107e47c0831b574f03cb991e74fff98431b (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
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
}

// 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"`
}

type StatsStrippedChallenge struct {
	Name string `json:"name"`
	FoundFlag int64 `json:"foundFlag"`
	FlagTries uint `json:"flagTries"`
}

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),
	}
}

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