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"
18 /* $ModDesc: Provides support for the +e channel mode */
19 /* $ModDep: ../../include/u_listmode.h */
21 /* Written by Om<om@inspircd.org>, April 2005. */
22 /* Rewritten to use the listmode utility by Om, December 2005 */
23 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
25 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
26 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
27 // Now supports CIDR and IP addresses -- Brain
30 /** Handles +e channel mode
32 class BanException : public ListModeBase
35 BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { }
39 class ModuleBanException : public Module
45 ModuleBanException(InspIRCd* Me) : Module(Me)
47 be = new BanException(ServerInstance);
48 if (!ServerInstance->Modes->AddMode(be))
49 throw ModuleException("Could not add new modes!");
50 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
52 be->DoImplements(this);
53 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan };
54 Me->Modules->Attach(list, this, 5);
58 virtual void On005Numeric(std::string &output)
60 output.append(" EXCEPTS=e");
63 virtual int OnCheckExtBan(User *user, Channel *chan, char type)
68 chan->GetExt(be->GetInfoKey(), list);
73 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
74 for (modelist::iterator it = list->begin(); it != list->end(); it++)
76 if (it->mask[0] != type || it->mask[1] != ':')
79 std::string maskptr = it->mask.substr(2);
81 if (match(user->GetFullRealHost(), maskptr) || match(user->GetFullHost(), maskptr) || (match(mask, maskptr, true)))
83 // They match an entry on the list, so let them pass this.
92 virtual int OnCheckBan(User* user, Channel* chan)
97 chan->GetExt(be->GetInfoKey(), list);
101 // No list, proceed normally
105 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
106 for (modelist::iterator it = list->begin(); it != list->end(); it++)
108 if (match(user->GetFullRealHost(), it->mask) || match(user->GetFullHost(), it->mask) || (match(mask, it->mask, true)))
110 // They match an entry on the list, so let them in.
118 virtual void OnCleanup(int target_type, void* item)
120 be->DoCleanup(target_type, item);
123 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
125 be->DoSyncChannel(chan, proto, opaque);
128 virtual void OnChannelDelete(Channel* chan)
130 be->DoChannelDelete(chan);
133 virtual void OnRehash(User* user, const std::string ¶m)
138 virtual const char* OnRequest(Request* request)
140 ListModeRequest* LM = (ListModeRequest*)request;
141 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
144 LM->chan->GetExt(be->GetInfoKey(), list);
147 std::string mask = std::string(LM->user->nick) + "!" + LM->user->ident + "@" + LM->user->GetIPString();
148 for (modelist::iterator it = list->begin(); it != list->end(); it++)
150 if (match(LM->user->GetFullRealHost(), it->mask) || match(LM->user->GetFullHost(), it->mask) || (match(mask, it->mask, true)))
152 // They match an entry
153 return (char*)it->mask.c_str();
162 virtual Version GetVersion()
164 return Version(1, 2, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
167 virtual ~ModuleBanException()
169 ServerInstance->Modes->DelMode(be);
171 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
175 MODULE_INIT(ModuleBanException)