Fix login race condition which caused rank loss

This commit is contained in:
calzoneman 2013-08-30 18:42:00 -05:00
parent bd348132e6
commit f90965c105
4 changed files with 23 additions and 4 deletions

View File

@ -472,6 +472,8 @@ Channel.prototype.getRank = function (name, callback) {
Channel.prototype.saveRank = function (user, callback) { Channel.prototype.saveRank = function (user, callback) {
if(!this.registered) if(!this.registered)
return; return;
if(!user.saverank)
return;
this.server.db.setChannelRank(this.name, user.name, user.rank, callback); this.server.db.setChannelRank(this.name, user.name, user.rank, callback);
} }
@ -728,6 +730,7 @@ Channel.prototype.search = function(query, callback) {
/* REGION User interaction */ /* REGION User interaction */
Channel.prototype.userJoin = function(user) { Channel.prototype.userJoin = function(user) {
var self = this;
var parts = user.ip.split("."); var parts = user.ip.split(".");
var slash24 = parts[0] + "." + parts[1] + "." + parts[2]; var slash24 = parts[0] + "." + parts[1] + "." + parts[2];
// GTFO // GTFO
@ -758,7 +761,17 @@ Channel.prototype.userJoin = function(user) {
this.users.push(user); this.users.push(user);
this.broadcastVoteskipUpdate(); this.broadcastVoteskipUpdate();
if(user.name != "") { 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(); this.broadcastUsercount();

View File

@ -20,6 +20,7 @@ var User = function(socket, Server) {
this.server = Server; this.server = Server;
this.socket = socket; this.socket = socket;
this.loggedIn = false; this.loggedIn = false;
this.saverank = false;
this.rank = Rank.Anonymous; this.rank = Rank.Anonymous;
this.global_rank = Rank.Anonymous; this.global_rank = Rank.Anonymous;
this.channel = null; this.channel = null;
@ -668,10 +669,13 @@ User.prototype.login = function(name, pw, session) {
}; };
if(self.channel !== null) { if(self.channel !== null) {
self.channel.getRank(name, function (err, rank) { self.channel.getRank(name, function (err, rank) {
if(!err) if(!err) {
self.saverank = true;
self.rank = rank; self.rank = rank;
else } else {
self.saverank = false;
self.rank = self.global_rank; self.rank = self.global_rank;
}
afterRankLookup(); afterRankLookup();
}); });
} else { } else {

View File

@ -43,9 +43,11 @@ Callbacks = {
/* fired when socket connection completes */ /* fired when socket connection completes */
connect: function() { connect: function() {
setTimeout(function () {
socket.emit("joinChannel", { socket.emit("joinChannel", {
name: CHANNEL.name name: CHANNEL.name
}); });
}, 2000);
if(NAME && SESSION) { if(NAME && SESSION) {
socket.emit("login", { socket.emit("login", {
name: NAME, name: NAME,

View File

@ -969,7 +969,7 @@ function handleModPermissions() {
function handlePermissionChange() { function handlePermissionChange() {
if(CLIENT.rank >= 2) { if(CLIENT.rank >= 2) {
$("#channelsettingswrap3").show(); $("#channelsettingswrap3").show();
if($("#channelsettingswrap").html() == "") { if($("#channelsettingswrap").html().trim() == "") {
$("#channelsettingswrap").load("channeloptions.html", handleModPermissions); $("#channelsettingswrap").load("channeloptions.html", handleModPermissions);
} }
else { else {