From 2f4431a5fb8d895ae01a9f92a01a11e860561c70 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 26 Oct 2020 21:06:03 -0400 Subject: [PATCH] fix #861 Allow messages-per-window to be 0 --- irc/fakelag.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/irc/fakelag.go b/irc/fakelag.go index 132e87d4..8f3a4c9e 100644 --- a/irc/fakelag.go +++ b/irc/fakelag.go @@ -90,10 +90,20 @@ func (fl *Fakelag) Touch() { if elapsed > fl.config.Cooldown { // let them burst again fl.state = FakelagBursting + fl.burstCount = 1 return } - // space them out by at least window/messagesperwindow - sleepDuration := time.Duration((int64(fl.config.Window) / int64(fl.config.MessagesPerWindow)) - int64(elapsed)) + var sleepDuration time.Duration + if fl.config.MessagesPerWindow > 0 { + // space them out by at least window/messagesperwindow + sleepDuration = time.Duration((int64(fl.config.Window) / int64(fl.config.MessagesPerWindow)) - int64(elapsed)) + } else { + // only burst messages are allowed: sleep until cooldown expires, + // then count this as a burst message + sleepDuration = time.Duration(int64(fl.config.Cooldown) - int64(elapsed)) + fl.state = FakelagBursting + fl.burstCount = 1 + } if sleepDuration > 0 { fl.sleepFunc(sleepDuration) // the touch time should take into account the time we slept