mirror of https://github.com/dirtbags/moth.git
Using better names for functions.
Better handling forced updated
This commit is contained in:
parent
22a646e200
commit
d8064e2b1a
|
@ -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{})
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
src/state.go
20
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")
|
||||
|
|
Loading…
Reference in New Issue