]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Fix order of arguments, this means that ban exceptions for extbans actually work...
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "wildcard.h"
17
18 /* $ModDesc: Provides support for the +e channel mode */
19 /* $ModDep: ../../include/u_listmode.h */
20
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 */
24
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
28
29
30 /** Handles +e channel mode
31  */
32 class BanException : public ListModeBase
33 {
34  public:
35         BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { }
36 };
37
38
39 class ModuleBanException : public Module
40 {
41         BanException* be;
42
43
44 public:
45         ModuleBanException(InspIRCd* Me) : Module(Me)
46         {
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);
51
52                 be->DoImplements(this);
53                 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan };
54                 Me->Modules->Attach(list, this, 6);
55
56         }
57
58         virtual void On005Numeric(std::string &output)
59         {
60                 output.append(" EXCEPTS=e");
61         }
62
63         virtual int OnCheckExtBan(User *user, Channel *chan, char type)
64         {
65                 if (chan != NULL)
66                 {
67                         modelist *list;
68                         chan->GetExt(be->GetInfoKey(), list);
69
70                         if (!list)
71                                 return 0;
72
73                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
74                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
75                         {
76                                 if (it->mask[0] != type || it->mask[1] != ':')
77                                         continue;
78
79                                 std::string maskptr = it->mask.substr(2);
80
81                                 if (match(user->GetFullRealHost(), maskptr) || match(user->GetFullHost(), maskptr) || (match(mask, maskptr, true)))
82                                 {
83                                         // They match an entry on the list, so let them pass this.
84                                         return 1;
85                                 }
86                         }
87                 }
88
89                 return 0;
90         }
91
92         virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
93         {
94                 if (chan != NULL)
95                 {
96                         modelist *list;
97                         chan->GetExt(be->GetInfoKey(), list);
98
99                         if (!list)
100                                 return 0;
101                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
102                         {
103                                 if (it->mask[0] != type || it->mask[1] != ':')
104                                         continue;
105
106                                 std::string maskptr = it->mask.substr(2);
107                                 if (match(str, maskptr))
108                                         return 1; // matches
109                         }
110                 }
111
112                 return 0;
113         }
114
115         virtual int OnCheckBan(User* user, Channel* chan)
116         {
117                 if (chan != NULL)
118                 {
119                         modelist* list;
120                         chan->GetExt(be->GetInfoKey(), list);
121
122                         if (!list)
123                         {
124                                 // No list, proceed normally
125                                 return 0;
126                         }
127
128                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
129                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
130                         {
131                                 if (match(user->GetFullRealHost(), it->mask) || match(user->GetFullHost(), it->mask) || (match(mask, it->mask, true)))
132                                 {
133                                         // They match an entry on the list, so let them in.
134                                         return 1;
135                                 }
136                         }
137                 }
138                 return 0;
139         }
140
141         virtual void OnCleanup(int target_type, void* item)
142         {
143                 be->DoCleanup(target_type, item);
144         }
145
146         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
147         {
148                 be->DoSyncChannel(chan, proto, opaque);
149         }
150
151         virtual void OnChannelDelete(Channel* chan)
152         {
153                 be->DoChannelDelete(chan);
154         }
155
156         virtual void OnRehash(User* user, const std::string &param)
157         {
158                 be->DoRehash();
159         }
160
161         virtual const char* OnRequest(Request* request)
162         {
163                 ListModeRequest* LM = (ListModeRequest*)request;
164                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
165                 {
166                         modelist* list;
167                         LM->chan->GetExt(be->GetInfoKey(), list);
168                         if (list)
169                         {
170                                 std::string mask = std::string(LM->user->nick) + "!" + LM->user->ident + "@" + LM->user->GetIPString();
171                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
172                                 {
173                                         if (match(LM->user->GetFullRealHost(), it->mask) || match(LM->user->GetFullHost(), it->mask) || (match(mask, it->mask, true)))
174                                         {
175                                                 // They match an entry
176                                                 return (char*)it->mask.c_str();
177                                         }
178                                 }
179                                 return NULL;
180                         }
181                 }
182                 return NULL;
183         }
184
185         virtual Version GetVersion()
186         {
187                 return Version(1, 2, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
188         }
189
190         virtual ~ModuleBanException()
191         {
192                 ServerInstance->Modes->DelMode(be);
193                 delete be;
194                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
195         }
196 };
197
198 MODULE_INIT(ModuleBanException)