|
@@ -90,10 +90,20 @@ func (fl *Fakelag) Touch() {
|
90
|
90
|
if elapsed > fl.config.Cooldown {
|
91
|
91
|
// let them burst again
|
92
|
92
|
fl.state = FakelagBursting
|
|
93
|
+ fl.burstCount = 1
|
93
|
94
|
return
|
94
|
95
|
}
|
95
|
|
- // space them out by at least window/messagesperwindow
|
96
|
|
- sleepDuration := time.Duration((int64(fl.config.Window) / int64(fl.config.MessagesPerWindow)) - int64(elapsed))
|
|
96
|
+ var sleepDuration time.Duration
|
|
97
|
+ if fl.config.MessagesPerWindow > 0 {
|
|
98
|
+ // space them out by at least window/messagesperwindow
|
|
99
|
+ sleepDuration = time.Duration((int64(fl.config.Window) / int64(fl.config.MessagesPerWindow)) - int64(elapsed))
|
|
100
|
+ } else {
|
|
101
|
+ // only burst messages are allowed: sleep until cooldown expires,
|
|
102
|
+ // then count this as a burst message
|
|
103
|
+ sleepDuration = time.Duration(int64(fl.config.Cooldown) - int64(elapsed))
|
|
104
|
+ fl.state = FakelagBursting
|
|
105
|
+ fl.burstCount = 1
|
|
106
|
+ }
|
97
|
107
|
if sleepDuration > 0 {
|
98
|
108
|
fl.sleepFunc(sleepDuration)
|
99
|
109
|
// the touch time should take into account the time we slept
|