X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_banexception.cpp;h=15c151aa5a086de23a57c85d499a9e76aa9a3357;hb=be609949e3ec2543d6cb16d23240870028732f36;hp=7c33e489e80881df653038967ba4f6d61fa57568;hpb=c2957516bca0fe70622c7668a12ade68576ddab2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_banexception.cpp b/src/modules/m_banexception.cpp index 7c33e489e..15c151aa5 100644 --- a/src/modules/m_banexception.cpp +++ b/src/modules/m_banexception.cpp @@ -13,7 +13,6 @@ #include "inspircd.h" #include "u_listmode.h" -#include "wildcard.h" /* $ModDesc: Provides support for the +e channel mode */ /* $ModDep: ../../include/u_listmode.h */ @@ -32,14 +31,14 @@ class BanException : public ListModeBase { public: - BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { } + BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { } }; class ModuleBanException : public Module { BanException* be; - + public: ModuleBanException(InspIRCd* Me) : Module(Me) @@ -50,40 +49,92 @@ public: ServerInstance->Modules->PublishInterface("ChannelBanList", this); be->DoImplements(this); - Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan }; - Me->Modules->Attach(list, this, 4); + Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan }; + Me->Modules->Attach(list, this, 6); } - + virtual void On005Numeric(std::string &output) { output.append(" EXCEPTS=e"); } + virtual int OnCheckExtBan(User *user, Channel *chan, char type) + { + if (chan != NULL) + { + modelist *list; + chan->GetExt(be->GetInfoKey(), list); + + if (!list) + return 0; + + std::string mask = std::string(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; + + std::string maskptr = it->mask.substr(2); + + if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr))) + { + // They match an entry on the list, so let them pass this. + return 1; + } + } + } + + return 0; + } + + virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type) + { + if (chan != NULL) + { + modelist *list; + chan->GetExt(be->GetInfoKey(), list); + + if (!list) + return 0; + for (modelist::iterator it = list->begin(); it != list->end(); it++) + { + if (it->mask[0] != type || it->mask[1] != ':') + continue; + + std::string maskptr = it->mask.substr(2); + if (InspIRCd::Match(str, maskptr)) + return 1; // matches + } + } + + return 0; + } + virtual int OnCheckBan(User* user, Channel* chan) { if (chan != NULL) { modelist* list; chan->GetExt(be->GetInfoKey(), list); - - if (list) + + if (!list) { - 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++) + // No list, proceed normally + return 0; + } + + std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString(); + for (modelist::iterator it = list->begin(); it != list->end(); it++) + { + if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask))) { - 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 in. + return 1; } - 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; + return 0; } virtual void OnCleanup(int target_type, void* item) @@ -108,34 +159,14 @@ public: virtual const 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) - { - 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 (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(); - } - } - return NULL; - } - } - return NULL; + return be->DoOnRequest(request); } virtual Version GetVersion() { - return Version(1, 2, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION); + return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); } - + virtual ~ModuleBanException() { ServerInstance->Modes->DelMode(be);