From 9306200a874712e7447d74f717948fc35d34a2ab Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 8 Jan 2014 20:12:02 -0600 Subject: [PATCH] Work on ban list and channel ranks --- lib/channel-new.js | 38 +++++++- lib/chatcommand.js | 8 +- lib/database/channels.js | 2 +- lib/server.js | 2 +- lib/user.js | 4 + templates/channel.jade | 4 +- templates/channeloptions.jade | 1 - templates/login.jade | 7 +- www/assets/js/callbacks.js | 160 +++++++++++++++------------------- 9 files changed, 118 insertions(+), 108 deletions(-) diff --git a/lib/channel-new.js b/lib/channel-new.js index a261b87b..70be6b3b 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -7,6 +7,7 @@ var Logger = require("./logger"); var AsyncQueue = require("./asyncqueue"); var MakeEmitter = require("./emitter"); var InfoGetter = require("./get-info"); +var ChatCommand = require("./chatcommand"); var fs = require("fs"); var path = require("path"); @@ -664,7 +665,7 @@ Channel.prototype.handleNameBan = function (actor, name, reason) { // If in the channel already, kick the banned user for (var i = 0; i < self.users.length; i++) { if (self.users[i].name.toLowerCase() == name) { - self.kick(self.users[i], "You're banned!"); + self.users[i].kick("You're banned!"); break; } } @@ -785,7 +786,7 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) { // If in the channel already, kick the banned user for (var i = 0; i < self.users.length; i++) { if (self.users[i].ip === ip) { - self.kick(self.users[i], "You're banned!"); + self.users[i].kick("You're banned!"); break; } } @@ -842,6 +843,21 @@ Channel.prototype.sendBanlist = function (users) { }); } + for (var name in self.namebans) { + bans.push({ + ip: "*", + name: name, + reason: self.namebans[name].reason, + bannedby: self.namebans[name].bannedby + }); + unmaskedbans.push({ + ip: "*", + name: name, + reason: self.namebans[name].reason, + bannedby: self.namebans[name].bannedby + }); + } + users.forEach(function (u) { if (!self.hasPermission(u, "ban")) { return; @@ -855,6 +871,24 @@ Channel.prototype.sendBanlist = function (users) { }); }; +/** + * Sends the channel ranks list + */ +Channel.prototype.sendChannelRanks = function (users) { + var self = this; + db.channels.allRanks(self.name, function (err, ranks) { + if (err) { + return; + } + + users.forEach(function (u) { + if (u.rank >= 3) { + u.socket.emit("channelRanks", ranks); + } + }); + }); +}; + /** * Sends the chat filter list */ diff --git a/lib/chatcommand.js b/lib/chatcommand.js index 967c1fdb..609b2a80 100644 --- a/lib/chatcommand.js +++ b/lib/chatcommand.js @@ -297,19 +297,19 @@ function handleKick(chan, user, args) { chan.logger.log("*** " + user.name + " kicked " + args[0]); args[0] = ""; var reason = args.join(" "); - chan.kick(kickee, reason); + kickee.kick(reason); } } } function handleIPBan(chan, user, args) { - chan.tryIPBan(user, args[0], args[1]); + chan.handleBanAllIP(user, args[0], "", args[1]); // Ban the name too for good measure - chan.tryNameBan(user, args[0]); + chan.handleNameBan(user, args[0], ""); } function handleBan(chan, user, args) { - chan.tryNameBan(user, args[0]); + chan.handleNameBan(user, args[0], ""); } function handleUnban(chan, user, args) { diff --git a/lib/database/channels.js b/lib/database/channels.js index 3a2a12e7..21db8ac1 100644 --- a/lib/database/channels.js +++ b/lib/database/channels.js @@ -549,7 +549,7 @@ module.exports = { } db.query("INSERT INTO `chan_" + chan + "_bans` (ip, name, reason, bannedby) " + - "VALUES (?, ?, ?, ?)", [ip, name, reason, bannedby], callback); + "VALUES (?, ?, ?, ?)", [ip, name, note, bannedby], callback); }, /** diff --git a/lib/server.js b/lib/server.js index 2b2b25a7..2fa57317 100644 --- a/lib/server.js +++ b/lib/server.js @@ -225,7 +225,7 @@ Server.prototype.isChannelLoaded = function (name) { Server.prototype.getChannel = function (name) { var cname = name.toLowerCase(); for (var i = 0; i < this.channels.length; i++) { - if (this.channels[i].canonical_name === cname) + if (this.channels[i].uniqueName === cname) return this.channels[i]; } diff --git a/lib/user.js b/lib/user.js index 1607d491..c85a4462 100644 --- a/lib/user.js +++ b/lib/user.js @@ -376,6 +376,10 @@ User.prototype.initChannelCallbacks = function () { self.channel.sendBanlist([self]); }); + wrap("requestChannelRanks", function () { + self.channel.sendChannelRanks([self]); + }); + wrap("requestChatFilter", function () { self.channel.sendChatFilters([self]); }); diff --git a/templates/channel.jade b/templates/channel.jade index 87d7ccb5..69057bdc 100644 --- a/templates/channel.jade +++ b/templates/channel.jade @@ -167,8 +167,8 @@ html(lang="en") li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD li: a(href="#cs-csseditor", data-toggle="tab", tabindex="-1") Edit CSS li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript - li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1") Edit user ranks - li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1") Ban list + li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit user ranks + li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list .modal-body .tab-content include channeloptions diff --git a/templates/channeloptions.jade b/templates/channeloptions.jade index 9d204655..4af9187d 100644 --- a/templates/channeloptions.jade +++ b/templates/channeloptions.jade @@ -78,7 +78,6 @@ mixin banlist th Unban th IP th Name - th Aliases th Banned by mixin recentjoins diff --git a/templates/login.jade b/templates/login.jade index 3f965dba..ac047c94 100644 --- a/templates/login.jade +++ b/templates/login.jade @@ -12,10 +12,7 @@ html(lang="en") ul.nav.navbar-nav mixin navdefaultlinks("/login") if loggedIn - if redirect - mixin navlogoutform(redirect) - else - mixin navlogoutform("/login") + mixin navlogoutform() section#mainpage.container if wasAlreadyLoggedIn .col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3 @@ -47,4 +44,4 @@ html(lang="en") br a(href=redirect) Return to previous page include footer - mixin footer() + mixin footer() diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 8ac6af6c..b6b4eef0 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -443,37 +443,27 @@ Callbacks = { }, banlist: function(entries) { - var tbl = $("#banlist table"); - // I originally added this check because of a race condition - // Now it seems to work without but I don't trust it - if(!tbl.hasClass("table")) { - setTimeout(function() { - Callbacks.banlist(entries); - }, 100); - return; - } - if(tbl.children().length > 1) { - $(tbl.children()[1]).remove(); - } + var tbl = $("#cs-banlist table"); + tbl.find("tbody").remove(); for(var i = 0; i < entries.length; i++) { - var tr = document.createElement("tr"); + var tr = $(""); var remove = $("