diff --git a/src/handlers.go b/src/handlers.go index 69d0729..00eca05 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -106,7 +106,7 @@ func (ctx *Instance) answerHandler(w http.ResponseWriter, req *http.Request) { pointstr := req.FormValue("points") answer := req.FormValue("answer") - if ! ctx.ValidTeamId(teamId) { + if !ctx.ValidTeamId(teamId) { respond( w, req, JSendFail, "Invalid team ID", @@ -251,7 +251,7 @@ func (ctx *Instance) staticHandler(w http.ResponseWriter, req *http.Request) { } func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) { - if (! ctx.Runtime.export_manifest) { + if !ctx.Runtime.export_manifest { http.Error(w, "Endpoint disabled", http.StatusForbidden) return } @@ -262,7 +262,7 @@ func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) { return } - if (req.Method == http.MethodHead) { + if req.Method == http.MethodHead { w.WriteHeader(http.StatusOK) return } @@ -273,13 +273,13 @@ func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) { // Pack up the theme files theme_root_re := regexp.MustCompile(fmt.Sprintf("^%s/", ctx.ThemeDir)) - filepath.Walk(ctx.ThemeDir, func (path string, info os.FileInfo, err error) error { + filepath.Walk(ctx.ThemeDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } - if ! info.IsDir() { // Only package up files - localized_path := theme_root_re.ReplaceAllLiteralString( path, "") + if !info.IsDir() { // Only package up files + localized_path := theme_root_re.ReplaceAllLiteralString(path, "") manifest = append(manifest, localized_path) } return nil @@ -287,13 +287,13 @@ func (ctx *Instance) manifestHandler(w http.ResponseWriter, req *http.Request) { // Package up files for currently-unlocked puzzles in categories for category_name, category := range ctx.categories { - if _, ok := ctx.MaxPointsUnlocked[category_name]; ok { // Check that the category is actually unlocked. This should never fail, probably + if _, ok := ctx.MaxPointsUnlocked[category_name]; ok { // Check that the category is actually unlocked. This should never fail, probably for _, file := range category.zf.File { parts := strings.Split(file.Name, "/") - if (parts[0] == "content") { // Only pick up content files, not thing like map.txt - for _, puzzlemap := range category.puzzlemap { // Figure out which puzzles are currently unlocked - if (puzzlemap.Path == parts[1] && puzzlemap.Points <= ctx.MaxPointsUnlocked[category_name]) { + if parts[0] == "content" { // Only pick up content files, not thing like map.txt + for _, puzzlemap := range category.puzzlemap { // Figure out which puzzles are currently unlocked + if puzzlemap.Path == parts[1] && puzzlemap.Points <= ctx.MaxPointsUnlocked[category_name] { manifest = append(manifest, path.Join("content", category_name, path.Join(parts[1:]...))) break diff --git a/src/instance.go b/src/instance.go index fc7112b..a415b40 100644 --- a/src/instance.go +++ b/src/instance.go @@ -26,16 +26,16 @@ type Instance struct { ThemeDir string AttemptInterval time.Duration - Runtime RuntimeConfig + Runtime RuntimeConfig - categories map[string]*Mothball - MaxPointsUnlocked map[string]int - update chan bool - jPuzzleList []byte - jPointsLog []byte - nextAttempt map[string]time.Time - nextAttemptMutex *sync.RWMutex - mux *http.ServeMux + categories map[string]*Mothball + MaxPointsUnlocked map[string]int + update chan bool + jPuzzleList []byte + jPointsLog []byte + nextAttempt map[string]time.Time + nextAttemptMutex *sync.RWMutex + mux *http.ServeMux } func (ctx *Instance) Initialize() error { @@ -139,15 +139,15 @@ func (ctx *Instance) ThemePath(parts ...string) string { func (ctx *Instance) TooFast(teamId string) bool { now := time.Now() - + ctx.nextAttemptMutex.RLock() next, _ := ctx.nextAttempt[teamId] ctx.nextAttemptMutex.RUnlock() - + ctx.nextAttemptMutex.Lock() ctx.nextAttempt[teamId] = now.Add(ctx.AttemptInterval) ctx.nextAttemptMutex.Unlock() - + return now.Before(next) } diff --git a/src/maintenance.go b/src/maintenance.go index c5b64bb..87f35dc 100644 --- a/src/maintenance.go +++ b/src/maintenance.go @@ -12,7 +12,6 @@ import ( "time" ) - func (pm *PuzzleMap) MarshalJSON() ([]byte, error) { if pm == nil { return []byte("null"), nil @@ -35,7 +34,6 @@ func (ctx *Instance) generatePuzzleList() { } } - ret := map[string][]PuzzleMap{} for catName, mb := range ctx.categories { filtered_puzzlemap := make([]PuzzleMap, 0, 30) @@ -273,11 +271,11 @@ func (ctx *Instance) isEnabled() bool { func (ctx *Instance) UpdateConfig() { // Handle export manifest if _, err := os.Stat(ctx.StatePath("export_manifest")); err == nil { - if (! ctx.Runtime.export_manifest) { + if !ctx.Runtime.export_manifest { log.Print("Enabling manifest export") ctx.Runtime.export_manifest = true } - } else if (ctx.Runtime.export_manifest) { + } else if ctx.Runtime.export_manifest { log.Print("Disabling manifest export") ctx.Runtime.export_manifest = false } diff --git a/src/mothball.go b/src/mothball.go index 42ba7f9..c59c195 100644 --- a/src/mothball.go +++ b/src/mothball.go @@ -13,16 +13,15 @@ import ( ) type PuzzleMap struct { - Points int - Path string + Points int + Path string } - type Mothball struct { - zf *zip.ReadCloser - filename string - puzzlemap []PuzzleMap - mtime time.Time + zf *zip.ReadCloser + filename string + puzzlemap []PuzzleMap + mtime time.Time } type MothballFile struct { @@ -161,7 +160,7 @@ func (m *Mothball) Refresh() error { mf, err := m.Open("map.txt") if err != nil { - // File isn't in there + // File isn't in there } else { defer mf.Close() @@ -183,11 +182,10 @@ func (m *Mothball) Refresh() error { pm = append(pm, PuzzleMap{pointval, dir}) - } - - m.puzzlemap = pm - } + } + m.puzzlemap = pm + } return nil }