]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "u_listmode.h"
16
17 /* $ModDesc: Provides support for the +e channel mode */
18 /* $ModDep: ../../include/u_listmode.h */
19
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 */
23
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
27
28
29 /** Handles +e channel mode
30  */
31 class BanException : public ListModeBase
32 {
33  public:
34         BanException(Module* Creator) : ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", 348, 349, true) { }
35 };
36
37
38 class ModuleBanException : public Module
39 {
40         BanException be;
41
42 public:
43         ModuleBanException() : be(this)
44         {
45                 if (!ServerInstance->Modes->AddMode(&be))
46                         throw ModuleException("Could not add new modes!");
47
48                 be.DoImplements(this);
49                 Implementation list[] = { I_OnRehash, I_On005Numeric, I_OnExtBanCheck, I_OnCheckChannelBan };
50                 ServerInstance->Modules->Attach(list, this, 4);
51
52         }
53
54         void On005Numeric(std::string &output)
55         {
56                 output.append(" EXCEPTS=e");
57         }
58
59         ModResult OnExtBanCheck(User *user, Channel *chan, char type)
60         {
61                 if (chan != NULL)
62                 {
63                         modelist *list = be.extItem.get(chan);
64
65                         if (!list)
66                                 return MOD_RES_PASSTHRU;
67
68                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
69                         {
70                                 if (it->mask[0] != type || it->mask[1] != ':')
71                                         continue;
72
73                                 if (chan->CheckBan(user, it->mask.substr(2)))
74                                 {
75                                         // They match an entry on the list, so let them pass this.
76                                         return MOD_RES_ALLOW;
77                                 }
78                         }
79                 }
80
81                 return MOD_RES_PASSTHRU;
82         }
83
84         ModResult OnCheckChannelBan(User* user, Channel* chan)
85         {
86                 if (chan)
87                 {
88                         modelist *list = be.extItem.get(chan);
89
90                         if (!list)
91                         {
92                                 // No list, proceed normally
93                                 return MOD_RES_PASSTHRU;
94                         }
95
96                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
97                         {
98                                 if (chan->CheckBan(user, it->mask))
99                                 {
100                                         // They match an entry on the list, so let them in.
101                                         return MOD_RES_ALLOW;
102                                 }
103                         }
104                 }
105                 return MOD_RES_PASSTHRU;
106         }
107
108         void OnCleanup(int target_type, void* item)
109         {
110                 be.DoCleanup(target_type, item);
111         }
112
113         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
114         {
115                 be.DoSyncChannel(chan, proto, opaque);
116         }
117
118         void OnRehash(User* user)
119         {
120                 be.DoRehash();
121         }
122
123         Version GetVersion()
124         {
125                 return Version("Provides support for the +e channel mode", VF_COMMON | VF_VENDOR);
126         }
127 };
128
129 MODULE_INIT(ModuleBanException)