1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
21 #include "u_listmode.h"
24 /* $ModDesc: Provides support for the +e channel mode */
25 /* $ModDep: ../../include/u_listmode.h */
27 /* Written by Om<om@inspircd.org>, April 2005. */
28 /* Rewritten to use the listmode utility by Om, December 2005 */
29 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
31 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
32 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
33 // Now supports CIDR and IP addresses -- Brain
36 /** Handles +e channel mode
38 class BanException : public ListModeBase
41 BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }
45 class ModuleBanException : public Module
51 ModuleBanException(InspIRCd* Me)
54 be = new BanException(ServerInstance);
55 if (!ServerInstance->AddMode(be, 'e'))
56 throw ModuleException("Could not add new modes!");
57 ServerInstance->PublishInterface("ChannelBanList", this);
60 virtual void Implements(char* List)
62 be->DoImplements(List);
63 List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckBan] = 1;
66 virtual void On005Numeric(std::string &output)
68 output.append(" EXCEPTS=e");
71 virtual int OnCheckBan(userrec* user, chanrec* chan)
76 chan->GetExt(be->GetInfoKey(), list);
81 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
82 for (modelist::iterator it = list->begin(); it != list->end(); it++)
84 if (ServerInstance->MatchText(user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(user->GetFullHost(), it->mask) || (match(mask, it->mask.c_str(), true)))
86 // They match an entry on the list, so let them in.
92 // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
97 virtual void OnCleanup(int target_type, void* item)
99 be->DoCleanup(target_type, item);
102 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
104 be->DoSyncChannel(chan, proto, opaque);
107 virtual void OnChannelDelete(chanrec* chan)
109 be->DoChannelDelete(chan);
112 virtual void OnRehash(userrec* user, const std::string ¶m)
117 virtual char* OnRequest(Request* request)
119 ListModeRequest* LM = (ListModeRequest*)request;
120 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
123 LM->chan->GetExt(be->GetInfoKey(), list);
127 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
128 for (modelist::iterator it = list->begin(); it != list->end(); it++)
130 if (ServerInstance->MatchText(LM->user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(LM->user->GetFullHost(), it->mask) ||
131 (match(mask, it->mask.c_str(), true)))
133 // They match an entry
134 return (char*)it->mask.c_str();
143 virtual Version GetVersion()
145 return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
148 virtual ~ModuleBanException()
150 ServerInstance->Modes->DelMode(be);
152 ServerInstance->UnpublishInterface("ChannelBanList", this);
156 class ModuleBanExceptionFactory : public ModuleFactory
159 ModuleBanExceptionFactory()
163 ~ModuleBanExceptionFactory()
167 virtual Module* CreateModule(InspIRCd* Me)
169 return new ModuleBanException(Me);
174 extern "C" void * init_module( void )
176 return new ModuleBanExceptionFactory;