From e2c3b2daad4f4dde8b79e16c2949ed61e57118fa Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 23 Apr 2015 21:49:01 -0500 Subject: [PATCH] Fix PM maxlength and throttling --- lib/channel/chat.js | 31 ++++++++++++++++++++++--------- www/js/callbacks.js | 2 ++ www/js/util.js | 4 ++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/channel/chat.js b/lib/channel/chat.js index d7527344..8c10cd61 100644 --- a/lib/channel/chat.js +++ b/lib/channel/chat.js @@ -22,6 +22,12 @@ const TYPE_PM = { meta: "object,optional" }; +const DEFAULT_ANTIFLOOD = { + burst: 4, + sustained: 1, + cooldown: 4 +}; + function ChatModule(channel) { ChannelModule.apply(this, arguments); this.buffer = []; @@ -192,7 +198,13 @@ ChatModule.prototype.handlePm = function (user, data) { return; } - var msg = data.msg.substring(0, 240); + if (user.chatLimiter.throttle(DEFAULT_ANTIFLOOD)) { + user.socket.emit("cooldown", 1000 / DEFAULT_ANTIFLOOD.sustained); + return; + } + + + data.msg = data.msg.substring(0, 240); var to = null; for (var i = 0; i < this.channel.users.length; i++) { if (this.channel.users[i].getLowerName() === data.to) { @@ -216,7 +228,7 @@ ChatModule.prototype.handlePm = function (user, data) { } } - if (msg.indexOf(">") === 0) { + if (data.msg.indexOf(">") === 0) { meta.addClass = "greentext"; } @@ -243,15 +255,16 @@ ChatModule.prototype.processChatMsg = function (user, data) { } var msgobj = this.formatMessage(user.getName(), data); + var antiflood = DEFAULT_ANTIFLOOD; if (this.channel.modules.options && - this.channel.modules.options.get("chat_antiflood") && - user.account.effectiveRank < 2) { + this.channel.modules.options.get("chat_antiflood")) { - var antiflood = this.channel.modules.options.get("chat_antiflood_params"); - if (user.chatLimiter.throttle(antiflood)) { - user.socket.emit("cooldown", 1000 / antiflood.sustained); - return; - } + antiflood = this.channel.modules.options.get("chat_antiflood_params"); + } + + if (user.chatLimiter.throttle(antiflood)) { + user.socket.emit("cooldown", 1000 / antiflood.sustained); + return; } if (user.is(Flags.U_SMUTED)) { diff --git a/www/js/callbacks.js b/www/js/callbacks.js index 25e0a804..1314ace3 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -124,6 +124,7 @@ Callbacks = { cooldown: function (time) { time = time + 200; $("#chatline").css("color", "#ff0000"); + $(".pm-input").css("color", "#ff0000"); if (CHATTHROTTLE && $("#chatline").data("throttle_timer")) { clearTimeout($("#chatline").data("throttle_timer")); } @@ -131,6 +132,7 @@ Callbacks = { $("#chatline").data("throttle_timer", setTimeout(function () { CHATTHROTTLE = false; $("#chatline").css("color", ""); + $(".pm-input").css("color", ""); }, time)); }, diff --git a/www/js/util.js b/www/js/util.js index 38b86088..0e97838c 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -2586,10 +2586,14 @@ function initPm(user) { var buffer = $("
").addClass("pm-buffer linewrap").appendTo(body); $("
").appendTo(body); var input = $("").addClass("form-control pm-input").attr("type", "text") + .attr("maxlength", 240) .appendTo(body); input.keydown(function (ev) { if (ev.keyCode === 13) { + if (CHATTHROTTLE) { + return; + } var meta = {}; var msg = input.val(); if (msg.trim() === "") {