mirror of https://github.com/calzoneman/sync.git
Tweak bans
This commit is contained in:
parent
ea9132624a
commit
505c628eb9
42
channel.js
42
channel.js
|
@ -260,6 +260,25 @@ Channel.prototype.saveRank = function(user) {
|
|||
return Database.saveChannelRank(this.name, user);
|
||||
}
|
||||
|
||||
Channel.prototype.getIPRank = function(ip) {
|
||||
var rank = 0;
|
||||
for(var i = 0; i < this.logins[ip].length; i++) {
|
||||
var r = this.getRank(this.logins[ip][i]);
|
||||
rank = (r > rank) ? r : rank;
|
||||
}
|
||||
return rank;
|
||||
}
|
||||
|
||||
Channel.prototype.seen = function(ip, name) {
|
||||
name = name.toLowerCase();
|
||||
for(var i = 0; i < this.logins[ip].length; i++) {
|
||||
if(this.logins[ip][i].toLowerCase() == name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Channel.prototype.cacheMedia = function(media) {
|
||||
if(media.temp) {
|
||||
return;
|
||||
|
@ -348,7 +367,6 @@ Channel.prototype.userJoin = function(user) {
|
|||
(slash24 in this.ipbans && this.ipbans[slash24] != null)) {
|
||||
this.logger.log("--- Kicking " + user.ip + " - banned");
|
||||
this.kick(user, "You're banned!");
|
||||
user.socket.disconnect(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -358,7 +376,7 @@ 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) {
|
||||
if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) {
|
||||
user.name = "";
|
||||
user.loggedIn = false;
|
||||
user.socket.emit("login", {
|
||||
|
@ -457,9 +475,16 @@ Channel.prototype.sendRankStuff = function(user) {
|
|||
var ents = [];
|
||||
for(var ip in this.ipbans) {
|
||||
if(this.ipbans[ip] != null) {
|
||||
var name;
|
||||
if(ip in this.logins) {
|
||||
name = this.logins[ip].join(", ");
|
||||
}
|
||||
else {
|
||||
name = this.ipbans[ip][0];
|
||||
}
|
||||
ents.push({
|
||||
ip: ip,
|
||||
name: this.ipbans[ip][0],
|
||||
name: name,
|
||||
banner: this.ipbans[ip][1]
|
||||
});
|
||||
}
|
||||
|
@ -563,7 +588,7 @@ Channel.prototype.broadcastUsercount = function() {
|
|||
}
|
||||
|
||||
Channel.prototype.broadcastNewUser = function(user) {
|
||||
if(this.logins[user.ip].join("").indexOf(user.name) == -1) {
|
||||
if(!this.seen(user.ip, user.name)) {
|
||||
this.logins[user.ip].push(user.name);
|
||||
}
|
||||
this.sendAll("addUser", {
|
||||
|
@ -610,9 +635,16 @@ Channel.prototype.broadcastBanlist = function() {
|
|||
var ents = [];
|
||||
for(var ip in this.ipbans) {
|
||||
if(this.ipbans[ip] != null) {
|
||||
var name;
|
||||
if(ip in this.logins) {
|
||||
name = this.logins[ip].join(", ");
|
||||
}
|
||||
else {
|
||||
name = this.ipbans[ip][0];
|
||||
}
|
||||
ents.push({
|
||||
ip: ip,
|
||||
name: this.ipbans[ip][0],
|
||||
name: name,
|
||||
banner: this.ipbans[ip][1]
|
||||
});
|
||||
}
|
||||
|
|
|
@ -55,9 +55,10 @@ function handle(chan, user, msg, data) {
|
|||
|
||||
function handleKick(chan, user, args) {
|
||||
if(Rank.hasPermission(user, "kick") && args.length > 0) {
|
||||
args[0] = args[0].toLowerCase();
|
||||
var kickee;
|
||||
for(var i = 0; i < chan.users.length; i++) {
|
||||
if(chan.users[i].name == args[0]) {
|
||||
if(chan.users[i].name.toLowerCase() == args[0]) {
|
||||
kickee = chan.users[i];
|
||||
break;
|
||||
}
|
||||
|
@ -73,9 +74,10 @@ function handleKick(chan, user, args) {
|
|||
|
||||
function handleBan(chan, user, args) {
|
||||
if(Rank.hasPermission(user, "ipban") && args.length > 0) {
|
||||
args[0] = args[0].toLowerCase();
|
||||
var kickee;
|
||||
for(var i = 0; i < chan.users.length; i++) {
|
||||
if(chan.users[i].name == args[0]) {
|
||||
if(chan.users[i].name.toLowerCase() == args[0]) {
|
||||
kickee = chan.users[i];
|
||||
break;
|
||||
}
|
||||
|
@ -89,23 +91,21 @@ function handleBan(chan, user, args) {
|
|||
}
|
||||
else if(!kickee && chan.getRank(args[0]) < user.rank) {
|
||||
for(var ip in chan.logins) {
|
||||
console.log(ip, chan.logins[ip]);
|
||||
if(chan.logins[ip].join("").indexOf(args[0]) != -1) {
|
||||
for(var i = 0; i < chan.logins[ip].length; i++) {
|
||||
if(chan.getRank(chan.logins[ip][i]) >= user.rank) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(args.length >= 2 && args[1] == "range") {
|
||||
var parts = ip.split(".");
|
||||
ip = parts[0] + "." + parts[1] + "." + parts[2];
|
||||
}
|
||||
chan.logger.log("*** " + user.name + " banned " + ip);
|
||||
chan.banIP(user, {
|
||||
ip: ip,
|
||||
name: args[0]
|
||||
});
|
||||
if(chan.getIPRank(ip) >= user.rank) {
|
||||
return;
|
||||
}
|
||||
if(!chan.seen(ip, args[0])) {
|
||||
continue;
|
||||
}
|
||||
if(args.length >= 2 && args[1] == "range") {
|
||||
var parts = ip.split(".");
|
||||
ip = parts[0] + "." + parts[1] + "." + parts[2];
|
||||
}
|
||||
chan.logger.log("*** " + user.name + " banned " + ip);
|
||||
chan.banIP(user, {
|
||||
ip: ip,
|
||||
name: args[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,13 +116,10 @@ function handleIpban(chan, user, args) {
|
|||
var name = "";
|
||||
for(var ip in chan.logins) {
|
||||
if(ip.indexOf(args[0]) == 0) {
|
||||
var names = chan.logins[ip];
|
||||
for(var i = 0; i < names.length; i++) {
|
||||
var r = chan.getRank(names[i]);
|
||||
if(r >= user.rank) {
|
||||
return;
|
||||
}
|
||||
if(chan.getIPRank(ip) >= user.rank) {
|
||||
return;
|
||||
}
|
||||
var names = chan.logins[ip];
|
||||
name = names[names.length - 1];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ Callbacks = {
|
|||
kick: function(data) {
|
||||
KICKED = true;
|
||||
$("<div/>").addClass("server-msg-disconnect")
|
||||
.text("Kicked: " + data.msg)
|
||||
.text("Kicked: " + data.reason)
|
||||
.appendTo($("#messagebuffer"));
|
||||
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollheight"));
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue