From 4c1b8e8c1aa61a2c0fc7e6ceb18a3cc8f4aa8859 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 21 May 2014 20:33:24 -0700 Subject: [PATCH] Add ability to blacklist channels in site config --- config.template.yaml | 4 ++++ lib/config.js | 11 ++++++++++- lib/user.js | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.template.yaml b/config.template.yaml index 7e3ac1a5..1073791b 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -171,3 +171,7 @@ contacts: # periodically, the garbage collector will be invoked immediately. # The server must be invoked with node --expose-gc index.js for this to have any effect. aggressive-gc: false + +# Allows you to blacklist certain channels. Users will be automatically kicked +# upon trying to join one. +channel-blacklist: [] diff --git a/lib/config.js b/lib/config.js index c4427291..fbd4ed2a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -103,7 +103,8 @@ var defaults = { playlist: { "max-items": 4000, "update-interval": 5 - } + }, + "channel-blacklist": [] }; /** @@ -324,6 +325,14 @@ function preprocessConfig(cfg) { reserved[key] = false; } } + + /* Convert channel blacklist to a hashtable */ + var tbl = {}; + cfg["channel-blacklist"].forEach(function (c) { + tbl[c.toLowerCase()] = true; + }); + cfg["channel-blacklist"] = tbl; + return cfg; } diff --git a/lib/user.js b/lib/user.js index 248b4006..1df5e0ff 100644 --- a/lib/user.js +++ b/lib/user.js @@ -46,6 +46,10 @@ function User(socket) { } data.name = data.name.toLowerCase(); + if (data.name in Config.get("channel-blacklist")) { + self.kick("This channel is blacklisted."); + } + self.waitFlag(Flags.U_READY, function () { var chan = Server.getServer().getChannel(data.name); chan.joinUser(self, data);