]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Refactor flood protection code.
authorChris Porter <redacted>
Fri, 19 Jun 2009 21:59:58 +0000 (22:59 +0100)
committerChris Porter <redacted>
Fri, 19 Jun 2009 21:59:58 +0000 (22:59 +0100)
js/irc/ircconnection.js

index 17f408acea83fa595342f58e89d058e3c2f44ada..a578701e4ca0172080336ef962b1e3983a92dbed 100644 (file)
@@ -40,24 +40,9 @@ qwebirc.irc.IRCConnection = new Class({
     if(this.disconnected)
       return null;
       
-    if(floodProtection) {
-      var t = new Date().getTime();
-      
-      if(t - this.__floodLastRequest < this.options.floodInterval) {
-        if(this.__floodLastFlood != 0 && (t - this.__floodLastFlood > this.options.floodReset)) {
-          this.__floodCounter = 0;
-        }
-
-        this.__floodLastFlood = t;
-        if(this.__floodCounter++ >= this.options.floodMax) {
-          if(!this.disconnected) {
-            this.disconnect();
-            this.__error("BUG: uncontrolled flood detected -- disconnected.");
-          }
-          return null;
-        }
-      }
-      this.__floodLastRequest = t;
+    if(floodProtection && !this.disconnected && this.__isFlooding()) {
+      this.disconnect();
+      this.__error("BUG: uncontrolled flood detected -- disconnected.");
     }
     
     var r = new Request.JSON({
@@ -84,6 +69,21 @@ qwebirc.irc.IRCConnection = new Class({
 
     return r;
   },
+  __isFlooding: function() {
+    var t = new Date().getTime();
+      
+    if(t - this.__floodLastRequest < this.options.floodInterval) {
+      if(this.__floodLastFlood != 0 && (t - this.__floodLastFlood > this.options.floodReset))
+        this.__floodCounter = 0;
+
+      this.__floodLastFlood = t;
+      if(this.__floodCounter++ >= this.options.floodMax)
+        return true;
+    }
+
+    this.__floodLastRequest = t;
+    return false;
+  },
   send: function(data) {
     if(this.disconnected)
       return false;