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)
65 chan->GetExt(be.GetInfoKey(), list);
68 return MOD_RES_PASSTHRU;
70 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
71 for (modelist::iterator it = list->begin(); it != list->end(); it++)
73 if (it->mask[0] != type || it->mask[1] != ':')
76 std::string maskptr = it->mask.substr(2);
78 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
80 // They match an entry on the list, so let them pass this.
86 return MOD_RES_PASSTHRU;
89 virtual ModResult OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
94 chan->GetExt(be.GetInfoKey(), list);
97 return MOD_RES_PASSTHRU;
98 for (modelist::iterator it = list->begin(); it != list->end(); it++)
100 if (it->mask[0] != type || it->mask[1] != ':')
103 std::string maskptr = it->mask.substr(2);
104 if (InspIRCd::Match(str, maskptr))
105 // They match an entry on the list, so let them in.
106 return MOD_RES_ALLOW;
110 return MOD_RES_PASSTHRU;
113 virtual ModResult OnCheckBan(User* user, Channel* chan)
118 chan->GetExt(be.GetInfoKey(), list);
122 // No list, proceed normally
123 return MOD_RES_PASSTHRU;
126 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
127 for (modelist::iterator it = list->begin(); it != list->end(); it++)
129 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
131 // They match an entry on the list, so let them in.
132 return MOD_RES_ALLOW;
136 return MOD_RES_PASSTHRU;
139 virtual void OnCleanup(int target_type, void* item)
141 be.DoCleanup(target_type, item);
144 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
146 be.DoSyncChannel(chan, proto, opaque);
149 virtual void OnChannelDelete(Channel* chan)
151 be.DoChannelDelete(chan);
154 virtual void OnRehash(User* user)
159 virtual const char* OnRequest(Request* request)
161 return be.DoOnRequest(request);
164 virtual Version GetVersion()
166 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
169 virtual ~ModuleBanException()
171 ServerInstance->Modes->DelMode(&be);
172 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
176 MODULE_INIT(ModuleBanException)