From 40ad039a06bfa0f7ca5ab0a82f1de746a7f25aa2 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 20 Apr 2013 20:17:38 -0500 Subject: [PATCH] Add configurable voteskip ratio, show # voteskips to mods --- channel.js | 25 +++++++++++++++++++++++-- rank.js | 1 + www/assets/js/callbacks.js | 10 ++++++++++ www/assets/js/client.js | 2 ++ www/index.html | 9 ++++++--- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/channel.js b/channel.js index bc2b9d9f..cd9935ca 100644 --- a/channel.js +++ b/channel.js @@ -43,6 +43,7 @@ var Channel = function(name) { qopen_allow_playnext: false, qopen_allow_delete: false, allow_voteskip: true, + voteskip_ratio: 0.5, pagetitle: this.name, customcss: "", customjs: "" @@ -292,6 +293,7 @@ Channel.prototype.userJoin = function(user) { user.socket.emit("channelNotRegistered"); } this.users.push(user); + this.broadcastVoteskipUpdate(); if(user.name != "") { this.broadcastNewUser(user); } @@ -342,6 +344,7 @@ Channel.prototype.userLeave = function(user) { var idx = this.users.indexOf(user); if(idx >= 0 && idx < this.users.length) this.users.splice(idx, 1); + this.broadcastVoteskipUpdate(); this.broadcastUsercount(); if(user.name != "") { this.sendAll("userLeave", { @@ -407,7 +410,8 @@ Channel.prototype.sendUserlist = function(user) { users.push({ name: this.users[i].name, rank: this.users[i].rank, - leader: this.users[i] == this.leader + leader: this.users[i] == this.leader, + meta: this.users[i].meta }); } } @@ -499,6 +503,20 @@ Channel.prototype.broadcastChatFilters = function() { } } +Channel.prototype.broadcastVoteskipUpdate = function() { + var amt = this.voteskip ? this.voteskip.counts[0] : 0; + var need = this.voteskip ? this.users.length * this.opts.voteskip_ratio + 1 : 0; + for(var i = 0; i < this.users.length; i++) { + if(Rank.hasPermission(this.users[i], "seeVoteskip") || + this.leader == this.users[i]) { + this.users[i].socket.emit("voteskip", { + count: amt, + need: need + }); + } + } +} + Channel.prototype.broadcastMotd = function() { this.sendAll("updateMotd", this.motd); } @@ -662,6 +680,7 @@ Channel.prototype.playNext = function() { // Reset voteskip this.voteskip = false; + this.broadcastVoteskipUpdate(); this.drinks = 0; this.broadcastDrinks(); @@ -708,6 +727,7 @@ Channel.prototype.jumpTo = function(pos) { // Reset voteskip this.voteskip = false; + this.broadcastVoteskipUpdate(); this.drinks = 0; this.broadcastDrinks(); @@ -866,7 +886,8 @@ Channel.prototype.tryVoteskip = function(user) { this.voteskip = new Poll("voteskip", "voteskip", ["yes"]); } this.voteskip.vote(user.ip, 0); - if(this.voteskip.counts[0] > this.users.length / 2) { + this.broadcastVoteskipUpdate(); + if(this.voteskip.counts[0] > this.users.length * this.opts.voteskip_ratio) { this.playNext(); } } diff --git a/rank.js b/rank.js index 3bddcaeb..63c4fd9f 100644 --- a/rank.js +++ b/rank.js @@ -32,6 +32,7 @@ var permissions = { chatFilter : exports.Moderator, updateMotd : exports.Moderator, drink : exports.Moderator, + seeVoteskip : exports.Moderator, search : exports.Guest, chat : exports.Guest, }; diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 9a32699e..7d298bea 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -75,6 +75,7 @@ function initCallbacks() { .insertAfter($("link[href='./assets/css/ytsync.css']")); } $("#opt_allow_voteskip").prop("checked", opts.allow_voteskip); + $("#opt_voteskip_ratio").val(opts.voteskip_ratio); if(opts.customjs.trim() != "") { $.getScript(opts.customjs); } @@ -100,6 +101,15 @@ function initCallbacks() { updateBanlist(data.entries); }); + socket.on("voteskip", function(data) { + if(data.count > 0) { + $("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")"); + } + else { + $("#voteskip").text("Voteskip"); + } + }); + /* REGION Rank Stuff */ socket.on("rank", function(data) { diff --git a/www/assets/js/client.js b/www/assets/js/client.js index fdc9edb1..ac9c3caf 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -359,12 +359,14 @@ $("#opt_submit").click(function() { if(ptitle == "") ptitle = $("#opt_pagetitle").attr("placeholder") var css = $("#opt_customcss").val(); + var ratio = +$("#opt_voteskip_ratio").val() || 0.5; opts = { qopen_allow_qnext: $("#opt_qopen_allow_qnext").prop("checked"), qopen_allow_move: $("#opt_qopen_allow_move").prop("checked"), qopen_allow_delete: $("#opt_qopen_allow_delete").prop("checked"), qopen_allow_playnext: $("#opt_qopen_allow_playnext").prop("checked"), allow_voteskip: $("#opt_allow_voteskip").prop("checked"), + voteskip_ratio: ratio, pagetitle: ptitle, customcss: css, customjs: $("#opt_customjs").val() diff --git a/www/index.html b/www/index.html index 9e5e30e7..aee0b0d7 100644 --- a/www/index.html +++ b/www/index.html @@ -22,10 +22,10 @@