More typechecking

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-04 22:57:27 +01:00
parent ad8bd1bff4
commit 924cc44a20
8 changed files with 42 additions and 22 deletions

View File

@@ -46,7 +46,9 @@ module.exports = function() {
socket.on('chromecast', function(msg) {
try {
if(typeof(msg) == "object" && msg.hasOwnProperty("guid") && msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel")) {
if(typeof(msg) == "object" && msg.hasOwnProperty("guid") &&
msg.hasOwnProperty("socket_id") && msg.hasOwnProperty("channel") && typeof(msg.guid) == "string" &&
typeof(msg.channel) == "string" && typeof(msg.socket_id) == "string") {
db.collection("connected_users").find({"_id": msg.channel}, function(err, connected_users_channel) {
if(connected_users_channel.length > 0 && connected_users_channel[0].users.indexOf(msg.guid) > -1) {
guid = msg.guid;
@@ -113,7 +115,8 @@ module.exports = function() {
});
socket.on("offline", function(msg){
if(!msg.hasOwnProperty('status') && !msg.hasOwnProperty('channel')) {
if(!msg.hasOwnProperty('status') || !msg.hasOwnProperty('channel') ||
typeof(msg.status) != "boolean" || typeof(msg.channel) != "string") {
socket.emit("update_required");
return;
}
@@ -159,6 +162,11 @@ module.exports = function() {
});
socket.on('get_history', function(msg) {
if(!msg.hasOwnProperty("channel") || !msg.hasOwnProperty("all") ||
typeof(msg.channel) != "string" || typeof(msg.all) != "boolean") {
socket.emit("update_required");
return;
}
Chat.get_history(msg.channel, msg.all, socket);
});
@@ -352,7 +360,8 @@ module.exports = function() {
socket.on('pos', function(obj)
{
if(!obj.hasOwnProperty("channel") || typeof(obj.channel) != "string" ||
(obj.hasOwnProperty("pass") && typeof(obj.pass) != "string"))
if(coll !== undefined) {
try {
coll = obj.channel;