server/frontend/settings.go

67 lines
1.5 KiB
Go
Raw Normal View History

2017-11-22 00:52:08 +00:00
package main
import (
"log"
"os"
"time"
"srs.epita.fr/fic-server/settings"
)
var startedFile = "started"
2017-11-22 00:52:08 +00:00
var touchTimer *time.Timer = nil
var challengeStart time.Time
var challengeEnd time.Time
2017-11-22 00:52:08 +00:00
func touchStartedFile() {
if fd, err := os.Create(startedFile); err == nil {
2017-11-22 00:52:08 +00:00
log.Println("Started! Go, Go, Go!!")
fd.Close()
} else {
log.Fatal("Unable to start challenge:", err)
}
}
func reloadSettings(config settings.FICSettings) {
if challengeStart != config.Start || challengeEnd != config.End {
2017-11-22 00:52:08 +00:00
if touchTimer != nil {
touchTimer.Stop()
}
if config.Start.Unix() == 0 {
log.Println("WARNING: No challenge start defined!")
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
os.Remove(startedFile)
}
return
}
2017-11-22 00:52:08 +00:00
startSub := config.Start.Sub(time.Now())
if startSub > 0 {
log.Println("Challenge will starts at", config.Start, "in", startSub)
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
os.Remove(startedFile)
2017-11-22 00:52:08 +00:00
}
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile)
} else {
log.Println("Challenge started at", config.Start, "since", -startSub)
touchStartedFile()
}
log.Println("Challenge ends on", config.End)
challengeStart = config.Start
challengeEnd = config.End
2017-11-22 00:52:08 +00:00
} else {
log.Println("Configuration reloaded, but start/end times doesn't change.")
}
enableResolutionRoute = config.EnableResolutionRoute
denyNameChange = config.DenyNameChange
allowRegistration = config.AllowRegistration
}