mirror of https://github.com/calzoneman/sync.git
Start on channel.js
This commit is contained in:
parent
448d50e796
commit
b7c02334ed
456
channel.js
456
channel.js
|
@ -24,26 +24,27 @@ var Playlist = require("./playlist");
|
||||||
var sanitize = require("validator").sanitize;
|
var sanitize = require("validator").sanitize;
|
||||||
|
|
||||||
var Channel = function(name, Server) {
|
var Channel = function(name, Server) {
|
||||||
|
var self = this;
|
||||||
Logger.syslog.log("Opening channel " + name);
|
Logger.syslog.log("Opening channel " + name);
|
||||||
this.initialized = false;
|
self.initialized = false;
|
||||||
this.server = Server;
|
self.server = Server;
|
||||||
|
|
||||||
this.name = name;
|
self.name = name;
|
||||||
this.canonical_name = name.toLowerCase();
|
self.canonical_name = name.toLowerCase();
|
||||||
// Initialize defaults
|
// Initialize defaults
|
||||||
this.registered = false;
|
self.registered = false;
|
||||||
this.users = [];
|
self.users = [];
|
||||||
this.afkers = [];
|
self.afkers = [];
|
||||||
this.playlist = new Playlist(this);
|
self.playlist = new Playlist(self);
|
||||||
this.library = {};
|
self.library = {};
|
||||||
this.position = -1;
|
self.position = -1;
|
||||||
this.drinks = 0;
|
self.drinks = 0;
|
||||||
this.leader = null;
|
self.leader = null;
|
||||||
this.chatbuffer = [];
|
self.chatbuffer = [];
|
||||||
this.openqueue = false;
|
self.openqueue = false;
|
||||||
this.poll = false;
|
self.poll = false;
|
||||||
this.voteskip = false;
|
self.voteskip = false;
|
||||||
this.permissions = {
|
self.permissions = {
|
||||||
oplaylistadd: -1,
|
oplaylistadd: -1,
|
||||||
oplaylistnext: 1.5,
|
oplaylistnext: 1.5,
|
||||||
oplaylistmove: 1.5,
|
oplaylistmove: 1.5,
|
||||||
|
@ -74,11 +75,11 @@ var Channel = function(name, Server) {
|
||||||
drink: 1.5,
|
drink: 1.5,
|
||||||
chat: 0
|
chat: 0
|
||||||
};
|
};
|
||||||
this.opts = {
|
self.opts = {
|
||||||
allow_voteskip: true,
|
allow_voteskip: true,
|
||||||
voteskip_ratio: 0.5,
|
voteskip_ratio: 0.5,
|
||||||
afk_timeout: 180,
|
afk_timeout: 180,
|
||||||
pagetitle: this.name,
|
pagetitle: self.name,
|
||||||
maxlength: 0,
|
maxlength: 0,
|
||||||
externalcss: "",
|
externalcss: "",
|
||||||
externaljs: "",
|
externaljs: "",
|
||||||
|
@ -86,42 +87,43 @@ var Channel = function(name, Server) {
|
||||||
show_public: false,
|
show_public: false,
|
||||||
enable_link_regex: true
|
enable_link_regex: true
|
||||||
};
|
};
|
||||||
this.filters = [
|
self.filters = [
|
||||||
new Filter("monospace", "`([^`]+)`", "g", "<code>$1</code>"),
|
new Filter("monospace", "`([^`]+)`", "g", "<code>$1</code>"),
|
||||||
new Filter("bold", "(^|\\s)\\*([^\\*]+)\\*", "g", "$1<strong>$2</strong>"),
|
new Filter("bold", "(^|\\s)\\*([^\\*]+)\\*", "g", "$1<strong>$2</strong>"),
|
||||||
new Filter("italic", "(^| )_([^_]+)_", "g", "$1<em>$2</em>"),
|
new Filter("italic", "(^| )_([^_]+)_", "g", "$1<em>$2</em>"),
|
||||||
new Filter("strikethrough", "~~([^~]+)~~", "g", "<s>$1</s>"),
|
new Filter("strikethrough", "~~([^~]+)~~", "g", "<s>$1</s>"),
|
||||||
new Filter("inline spoiler", "\\[spoiler\\](.*)\\[\\/spoiler\\]", "ig", "<span class=\"spoiler\">$1</span>"),
|
new Filter("inline spoiler", "\\[spoiler\\](.*)\\[\\/spoiler\\]", "ig", "<span class=\"spoiler\">$1</span>"),
|
||||||
];
|
];
|
||||||
this.motd = {
|
self.motd = {
|
||||||
motd: "",
|
motd: "",
|
||||||
html: ""
|
html: ""
|
||||||
};
|
};
|
||||||
this.ipbans = {};
|
self.ipbans = {};
|
||||||
this.namebans = {};
|
self.namebans = {};
|
||||||
this.ip_alias = {};
|
self.ip_alias = {};
|
||||||
this.name_alias = {};
|
self.name_alias = {};
|
||||||
this.login_hist = [];
|
self.login_hist = [];
|
||||||
this.logger = new Logger.Logger("chanlogs/" + this.canonical_name + ".log");
|
self.logger = new Logger.Logger("chanlogs/" + self.canonical_name + ".log");
|
||||||
this.i = 0;
|
self.i = 0;
|
||||||
this.time = new Date().getTime();
|
self.time = new Date().getTime();
|
||||||
this.plmeta = {
|
self.plmeta = {
|
||||||
count: 0,
|
count: 0,
|
||||||
time: "00:00"
|
time: "00:00"
|
||||||
};
|
};
|
||||||
|
|
||||||
this.css = "";
|
self.css = "";
|
||||||
this.js = "";
|
self.js = "";
|
||||||
|
|
||||||
this.ipkey = "";
|
self.ipkey = "";
|
||||||
for(var i = 0; i < 15; i++) {
|
for(var i = 0; i < 15; i++) {
|
||||||
this.ipkey += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[parseInt(Math.random() * 65)]
|
self.ipkey += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[parseInt(Math.random() * 65)]
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.db.loadChannel(this);
|
Server.db.loadChannelData(self, function () {
|
||||||
if(this.registered) {
|
if(self.registered) {
|
||||||
this.loadDump();
|
self.loadDump();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* REGION Permissions */
|
/* REGION Permissions */
|
||||||
|
@ -338,18 +340,19 @@ Channel.prototype.tryReadLog = function (user) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryRegister = function(user) {
|
Channel.prototype.tryRegister = function (user) {
|
||||||
if(this.registered) {
|
var self = this;
|
||||||
ActionLog.record(user.ip, user.name, "channel-register-failure", [
|
if(self.registered) {
|
||||||
this.name, "Channel already registered"]);
|
ActionLog.record(user.ip, user.name, "channel-register-failure",
|
||||||
|
[self.name, "Channel already registered"]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "This channel is already registered"
|
error: "This channel is already registered"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(!user.loggedIn) {
|
else if(!user.loggedIn) {
|
||||||
ActionLog.record(user.ip, user.name, "channel-register-failure", [
|
ActionLog.record(user.ip, user.name, "channel-register-failure",
|
||||||
this.name, "Not logged in"]);
|
[self.name, "Not logged in"]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You must log in to register a channel"
|
error: "You must log in to register a channel"
|
||||||
|
@ -357,70 +360,135 @@ Channel.prototype.tryRegister = function(user) {
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!Rank.hasPermission(user, "registerChannel")) {
|
else if(!Rank.hasPermission(user, "registerChannel")) {
|
||||||
ActionLog.record(user.ip, user.name, "channel-register-failure", [
|
ActionLog.record(user.ip, user.name, "channel-register-failure",
|
||||||
this.name, "Insufficient permissions"]);
|
[self.name, "Insufficient permissions"]);
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "You don't have permission to register this channel"
|
error: "You don't have permission to register self channel"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(this.server.db.registerChannel(this.name, user.name)) {
|
self.server.db.registerChannel(self.name, user.name,
|
||||||
ActionLog.record(user.ip, user.name, "channel-register-success", this.name);
|
function (err, res) {
|
||||||
this.registered = true;
|
if(err) {
|
||||||
this.initialized = true;
|
|
||||||
this.saveDump();
|
|
||||||
this.saveRank(user);
|
|
||||||
user.socket.emit("registerChannel", {
|
|
||||||
success: true,
|
|
||||||
});
|
|
||||||
this.logger.log("*** " + user.name + " registered the channel");
|
|
||||||
Logger.syslog.log("Channel " + this.name + " was registered by " + user.name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
user.socket.emit("registerChannel", {
|
user.socket.emit("registerChannel", {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Unable to register channel, see an admin"
|
error: "Unable to register channel: " + err
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionLog.record(user.ip, user.name,
|
||||||
|
"channel-register-success", self.name);
|
||||||
|
self.registered = true;
|
||||||
|
self.initialized = true;
|
||||||
|
self.saveDump();
|
||||||
|
self.saveRank(user);
|
||||||
|
user.socket.emit("registerChannel", {
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
self.logger.log("*** " + user.name + " registered the channel");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel.prototype.unregister = function (user) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if(!self.registered) {
|
||||||
|
user.socket.emit("unregisterChannel", {
|
||||||
|
success: false,
|
||||||
|
error: "This channel is already unregistered"
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Channel.prototype.unregister = function() {
|
if(user.rank < 10) {
|
||||||
if(this.server.db.deleteChannel(this.name)) {
|
user.socket.emit("unregisterChannel", {
|
||||||
this.registered = false;
|
success: false,
|
||||||
return true;
|
error: "You must be the channel owner to unregister it"
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
self.server.db.dropChannel(self.name, function (err, res) {
|
||||||
}
|
if(err) {
|
||||||
|
user.socket.emit("unregisterChannel", {
|
||||||
Channel.prototype.getRank = function(name) {
|
success: false,
|
||||||
var global = Auth.getGlobalRank(name);
|
error: "Unregistration failed: " + err
|
||||||
if(!this.registered) {
|
});
|
||||||
return global;
|
return;
|
||||||
}
|
}
|
||||||
var local = this.server.db.getChannelRank(this.name, name);
|
|
||||||
return local > global ? local : global;
|
self.registered = false;
|
||||||
|
user.socket.emit("unregisterChannel", { success: true });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.saveRank = function(user) {
|
Channel.prototype.getRank = function (name, callback) {
|
||||||
return this.server.db.setChannelRank(this.name, user.name, user.rank);
|
var self = this;
|
||||||
|
self.server.db.getGlobalRank(name, function (err, global) {
|
||||||
|
if(err) {
|
||||||
|
callback(err, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!self.registered) {
|
||||||
|
callback(null, global);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.server.db.getChannelRank(self.name, name,
|
||||||
|
function (err, rank) {
|
||||||
|
if(err) {
|
||||||
|
callback(err, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, rank > global ? rank : global);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.getIPRank = function(ip) {
|
Channel.prototype.saveRank = function (user) {
|
||||||
|
this.server.db.setChannelRank(this.name, user.name, user.rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel.prototype.getIPRank = function (ip, callback) {
|
||||||
|
var self = this;
|
||||||
var names = [];
|
var names = [];
|
||||||
if(!(ip in this.ip_alias))
|
var next = function (names) {
|
||||||
this.ip_alias[ip] = this.server.db.getAliases(ip);
|
self.server.db.getChannelRank(self.name, names,
|
||||||
this.ip_alias[ip].forEach(function(name) {
|
function (err, res) {
|
||||||
names.push(name);
|
if(err) {
|
||||||
});
|
callback(err, null);
|
||||||
|
return;
|
||||||
var ranks = this.server.db.getChannelRank(this.name, names);
|
}
|
||||||
var rank = 0;
|
|
||||||
for(var i = 0; i < ranks.length; i++) {
|
var rank = 0;
|
||||||
rank = (ranks[i] > rank) ? ranks[i] : rank;
|
for(var i in res) {
|
||||||
|
rank = (res[i].rank > rank) ? res[i].rank : rank;
|
||||||
|
}
|
||||||
|
callback(null, rank);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if(ip in self.ip_alias) {
|
||||||
|
names = self.ip_alias[ip];
|
||||||
|
next(names);
|
||||||
|
} else if(ip.match(/^(\d+)\.(\d+)\.(\d+)$/)) {
|
||||||
|
// Range
|
||||||
|
for(var ip2 in self.ip_alias) {
|
||||||
|
if(ip2.indexOf(ip) == 0) {
|
||||||
|
for(var i in self.ip_aliases[ip2])
|
||||||
|
names.push(self.ip_aliases[ip2][i]);
|
||||||
|
}
|
||||||
|
next(names);
|
||||||
|
} else{
|
||||||
|
self.server.db.listAliases(ip, function (err, names) {
|
||||||
|
self.ip_alias[ip] = names;
|
||||||
|
next(names);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return rank;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.cacheMedia = function(media) {
|
Channel.prototype.cacheMedia = function(media) {
|
||||||
|
@ -437,35 +505,46 @@ Channel.prototype.cacheMedia = function(media) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryNameBan = function(actor, name) {
|
Channel.prototype.tryNameBan = function(actor, name) {
|
||||||
if(!this.hasPermission(actor, "ban")) {
|
var self = this;
|
||||||
|
if(!self.hasPermission(actor, "ban")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
|
|
||||||
var rank = this.getRank(name);
|
self.getRank(name, function (err, rank) {
|
||||||
if(rank >= actor.rank) {
|
if(err) {
|
||||||
actor.socket.emit("errorMsg", {msg: "You don't have permission to ban this person."});
|
actor.socket.emit("errorMsg", {
|
||||||
return false;
|
msg: "Internal error"
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.namebans[name] = actor.name;
|
if(rank >= actor.rank) {
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
actor.socket.emit("errorMsg", {
|
||||||
if(this.users[i].name.toLowerCase() == name) {
|
msg: "You don't have permission to ban this person."
|
||||||
this.kick(this.users[i], "You're banned!");
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.namebans[name] = actor.name;
|
||||||
|
for(var i = 0; i < self.users.length; i++) {
|
||||||
|
if(self.users[i].name.toLowerCase() == name) {
|
||||||
|
self.kick(self.users[i], "You're banned!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.log("*** " + actor.name + " namebanned " + name);
|
self.logger.log("*** " + actor.name + " namebanned " + name);
|
||||||
var chan = this;
|
self.users.forEach(function(u) {
|
||||||
this.users.forEach(function(u) {
|
self.sendBanlist(u);
|
||||||
chan.sendBanlist(u);
|
|
||||||
});
|
});
|
||||||
if(!this.registered) {
|
|
||||||
return false;
|
if(!self.registered) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.server.db.channelBan(this.name, "*", name, actor.name);
|
self.server.db.addChannelBan(self.name, "*", name, actor.name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.unbanName = function(actor, name) {
|
Channel.prototype.unbanName = function(actor, name) {
|
||||||
|
@ -485,50 +564,54 @@ Channel.prototype.unbanName = function(actor, name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryIPBan = function(actor, name, range) {
|
Channel.prototype.tryIPBan = function(actor, name, range) {
|
||||||
if(!this.hasPermission(actor, "ban")) {
|
var self = this;
|
||||||
return false;
|
if(!self.hasPermission(actor, "ban")) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(typeof name != "string") {
|
if(typeof name != "string") {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
var ips = this.server.db.ipForName(name);
|
var ips = self.server.db.ipForName(name);
|
||||||
var chan = this;
|
ips.forEach(function (ip) {
|
||||||
ips.forEach(function(ip) {
|
if(range)
|
||||||
if(chan.getIPRank(ip) >= actor.rank) {
|
|
||||||
actor.socket.emit("errorMsg", {msg: "You don't have permission to ban IP: x.x." + ip.replace(/\d+\.\d+\.(\d+\.\d+)/, "$1")});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(range) {
|
|
||||||
ip = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, "$1.$2.$3");
|
ip = ip.replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)/, "$1.$2.$3");
|
||||||
for(var ip2 in chan.ip_alias) {
|
self.getIPRank(ip, function (err, rank) {
|
||||||
if(ip2.indexOf(ip) == 0 && chan.getIPRank(ip2) >= actor.rank) {
|
if(err) {
|
||||||
actor.socket.emit("errorMsg", {msg: "You don't have permission to ban IP: x.x." + ip2.replace(/\d+\.\d+\.(\d+\.\d+)/, "$1")});
|
actor.socket.emit("errorMsg", {
|
||||||
return false;
|
msg: "Internal error"
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
chan.ipbans[ip] = [name, actor.name];
|
|
||||||
//chan.broadcastBanlist();
|
|
||||||
chan.logger.log("*** " + actor.name + " banned " + ip + " (" + name + ")");
|
|
||||||
|
|
||||||
for(var i = 0; i < chan.users.length; i++) {
|
if(rank >= actor.rank) {
|
||||||
if(chan.users[i].ip.indexOf(ip) == 0) {
|
actor.socket.emit("errorMsg", {
|
||||||
chan.kick(chan.users[i], "Your IP is banned!");
|
msg: "You don't have permission to ban IP: x.x." +
|
||||||
|
ip.replace(/\d+\.\d+\.(\d+\.\d+)/, "$1")
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.ipbans[ip] = [name, actor.name];
|
||||||
|
self.logger.log("*** " + actor.name + " banned " + ip +
|
||||||
|
" (" + name + ")");
|
||||||
|
|
||||||
|
for(var i = 0; i < self.users.length; i++) {
|
||||||
|
if(self.users[i].ip.indexOf(ip) == 0) {
|
||||||
|
self.kick(self.users[i], "Your IP is banned!");
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!chan.registered)
|
if(!self.registered)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
// Update database ban table
|
self.server.db.addChannelBan(chan.name, ip, name, actor.name
|
||||||
return chan.server.db.channelBan(chan.name, ip, name, actor.name);
|
function (err, res) {
|
||||||
|
self.users.forEach(function(u) {
|
||||||
|
self.sendBanlist(u);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var chan = this;
|
|
||||||
this.users.forEach(function(u) {
|
|
||||||
chan.sendBanlist(u);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1858,6 +1941,7 @@ Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
|
||||||
/* REGION Rank stuff */
|
/* REGION Rank stuff */
|
||||||
|
|
||||||
Channel.prototype.trySetRank = function(user, data) {
|
Channel.prototype.trySetRank = function(user, data) {
|
||||||
|
var self = this;
|
||||||
if(!Rank.hasPermission(user, "promote"))
|
if(!Rank.hasPermission(user, "promote"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1871,9 +1955,9 @@ Channel.prototype.trySetRank = function(user, data) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var receiver;
|
var receiver;
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
for(var i = 0; i < self.users.length; i++) {
|
||||||
if(this.users[i].name == data.user) {
|
if(self.users[i].name == data.user) {
|
||||||
receiver = this.users[i];
|
receiver = self.users[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1883,94 +1967,24 @@ Channel.prototype.trySetRank = function(user, data) {
|
||||||
return;
|
return;
|
||||||
receiver.rank = data.rank;
|
receiver.rank = data.rank;
|
||||||
if(receiver.loggedIn) {
|
if(receiver.loggedIn) {
|
||||||
this.saveRank(receiver);
|
self.saveRank(receiver);
|
||||||
}
|
}
|
||||||
this.broadcastUserUpdate(receiver);
|
self.broadcastUserUpdate(receiver);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var rrank = this.getRank(data.user);
|
self.getRank(data.user, function (err, rrank) {
|
||||||
|
if(err)
|
||||||
|
return;
|
||||||
if(rrank >= user.rank)
|
if(rrank >= user.rank)
|
||||||
return;
|
return;
|
||||||
this.server.db.setChannelRank(this.name, data.user, data.rank);
|
self.server.db.setChannelRank(this.name, data.user,
|
||||||
}
|
data.rank, function (err, res) {
|
||||||
|
|
||||||
this.logger.log("*** " + user.name + " set " + data.user + "'s rank to " +
|
self.logger.log("*** " + user.name + " set " +
|
||||||
data.rank);
|
data.user + "'s rank to " + data.rank);
|
||||||
this.sendAllWithPermission("acl", "setChannelRank", data);
|
self.sendAllWithPermission("acl", "setChannelRank", data);
|
||||||
}
|
});
|
||||||
|
});
|
||||||
Channel.prototype.tryPromoteUser = function(actor, data) {
|
|
||||||
if(!Rank.hasPermission(actor, "promote")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.name == undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = data.name;
|
|
||||||
|
|
||||||
var receiver;
|
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
|
||||||
if(this.users[i].name == name) {
|
|
||||||
receiver = this.users[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rank = receiver ? receiver.rank : this.getRank(data.name);
|
|
||||||
|
|
||||||
if(actor.rank > rank + 1) {
|
|
||||||
rank++;
|
|
||||||
if(receiver) {
|
|
||||||
receiver.rank++;
|
|
||||||
if(receiver.loggedIn) {
|
|
||||||
this.saveRank(receiver);
|
|
||||||
}
|
|
||||||
this.broadcastUserUpdate(receiver);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.server.db.setChannelRank(this.name, data.name, rank);
|
|
||||||
}
|
|
||||||
this.logger.log("*** " + actor.name + " promoted " + data.name + " from " + (rank - 1) + " to " + rank);
|
|
||||||
//this.broadcastRankTable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Channel.prototype.tryDemoteUser = function(actor, data) {
|
|
||||||
if(!Rank.hasPermission(actor, "promote")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.name == undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = data.name;
|
|
||||||
var receiver;
|
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
|
||||||
if(this.users[i].name == name) {
|
|
||||||
receiver = this.users[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var rank = receiver ? receiver.rank : this.getRank(data.name);
|
|
||||||
|
|
||||||
if(actor.rank > rank) {
|
|
||||||
rank--;
|
|
||||||
if(receiver) {
|
|
||||||
receiver.rank--;
|
|
||||||
if(receiver.loggedIn) {
|
|
||||||
this.saveRank(receiver);
|
|
||||||
}
|
|
||||||
this.broadcastUserUpdate(receiver);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.server.db.setChannelRank(this.name, data.name, rank);
|
|
||||||
}
|
|
||||||
this.logger.log("*** " + actor.name + " demoted " + data.name + " from " + (rank + 1) + " to " + rank);
|
|
||||||
//this.broadcastRankTable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
user.js
24
user.js
|
@ -343,29 +343,7 @@ User.prototype.initCallbacks = function() {
|
||||||
if(this.channel == null) {
|
if(this.channel == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!this.channel.registered) {
|
this.channel.unregister(this);
|
||||||
this.socket.emit("unregisterChannel", {
|
|
||||||
success: false,
|
|
||||||
error: "This channel is already unregistered"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if(this.rank < 10) {
|
|
||||||
this.socket.emit("unregisterChannel", {
|
|
||||||
success: false,
|
|
||||||
error: "You don't have permission to unregister"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if(this.channel.unregister()) {
|
|
||||||
this.socket.emit("unregisterChannel", {
|
|
||||||
success: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.socket.emit("unregisterChannel", {
|
|
||||||
success: false,
|
|
||||||
error: "Unregistration failed. Please see a site admin if this continues."
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.socket.on("setOptions", function(data) {
|
this.socket.on("setOptions", function(data) {
|
||||||
|
|
Loading…
Reference in New Issue