From 40d0bdf120e7f04b0213d4d0cd915f0ee7b64a07 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sun, 9 Jun 2013 11:47:46 -0400 Subject: [PATCH] Fix side effects of Channel.tryIPBan --- channel.js | 31 +++++++++++++++++++++++++++++-- user.js | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/channel.js b/channel.js index 708054f5..651b3e96 100644 --- a/channel.js +++ b/channel.js @@ -313,10 +313,15 @@ Channel.prototype.saveRank = function(user) { } Channel.prototype.getIPRank = function(ip) { - var names = this.logins[ip] || []; - if(names.length == 0) { + var names = []; + if(this.logins[ip] === undefined || this.logins[ip].length == 0) { return 0; } + + this.logins[ip].forEach(function(name) { + names.push(name); + }); + var ranks = Database.getChannelRank(this.name, names); var rank = 0; for(var i = 0; i < ranks.length; i++) { @@ -708,6 +713,28 @@ Channel.prototype.sendRankStuff = function(user) { this.sendACL(user); } +Channel.prototype.sendSeenLogins = function(user) { + if(Rank.hasPermission(user, "seenlogins")) { + var ents = []; + for(var ip in this.logins) { + var disp = ip; + if(user.rank < Rank.Siteadmin) { + disp = "(Hidden)"; + } + var banned = (ip in this.ipbans && this.ipbans[ip] != null); + var range = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, "$1.$2.$3"); + banned = banned || (range in this.ipbans && this.ipbans[range] != null); + ents.push({ + ip: disp, + id: this.hideIP(ip), + names: this.logins[ip], + banned: banned + }); + } + user.socket.emit("seenlogins", {entries: ents}); + } +} + Channel.prototype.sendACL = function(user) { if(Rank.hasPermission(user, "acl")) { user.socket.emit("acl", Database.listChannelRanks(this.name)); diff --git a/user.js b/user.js index 549ac99e..4396b2a1 100644 --- a/user.js +++ b/user.js @@ -397,7 +397,7 @@ User.prototype.initCallbacks = function() { if(this.noflood("requestSeenLogins", 0.25)) { return; } - this.channel.sendRankStuff(this); + this.channel.sendSeenLogins(this); } }.bind(this));