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