mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Trying fix for some users not getting a chat-name in the chat
This commit is contained in:
@@ -89,13 +89,7 @@ function chat(msg, guid, offline, socket) {
|
||||
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 &&
|
||||
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) {
|
||||
@@ -236,11 +230,7 @@ function namechange(data, guid, socket, tried, callback) {
|
||||
var old_name = names[0].name;
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: old_name}}, function() {});
|
||||
}
|
||||
var updateElement = {$set: {name: name, icon: icon}};
|
||||
if(data.hasOwnProperty("channel") && data.channel != "") {
|
||||
updateElement["$addToSet"] = {channels: data.channel};
|
||||
}
|
||||
db.collection("user_names").update({"guid": guid}, updateElement, {upsert: true}, function(err, docs) {
|
||||
db.collection("user_names").update({"guid": guid}, {$set: {name: name, icon: icon}}, {upsert: true}, 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 && !no_name) {
|
||||
@@ -286,7 +276,7 @@ function removename(guid, coll, socket) {
|
||||
});
|
||||
}
|
||||
|
||||
function generate_name(guid, announce_payload, second, round, channel) {
|
||||
function generate_name(guid, announce_payload, second, round) {
|
||||
if(round == undefined) round = 0;
|
||||
var tmp_name = Functions.rndName(second ? second : guid, Math.floor(8 + round));
|
||||
db.collection("registered_users").find({"_id": tmp_name}, function(err, docs) {
|
||||
@@ -294,8 +284,8 @@ function generate_name(guid, announce_payload, second, round, channel) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) {
|
||||
if(updated.nModified == 1 || (updated.hasOwnProperty("upserted") && updated.hasOwnProperty("n") && updated.n == 1)) {
|
||||
var updateElement = {$set: {name: tmp_name, icon: false}};
|
||||
if(channel != undefined && channel != "") {
|
||||
updateElement["$addToSet"] = {channels: channel};
|
||||
if(announce_payload.hasOwnProperty("channel") && announce_payload.channel != "" && announce_payload.channel != undefined) {
|
||||
updateElement["$addToSet"] = {channels: announce_payload.channel};
|
||||
}
|
||||
db.collection("user_names").update({"guid": guid}, updateElement, {upsert: true}, function(err, update){
|
||||
name = tmp_name;
|
||||
@@ -309,11 +299,11 @@ function generate_name(guid, announce_payload, second, round, channel) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25, channel);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -322,7 +312,7 @@ function get_name(guid, announce_payload, first) {
|
||||
if(!announce_payload.announce && announce_payload.hasOwnProperty("socket")) {
|
||||
Functions.getSessionChatPass(Functions.getSession(announce_payload.socket), function(name, pass) {
|
||||
if(name == "" || pass == "") {
|
||||
get_name_generate(guid, announce_payload, first, announce_payload.channel);
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
return;
|
||||
}
|
||||
db.collection("registered_users").find({"_id": name.toLowerCase()}, function(err, docs) {
|
||||
@@ -342,14 +332,14 @@ function get_name(guid, announce_payload, first) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
get_name_generate(guid, announce_payload, first, announce_payload.channel);
|
||||
get_name_generate(guid, announce_payload, first);
|
||||
}
|
||||
}
|
||||
|
||||
function get_name_generate(guid, announce_payload, first, channel) {
|
||||
function get_name_generate(guid, announce_payload, first) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
if(docs.length == 0) {
|
||||
generate_name(guid, announce_payload, channel);
|
||||
generate_name(guid, announce_payload);
|
||||
} else {
|
||||
name = docs[0].name;
|
||||
}
|
||||
|
||||
@@ -142,6 +142,12 @@ function check_inlist(coll, guid, socket, offline, callback)
|
||||
if(docs[0].icon != undefined) icon = docs[0].icon;
|
||||
db.collection("user_names").update({"guid": guid}, {$addToSet:{channels: coll}}, function(err, doc){});
|
||||
socket.broadcast.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " joined"});
|
||||
} else if(docs.length == 0) {
|
||||
console.log("User doesn't have a name for some reason.");
|
||||
console.log("guid", guid);
|
||||
console.log("channel", coll);
|
||||
console.log("Trying to get a chat-name");
|
||||
Chat.get_name(guid, {announce: false, socket: socket, channel: coll});
|
||||
}
|
||||
});
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$addToSet: {total_users: guid + coll}}, function(err, docs){
|
||||
@@ -371,6 +377,11 @@ function removeSessionAdminPass(id, channel, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function remove_from_chat_channel(coll, guid) {
|
||||
db.collection("user_names").update({"guid": guid}, {$pull: {channels: coll}}, function(err, docs) {
|
||||
});
|
||||
}
|
||||
|
||||
function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
if(!coll) {
|
||||
if(!change) {
|
||||
@@ -395,6 +406,8 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
socket.leave(coll);
|
||||
if(!change) {
|
||||
remove_name_from_db(guid, coll);
|
||||
} else {
|
||||
remove_from_chat_channel(coll, guid);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -405,6 +418,8 @@ function left_channel(coll, guid, short_id, in_list, socket, change) {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
|
||||
if(!change) {
|
||||
remove_name_from_db(guid, coll);
|
||||
} else {
|
||||
remove_from_chat_channel(coll, guid);
|
||||
}
|
||||
//}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user