Fix login race condition which caused rank loss
This commit is contained in:
parent
bd348132e6
commit
f90965c105
15
channel.js
15
channel.js
|
@ -472,6 +472,8 @@ Channel.prototype.getRank = function (name, callback) {
|
|||
Channel.prototype.saveRank = function (user, callback) {
|
||||
if(!this.registered)
|
||||
return;
|
||||
if(!user.saverank)
|
||||
return;
|
||||
this.server.db.setChannelRank(this.name, user.name, user.rank, callback);
|
||||
}
|
||||
|
||||
|
@ -728,6 +730,7 @@ Channel.prototype.search = function(query, callback) {
|
|||
/* REGION User interaction */
|
||||
|
||||
Channel.prototype.userJoin = function(user) {
|
||||
var self = this;
|
||||
var parts = user.ip.split(".");
|
||||
var slash24 = parts[0] + "." + parts[1] + "." + parts[2];
|
||||
// GTFO
|
||||
|
@ -758,7 +761,17 @@ Channel.prototype.userJoin = function(user) {
|
|||
this.users.push(user);
|
||||
this.broadcastVoteskipUpdate();
|
||||
if(user.name != "") {
|
||||
this.broadcastNewUser(user);
|
||||
self.getRank(user.name, function (err, rank) {
|
||||
if(err) {
|
||||
user.rank = user.global_rank;
|
||||
user.saverank = false;
|
||||
} else {
|
||||
user.saverank = true;
|
||||
user.rank = rank;
|
||||
}
|
||||
user.socket.emit("rank", rank);
|
||||
self.broadcastNewUser(user);
|
||||
});
|
||||
}
|
||||
this.broadcastUsercount();
|
||||
|
||||
|
|
8
user.js
8
user.js
|
@ -20,6 +20,7 @@ var User = function(socket, Server) {
|
|||
this.server = Server;
|
||||
this.socket = socket;
|
||||
this.loggedIn = false;
|
||||
this.saverank = false;
|
||||
this.rank = Rank.Anonymous;
|
||||
this.global_rank = Rank.Anonymous;
|
||||
this.channel = null;
|
||||
|
@ -668,10 +669,13 @@ User.prototype.login = function(name, pw, session) {
|
|||
};
|
||||
if(self.channel !== null) {
|
||||
self.channel.getRank(name, function (err, rank) {
|
||||
if(!err)
|
||||
if(!err) {
|
||||
self.saverank = true;
|
||||
self.rank = rank;
|
||||
else
|
||||
} else {
|
||||
self.saverank = false;
|
||||
self.rank = self.global_rank;
|
||||
}
|
||||
afterRankLookup();
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -43,9 +43,11 @@ Callbacks = {
|
|||
|
||||
/* fired when socket connection completes */
|
||||
connect: function() {
|
||||
setTimeout(function () {
|
||||
socket.emit("joinChannel", {
|
||||
name: CHANNEL.name
|
||||
});
|
||||
}, 2000);
|
||||
if(NAME && SESSION) {
|
||||
socket.emit("login", {
|
||||
name: NAME,
|
||||
|
|
|
@ -969,7 +969,7 @@ function handleModPermissions() {
|
|||
function handlePermissionChange() {
|
||||
if(CLIENT.rank >= 2) {
|
||||
$("#channelsettingswrap3").show();
|
||||
if($("#channelsettingswrap").html() == "") {
|
||||
if($("#channelsettingswrap").html().trim() == "") {
|
||||
$("#channelsettingswrap").load("channeloptions.html", handleModPermissions);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue