diff --git a/src/LegacyMOTHState.go b/src/LegacyMOTHState.go index 6b419b4..a84abf4 100644 --- a/src/LegacyMOTHState.go +++ b/src/LegacyMOTHState.go @@ -33,7 +33,7 @@ func (state *LegacyMOTHState) Initialize() (bool, error) { } func (state *LegacyMOTHState) login(teamName string, token string) (bool, error) { - for a, _ := range state.getTeamIds() { + for a, _ := range state.getValidTeamIds() { if a == token { f, err := os.OpenFile(state.StatePath("teams", token), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) if err != nil { @@ -181,7 +181,7 @@ func (state *LegacyMOTHState) Maintenance(maintenanceInterval time.Duration) { } } -func (state *LegacyMOTHState) getTeamIds() map[string]struct{} { +func (state *LegacyMOTHState) getValidTeamIds() map[string]struct{} { filepath := state.StatePath("teamids.txt") teamids, err := os.Open(filepath) teams := make(map[string]struct{}) diff --git a/src/handlers.go b/src/handlers.go index af7b2ef..c873bb9 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -161,6 +161,7 @@ func (ctx *Instance) answerHandler(w http.ResponseWriter, req *http.Request) { "Points awarded", fmt.Sprintf("%d points for %s!", points, teamId), ) + ctx.update <- true } func (ctx *Instance) puzzlesHandler(w http.ResponseWriter, req *http.Request) { diff --git a/src/maintenance.go b/src/maintenance.go index fcd2c54..d5327ac 100644 --- a/src/maintenance.go +++ b/src/maintenance.go @@ -146,7 +146,7 @@ func (ctx *Instance) tidy() { // readTeams reads in the list of team IDs, // so we can quickly validate them. func (ctx *Instance) readTeams() { - teamList := ctx.State.getTeamIds() + teamList := ctx.State.getValidTeamIds() // For any new team IDs, set their next attempt time to right now now := time.Now() @@ -207,7 +207,7 @@ func (ctx *Instance) Maintenance(maintenanceInterval time.Duration) { case <-ctx.update: // log.Print("Forced update") case <-time.After(maintenanceInterval): - // log.Print("Housekeeping...") + // log.Print("Housekeeping in main instance...") } } } diff --git a/src/state.go b/src/state.go index 5c31c76..ef64ece 100644 --- a/src/state.go +++ b/src/state.go @@ -5,15 +5,29 @@ import ( ) type MOTHState interface { + // Perform any setup needed + Initialize() (bool, error) + + // Return a list of awarded points PointsLog(teamId string) []*Award + + // Award points to a team AwardPoints(teamID string, category string, points int) error + // Given a team hash/token/id, retrieve the team name, if possible TeamName(teamId string) (string, error) + + // Returns true if the event is currently enabled isEnabled() bool + + // Attempt to read an arbitrary configuration item, if possible getConfig(configName string) (string, error) - getTeamIds() map[string]struct{} - login(teamId string, token string) (bool, error) - Initialize() (bool, error) + + // Return a list of valid team IDs + getValidTeamIds() map[string]struct{} + + // Attempt to register/log in. + login(teamName string, token string) (bool, error) } var ErrAlreadyRegistered = errors.New("This team ID has already been registered")