mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
More clever way of detecting if a name should be removed when user leaves
This commit is contained in:
@@ -261,8 +261,9 @@ function removename(guid, coll, socket) {
|
||||
});
|
||||
}
|
||||
|
||||
function generate_name(guid, announce_payload, second) {
|
||||
var tmp_name = Functions.rndName(second ? second : guid, 8);
|
||||
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) {
|
||||
if(docs.length == 0) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$addToSet: {names: tmp_name}}, {upsert: true}, function(err, updated) {
|
||||
@@ -279,11 +280,11 @@ function generate_name(guid, announce_payload, second) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
generate_name(guid, announce_payload, tmp_name);
|
||||
generate_name(guid, announce_payload, tmp_name, round + 0.25);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,8 +37,16 @@ function remove_unique_id(short_id) {
|
||||
}
|
||||
|
||||
function remove_name_from_db(guid, name) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) {
|
||||
db.collection("user_names").remove({"guid": guid}, function(err, removed) { });
|
||||
// Use temporary, with caution. Can bottleneck in large quantity of users.
|
||||
//
|
||||
// Find a way of indexing users in lists in a clever way, to avoid the search here
|
||||
db.collection("connected_users").find({"_id": "total_users"}, function(err, all_users) {
|
||||
var hasOne = all_users[0].total_users.some(function(v){ return v.indexOf(guid)>=0 });
|
||||
if(!hasOne) {
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: name}}, function(err, updated) {
|
||||
db.collection("user_names").remove({"guid": guid}, function(err, removed) { });
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user