function del(params, socket, socketid) { if(params.id){ var coll = Functions.removeEmojis(params.channel).toLowerCase(); //coll = coll.replace(/_/g, "").replace(/ /g,''); //coll = filter.clean(coll); db.collection(coll + "_settings").find(function(err, docs){ if(docs !== null && docs.length !== 0 && docs[0].adminpass == params.adminpass) { db.collection(coll).find({id:params.id}, function(err, docs){ var dont_increment = false; if(docs[0]){ if(docs[0].type == "suggested"){ dont_increment = true; } db.collection(coll).remove({id:params.id}, function(err, docs){ socket.emit("toast", "deletesong"); io.to(coll).emit("channel", {type:"deleted", value: params.id}); if(!dont_increment) db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){}); }); } }); } }); } }
function all_chat(msg, guid, offline, socket) { if(typeof(msg) !== 'object' || !msg.hasOwnProperty("channel") || !msg.hasOwnProperty("data") || typeof(msg.data) != "string" || typeof(msg.channel) != "string") { var result = { data: { expected: "string", got: msg.hasOwnProperty("data") ? typeof(msg.data) : undefined, }, channel: { expected: "string", got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined } }; socket.emit('update_required', result); return; } var coll = msg.channel.toLowerCase();//.replace(/ /g,''); var data = msg.data; coll = Functions.removeEmojis(coll).toLowerCase(); //coll = filter.clean(coll); Functions.check_inlist(coll, guid, socket, offline, function() { if(data !== "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length){ db.collection("user_names").find({"guid": guid}, function(err, docs) { if(docs.length == 1) { db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) { var icon = false; if(n.length > 0 && n[0].icon) { icon = n[0].icon; } db.collection("chat_logs").insert({ "createdAt": new Date(), all: true, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon }, function(err, docs) {}); io.sockets.emit('chat.all', {from: docs[0].name, msg: ": " + data, channel: coll, icon: icon}); }); } else if(docs.length == 0) { get_name(guid, {announce: false, channel: coll, message: data, all: true, socket: socket}); } }); } }, "place 2"); }
function delete_all(msg, coll, guid, offline, socket) { var socketid = socket.zoff_id; if(typeof(msg) == 'object' ) { if(!msg.hasOwnProperty('channel') || typeof(msg.channel) != "string") { var result = { channel: { expected: "string", got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined, }, adminpass: { expected: "adminpass", got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined, }, pass: { expected: "string", got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined, }, }; socket.emit('update_required', result); return; } if(coll == undefined) { coll = msg.channel; } //coll = coll.replace(/ /g,''); coll = Functions.removeEmojis(coll).toLowerCase(); //coll = filter.clean(coll); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) { if(adminpass != "" || msg.adminpass == undefined) { msg.adminpass = Functions.hash_pass(adminpass); } else if(msg.adminpass != "") { msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true)); } if(userpass != "" || msg.pass == undefined) { msg.pass = userpass; } else { msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64"); } var hash = msg.adminpass; var hash_userpass = msg.pass; db.collection(coll + "_settings").find(function(err, conf) { if(conf.length == 1 && conf) { conf = conf[0]; if(conf.adminpass == hash && conf.adminpass != "" && (conf.userpass == "" || conf.userpass == undefined || (conf.userpass != "" && conf.userpass != undefined && conf.pass == hash_userpass))) { db.collection(coll).remove({views: {$exists: false}, type: "video"}, {multi: true}, function(err, succ) { List.send_list(coll, false, true, true, true); db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: Functions.get_time()}}, {upsert: true}, function(err, docs) {}); socket.emit("toast", "deleted_songs"); }); } else { socket.emit("toast", "listhaspass"); } } }); }); } else { var result = { msg: { expected: "object", got: typeof(msg) }, }; socket.emit('update_required', result); return; } }
function shuffle(msg, coll, guid, offline, socket) { var socketid = socket.zoff_id; if(!msg.hasOwnProperty("channel") || typeof(msg.channel) != "string") { var result = { channel: { expected: "string", got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined, }, adminpass: { expected: "string", got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined, }, pass: { expected: "string", got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined, }, }; socket.emit('update_required', result); return; } coll = msg.channel.toLowerCase();//.replace(/ /g,''); coll = Functions.removeEmojis(coll).toLowerCase(); //coll = filter.clean(coll); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { if(adminpass != "" || msg.adminpass == undefined) { msg.adminpass = Functions.hash_pass(adminpass); } else if(msg.adminpass != ""){ msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true)); } else { msg.adminpass = ""; } if(userpass != "" || msg.pass == undefined) { msg.pass = userpass; } else if(msg.hasOwnProperty("pass")) { msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64"); } Functions.checkTimeout("shuffle", 5, coll, coll, "foo", "bar", socket, function() { Functions.check_inlist(coll, guid, socket, offline, undefined, "place 7"); var hash = msg.adminpass; db.collection(coll + "_settings").find(function(err, docs){ if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) { if(docs !== null && 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){ List.send_list(coll, undefined, false, true, false, true); socket.emit("toast", "shuffled"); return; }else{ num = Math.floor(Math.random()*1000000); db.collection(coll).update({id:docs.id}, {$set:{added:num}}); } }); }else socket.emit("toast", "wrongpass"); } else { socket.emit("auth_required"); } }); var complete = function(tot, curr){ if(tot == curr) { List.send_list(coll, undefined, false, true, false); List.getNextSong(coll, undefined); } }; }); }); }
function voteUndecided(msg, coll, guid, offline, socket) { var socketid = socket.zoff_id; if(typeof(msg) === 'object' && msg !== undefined && msg !== null){ if(msg.hasOwnProperty("id")) msg.id = msg.id + ""; if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("id") || !msg.hasOwnProperty("type") || typeof(msg.channel) != "string" || typeof(msg.id) != "string" || typeof(msg.type) != "string") { var result = { channel: { expected: "string", got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined, }, id: { expected: "string", got: msg.hasOwnProperty("id") ? typeof(msg.id) : undefined, }, type: { expected: "string", got: msg.hasOwnProperty("type") ? typeof(msg.type) : undefined, }, adminpass: { expected: "adminpass", got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined, }, pass: { expected: "string", got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined, }, }; socket.emit('update_required', result); return; } coll = msg.channel.toLowerCase();//.replace(/ /g,''); coll = Functions.removeEmojis(coll).toLowerCase(); //coll = filter.clean(coll); Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { if(adminpass != "" || msg.adminpass == undefined) { msg.adminpass = Functions.hash_pass(adminpass); } else { msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)); } if(userpass != "" || msg.pass == undefined) { msg.pass = userpass; } else if(msg.hasOwnProperty("pass")){ msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64"); } db.collection(coll + "_settings").find({id: "config"}, function(err, docs){ if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) { Functions.check_inlist(coll, guid, socket, offline, undefined, "place 6"); if(msg.type == "del") { del(msg, socket, socketid); } else { var id = msg.id; var hash = msg.adminpass; if(docs !== null && docs.length !== 0 && ((docs[0].vote === true && (hash == docs[0].adminpass || docs[0].adminpass === "")) || docs[0].vote === false)) { vote(coll, id, guid, socket); } else { socket.emit("toast", "listhaspass"); } } } else { socket.emit("auth_required"); } }); }); } else { var result = { msg: { expected: "object", got: typeof(msg) } }; socket.emit('update_required', result); } }
function chat(msg, guid, offline, socket) { if(typeof(msg) !== 'object' || !msg.hasOwnProperty('data') || !msg.hasOwnProperty('channel') || typeof(msg.data) != "string" || typeof(msg.channel) != "string") { var result = { data: { expected: "string", got: msg.hasOwnProperty("data") ? typeof(msg.data) : undefined, }, channel: { expected: "string", got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined }, pass: { expected: "string", got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined } }; socket.emit('update_required', result); return; } var coll = msg.channel.toLowerCase();//.replace(/ /g,''); coll = Functions.removeEmojis(coll).toLowerCase(); //coll = filter.clean(coll); checkIfUserIsBanned(coll, socket, guid, function() { Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) { if(userpass != "" || msg.pass == undefined) { msg.pass = userpass; } else { msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64"); } db.collection(coll + "_settings").find(function(err, conf){ if(conf.length > 0 && (conf[0].hasOwnProperty("toggleChat") && !conf[0].toggleChat)) { socket.emit('chat', {from: "System", msg: ": Chat for this channel has been disabled.", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } else if(conf.length > 0 && (conf[0].userpass == undefined || conf[0].userpass == "" || (msg.hasOwnProperty('pass') && conf[0].userpass == msg.pass))) { var data = msg.data; Functions.check_inlist(coll, guid, socket, offline, function() { if(data == "/who") { db.collection("user_names").distinct("name", {channels: coll}, function(err, docs) { var userAdd = "s"; if(docs.length == 1) userAdd = ""; socket.emit('chat', {from: "System", msg: ": User" + userAdd + " in channel are: " + docs.join(", "), icon: "https://zoff.me/assets/images/favicon-32x32.png"}); }); } else if(data !== "" && data !== undefined && data !== null && data.length < 151 && data.replace(/\s/g, '').length){ db.collection("user_names").find({"guid": guid}, function(err, docs) { if(docs.length == 1) { var splitData = data.split(" "); if((data.startsWith("/ban") && splitData.length >= 3) || (data.startsWith("/unban") && splitData.length >= 2)) { if(splitData[1].length > 0) { var passToCompare = Functions.hash_pass(adminpass); if(passToCompare == conf[0].adminpass) { db.collection("user_names").find({name: splitData[1]}, function(err, name) { if(name.length == 1) { if(data.startsWith("/ban") && splitData.length >= 3) { var reason = splitData.slice(2, splitData.length).join(" "); var connection_id = name[0].connection_id; var yourSelf = Functions.hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]); if(connection_id != yourSelf) { db.collection(coll + "_banned_chat").update({ connection_id: connection_id }, { connection_id: connection_id, by: docs[0].name, reason: reason }, { upsert: true }, function(err, results) { io.to(coll).emit('chat', {from: "System", msg: ": " + docs[0].name + " has banned " + splitData[1] + " for: " + reason, icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; }); } else { socket.emit('chat', {from: "System", msg: ": I'm sorry but you can't ban yourself..", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } } else if(data.startsWith("/unban")) { db.collection(coll + "_banned_chat").remove({connection_id: name[0].connection_id}, function(err, results) { if(results.hasOwnProperty("n") && results.n == 1 && results.hasOwnProperty("deletedCount") && results.deletedCount == 1) { io.to(coll).emit('chat', {from: "System", msg: ": " + docs[0].name + " has unbanned " + splitData[1], icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } else { socket.emit('chat', {from: "System", msg: ": Cannot find anyone with that username in this chat.", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } }) } else if(data.startsWith("/ban") && splitData.length < 3) { socket.emit('chat', {from: "System", msg: ": You are doing that command wrong. its /ban USERNAME", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } } else { socket.emit('chat', {from: "System", msg: ": No user by that name.", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } }); } else { socket.emit('chat', {from: "System", msg: ": You are not logged in as an admin to the channel, don't try any funnybusiness.", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } } else { socket.emit('chat', {from: "System", msg: ": You are doing that command wrong. its /ban USERNAME REASON or /unban USERNAME", icon: "https://zoff.me/assets/images/favicon-32x32.png"}); return; } } else { db.collection("registered_users").find({"_id": docs[0].name}, function(err, n) { var icon = false; if(n.length > 0 && n[0].icon) { icon = n[0].icon; } db.collection("chat_logs").insert({ "createdAt": new Date(), all: false, channel: coll, from: docs[0].name, msg: ": " + data, icon: icon }); io.to(coll).emit('chat', {from: docs[0].name, msg: ": " + data, icon: icon}); }); } } else if(docs.length == 0){ get_name(guid, {announce: false, channel: coll, message: data, all: false, socket: socket}); } }); } }, "place 1"); } else { socket.emit('auth_required'); } }); }); }); }