diff --git a/server/handlers/chat.js b/server/handlers/chat.js index 72f6f199..d8fd0114 100644 --- a/server/handlers/chat.js +++ b/server/handlers/chat.js @@ -85,7 +85,7 @@ function all_chat(msg, guid, offline, socket) { } } -function namechange(data, guid, socket) { +function namechange(data, guid, socket, tried) { if(!data.hasOwnProperty("name") || data.name.length > 10 || !data.hasOwnProperty("channel")) return; var pw = ""; var new_password; @@ -122,17 +122,26 @@ function namechange(data, guid, socket) { } if(accepted_password) { db.collection("user_names").find({"guid": guid}, function(err, names) { - var old_name = names[0].name; - db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {}); - db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) { - db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) { - socket.emit('name', {type: "name", accepted: true}); - if(old_name != name && !first) { - io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name}); - io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel}); - } + if(names.length > 0) { + var old_name = names[0].name; + db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {}); + db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) { + db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) { + socket.emit('name', {type: "name", accepted: true}); + if(old_name != name && !first) { + io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name}); + io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel}); + } + }); }); - }); + } else { + if(tried < 3 || tried == undefined) { + if(tried == undefined) { + tried = 1; + } + namechange(data, guid, socket, tried + 1); + } + } }); } else { socket.emit('name', {type: "name", accepted: false}); diff --git a/server/index.js b/server/index.js index 5f7a65e1..4fb70903 100755 --- a/server/index.js +++ b/server/index.js @@ -2,13 +2,12 @@ VERSION = 3; var server; var add = ""; -const path = require('path'); -const publicPath = path.join(__dirname, 'public'); +var path = require('path'); +var publicPath = path.join(__dirname, 'public'); pathThumbnails = __dirname; var express = require('express'); var app = express(); var exphbs = require('express-handlebars'); -console.log(path.join(__dirname, 'config')); var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js')); var hbs = exphbs.create({ defaultLayout: publicPath + '/layouts/main',