From 873330e99108c86b38a12cc3516b22d19c95efc7 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 29 Nov 2013 21:09:19 -0600 Subject: [PATCH 1/2] Fix #312 --- lib/channel.js | 6 ++++-- lib/user.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index 98a8c8f9..36f5235a 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -2122,7 +2122,7 @@ Channel.prototype.tryUpdateOptions = function(user, data) { if ("afk_timeout" in data) { data.afk_timeout = parseInt(data.afk_timeout); - if(data.afk_timeout < 0) + if (isNaN(data.afk_timeout) || data.afk_timeout < 0) data.afk_timeout = 0; } @@ -2144,12 +2144,14 @@ Channel.prototype.tryUpdateOptions = function(user, data) { this.opts.chat_antiflood_params.cooldown = c; continue; } - this.opts[key] = data[key]; if(key === "afk_timeout" && this.opts[key] != data[key]) { + console.log(typeof data[key], data[key]); + this.opts[key] = data[key]; this.users.forEach(function (u) { u.autoAFK(); }); } + this.opts[key] = data[key]; } } diff --git a/lib/user.js b/lib/user.js index d29784aa..5810931e 100644 --- a/lib/user.js +++ b/lib/user.js @@ -111,12 +111,22 @@ User.prototype.autoAFK = function () { if (self.awaytimer) clearTimeout(self.awaytimer); - if (!self.inChannel() || self.channel.opts.afk_timeout === 0) + if (!self.inChannel()) { return; + } + + var timeout = parseFloat(self.channel.opts.afk_timeout); + if (isNaN(timeout)) { + return; + } + + if (timeout <= 0) { + return; + } self.awaytimer = setTimeout(function () { self.setAFK(true); - }, self.channel.opts.afk_timeout * 1000); + }, timeout * 1000); }; User.prototype.kick = function (reason) { From 3f1e665922a602a15de36ecc78d84d06b0b5ecfa Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 29 Nov 2013 21:21:49 -0600 Subject: [PATCH 2/2] Add strict type checking to channel options --- lib/channel.js | 103 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 30 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index 36f5235a..e6af0b23 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -2120,39 +2120,82 @@ Channel.prototype.tryUpdateOptions = function(user, data) { show_public: true }; - if ("afk_timeout" in data) { - data.afk_timeout = parseInt(data.afk_timeout); - if (isNaN(data.afk_timeout) || data.afk_timeout < 0) - data.afk_timeout = 0; + if ("allow_voteskip" in data) { + var vs = Boolean(data.allow_voteskip); + this.opts.voteskip = vs; } - for(var key in this.opts) { - if(key in 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 = b / s; - this.opts.chat_antiflood_params.burst = b; - this.opts.chat_antiflood_params.sustained = s; - this.opts.chat_antiflood_params.cooldown = c; - continue; - } - if(key === "afk_timeout" && this.opts[key] != data[key]) { - console.log(typeof data[key], data[key]); - this.opts[key] = data[key]; - this.users.forEach(function (u) { - u.autoAFK(); - }); - } - this.opts[key] = data[key]; + if ("voteskip_ratio" in data) { + var ratio = parseFloat(data.voteskip_ratio); + if (isNaN(ratio) || ratio < 0) { + ratio = 0; } + this.opts.voteskip_ratio = ratio; + } + + if ("afk_timeout" in data) { + var tm = parseInt(data.afk_timeout); + if (isNaN(tm) || tm < 0) { + tm = 0; + } + var same = tm == this.opts.afk_timeout; + this.opts.afk_timeout = tm; + if (!same) { + this.users.forEach(function (u) { + u.autoAFK(); + }); + } + } + + if ("pagetitle" in data && user.rank >= 3) { + this.opts.pagetitle = ""+data.pagetitle; + } + + if ("maxlength" in data) { + var ml = parseInt(data.maxlength); + if (isNaN(ml) || ml < 0) { + ml = 0; + } + this.opts.maxlength = ml; + } + + if ("externalcss" in data && user.rank >= 3) { + this.opts.externalcss = ""+data.externalcss; + } + + if ("externaljs" in data && user.rank >= 3) { + this.opts.externaljs = ""+data.externaljs; + } + + if ("chat_antiflood" in data) { + this.opts.chat_antiflood = Boolean(data.chat_antiflood); + } + + if ("chat_antiflood_params" in data) { + if (typeof data.chat_antiflood_params !== "object") { + data.chat_antiflood_params = { + burst: 4, + sustained: 1 + }; + } + var b = parseInt(data.chat_antiflood_params.burst); + if (isNaN(b) || b < 0) + b = 1; + var s = parseFloat(data.chat_antiflood_params.sustained); + if (isNaN(s) || s <= 0) + s = 1; + var c = b / s; + this.opts.chat_antiflood_params.burst = b; + this.opts.chat_antiflood_params.sustained = s; + this.opts.chat_antiflood_params.cooldown = c; + } + + if ("show_public" in data && user.rank >= 3) { + this.opts.show_public = Boolean(data.show_public); + } + + if ("enable_link_regex" in data) { + this.opts.enable_link_regex = Boolean(data.enable_link_regex); } this.logger.log("%%% " + user.name + " updated channel options");