mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Added some error handlers, and tracking a logger
This commit is contained in:
710
server/server.js
710
server/server.js
@@ -73,383 +73,414 @@ io.on('connection', function(socket){
|
|||||||
socket.emit("playlists", playlists_to_send);
|
socket.emit("playlists", playlists_to_send);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('list', function(list)
|
socket.on('list', function(list)
|
||||||
{
|
{
|
||||||
in_list = true;
|
if(list !== undefined && list !== null && list != "")
|
||||||
list = list.split(',');
|
|
||||||
coll = list[0].toLowerCase();
|
|
||||||
guid = list[1];
|
|
||||||
|
|
||||||
console.log(guid + " joined list " + coll);
|
|
||||||
|
|
||||||
if(lists[coll] == undefined)
|
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
in_list = true;
|
||||||
lists[coll].push(guid);
|
list = list.split(',');
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
coll = list[0].toLowerCase();
|
||||||
}else if(!contains(lists[coll], guid))
|
guid = list[1];
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
console.log(guid + " joined list " + coll);
|
||||||
|
|
||||||
|
if(lists[coll] == undefined)
|
||||||
|
{
|
||||||
|
lists[coll] = [];
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}else if(!contains(lists[coll], guid))
|
||||||
|
{
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}
|
||||||
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
|
||||||
|
db.getCollectionNames(function(err, docs){
|
||||||
|
|
||||||
|
if(contains(docs, coll))
|
||||||
|
{
|
||||||
|
sort_list(coll, socket, true, false);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
db.createCollection(coll, function(err, docs){
|
||||||
|
db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":false, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false}, function(err, docs)
|
||||||
|
{
|
||||||
|
sort_list(coll, socket, true, false);
|
||||||
|
/*db.collection(coll).find().sort({votes:-1}, function(err, docs) {
|
||||||
|
socket.emit(coll, docs);
|
||||||
|
//send_play(coll, socket);
|
||||||
|
});*/
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
|
|
||||||
db.getCollectionNames(function(err, docs){
|
|
||||||
if(contains(docs, coll))
|
|
||||||
{
|
|
||||||
sort_list(coll, socket, true, false);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
db.createCollection(coll, function(err, docs){
|
|
||||||
db.collection(coll).insert({"addsongs":false, "adminpass":"", "allvideos":false, "frontpage":true, "longsongs":false, "removeplay": false, "shuffle": true, "skip": false, "skips": [], "startTime":get_time(), "views": [], "vote": false}, function(err, docs)
|
|
||||||
{
|
|
||||||
sort_list(coll, socket, true, false);
|
|
||||||
/*db.collection(coll).find().sort({votes:-1}, function(err, docs) {
|
|
||||||
socket.emit(coll, docs);
|
|
||||||
//send_play(coll, socket);
|
|
||||||
});*/
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('end', function(id)
|
socket.on('end', function(id)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(id !== undefined && id !== null && id != "")
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
{
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
lists[coll] = [];
|
||||||
}else if(!contains(lists[coll], guid))
|
lists[coll].push(guid);
|
||||||
{
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
lists[coll].push(guid);
|
}else if(!contains(lists[coll], guid))
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
{
|
||||||
}
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}
|
||||||
|
|
||||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||||
//console.log(docs);
|
//console.log(docs);
|
||||||
//console.log(docs.length);
|
//console.log(docs.length);
|
||||||
if(np.length == 1 && np[0]["id"] == id){
|
if(np.length == 1 && np[0]["id"] == id){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
var startTime = docs[0]["startTime"];
|
var startTime = docs[0]["startTime"];
|
||||||
if(docs[0]["removeplay"] == true)
|
if(docs[0]["removeplay"] == true)
|
||||||
{
|
|
||||||
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
|
||||||
{
|
{
|
||||||
change_song_post(coll);
|
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
||||||
})
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
console.log(np[0]["title"] + " before if");
|
|
||||||
if(startTime+parseInt(np[0]["duration"])<=get_time()+2)
|
|
||||||
{
|
{
|
||||||
console.log(np[0]["title"] + " after if");
|
change_song_post(coll);
|
||||||
db.collection(coll).update({now_playing:true, id:id},
|
})
|
||||||
{$set:{
|
}else
|
||||||
now_playing:false,
|
{
|
||||||
votes:0,
|
console.log(np[0]["title"] + " before if");
|
||||||
guids:[]
|
if(startTime+parseInt(np[0]["duration"])<=get_time()+2)
|
||||||
}}, function(err, docs)
|
{
|
||||||
{
|
console.log(np[0]["title"] + " after if");
|
||||||
//console.log(err);
|
db.collection(coll).update({now_playing:true, id:id},
|
||||||
//console.log(docs["n"]);
|
{$set:{
|
||||||
if(docs["n"] == 1)
|
now_playing:false,
|
||||||
|
votes:0,
|
||||||
|
guids:[]
|
||||||
|
}}, function(err, docs)
|
||||||
{
|
{
|
||||||
db.collection(coll).aggregate([
|
//console.log(err);
|
||||||
{$match:{now_playing:false}},
|
//console.log(docs["n"]);
|
||||||
{$sort:{votes:-1, added:1}},
|
if(docs["n"] == 1)
|
||||||
{$limit:1}], function(err, docs){
|
{
|
||||||
if(docs.length > 0){
|
db.collection(coll).aggregate([
|
||||||
db.collection(coll).update({id:docs[0]["id"]},
|
{$match:{now_playing:false}},
|
||||||
{$set:{
|
{$sort:{votes:-1, added:1}},
|
||||||
now_playing:true,
|
{$limit:1}], function(err, docs){
|
||||||
votes:0,
|
if(docs.length > 0){
|
||||||
guids:[],
|
db.collection(coll).update({id:docs[0]["id"]},
|
||||||
added:get_time()}}, function(err, docs){
|
{$set:{
|
||||||
db.collection(coll).update({views:{$exists:true}},
|
now_playing:true,
|
||||||
{$set:{startTime:get_time(), skips:[]}}, function(err, docs){
|
votes:0,
|
||||||
sort_list(coll, undefined, true, true);
|
guids:[],
|
||||||
|
added:get_time()}}, function(err, docs){
|
||||||
|
db.collection(coll).update({views:{$exists:true}},
|
||||||
|
{$set:{startTime:get_time(), skips:[]}}, function(err, docs){
|
||||||
|
sort_list(coll, undefined, true, true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('add', function(arr)
|
socket.on('add', function(arr)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(arr !== undefined && arr !== null && arr != "")
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}else if(!contains(lists[coll], guid))
|
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var id = arr[0];
|
|
||||||
var title = arr[1];
|
|
||||||
var hash = hash_pass(arr[2]);
|
|
||||||
var duration = parseInt(arr[3]);
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
|
||||||
{
|
|
||||||
if((docs[0]["addsongs"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == "")) || docs[0]["addsongs"] == false)
|
|
||||||
{
|
{
|
||||||
db.collection(coll).find({id:id}, function(err, docs){
|
lists[coll] = [];
|
||||||
if(docs.length == 0)
|
lists[coll].push(guid);
|
||||||
{
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
var guids = [guid];
|
}else if(!contains(lists[coll], guid))
|
||||||
var votes = 1;
|
{
|
||||||
//var guids = [];
|
lists[coll].push(guid);
|
||||||
//var votes = 0;
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
db.collection(coll).find({now_playing:true}, function(err, docs){
|
}
|
||||||
if(docs.length == 0)
|
|
||||||
np = true;
|
var id = arr[0];
|
||||||
else
|
var title = arr[1];
|
||||||
np = false;
|
var hash = hash_pass(arr[2]);
|
||||||
db.collection(coll).insert({"added":get_time(),"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, function(err, docs){
|
var duration = parseInt(arr[3]);
|
||||||
sort_list(coll, undefined, np, true);
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
||||||
});
|
{
|
||||||
});
|
if(docs.length != 0 && ((docs[0]["addsongs"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == ""))
|
||||||
}else{
|
|| docs[0]["addsongs"] == false))
|
||||||
vote(coll, id, guid, socket);
|
{
|
||||||
}
|
db.collection(coll).find({id:id}, function(err, docs){
|
||||||
});
|
if(docs.length == 0)
|
||||||
}else
|
{
|
||||||
socket.emit("toast", "listhaspass");
|
var guids = [guid];
|
||||||
});
|
var votes = 1;
|
||||||
|
//var guids = [];
|
||||||
|
//var votes = 0;
|
||||||
|
db.collection(coll).find({now_playing:true}, function(err, docs){
|
||||||
|
if(docs.length == 0)
|
||||||
|
np = true;
|
||||||
|
else
|
||||||
|
np = false;
|
||||||
|
db.collection(coll).insert({"added":get_time(),"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration}, function(err, docs){
|
||||||
|
sort_list(coll, undefined, np, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
vote(coll, id, guid, socket);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else
|
||||||
|
socket.emit("toast", "listhaspass");
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('vote', function(msg)
|
socket.on('vote', function(msg)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(msg !== undefined && msg !== null)
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}else if(!contains(lists[coll], guid))
|
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(msg[2] == "del")
|
|
||||||
del(msg, socket);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var id = msg[1];
|
|
||||||
guid = msg[3];
|
|
||||||
var hash = hash_pass(msg[4]);
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
|
||||||
{
|
{
|
||||||
if((docs[0]["vote"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == "")) || docs[0]["vote"] == false)
|
lists[coll] = [];
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}else if(!contains(lists[coll], guid))
|
||||||
|
{
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(msg[2] == "del")
|
||||||
|
del(msg, socket);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var id = msg[1];
|
||||||
|
guid = msg[3];
|
||||||
|
var hash = hash_pass(msg[4]);
|
||||||
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
||||||
{
|
{
|
||||||
vote(coll, id, guid, socket);
|
if(docs.length != 0 && ((docs[0]["vote"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == ""))
|
||||||
}else{
|
|| docs[0]["vote"] == false))
|
||||||
socket.emit("toast", "listhaspass");
|
{
|
||||||
}
|
vote(coll, id, guid, socket);
|
||||||
});
|
}else{
|
||||||
|
socket.emit("toast", "listhaspass");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('password', function(inp)
|
socket.on('password', function(inp)
|
||||||
{
|
{
|
||||||
console.log(inp);
|
if(inp !== undefined && inp !== null && inp != "" && inp.length == 3)
|
||||||
pw = inp[0];
|
|
||||||
coll = inp[1];
|
|
||||||
guid = inp[2];
|
|
||||||
if(lists[coll] == undefined)
|
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
pw = inp[0];
|
||||||
lists[coll].push(guid);
|
coll = inp[1];
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
guid = inp[2];
|
||||||
}else if(!contains(lists[coll], guid))
|
if(lists[coll] == undefined)
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}
|
|
||||||
//console.log(coll);
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
|
||||||
//console.log(docs);
|
|
||||||
console.log(docs);
|
|
||||||
if(docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash_pass(pw))
|
|
||||||
{
|
{
|
||||||
db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:hash_pass(pw)}}, function(err, docs)
|
lists[coll] = [];
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}else if(!contains(lists[coll], guid))
|
||||||
|
{
|
||||||
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}
|
||||||
|
//console.log(coll);
|
||||||
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
|
//console.log(docs);
|
||||||
|
console.log(docs + " yy here?");
|
||||||
|
if(docs.length != 0)
|
||||||
{
|
{
|
||||||
socket.emit("pw", pw);
|
if(docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash_pass(pw))
|
||||||
})
|
{
|
||||||
}else
|
db.collection(coll).update({views:{$exists:true}}, {$set:{adminpass:hash_pass(pw)}}, function(err, docs)
|
||||||
socket.emit("toast", "wrongpass");
|
{
|
||||||
});
|
socket.emit("pw", pw);
|
||||||
|
})
|
||||||
|
}else
|
||||||
|
socket.emit("toast", "wrongpass");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('skip', function(list)
|
socket.on('skip', function(list)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(list !== undefined && list !== null && list != "")
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
{
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
lists[coll] = [];
|
||||||
}else if(!contains(lists[coll], guid))
|
lists[coll].push(guid);
|
||||||
{
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
lists[coll].push(guid);
|
}else if(!contains(lists[coll], guid))
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
{
|
||||||
}
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
|
}
|
||||||
|
|
||||||
adminpass = "";
|
adminpass = "";
|
||||||
|
|
||||||
var error = false;
|
var error = false;
|
||||||
if(list != "5" && list != "100" && list != "101" && list != "150" && list !== undefined)
|
if(list != "5" && list != "100" && list != "101" && list != "150" && list !== undefined)
|
||||||
{
|
{
|
||||||
adminpass = list[2];
|
adminpass = list[2];
|
||||||
}else if(list == "5" || list == "100" || list == "101" || list == "150"){
|
}else if(list == "5" || list == "100" || list == "101" || list == "150"){
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(adminpass);
|
|
||||||
|
|
||||||
if(adminpass !== undefined && adminpass !== null && adminpass != "")
|
|
||||||
var hash = hash_pass(adminpass);
|
|
||||||
else
|
|
||||||
var hash = "";
|
|
||||||
|
|
||||||
db.collection(coll).find({views: {$exists:true}}, function(err, docs){
|
|
||||||
//console.log(adminpass);
|
//console.log(adminpass);
|
||||||
//console.log(docs[0]["adminpass"]);
|
|
||||||
//console.log(error);
|
if(adminpass !== undefined && adminpass !== null && adminpass != "")
|
||||||
if(!docs[0]["skip"] || (docs[0]["adminpass"] == hash && docs[0]["adminpass"] != "") || error)
|
var hash = hash_pass(adminpass);
|
||||||
{
|
else
|
||||||
if((lists[coll].length/2 <= docs[0]["skips"].length+1 && !contains(docs[0]["skips"], guid) && (get_time() - docs[0]["startTime"] >= 10
|
var hash = "";
|
||||||
|| lists[coll].length != 2)) || (docs[0]["adminpass"] == adminpass && docs[0]["adminpass"] != ""))
|
|
||||||
{
|
db.collection(coll).find({views: {$exists:true}}, function(err, docs){
|
||||||
change_song(coll);
|
//console.log(adminpass);
|
||||||
socket.emit("toast", "skip");
|
//console.log(docs[0]["adminpass"]);
|
||||||
}else if(get_time() - docs[0]["startTime"] < 10 && lists[coll].length == 2 && !error)
|
//console.log(error);
|
||||||
|
if(docs.length != 0)
|
||||||
{
|
{
|
||||||
socket.emit("toast", "notyetskip");
|
if(!docs[0]["skip"] || (docs[0]["adminpass"] == hash && docs[0]["adminpass"] != "") || error)
|
||||||
}else if(!contains(docs[0]["skips"], guid) && get_time() - docs[0]["startTime"] >= 30){
|
{
|
||||||
db.collection(coll).update({views:{$exists:true}}, {$push:{skips:guid}}, function(err, d){
|
if((lists[coll].length/2 <= docs[0]["skips"].length+1 && !contains(docs[0]["skips"], guid) && (get_time() - docs[0]["startTime"] >= 10
|
||||||
socket.emit("toast", (Math.ceil(lists[coll].length/2) - docs[0]["skips"].length-1) + " more are needed to skip!");
|
|| lists[coll].length != 2)) || (docs[0]["adminpass"] == adminpass && docs[0]["adminpass"] != ""))
|
||||||
});
|
{
|
||||||
}else{
|
change_song(coll);
|
||||||
socket.emit("toast", "alreadyskip");
|
socket.emit("toast", "skip");
|
||||||
|
}else if(get_time() - docs[0]["startTime"] < 10 && lists[coll].length == 2 && !error)
|
||||||
|
{
|
||||||
|
socket.emit("toast", "notyetskip");
|
||||||
|
}else if(!contains(docs[0]["skips"], guid) && get_time() - docs[0]["startTime"] >= 30){
|
||||||
|
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!");
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
socket.emit("toast", "alreadyskip");
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
socket.emit("toast", "noskip");
|
||||||
}
|
}
|
||||||
}else
|
});
|
||||||
socket.emit("toast", "noskip");
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('conf', function(params)
|
socket.on('conf', function(params)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(params !== undefined && params !== null && params != "")
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}else if(!contains(lists[coll], guid))
|
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var voting = params[0];
|
|
||||||
var addsongs = params[1];
|
|
||||||
var longsongs = params[2];
|
|
||||||
var frontpage = params[3];
|
|
||||||
var allvideos = params[4];
|
|
||||||
var removeplay = params[5];
|
|
||||||
var adminpass = params[6];
|
|
||||||
var skipping = params[7];
|
|
||||||
var shuffling = params[8];
|
|
||||||
|
|
||||||
if(adminpass != "")
|
|
||||||
var hash = hash_pass(adminpass);
|
|
||||||
else
|
|
||||||
var hash = adminpass;
|
|
||||||
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
|
||||||
if(docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash)
|
|
||||||
{
|
{
|
||||||
db.collection(coll).update({views:{$exists:true}}, {
|
lists[coll] = [];
|
||||||
$set:{addsongs:addsongs,
|
lists[coll].push(guid);
|
||||||
allvideos:allvideos,
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
frontpage:frontpage,
|
}else if(!contains(lists[coll], guid))
|
||||||
skip:skipping,
|
|
||||||
vote:voting,
|
|
||||||
removeplay:removeplay,
|
|
||||||
shuffle:shuffling,
|
|
||||||
longsongs:longsongs,
|
|
||||||
adminpass:hash}}, function(err, docs){
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
|
||||||
{
|
|
||||||
io.sockets.emit(coll+",conf", docs);
|
|
||||||
socket.emit("toast", "savedsettings");
|
|
||||||
});
|
|
||||||
//sort_list(coll,undefined,false);
|
|
||||||
});
|
|
||||||
|
|
||||||
}else
|
|
||||||
{
|
{
|
||||||
socket.emit("toast", "wrongpass");
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
var voting = params[0];
|
||||||
|
var addsongs = params[1];
|
||||||
|
var longsongs = params[2];
|
||||||
|
var frontpage = params[3];
|
||||||
|
var allvideos = params[4];
|
||||||
|
var removeplay = params[5];
|
||||||
|
var adminpass = params[6];
|
||||||
|
var skipping = params[7];
|
||||||
|
var shuffling = params[8];
|
||||||
|
|
||||||
|
if(adminpass != "")
|
||||||
|
var hash = hash_pass(adminpass);
|
||||||
|
else
|
||||||
|
var hash = adminpass;
|
||||||
|
|
||||||
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
|
if(docs.length != 0 && docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash)
|
||||||
|
{
|
||||||
|
db.collection(coll).update({views:{$exists:true}}, {
|
||||||
|
$set:{addsongs:addsongs,
|
||||||
|
allvideos:allvideos,
|
||||||
|
frontpage:frontpage,
|
||||||
|
skip:skipping,
|
||||||
|
vote:voting,
|
||||||
|
removeplay:removeplay,
|
||||||
|
shuffle:shuffling,
|
||||||
|
longsongs:longsongs,
|
||||||
|
adminpass:hash}}, function(err, docs){
|
||||||
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
|
||||||
|
{
|
||||||
|
io.sockets.emit(coll+",conf", docs);
|
||||||
|
socket.emit("toast", "savedsettings");
|
||||||
|
});
|
||||||
|
//sort_list(coll,undefined,false);
|
||||||
|
});
|
||||||
|
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
socket.emit("toast", "wrongpass");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('shuffle', function(pass)
|
socket.on('shuffle', function(pass)
|
||||||
{
|
{
|
||||||
if(lists[coll] == undefined)
|
if(pass !== undefined && pass !== null && pass != "")
|
||||||
{
|
{
|
||||||
lists[coll] = [];
|
if(lists[coll] == undefined)
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}else if(!contains(lists[coll], guid))
|
|
||||||
{
|
|
||||||
lists[coll].push(guid);
|
|
||||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var hash = hash_pass(pass);
|
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
|
||||||
if((docs[0]["adminpass"] == hash || docs[0]["adminpass"] == "") || docs[0]["shuffle"] == false)
|
|
||||||
{
|
{
|
||||||
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
lists[coll] = [];
|
||||||
if(!docs){
|
lists[coll].push(guid);
|
||||||
sort_list(coll, undefined, false, true);
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
socket.emit("toast", "shuffled");
|
}else if(!contains(lists[coll], guid))
|
||||||
return;
|
|
||||||
}else{
|
|
||||||
num = Math.floor(Math.random()*1000000);
|
|
||||||
db.collection(coll).update({id:docs["id"]}, {$set:{added:num}}, function(err, d)
|
|
||||||
{
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}else
|
|
||||||
socket.emit("toast", "wrongpass");
|
|
||||||
});
|
|
||||||
|
|
||||||
var complete = function(tot, curr){
|
|
||||||
if(tot == curr)
|
|
||||||
{
|
{
|
||||||
sort_list(coll, undefined, false, true);
|
lists[coll].push(guid);
|
||||||
|
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
var hash = hash_pass(pass);
|
||||||
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
|
if(docs.length != 0 && ((docs[0]["adminpass"] == hash || docs[0]["adminpass"] == "") || docs[0]["shuffle"] == false))
|
||||||
|
{
|
||||||
|
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
|
||||||
|
if(!docs){
|
||||||
|
sort_list(coll, undefined, false, true);
|
||||||
|
socket.emit("toast", "shuffled");
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
num = Math.floor(Math.random()*1000000);
|
||||||
|
db.collection(coll).update({id:docs["id"]}, {$set:{added:num}}, function(err, d)
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else
|
||||||
|
socket.emit("toast", "wrongpass");
|
||||||
|
});
|
||||||
|
|
||||||
|
var complete = function(tot, curr){
|
||||||
|
if(tot == curr)
|
||||||
|
{
|
||||||
|
sort_list(coll, undefined, false, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', function()
|
socket.on('disconnect', function()
|
||||||
@@ -487,7 +518,7 @@ function del(params, socket)
|
|||||||
{
|
{
|
||||||
var coll = params[0].toLowerCase();
|
var coll = params[0].toLowerCase();
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
if(docs[0]["adminpass"] == hash_pass(params[4]))
|
if(docs.length != 0 && docs[0]["adminpass"] == hash_pass(params[4]))
|
||||||
{
|
{
|
||||||
db.collection(coll).remove({id:params[1]}, function(err, docs){
|
db.collection(coll).remove({id:params[1]}, function(err, docs){
|
||||||
socket.emit("toast", "deletesong");
|
socket.emit("toast", "deletesong");
|
||||||
@@ -528,26 +559,29 @@ function change_song(coll, id, np_id)
|
|||||||
{
|
{
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
var startTime = docs[0]["startTime"];
|
var startTime = docs[0]["startTime"];
|
||||||
if(docs[0]["removeplay"] == true)
|
if(docs.length != 0)
|
||||||
{
|
{
|
||||||
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
if(docs[0]["removeplay"] == true)
|
||||||
{
|
{
|
||||||
change_song_post(coll);
|
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
||||||
})
|
{
|
||||||
}else
|
change_song_post(coll);
|
||||||
{
|
})
|
||||||
//console.log("undef");
|
}else
|
||||||
db.collection(coll).update({now_playing:true},
|
{
|
||||||
{$set:{
|
//console.log("undef");
|
||||||
now_playing:false,
|
db.collection(coll).update({now_playing:true},
|
||||||
votes:0,
|
{$set:{
|
||||||
guids:[]
|
now_playing:false,
|
||||||
}},{multi:true}, function(err, docs)
|
votes:0,
|
||||||
{
|
guids:[]
|
||||||
change_song_post(coll);
|
}},{multi:true}, function(err, docs)
|
||||||
});
|
{
|
||||||
|
change_song_post(coll);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_song_post(coll)
|
function change_song_post(coll)
|
||||||
@@ -592,13 +626,19 @@ function sort_list(coll, socket, send, list_send)
|
|||||||
function send_play(coll, socket)
|
function send_play(coll, socket)
|
||||||
{
|
{
|
||||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
if(np.length != 0)
|
||||||
toSend = [np,conf,get_time()];
|
{
|
||||||
if(socket === undefined)
|
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
||||||
io.sockets.emit(coll+",np", toSend);
|
if(conf.length != 0)
|
||||||
else
|
{
|
||||||
socket.emit(coll+",np", toSend);
|
toSend = [np,conf,get_time()];
|
||||||
});
|
if(socket === undefined)
|
||||||
|
io.sockets.emit(coll+",np", toSend);
|
||||||
|
else
|
||||||
|
socket.emit(coll+",np", toSend);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user