Fix side effects of Channel.tryIPBan

This commit is contained in:
calzoneman 2013-06-09 11:47:46 -04:00
parent 261abadf12
commit 40d0bdf120
2 changed files with 30 additions and 3 deletions

View file

@ -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));

View file

@ -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));