From 0becaacabf97f8e3d2f6c0c361cf5cd395ef9049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Thu, 11 Jun 2015 01:47:38 +0200 Subject: [PATCH] If there is 2 viewers, both viewers has to want to skip --- server/server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/server.js b/server/server.js index c37467f9..b89be95e 100755 --- a/server/server.js +++ b/server/server.js @@ -358,7 +358,8 @@ io.on('connection', function(socket){ { if(!docs[0]["skip"] || (docs[0]["adminpass"] == hash && docs[0]["adminpass"] != "") || error) { - if((lists[coll].length/2 <= docs[0]["skips"].length+1 && !contains(docs[0]["skips"], guid)) + if((lists[coll].length/2 <= docs[0]["skips"].length+1 && !contains(docs[0]["skips"], guid) && lists[coll].length != 2) + || (lists[coll].length == 2 && docs[0]["skips"].length+1 == 2 && !contains(docs[0]["skips"], guid)) || (docs[0]["adminpass"] == hash && docs[0]["adminpass"] != "" && docs[0]["skip"])) { change_song(coll); @@ -369,7 +370,11 @@ io.on('connection', function(socket){ socket.emit("toast", "notyetskip"); }*/else if(!contains(docs[0]["skips"], guid)){ db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){ - socket.emit("toast", (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1) + " more are needed to skip!"); + if(lists[coll].length == 2) + to_skip = 1; + else + to_skip = (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1); + socket.emit("toast", to_skip + " more are needed to skip!"); socket.broadcast.emit('chat,'+coll, [name, " voted to skip"]); }); }else{