瀏覽代碼

Merge pull request #1360 from slingamn/issue861_fakelag

fix #861
tags/v2.4.0-rc1
Shivaram Lingamneni 3 年之前
父節點
當前提交
70b8bf75c5
No account linked to committer's email address
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12
    2
      irc/fakelag.go

+ 12
- 2
irc/fakelag.go 查看文件

@@ -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

Loading…
取消
儲存