From 92d73026be0686e3b0357481abf3ff62fa8e1ba8 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sun, 17 Mar 2013 09:39:22 -0500 Subject: [PATCH] Fix duplicate login bug Fixes Issue #1 --- channel.js | 13 +++++++++++++ user.js | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/channel.js b/channel.js index a71ab10e..86c312a5 100644 --- a/channel.js +++ b/channel.js @@ -201,6 +201,19 @@ Channel.prototype.searchLibrary = function(query) { // Called when a new user enters the channel Channel.prototype.userJoin = function(user) { + // Prevent duplicate login + if(user.name != "") { + for(var i = 0; i < this.users.length; i++) { + if(this.users[i].name == user.name) { + user.name = ""; + user.loggedIn = false; + user.socket.emit('login', { + success: false, + error: "The username " + user.name + " is already in use on this channel" + }); + } + } + } // If the channel is empty and isn't registered, the first person // gets ownership of the channel (temporarily) if(this.users.length == 0 && !this.registered) { diff --git a/user.js b/user.js index d42c450b..1bca89c1 100644 --- a/user.js +++ b/user.js @@ -226,6 +226,17 @@ User.prototype.handleAdm = function(data) { // Attempt to login User.prototype.login = function(name, sha256) { + if(this.channel != null && name != "") { + for(var i = 0; i < this.channel.users.length; i++) { + if(this.channel.users[i].name == name) { + this.socket.emit('login', { + success: false, + error: "The username " + name + " is already in use on this channel" + }); + return false; + } + } + } // No password => try guest login if(sha256 == "") { // Sorry bud, can't take that name