X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_banexception.cpp;h=1811f743de59e5dd7fc64124b1d66ba5ccb9cb32;hb=e2f1a61fc67500c4c101ff8a3f7847914298375e;hp=4f36fb8c9f0cb84e8e2f9fea26bd4aef5999b6f5;hpb=8394be69a0e3b5fea617c69b69aa27daf547fc4e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp index 4f36fb8c9..1811f743d 100644 --- a/src/modules/m_banexception.cpp +++ b/src/modules/m_banexception.cpp @@ -1,19 +1,28 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2006-2008 Craig Edwards + * Copyright (C) 2007-2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006 Oliver Lupton * - * 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 "u_listmode.h" -#include "wildcard.h" /* $ModDesc: Provides support for the +e channel mode */ /* $ModDep: ../../include/u_listmode.h */ @@ -32,117 +41,95 @@ class BanException : public ListModeBase { public: - BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { } + BanException(Module* Creator) : ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", 348, 349, true) { } }; class ModuleBanException : public Module { - BanException* be; - + BanException be; public: - ModuleBanException(InspIRCd* Me) - : Module(Me) + ModuleBanException() : be(this) { - be = new BanException(ServerInstance); - if (!ServerInstance->AddMode(be, 'e')) - throw ModuleException("Could not add new modes!"); - ServerInstance->Modules->PublishInterface("ChannelBanList", this); } - - virtual void Implements(char* List) + + void init() { - be->DoImplements(List); - List[I_OnRehash] = List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckBan] = 1; + ServerInstance->Modules->AddService(be); + + be.DoImplements(this); + Implementation list[] = { I_OnRehash, I_On005Numeric, I_OnExtBanCheck, I_OnCheckChannelBan }; + ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation)); } - - virtual void On005Numeric(std::string &output) + + void On005Numeric(std::string &output) { output.append(" EXCEPTS=e"); } - virtual int OnCheckBan(userrec* user, chanrec* chan) + ModResult OnExtBanCheck(User *user, Channel *chan, char type) { if (chan != NULL) { - modelist* list; - chan->GetExt(be->GetInfoKey(), list); - - if (list) + modelist *list = be.extItem.get(chan); + + if (!list) + return MOD_RES_PASSTHRU; + + for (modelist::iterator it = list->begin(); it != list->end(); it++) { - char mask[MAXBUF]; - snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString()); - for (modelist::iterator it = list->begin(); it != list->end(); it++) + if (it->mask[0] != type || it->mask[1] != ':') + continue; + + if (chan->CheckBan(user, it->mask.substr(2))) { - if (match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true))) - { - // They match an entry on the list, so let them in. - return 1; - } + // They match an entry on the list, so let them pass this. + return MOD_RES_ALLOW; } - return 0; } - // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything. } - return 0; - } - - virtual void OnCleanup(int target_type, void* item) - { - be->DoCleanup(target_type, item); - } - virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque) - { - be->DoSyncChannel(chan, proto, opaque); + return MOD_RES_PASSTHRU; } - virtual void OnChannelDelete(chanrec* chan) + ModResult OnCheckChannelBan(User* user, Channel* chan) { - be->DoChannelDelete(chan); - } + if (chan) + { + modelist *list = be.extItem.get(chan); - virtual void OnRehash(userrec* user, const std::string ¶m) - { - be->DoRehash(); - } + if (!list) + { + // No list, proceed normally + return MOD_RES_PASSTHRU; + } - virtual char* OnRequest(Request* request) - { - ListModeRequest* LM = (ListModeRequest*)request; - if (strcmp("LM_CHECKLIST", request->GetId()) == 0) - { - modelist* list; - LM->chan->GetExt(be->GetInfoKey(), list); - if (list) + for (modelist::iterator it = list->begin(); it != list->end(); it++) { - char mask[MAXBUF]; - snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString()); - for (modelist::iterator it = list->begin(); it != list->end(); it++) + if (chan->CheckBan(user, it->mask)) { - if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true))) - { - // They match an entry - return (char*)it->mask.c_str(); - } + // They match an entry on the list, so let them in. + return MOD_RES_ALLOW; } - return NULL; } } - return NULL; + return MOD_RES_PASSTHRU; + } + + void OnSyncChannel(Channel* chan, Module* proto, void* opaque) + { + be.DoSyncChannel(chan, proto, opaque); } - virtual Version GetVersion() + void OnRehash(User* user) { - return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION); + be.DoRehash(); } - - virtual ~ModuleBanException() + + Version GetVersion() { - ServerInstance->Modes->DelMode(be); - delete be; - ServerInstance->Modules->UnpublishInterface("ChannelBanList", this); + return Version("Provides support for the +e channel mode", VF_VENDOR); } };