mirror of https://github.com/calzoneman/sync.git
Do a bit more work
This commit is contained in:
parent
b7c02334ed
commit
e155a30a17
74
channel.js
74
channel.js
|
@ -492,14 +492,14 @@ Channel.prototype.getIPRank = function (ip, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.cacheMedia = function(media) {
|
Channel.prototype.cacheMedia = function(media) {
|
||||||
|
var self = this;
|
||||||
// Prevent the copy in the playlist from messing with this one
|
// Prevent the copy in the playlist from messing with this one
|
||||||
media = media.dup();
|
media = media.dup();
|
||||||
if(media.temp) {
|
if(media.temp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.library[media.id] = media;
|
if(self.registered) {
|
||||||
if(this.registered) {
|
self.server.db.addToLibrary(self.name, media);
|
||||||
return this.server.db.addToLibrary(this.name, media);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -548,19 +548,21 @@ Channel.prototype.tryNameBan = function(actor, name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.unbanName = function(actor, name) {
|
Channel.prototype.unbanName = function(actor, name) {
|
||||||
if(!this.hasPermission(actor, "ban")) {
|
var self = this;
|
||||||
|
if(!self.hasPermission(actor, "ban")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.namebans[name] = null;
|
self.namebans[name] = null;
|
||||||
delete this.namebans[name];
|
delete self.namebans[name];
|
||||||
this.logger.log("*** " + actor.name + " un-namebanned " + name);
|
self.logger.log("*** " + actor.name + " un-namebanned " + name);
|
||||||
|
|
||||||
var chan = this;
|
self.server.db.clearChannelNameBan(self.name, name, function (err, res) {
|
||||||
this.users.forEach(function(u) {
|
|
||||||
chan.sendBanlist(u);
|
self.users.forEach(function(u) {
|
||||||
|
self.sendBanlist(u);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return this.server.db.channelUnbanName(this.name, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryIPBan = function(actor, name, range) {
|
Channel.prototype.tryIPBan = function(actor, name, range) {
|
||||||
|
@ -571,7 +573,13 @@ Channel.prototype.tryIPBan = function(actor, name, range) {
|
||||||
if(typeof name != "string") {
|
if(typeof name != "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var ips = self.server.db.ipForName(name);
|
self.server.db.listIPsForName(name, function (err, ips) {
|
||||||
|
if(err) {
|
||||||
|
actor.socket.emit("errorMsg", {
|
||||||
|
msg: "Internal error"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
ips.forEach(function (ip) {
|
ips.forEach(function (ip) {
|
||||||
if(range)
|
if(range)
|
||||||
ip = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, "$1.$2.$3");
|
ip = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, "$1.$2.$3");
|
||||||
|
@ -605,7 +613,8 @@ Channel.prototype.tryIPBan = function(actor, name, range) {
|
||||||
if(!self.registered)
|
if(!self.registered)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.server.db.addChannelBan(chan.name, ip, name, actor.name
|
self.server.db.addChannelBan(chan.name, ip, name,
|
||||||
|
actor.name,
|
||||||
function (err, res) {
|
function (err, res) {
|
||||||
self.users.forEach(function(u) {
|
self.users.forEach(function(u) {
|
||||||
self.sendBanlist(u);
|
self.sendBanlist(u);
|
||||||
|
@ -613,47 +622,26 @@ Channel.prototype.tryIPBan = function(actor, name, range) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
Channel.prototype.banIP = function(actor, receiver) {
|
|
||||||
if(!this.hasPermission(actor, "ban"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this.ipbans[receiver.ip] = [receiver.name, actor.name];
|
|
||||||
try {
|
|
||||||
receiver.socket.disconnect(true);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
// Socket already disconnected
|
|
||||||
}
|
|
||||||
//this.broadcastBanlist();
|
|
||||||
this.logger.log(receiver.ip + " (" + receiver.name + ") was banned by " + actor.name);
|
|
||||||
|
|
||||||
if(!this.registered)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Update database ban table
|
|
||||||
return this.server.db.channelBanIP(this.name, receiver.ip, receiver.name, actor.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.unbanIP = function(actor, ip) {
|
Channel.prototype.unbanIP = function(actor, ip) {
|
||||||
if(!this.hasPermission(actor, "ban"))
|
var self = this;
|
||||||
|
if(!self.hasPermission(actor, "ban"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.ipbans[ip] = null;
|
self.ipbans[ip] = null;
|
||||||
var chan = this;
|
self.users.forEach(function(u) {
|
||||||
this.users.forEach(function(u) {
|
self.sendBanlist(u);
|
||||||
chan.sendBanlist(u);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.log("*** " + actor.name + " unbanned " + ip);
|
self.logger.log("*** " + actor.name + " unbanned " + ip);
|
||||||
|
|
||||||
if(!this.registered)
|
if(!self.registered)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//this.broadcastBanlist();
|
|
||||||
// Update database ban table
|
// Update database ban table
|
||||||
return this.server.db.channelUnbanIP(this.name, ip);
|
self.server.db.clearChannelIPBan(self.name, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryUnban = function(actor, data) {
|
Channel.prototype.tryUnban = function(actor, data) {
|
||||||
|
|
Loading…
Reference in New Issue