mirror of https://github.com/calzoneman/sync.git
Add chat antiflood option
This commit is contained in:
parent
3f5ec309e9
commit
6b5466f5ae
35
user.js
35
user.js
|
@ -28,6 +28,8 @@ var User = function(socket, ip) {
|
||||||
this.meta = {
|
this.meta = {
|
||||||
afk: false
|
afk: false
|
||||||
};
|
};
|
||||||
|
this.throttle = {};
|
||||||
|
this.flooded = {};
|
||||||
|
|
||||||
this.initCallbacks();
|
this.initCallbacks();
|
||||||
if(Server.announcement != null) {
|
if(Server.announcement != null) {
|
||||||
|
@ -35,6 +37,38 @@ var User = function(socket, ip) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Throttling/cooldown
|
||||||
|
User.prototype.noflood = function(name, hz) {
|
||||||
|
var time = new Date().getTime();
|
||||||
|
if(!(name in this.throttle)) {
|
||||||
|
this.throttle[name] = [time];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(name in this.flooded && time < this.flooded[name]) {
|
||||||
|
this.socket.emit("noflood", {
|
||||||
|
action: name,
|
||||||
|
msg: "You're still on cooldown!"
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.throttle[name].push(time);
|
||||||
|
var diff = (time - this.throttle[name][0]) / 1000.0;
|
||||||
|
if(diff > 1.0) {
|
||||||
|
var rate = this.throttle[name].length / diff;
|
||||||
|
this.throttle[name] = [time];
|
||||||
|
if(rate > hz) {
|
||||||
|
this.flooded[name] = time + 5000;
|
||||||
|
this.socket.emit("noflood", {
|
||||||
|
action: name,
|
||||||
|
msg: "Stop doing that so fast! Cooldown: 5s"
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
User.prototype.initCallbacks = function() {
|
User.prototype.initCallbacks = function() {
|
||||||
this.socket.on("disconnect", function() {
|
this.socket.on("disconnect", function() {
|
||||||
|
@ -258,6 +292,7 @@ User.prototype.initCallbacks = function() {
|
||||||
this.socket.on("requestAcl", function() {
|
this.socket.on("requestAcl", function() {
|
||||||
if(this.channel != null) {
|
if(this.channel != null) {
|
||||||
this.channel.sendACL(this);
|
this.channel.sendACL(this);
|
||||||
|
this.noflood("requestAcl", 0.25);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,15 @@ function initCallbacks() {
|
||||||
.addClass("server-msg-disconnect")
|
.addClass("server-msg-disconnect")
|
||||||
.text("Kicked: " + data.reason)
|
.text("Kicked: " + data.reason)
|
||||||
.appendTo($("#messagebuffer"));
|
.appendTo($("#messagebuffer"));
|
||||||
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("noflood", function(data) {
|
||||||
|
$("<div/>")
|
||||||
|
.addClass("server-msg-disconnect")
|
||||||
|
.text(data.action + ": " + data.msg)
|
||||||
|
.appendTo($("#messagebuffer"));
|
||||||
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("channelNotRegistered", function() {
|
socket.on("channelNotRegistered", function() {
|
||||||
|
@ -67,6 +76,7 @@ function initCallbacks() {
|
||||||
PAGETITLE = opts.pagetitle;
|
PAGETITLE = opts.pagetitle;
|
||||||
$("#opt_customcss").val(opts.customcss);
|
$("#opt_customcss").val(opts.customcss);
|
||||||
$("#opt_customjs").val(opts.customjs);
|
$("#opt_customjs").val(opts.customjs);
|
||||||
|
$("#opt_chat_antiflood").prop("checked", opts.chat_antiflood);
|
||||||
$("#customCss").remove();
|
$("#customCss").remove();
|
||||||
if(opts.customcss.trim() != "") {
|
if(opts.customcss.trim() != "") {
|
||||||
$("<link/>").attr("rel", "stylesheet")
|
$("<link/>").attr("rel", "stylesheet")
|
||||||
|
|
|
@ -125,6 +125,7 @@ socket.on("connect", function() {
|
||||||
$("<div/>").addClass("server-msg-reconnect")
|
$("<div/>").addClass("server-msg-reconnect")
|
||||||
.text("Connected")
|
.text("Connected")
|
||||||
.appendTo($("#messagebuffer"));
|
.appendTo($("#messagebuffer"));
|
||||||
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
||||||
setTimeout(function() { $("#reconnect_box").remove(); }, 3000);
|
setTimeout(function() { $("#reconnect_box").remove(); }, 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -377,7 +378,8 @@ $("#opt_submit").click(function() {
|
||||||
voteskip_ratio: ratio,
|
voteskip_ratio: ratio,
|
||||||
pagetitle: ptitle,
|
pagetitle: ptitle,
|
||||||
customcss: css,
|
customcss: css,
|
||||||
customjs: $("#opt_customjs").val()
|
customjs: $("#opt_customjs").val(),
|
||||||
|
chat_antiflood: $("#opt_chat_antiflood").prop("checked")
|
||||||
};
|
};
|
||||||
socket.emit("channelOpts", opts);
|
socket.emit("channelOpts", opts);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,7 @@ function handleDisconnect() {
|
||||||
.addClass("server-msg-disconnect")
|
.addClass("server-msg-disconnect")
|
||||||
.text("Disconnected from server. Attempting reconnection...")
|
.text("Disconnected from server. Attempting reconnection...")
|
||||||
.appendTo($("#messagebuffer"));
|
.appendTo($("#messagebuffer"));
|
||||||
|
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a user to the chatbox userlist
|
// Adds a user to the chatbox userlist
|
||||||
|
|
|
@ -167,6 +167,11 @@
|
||||||
<label>Voteskip Ratio
|
<label>Voteskip Ratio
|
||||||
<input type="text" id="opt_voteskip_ratio" class="pull-right">
|
<input type="text" id="opt_voteskip_ratio" class="pull-right">
|
||||||
</label>
|
</label>
|
||||||
|
<br>
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" id="opt_chat_antiflood">
|
||||||
|
Prevent chat flood
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="span10">
|
<div class="span10">
|
||||||
|
|
Loading…
Reference in New Issue