mirror of https://github.com/calzoneman/sync.git
(Hopefully) fix voteskip problems
This commit is contained in:
parent
ba8730b722
commit
a1b39833ed
35
channel.js
35
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
|
25
user.js
25
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue