X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_restrictchans.cpp;h=8cc882d9050e736d0d387180a92e6962dc5fbf9c;hb=a59d08fffd3dc8a9850ce34c9928fb6382b9b37f;hp=eb1feffa8f64e43229c83ac459e401bbce98c7f8;hpb=d0b4bb3811458aa335857514e4cbb95d5c84f433;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp index eb1feffa8..8cc882d90 100644 --- a/src/modules/m_restrictchans.cpp +++ b/src/modules/m_restrictchans.cpp @@ -2,116 +2,77 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits + * * This program is free but copyrighted software; see - * the file COPYING for details. + * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - -#include -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "helperfuncs.h" #include "inspircd.h" /* $ModDesc: Only opers may create new channels if this module is loaded */ class ModuleRestrictChans : public Module { - - - std::map allowchans; + std::set allowchans; void ReadConfig() { - ConfigReader* MyConf = new ConfigReader(); allowchans.clear(); - for (int i = 0; i < MyConf->Enumerate("allowchannel"); i++) + for (int i = 0;; i++) { - std::string txt; - txt = MyConf->ReadValue("allowchannel", "name", i); - irc::string channel = txt.c_str(); - allowchans[channel] = 1; + ConfigTag* tag = ServerInstance->Config->ConfValue("allowchannel", i); + if (!tag) + return; + std::string txt = tag->getString("name"); + allowchans.insert(txt.c_str()); } - DELETE(MyConf); } public: - ModuleRestrictChans(InspIRCd* Me) - : Module::Module(Me) + ModuleRestrictChans() { - ReadConfig(); + Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash }; + ServerInstance->Modules->Attach(eventlist, this, 2); } - virtual void OnRehash(const std::string ¶meter) + virtual void OnRehash(User* user) { ReadConfig(); } - void Implements(char* List) - { - List[I_OnUserPreJoin] = List[I_OnRehash] = 1; - } - - virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) + + virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) { irc::string x = cname; - // user is not an oper and its not in the allow list - if ((!*user->oper) && (allowchans.find(x) == allowchans.end())) + 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) { - // channel does not yet exist (record is null, about to be created IF we were to allow it) - if (!chan) + // user is not an oper and its not in the allow list + if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end())) { - user->WriteServ("530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname); - return 1; + user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname); + return MOD_RES_DENY; } } - return 0; - } - - virtual ~ModuleRestrictChans() - { - } - - virtual Version GetVersion() - { - return Version(1,0,0,1,VF_VENDOR); + return MOD_RES_PASSTHRU; } -}; - -class ModuleRestrictChansFactory : public ModuleFactory -{ - public: - ModuleRestrictChansFactory() - { - } - - ~ModuleRestrictChansFactory() + virtual ~ModuleRestrictChans() { } - - virtual Module * CreateModule(InspIRCd* Me) + + virtual Version GetVersion() { - return new ModuleRestrictChans(Me); + return Version("Only opers may create new channels if this module is loaded",VF_VENDOR); } - }; - -extern "C" void * init_module( void ) -{ - return new ModuleRestrictChansFactory; -} - +MODULE_INIT(ModuleRestrictChans)