diff --git a/lib/channel-new.js b/lib/channel-new.js index 14078af4..87d5082a 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -446,6 +446,18 @@ Channel.prototype.getIPRank = function (ip, callback) { Channel.prototype.join = function (user, password) { 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 () { if (self.dead) { return; @@ -497,23 +509,19 @@ Channel.prototype.join = function (user, password) { } } - 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); - self.sendUserJoin(self.users, user); - self.sendUserlist([user]); - }); + self.sendUserJoin(self.users, user); + self.sendUserlist([user]); }; self.whenReady(function () { if (self.opts.password !== false && user.rank < 2) { 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; } } diff --git a/lib/user.js b/lib/user.js index b5d8cf83..a362d9a0 100644 --- a/lib/user.js +++ b/lib/user.js @@ -176,6 +176,10 @@ User.prototype.initChannelCallbacks = function () { }); self.socket.on("joinChannel", typecheck("object", {}, function (data) { + if (self.inChannel()) { + return; + } + if (typeof data.name !== "string") { return; } diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 0c30bd2a..0b65dbbc 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -138,7 +138,10 @@ Callbacks = { var parent = chatDialog(div); parent.attr("id", "needpw"); var sendpw = function () { - socket.emit("channelPassword", pwbox.val()); + socket.emit("joinChannel", { + name: CHANNEL.name, + pw: pwbox.val() + }); parent.remove(); }; submit.click(sendpw);