1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
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) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { }
38 class ModuleBanException : public Module
44 ModuleBanException(InspIRCd* Me) : Module(Me)
46 be = new BanException(ServerInstance);
47 if (!ServerInstance->Modes->AddMode(be))
48 throw ModuleException("Could not add new modes!");
49 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
51 be->DoImplements(this);
52 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan };
53 Me->Modules->Attach(list, this, 6);
57 virtual void On005Numeric(std::string &output)
59 output.append(" EXCEPTS=e");
62 virtual int OnCheckExtBan(User *user, Channel *chan, char type)
67 chan->GetExt(be->GetInfoKey(), list);
72 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
73 for (modelist::iterator it = list->begin(); it != list->end(); it++)
75 if (it->mask[0] != type || it->mask[1] != ':')
78 std::string maskptr = it->mask.substr(2);
80 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
82 // They match an entry on the list, so let them pass this.
91 virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
96 chan->GetExt(be->GetInfoKey(), list);
100 for (modelist::iterator it = list->begin(); it != list->end(); it++)
102 if (it->mask[0] != type || it->mask[1] != ':')
105 std::string maskptr = it->mask.substr(2);
106 if (InspIRCd::Match(str, maskptr))
114 virtual int OnCheckBan(User* user, Channel* chan)
119 chan->GetExt(be->GetInfoKey(), list);
123 // No list, proceed normally
127 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
128 for (modelist::iterator it = list->begin(); it != list->end(); it++)
130 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
132 // They match an entry on the list, so let them in.
140 virtual void OnCleanup(int target_type, void* item)
142 be->DoCleanup(target_type, item);
145 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
147 be->DoSyncChannel(chan, proto, opaque);
150 virtual void OnChannelDelete(Channel* chan)
152 be->DoChannelDelete(chan);
155 virtual void OnRehash(User* user, const std::string ¶m)
160 virtual const char* OnRequest(Request* request)
162 return be->DoOnRequest(request);
165 virtual Version GetVersion()
167 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
170 virtual ~ModuleBanException()
172 ServerInstance->Modes->DelMode(be);
174 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
178 MODULE_INIT(ModuleBanException)