1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "u_listmode.h"
17 /* $ModDesc: Provides support for the +e channel mode */
18 /* $ModDep: ../../include/u_listmode.h */
20 /* Written by Om<om@inspircd.org>, April 2005. */
21 /* Rewritten to use the listmode utility by Om, December 2005 */
22 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
24 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
25 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
26 // Now supports CIDR and IP addresses -- Brain
29 /** Handles +e channel mode
31 class BanException : public ListModeBase
34 BanException(InspIRCd* Instance, Module* Creator) : ListModeBase(Instance, Creator, 'e', "End of Channel Exception List", 348, 349, true) { }
38 class ModuleBanException : public Module
43 ModuleBanException(InspIRCd* Me) : Module(Me), be(Me, this)
45 if (!ServerInstance->Modes->AddMode(&be))
46 throw ModuleException("Could not add new modes!");
47 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
49 be.DoImplements(this);
50 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan };
51 Me->Modules->Attach(list, this, 6);
55 virtual void On005Numeric(std::string &output)
57 output.append(" EXCEPTS=e");
60 virtual ModResult OnCheckExtBan(User *user, Channel *chan, char type)
64 modelist *list = be.extItem.get(chan);
67 return MOD_RES_PASSTHRU;
69 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
70 for (modelist::iterator it = list->begin(); it != list->end(); it++)
72 if (it->mask[0] != type || it->mask[1] != ':')
75 std::string maskptr = it->mask.substr(2);
77 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
79 // They match an entry on the list, so let them pass this.
85 return MOD_RES_PASSTHRU;
88 virtual ModResult OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
92 modelist *list = be.extItem.get(chan);
95 return MOD_RES_PASSTHRU;
96 for (modelist::iterator it = list->begin(); it != list->end(); it++)
98 if (it->mask[0] != type || it->mask[1] != ':')
101 std::string maskptr = it->mask.substr(2);
102 if (InspIRCd::Match(str, maskptr))
103 // They match an entry on the list, so let them in.
104 return MOD_RES_ALLOW;
108 return MOD_RES_PASSTHRU;
111 virtual ModResult OnCheckBan(User* user, Channel* chan)
115 modelist *list = be.extItem.get(chan);
119 // No list, proceed normally
120 return MOD_RES_PASSTHRU;
123 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
124 for (modelist::iterator it = list->begin(); it != list->end(); it++)
126 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
128 // They match an entry on the list, so let them in.
129 return MOD_RES_ALLOW;
133 return MOD_RES_PASSTHRU;
136 virtual void OnCleanup(int target_type, void* item)
138 be.DoCleanup(target_type, item);
141 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
143 be.DoSyncChannel(chan, proto, opaque);
146 virtual void OnRehash(User* user)
151 virtual const char* OnRequest(Request* request)
153 return be.DoOnRequest(request);
156 virtual Version GetVersion()
158 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
161 virtual ~ModuleBanException()
163 ServerInstance->Modes->DelMode(&be);
164 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
168 MODULE_INIT(ModuleBanException)