mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	Trying a fix for chat names crashing the server
This commit is contained in:
		| @@ -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; |     if(!data.hasOwnProperty("name") || data.name.length > 10 || !data.hasOwnProperty("channel")) return; | ||||||
|     var pw = ""; |     var pw = ""; | ||||||
|     var new_password; |     var new_password; | ||||||
| @@ -122,17 +122,26 @@ function namechange(data, guid, socket) { | |||||||
|         } |         } | ||||||
|         if(accepted_password) { |         if(accepted_password) { | ||||||
|             db.collection("user_names").find({"guid": guid}, function(err, names) { |             db.collection("user_names").find({"guid": guid}, function(err, names) { | ||||||
|                 var old_name = names[0].name; |                 if(names.length > 0) { | ||||||
|                 db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {}); |                     var old_name = names[0].name; | ||||||
|                 db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) { |                     db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {}); | ||||||
|                     db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) { |                     db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, function(err, docs) { | ||||||
|                         socket.emit('name', {type: "name", accepted: true}); |                         db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: name}}, function(err, docs) { | ||||||
|                         if(old_name != name && !first) { |                             socket.emit('name', {type: "name", accepted: true}); | ||||||
|                             io.to(data.channel).emit('chat', {from: old_name, msg: " changed name to " + name}); |                             if(old_name != name && !first) { | ||||||
|                             io.sockets.emit('chat.all', {from: old_name , msg: " changed name to " + name, channel: data.channel}); |                                 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 { |         } else { | ||||||
|             socket.emit('name', {type: "name", accepted: false}); |             socket.emit('name', {type: "name", accepted: false}); | ||||||
|   | |||||||
| @@ -2,13 +2,12 @@ VERSION = 3; | |||||||
|  |  | ||||||
| var server; | var server; | ||||||
| var add = ""; | var add = ""; | ||||||
| const path = require('path'); | var path = require('path'); | ||||||
| const publicPath = path.join(__dirname, 'public'); | var publicPath = path.join(__dirname, 'public'); | ||||||
| pathThumbnails = __dirname; | pathThumbnails = __dirname; | ||||||
| var express = require('express'); | var express = require('express'); | ||||||
| var app = express(); | var app = express(); | ||||||
| var exphbs = require('express-handlebars'); | 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 cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js')); | ||||||
| var hbs = exphbs.create({ | var hbs = exphbs.create({ | ||||||
| 	defaultLayout: publicPath + '/layouts/main', | 	defaultLayout: publicPath + '/layouts/main', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user