From a1b39833ed85eb247a81ce00b3f4c6cc0733683f Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 1 Aug 2013 09:39:10 -0400 Subject: [PATCH] (Hopefully) fix voteskip problems --- channel.js | 35 ++++++++++++++++++++++++++--------- package.json | 2 +- server.js | 2 +- user.js | 25 ++++++++----------------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/channel.js b/channel.js index 64a97eef..9d0a32ee 100644 --- a/channel.js +++ b/channel.js @@ -34,7 +34,7 @@ var Channel = function(name, Server) { // Initialize defaults this.registered = false; this.users = []; - this.afkcount = 0; + this.afkers = []; this.playlist = new Playlist(this); this.library = {}; this.position = -1; @@ -642,9 +642,10 @@ Channel.prototype.userLeave = function(user) { var idx = this.users.indexOf(user); if(idx >= 0 && idx < this.users.length) this.users.splice(idx, 1); - if(user.meta.afk) - this.afkcount--; - this.broadcastVoteskipUpdate(); + idx = this.afkers.indexOf(user.name.toLowerCase()); + if(idx >= 0 && idx < this.afkers.length) + this.afkers.splice(idx, 1); + this.checkVoteskipPass(); this.broadcastUsercount(); if(user.name != "") { this.sendAll("userLeave", { @@ -963,7 +964,7 @@ Channel.prototype.broadcastChatFilters = function() { Channel.prototype.broadcastVoteskipUpdate = function() { var amt = this.voteskip ? this.voteskip.counts[0] : 0; - var count = this.users.length - this.afkcount; + var count = this.users.length - this.afkers.length; var need = this.voteskip ? parseInt(count * this.opts.voteskip_ratio) : 0; for(var i = 0; i < this.users.length; i++) { if(Rank.hasPermission(this.users[i], "seeVoteskip") || @@ -1551,12 +1552,28 @@ Channel.prototype.tryVoteskip = function(user) { this.voteskip = new Poll("voteskip", "voteskip", ["yes"]); } this.voteskip.vote(user.ip, 0); - this.broadcastVoteskipUpdate(); - var count = this.users.length - this.afkcount; + this.checkVoteskipPass(); +} + +Channel.prototype.checkVoteskipPass = function () { + if(!this.opts.allow_voteskip) + return false; + + if(!this.voteskip) + return false; + + var count = this.users.length - this.afkers.length; var need = parseInt(count * this.opts.voteskip_ratio); - if(this.voteskip.counts[0] >= need) { - this.playNext(); + if(this.server.cfg["debug"]) { + console.log("afkers=", this.afkers.length); + console.log("users =", this.users.length); + console.log("DBG", this.voteskip.counts[0], "/", need); } + if(this.voteskip.counts[0] >= need) + this.playNext(); + + this.broadcastVoteskipUpdate(); + return true; } diff --git a/package.json b/package.json index a106fc54..2d5703dc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "2.2.1", + "version": "2.2.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/server.js b/server.js index 95ae43c1..5ba38b12 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ var Logger = require("./logger"); var Channel = require("./channel"); var User = require("./user"); -const VERSION = "2.2.1"; +const VERSION = "2.2.2"; function getIP(req) { var raw = req.connection.remoteAddress; diff --git a/user.js b/user.js index 5678bcc7..ba946344 100644 --- a/user.js +++ b/user.js @@ -86,25 +86,16 @@ User.prototype.setAFK = function (afk) { var changed = this.meta.afk != afk; var chan = this.channel; this.meta.afk = afk; - if(!afk) + if(afk) { + if(chan.afkers.indexOf(this.name.toLowerCase()) == -1) + chan.afkers.push(this.name.toLowerCase()); + } + else { + if(chan.afkers.indexOf(this.name.toLowerCase()) != -1) + chan.afkers.splice(chan.afkers.indexOf(this.name.toLowerCase()), 1); this.autoAFK(); - if(changed) { - if(this.meta.afk) - chan.afkcount++; - else - chan.afkcount--; - } - if(chan.voteskip) { - chan.voteskip.unvote(this.ip); - var count = chan.users.length - chan.afkcount; - var need = parseInt(count * chan.opts.voteskip_ratio); - if(chan.voteskip.counts[0] >= need) { - chan.playNext(); - } - else { - chan.broadcastVoteskipUpdate(); - } } + chan.checkVoteskipPass(); chan.broadcastUserUpdate(this); }