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:
@@ -73,10 +73,11 @@ io.on('connection', function(socket){
|
||||
socket.emit("playlists", playlists_to_send);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socket.on('list', function(list)
|
||||
{
|
||||
if(list !== undefined && list !== null && list != "")
|
||||
{
|
||||
in_list = true;
|
||||
list = list.split(',');
|
||||
@@ -99,6 +100,7 @@ io.on('connection', function(socket){
|
||||
io.sockets.emit(coll+",viewers", lists[coll].length);
|
||||
|
||||
db.getCollectionNames(function(err, docs){
|
||||
|
||||
if(contains(docs, coll))
|
||||
{
|
||||
sort_list(coll, socket, true, false);
|
||||
@@ -116,9 +118,12 @@ io.on('connection', function(socket){
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('end', function(id)
|
||||
{
|
||||
if(id !== undefined && id !== null && id != "")
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -186,10 +191,13 @@ io.on('connection', function(socket){
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('add', function(arr)
|
||||
{
|
||||
if(arr !== undefined && arr !== null && arr != "")
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -208,7 +216,8 @@ io.on('connection', function(socket){
|
||||
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)
|
||||
if(docs.length != 0 && ((docs[0]["addsongs"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == ""))
|
||||
|| docs[0]["addsongs"] == false))
|
||||
{
|
||||
db.collection(coll).find({id:id}, function(err, docs){
|
||||
if(docs.length == 0)
|
||||
@@ -233,9 +242,12 @@ io.on('connection', function(socket){
|
||||
}else
|
||||
socket.emit("toast", "listhaspass");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('vote', function(msg)
|
||||
{
|
||||
if(msg !== undefined && msg !== null)
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -257,7 +269,8 @@ io.on('connection', function(socket){
|
||||
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)
|
||||
if(docs.length != 0 && ((docs[0]["vote"] == true && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == ""))
|
||||
|| docs[0]["vote"] == false))
|
||||
{
|
||||
vote(coll, id, guid, socket);
|
||||
}else{
|
||||
@@ -265,11 +278,13 @@ io.on('connection', function(socket){
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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];
|
||||
@@ -286,7 +301,9 @@ io.on('connection', function(socket){
|
||||
//console.log(coll);
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
//console.log(docs);
|
||||
console.log(docs);
|
||||
console.log(docs + " yy here?");
|
||||
if(docs.length != 0)
|
||||
{
|
||||
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)
|
||||
@@ -295,10 +312,14 @@ io.on('connection', function(socket){
|
||||
})
|
||||
}else
|
||||
socket.emit("toast", "wrongpass");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('skip', function(list)
|
||||
{
|
||||
if(list !== undefined && list !== null && list != "")
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -332,6 +353,8 @@ io.on('connection', function(socket){
|
||||
//console.log(adminpass);
|
||||
//console.log(docs[0]["adminpass"]);
|
||||
//console.log(error);
|
||||
if(docs.length != 0)
|
||||
{
|
||||
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) && (get_time() - docs[0]["startTime"] >= 10
|
||||
@@ -351,10 +374,14 @@ io.on('connection', function(socket){
|
||||
}
|
||||
}else
|
||||
socket.emit("toast", "noskip");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('conf', function(params)
|
||||
{
|
||||
if(params !== undefined && params !== null && params != "")
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -383,7 +410,7 @@ io.on('connection', function(socket){
|
||||
var hash = adminpass;
|
||||
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
if(docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash)
|
||||
if(docs.length != 0 && docs[0]["adminpass"] == "" || docs[0]["adminpass"] == hash)
|
||||
{
|
||||
db.collection(coll).update({views:{$exists:true}}, {
|
||||
$set:{addsongs:addsongs,
|
||||
@@ -408,9 +435,12 @@ io.on('connection', function(socket){
|
||||
socket.emit("toast", "wrongpass");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('shuffle', function(pass)
|
||||
{
|
||||
if(pass !== undefined && pass !== null && pass != "")
|
||||
{
|
||||
if(lists[coll] == undefined)
|
||||
{
|
||||
@@ -425,7 +455,7 @@ io.on('connection', function(socket){
|
||||
|
||||
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)
|
||||
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){
|
||||
@@ -450,6 +480,7 @@ io.on('connection', function(socket){
|
||||
sort_list(coll, undefined, false, true);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', function()
|
||||
@@ -487,7 +518,7 @@ function del(params, socket)
|
||||
{
|
||||
var coll = params[0].toLowerCase();
|
||||
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){
|
||||
socket.emit("toast", "deletesong");
|
||||
@@ -528,6 +559,8 @@ function change_song(coll, id, np_id)
|
||||
{
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||
var startTime = docs[0]["startTime"];
|
||||
if(docs.length != 0)
|
||||
{
|
||||
if(docs[0]["removeplay"] == true)
|
||||
{
|
||||
db.collection(coll).remove({now_playing:true}, function(err, docs)
|
||||
@@ -547,7 +580,8 @@ function change_song(coll, id, np_id)
|
||||
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)
|
||||
{
|
||||
db.collection(coll).find({now_playing:true}, function(err, np){
|
||||
if(np.length != 0)
|
||||
{
|
||||
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
||||
if(conf.length != 0)
|
||||
{
|
||||
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