From 645fb64db3ab4ce86fe7dcee1c140ca82772434f Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Sun, 7 Mar 2021 12:06:54 +0000 Subject: [PATCH] randomise timer, add some comments --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 1ccae86..e0a06b2 100644 --- a/main.go +++ b/main.go @@ -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" {