diff --git a/lib/channel.js b/lib/channel.js
index c5f09fe7..792b0e30 100644
--- a/lib/channel.js
+++ b/lib/channel.js
@@ -84,14 +84,19 @@ var Channel = function(name) {
self.opts = {
allow_voteskip: true,
voteskip_ratio: 0.5,
- afk_timeout: 180,
+ afk_timeout: 600,
pagetitle: self.name,
maxlength: 0,
externalcss: "",
externaljs: "",
chat_antiflood: false,
+ chat_antiflood_params: {
+ burst: 4,
+ sustained: 1,
+ cooldown: 4
+ },
show_public: false,
- enable_link_regex: true
+ enable_link_regex: true,
};
self.filters = [
new Filter("monospace", "`([^`]+)`", "g", "$1"),
@@ -2099,12 +2104,27 @@ Channel.prototype.tryUpdateOptions = function(user, data) {
if(key in adminonly && user.rank < 3) {
continue;
}
+ if (key === "chat_antiflood_params") {
+ var b = parseInt(data[key].burst);
+ if (isNaN(b) || b < 0)
+ b = 1;
+ var s = parseFloat(data[key].sustained);
+ if (isNaN(s) || s <= 0)
+ s = 1;
+ var c = parseFloat(data[key].cooldown);
+ if (isNaN(c) || c < 0)
+ c = 0;
+ this.opts.chat_antiflood_params.burst = b;
+ this.opts.chat_antiflood_params.sustained = s;
+ this.opts.chat_antiflood_params.cooldown = c;
+ continue;
+ }
+ this.opts[key] = data[key];
if(key === "afk_timeout" && this.opts[key] != data[key]) {
this.users.forEach(function (u) {
u.autoAFK();
});
}
- this.opts[key] = data[key];
}
}
@@ -2222,7 +2242,16 @@ Channel.prototype.tryChat = function(user, data) {
if(msg.length > 240) {
msg = msg.substring(0, 240);
}
- if(this.opts.chat_antiflood && user.noflood("chat", 2.0)) {
+
+ if (this.opts.chat_antiflood &&
+ user.chatLimiter.throttle(this.opts.chat_antiflood_params)) {
+ user.socket.emit("chatCooldown", 1000/this.opts.chat_antiflood_params.sustained);
+ /*
+ user.socket.emit("noflood", {
+ action: "chat",
+ msg: "sending messages too quickly!"
+ });
+ */
return;
}
diff --git a/lib/user.js b/lib/user.js
index 07b56f43..3dfe11bd 100644
--- a/lib/user.js
+++ b/lib/user.js
@@ -36,6 +36,7 @@ var User = function (socket) {
this.throttle = {};
this.flooded = {};
this.queueLimiter = $util.newRateLimiter();
+ this.chatLimiter = $util.newRateLimiter();
this.profile = {
image: "",
text: ""
diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js
index c0f61ed0..412448ee 100644
--- a/www/assets/js/callbacks.js
+++ b/www/assets/js/callbacks.js
@@ -127,6 +127,43 @@ Callbacks = {
scrollChat();
},
+ chatCooldown: function (time) {
+ time = time + 200;
+ /*
+ var msg = $("#chat-cooldown-msg");
+ if (msg.length > 0) {
+ var timer = msg.data("timer");
+ if (timer) {
+ clearTimeout(timer);
+ }
+ } else {
+ msg = $("