]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
0cd915ef9dc5dfd5a3938bb5c72f57f5014a0fd9
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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(InspIRCd* Instance, Module* Creator) : ListModeBase(Instance, Creator, '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(InspIRCd* Me) : Module(Me), be(Me, this)
44         {
45                 if (!ServerInstance->Modes->AddMode(&be))
46                         throw ModuleException("Could not add new modes!");
47                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
48
49                 be.DoImplements(this);
50                 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnExtBanCheck, I_OnCheckChannelBan };
51                 Me->Modules->Attach(list, this, 5);
52
53         }
54
55         void On005Numeric(std::string &output)
56         {
57                 output.append(" EXCEPTS=e");
58         }
59
60         ModResult OnExtBanCheck(User *user, Channel *chan, char type)
61         {
62                 if (chan != NULL)
63                 {
64                         modelist *list = be.extItem.get(chan);
65
66                         if (!list)
67                                 return MOD_RES_PASSTHRU;
68
69                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
70                         {
71                                 if (it->mask[0] != type || it->mask[1] != ':')
72                                         continue;
73
74                                 if (chan->CheckBan(user, it->mask.substr(2)))
75                                 {
76                                         // They match an entry on the list, so let them pass this.
77                                         return MOD_RES_ALLOW;
78                                 }
79                         }
80                 }
81
82                 return MOD_RES_PASSTHRU;
83         }
84
85         ModResult OnCheckChannelBan(User* user, Channel* chan)
86         {
87                 if (chan)
88                 {
89                         modelist *list = be.extItem.get(chan);
90
91                         if (!list)
92                         {
93                                 // No list, proceed normally
94                                 return MOD_RES_PASSTHRU;
95                         }
96
97                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
98                         {
99                                 if (chan->CheckBan(user, it->mask))
100                                 {
101                                         // They match an entry on the list, so let them in.
102                                         return MOD_RES_ALLOW;
103                                 }
104                         }
105                 }
106                 return MOD_RES_PASSTHRU;
107         }
108
109         void OnCleanup(int target_type, void* item)
110         {
111                 be.DoCleanup(target_type, item);
112         }
113
114         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
115         {
116                 be.DoSyncChannel(chan, proto, opaque);
117         }
118
119         void OnRehash(User* user)
120         {
121                 be.DoRehash();
122         }
123
124         const char* OnRequest(Request* request)
125         {
126                 return be.DoOnRequest(request);
127         }
128
129         Version GetVersion()
130         {
131                 return Version("Provides support for the +e channel mode", VF_COMMON | VF_VENDOR, API_VERSION);
132         }
133
134         ~ModuleBanException()
135         {
136                 ServerInstance->Modes->DelMode(&be);
137                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
138         }
139 };
140
141 MODULE_INIT(ModuleBanException)