(Hopefully) fix voteskip problems

This commit is contained in:
calzoneman 2013-08-01 09:39:10 -04:00
parent ba8730b722
commit a1b39833ed
4 changed files with 36 additions and 28 deletions

View File

@ -34,7 +34,7 @@ var Channel = function(name, Server) {
// Initialize defaults // Initialize defaults
this.registered = false; this.registered = false;
this.users = []; this.users = [];
this.afkcount = 0; this.afkers = [];
this.playlist = new Playlist(this); this.playlist = new Playlist(this);
this.library = {}; this.library = {};
this.position = -1; this.position = -1;
@ -642,9 +642,10 @@ Channel.prototype.userLeave = function(user) {
var idx = this.users.indexOf(user); var idx = this.users.indexOf(user);
if(idx >= 0 && idx < this.users.length) if(idx >= 0 && idx < this.users.length)
this.users.splice(idx, 1); this.users.splice(idx, 1);
if(user.meta.afk) idx = this.afkers.indexOf(user.name.toLowerCase());
this.afkcount--; if(idx >= 0 && idx < this.afkers.length)
this.broadcastVoteskipUpdate(); this.afkers.splice(idx, 1);
this.checkVoteskipPass();
this.broadcastUsercount(); this.broadcastUsercount();
if(user.name != "") { if(user.name != "") {
this.sendAll("userLeave", { this.sendAll("userLeave", {
@ -963,7 +964,7 @@ Channel.prototype.broadcastChatFilters = function() {
Channel.prototype.broadcastVoteskipUpdate = function() { Channel.prototype.broadcastVoteskipUpdate = function() {
var amt = this.voteskip ? this.voteskip.counts[0] : 0; 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; var need = this.voteskip ? parseInt(count * this.opts.voteskip_ratio) : 0;
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
if(Rank.hasPermission(this.users[i], "seeVoteskip") || 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 = new Poll("voteskip", "voteskip", ["yes"]);
} }
this.voteskip.vote(user.ip, 0); this.voteskip.vote(user.ip, 0);
this.broadcastVoteskipUpdate(); this.checkVoteskipPass();
var count = this.users.length - this.afkcount; }
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); var need = parseInt(count * this.opts.voteskip_ratio);
if(this.voteskip.counts[0] >= need) { if(this.server.cfg["debug"]) {
this.playNext(); 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;
} }

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": "2.2.1", "version": "2.2.2",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -6,7 +6,7 @@ var Logger = require("./logger");
var Channel = require("./channel"); var Channel = require("./channel");
var User = require("./user"); var User = require("./user");
const VERSION = "2.2.1"; const VERSION = "2.2.2";
function getIP(req) { function getIP(req) {
var raw = req.connection.remoteAddress; var raw = req.connection.remoteAddress;

25
user.js
View File

@ -86,25 +86,16 @@ User.prototype.setAFK = function (afk) {
var changed = this.meta.afk != afk; var changed = this.meta.afk != afk;
var chan = this.channel; var chan = this.channel;
this.meta.afk = afk; 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(); 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); chan.broadcastUserUpdate(this);
} }