Fix passwords (hopefully)

This commit is contained in:
calzoneman 2014-01-25 17:44:32 -06:00
parent e33c6c7860
commit 0329e564a9
3 changed files with 28 additions and 13 deletions

View File

@ -446,6 +446,18 @@ Channel.prototype.getIPRank = function (ip, callback) {
Channel.prototype.join = function (user, password) { Channel.prototype.join = function (user, password) {
var self = this; var self = this;
user.whenLoggedIn(function () {
self.getRank(user.name, function (err, rank) {
if (err) {
user.rank = user.global_rank;
} else {
user.rank = Math.max(rank, user.global_rank);
}
user.socket.emit("rank", user.rank);
});
});
var afterIPBanCheck = function () { var afterIPBanCheck = function () {
if (self.dead) { if (self.dead) {
return; return;
@ -497,23 +509,19 @@ Channel.prototype.join = function (user, password) {
} }
} }
self.getRank(user.name, function (err, rank) { self.sendUserJoin(self.users, user);
if (err) { self.sendUserlist([user]);
user.rank = user.global_rank;
} else {
user.rank = Math.max(rank, user.global_rank);
}
user.socket.emit("rank", user.rank);
self.sendUserJoin(self.users, user);
self.sendUserlist([user]);
});
}; };
self.whenReady(function () { self.whenReady(function () {
if (self.opts.password !== false && user.rank < 2) { if (self.opts.password !== false && user.rank < 2) {
if (password !== self.opts.password) { if (password !== self.opts.password) {
user.socket.emit("needPassword", typeof password === "undefined"); user.socket.emit("needPassword", typeof password !== "undefined");
user.whenLoggedIn(function () {
if (user.rank >= 2) {
self.join(user);
}
});
return; return;
} }
} }

View File

@ -176,6 +176,10 @@ User.prototype.initChannelCallbacks = function () {
}); });
self.socket.on("joinChannel", typecheck("object", {}, function (data) { self.socket.on("joinChannel", typecheck("object", {}, function (data) {
if (self.inChannel()) {
return;
}
if (typeof data.name !== "string") { if (typeof data.name !== "string") {
return; return;
} }

View File

@ -138,7 +138,10 @@ Callbacks = {
var parent = chatDialog(div); var parent = chatDialog(div);
parent.attr("id", "needpw"); parent.attr("id", "needpw");
var sendpw = function () { var sendpw = function () {
socket.emit("channelPassword", pwbox.val()); socket.emit("joinChannel", {
name: CHANNEL.name,
pw: pwbox.val()
});
parent.remove(); parent.remove();
}; };
submit.click(sendpw); submit.click(sendpw);