X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_restrictchans.cpp;h=853b6b75c14d647e000efbf2419c1af16bf1969d;hb=9982ec4e5b027ed24b1fda5e6fd3ab35b98de1a7;hp=8cc882d9050e736d0d387180a92e6962dc5fbf9c;hpb=a59d08fffd3dc8a9850ce34c9928fb6382b9b37f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp index 8cc882d90..853b6b75c 100644 --- a/src/modules/m_restrictchans.cpp +++ b/src/modules/m_restrictchans.cpp @@ -1,77 +1,90 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2007 Robin Burchell + * Copyright (C) 2005-2006 Craig Edwards * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd.h" +#include "modules/account.h" -/* $ModDesc: Only opers may create new channels if this module is loaded */ +typedef insp::flat_set AllowChans; class ModuleRestrictChans : public Module { - std::set allowchans; + AllowChans allowchans; + bool allowregistered; - void ReadConfig() + bool CanCreateChannel(LocalUser* user, const std::string& name) { - allowchans.clear(); - for (int i = 0;; i++) + const AccountExtItem* accountext = GetAccountExtItem(); + if (allowregistered && accountext && accountext->get(user)) + return true; + + if (user->HasPrivPermission("channels/restricted-create")) + return true; + + for (AllowChans::const_iterator it = allowchans.begin(), it_end = allowchans.end(); it != it_end; ++it) { - ConfigTag* tag = ServerInstance->Config->ConfValue("allowchannel", i); - if (!tag) - return; - std::string txt = tag->getString("name"); - allowchans.insert(txt.c_str()); + if (InspIRCd::Match(name, *it)) + return true; } + + return false; } public: ModuleRestrictChans() + : allowregistered(false) { - ReadConfig(); - Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash }; - ServerInstance->Modules->Attach(eventlist, this, 2); } - virtual void OnRehash(User* user) - { - ReadConfig(); - } - - - virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { - irc::string x = cname; - if (!IS_LOCAL(user)) - return MOD_RES_PASSTHRU; - - // channel does not yet exist (record is null, about to be created IF we were to allow it) - if (!chan) + AllowChans newallows; + ConfigTagList tags = ServerInstance->Config->ConfTags("allowchannel"); + for (ConfigIter i = tags.first; i != tags.second; ++i) { - // user is not an oper and its not in the allow list - if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end())) - { - user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname); - return MOD_RES_DENY; - } + const std::string name = i->second->getString("name"); + if (name.empty()) + throw ModuleException("Empty at " + i->second->getTagLocation()); + + newallows.insert(name); } - return MOD_RES_PASSTHRU; + allowchans.swap(newallows); + + // Global config + ConfigTag* tag = ServerInstance->Config->ConfValue("restrictchans"); + allowregistered = tag->getBool("allowregistered", false); } - virtual ~ModuleRestrictChans() + ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE { + // channel does not yet exist (record is null, about to be created IF we were to allow it) + if (!chan && !CanCreateChannel(user, cname)) + return MOD_RES_DENY; + + return MOD_RES_PASSTHRU; } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version("Only opers may create new channels if this module is loaded",VF_VENDOR); + return Version("Allows restricting who can create channels", VF_VENDOR); } };