Clamp timeouts to 1 day

This commit is contained in:
Calvin Montgomery 2019-04-28 22:30:08 -07:00
parent 2a1f1df17b
commit 60c348a905
3 changed files with 30 additions and 11 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.65.0", "version": "3.65.1",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -59,6 +59,7 @@ OptionsModule.prototype.load = function (data) {
10, 10,
this.opts.chat_antiflood_params.sustained this.opts.chat_antiflood_params.sustained
); );
this.opts.afk_timeout = Math.min(86400 /* one day */, this.opts.afk_timeout);
this.dirty = false; this.dirty = false;
}; };
@ -139,18 +140,26 @@ OptionsModule.prototype.handleSetOptions = function (user, data) {
if ("afk_timeout" in data) { if ("afk_timeout" in data) {
var tm = parseInt(data.afk_timeout); var tm = parseInt(data.afk_timeout);
if (isNaN(tm) || tm < 0) { if (isNaN(tm) || tm < 0 || tm > 86400 /* one day */) {
tm = 0; tm = 0;
} user.socket.emit("validationError", {
target: "#cs-afk_timeout",
var same = tm === this.opts.afk_timeout; message: "AFK timeout must be between 1 and 86400 seconds (or 0 to disable)"
this.opts.afk_timeout = tm;
if (!same) {
this.channel.users.forEach(function (u) {
u.autoAFK();
}); });
} else {
user.socket.emit("validationPassed", {
target: "#cs-afk_timeout",
});
var same = tm === this.opts.afk_timeout;
this.opts.afk_timeout = tm;
if (!same) {
this.channel.users.forEach(function (u) {
u.autoAFK();
});
}
sendUpdate = true;
} }
sendUpdate = true;
} }
if ("pagetitle" in data && user.account.effectiveRank >= 3) { if ("pagetitle" in data && user.account.effectiveRank >= 3) {

View File

@ -187,9 +187,19 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) {
return; return;
} }
if (data.hasOwnProperty("timeout") &&
(isNaN(data.timeout) || data.timeout < 1 || data.timeout > 86400)) {
ack({
error: {
message: "Poll timeout must be between 1 and 86400 seconds"
}
});
return;
}
var poll = new Poll(user.getName(), data.title, data.opts, data.obscured); var poll = new Poll(user.getName(), data.title, data.opts, data.obscured);
var self = this; var self = this;
if (data.hasOwnProperty("timeout") && !isNaN(data.timeout) && data.timeout > 0) { if (data.hasOwnProperty("timeout")) {
poll.timer = setTimeout(function () { poll.timer = setTimeout(function () {
if (self.poll === poll) { if (self.poll === poll) {
self.handleClosePoll({ self.handleClosePoll({