Start switching chat flood system
This commit is contained in:
parent
21bb2b9a4e
commit
ee9b19b0ff
8 changed files with 108 additions and 4 deletions
|
|
@ -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", "<code>$1</code>"),
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ var User = function (socket) {
|
|||
this.throttle = {};
|
||||
this.flooded = {};
|
||||
this.queueLimiter = $util.newRateLimiter();
|
||||
this.chatLimiter = $util.newRateLimiter();
|
||||
this.profile = {
|
||||
image: "",
|
||||
text: ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue