randomise timer, add some comments

This commit is contained in:
Nico 2021-03-07 12:06:54 +00:00
parent b2065f86a7
commit 645fb64db3
1 changed files with 5 additions and 2 deletions

View File

@ -15,6 +15,7 @@ package main
* regexp to help parse messages.
* sync to make things concurrency safe
* time to sleep for some time before reducing the counter
* rand to randomise the timer ticks
*/
import (
"bufio"
@ -24,6 +25,7 @@ import (
"strings"
"sync"
"time"
"math/rand"
)
/*
@ -141,7 +143,8 @@ func getCounter() int {
func countdown(conn *net.Conn, reset chan int) {
locked := false
for {
timer := time.NewTimer(time.Duration(maxTime) * time.Second) // TODO randomise a bit, longer times
duration := rand.Intn(maxTime-minTime) + minTime
timer := time.NewTimer(time.Duration(duration) * time.Second) // TODO randomise a bit, longer times
select {
case <-timer.C: // on a timer timeout
if !locked {
@ -251,7 +254,7 @@ func main() {
sendMessage(&conn, channel, "The timer is locked! You can't press the button.")
}
} else if msgContent == ",reset" {
// TODO maybe check
// TODO maybe check some kind of auth on doing this
reset <- 0
sendMessage(&conn, channel, "Timer reset!")
} else if msgContent == ",count" {