Fix PM maxlength and throttling

This commit is contained in:
calzoneman 2015-04-23 21:49:01 -05:00
parent 2aba640ec5
commit e2c3b2daad
3 changed files with 28 additions and 9 deletions

View File

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

View File

@ -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));
},

View File

@ -2586,10 +2586,14 @@ function initPm(user) {
var buffer = $("<div/>").addClass("pm-buffer linewrap").appendTo(body);
$("<hr/>").appendTo(body);
var input = $("<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() === "") {