2017-11-22 00:52:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"srs.epita.fr/fic-server/settings"
|
|
|
|
)
|
|
|
|
|
2018-01-22 17:09:05 +00:00
|
|
|
var startedFile = "started"
|
2017-11-22 00:52:08 +00:00
|
|
|
|
|
|
|
var touchTimer *time.Timer = nil
|
2018-08-17 20:17:51 +00:00
|
|
|
var challengeStart time.Time
|
2023-05-12 12:53:15 +00:00
|
|
|
var challengeEnd *time.Time
|
2017-11-22 00:52:08 +00:00
|
|
|
|
|
|
|
func touchStartedFile() {
|
2018-01-22 17:09:05 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-01 20:15:16 +00:00
|
|
|
func reloadSettings(config *settings.Settings) {
|
2018-08-17 20:17:51 +00:00
|
|
|
if challengeStart != config.Start || challengeEnd != config.End {
|
2017-11-22 00:52:08 +00:00
|
|
|
if touchTimer != nil {
|
|
|
|
touchTimer.Stop()
|
|
|
|
}
|
2018-08-17 20:17:51 +00:00
|
|
|
|
|
|
|
if config.Start.Unix() == 0 {
|
|
|
|
log.Println("WARNING: No challenge start defined!")
|
|
|
|
|
|
|
|
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
|
|
|
|
os.Remove(startedFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-22 14:35:07 +00:00
|
|
|
startSub := time.Until(config.Start)
|
2017-11-22 00:52:08 +00:00
|
|
|
if startSub > 0 {
|
|
|
|
log.Println("Challenge will starts at", config.Start, "in", startSub)
|
|
|
|
|
2018-01-22 17:09:05 +00:00
|
|
|
if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
|
|
|
|
os.Remove(startedFile)
|
2017-11-22 00:52:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 14:35:07 +00:00
|
|
|
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1*time.Second))), touchStartedFile)
|
2017-11-22 00:52:08 +00:00
|
|
|
} else {
|
|
|
|
log.Println("Challenge started at", config.Start, "since", -startSub)
|
|
|
|
touchStartedFile()
|
|
|
|
}
|
|
|
|
log.Println("Challenge ends on", config.End)
|
|
|
|
|
2018-08-17 20:17:51 +00:00
|
|
|
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
|
2020-01-24 19:04:46 +00:00
|
|
|
acceptNewIssues = config.AcceptNewIssue
|
2017-11-22 00:52:08 +00:00
|
|
|
allowRegistration = config.AllowRegistration
|
2023-11-04 20:14:16 +00:00
|
|
|
enableResetProgression = config.WorkInProgress && config.CanResetProgression
|
2017-11-22 00:52:08 +00:00
|
|
|
}
|