]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Fix a lot of calls to match() and uses of wildcard.h (which doesn't exist anymore...
[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
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) : ListModeBase(Instance, 'e', "End of Channel Exception List", 348, 349, true) { }
35 };
36
37
38 class ModuleBanException : public Module
39 {
40         BanException* be;
41
42
43 public:
44         ModuleBanException(InspIRCd* Me) : Module(Me)
45         {
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);
50
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);
54
55         }
56
57         virtual void On005Numeric(std::string &output)
58         {
59                 output.append(" EXCEPTS=e");
60         }
61
62         virtual int OnCheckExtBan(User *user, Channel *chan, char type)
63         {
64                 if (chan != NULL)
65                 {
66                         modelist *list;
67                         chan->GetExt(be->GetInfoKey(), list);
68
69                         if (!list)
70                                 return 0;
71
72                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
73                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
74                         {
75                                 if (it->mask[0] != type || it->mask[1] != ':')
76                                         continue;
77
78                                 std::string maskptr = it->mask.substr(2);
79
80                                 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || match(user->GetFullHost(), maskptr) || (InspIRCd::Match(mask, maskptr, true)))
81                                 {
82                                         // They match an entry on the list, so let them pass this.
83                                         return 1;
84                                 }
85                         }
86                 }
87
88                 return 0;
89         }
90
91         virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
92         {
93                 if (chan != NULL)
94                 {
95                         modelist *list;
96                         chan->GetExt(be->GetInfoKey(), list);
97
98                         if (!list)
99                                 return 0;
100                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
101                         {
102                                 if (it->mask[0] != type || it->mask[1] != ':')
103                                         continue;
104
105                                 std::string maskptr = it->mask.substr(2);
106                                 if (InspIRCd::Match(str, maskptr))
107                                         return 1; // matches
108                         }
109                 }
110
111                 return 0;
112         }
113
114         virtual int OnCheckBan(User* user, Channel* chan)
115         {
116                 if (chan != NULL)
117                 {
118                         modelist* list;
119                         chan->GetExt(be->GetInfoKey(), list);
120
121                         if (!list)
122                         {
123                                 // No list, proceed normally
124                                 return 0;
125                         }
126
127                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
128                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
129                         {
130                                 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || match(user->GetFullHost(), it->mask) || (InspIRCd::Match(mask, it->mask, true)))
131                                 {
132                                         // They match an entry on the list, so let them in.
133                                         return 1;
134                                 }
135                         }
136                 }
137                 return 0;
138         }
139
140         virtual void OnCleanup(int target_type, void* item)
141         {
142                 be->DoCleanup(target_type, item);
143         }
144
145         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
146         {
147                 be->DoSyncChannel(chan, proto, opaque);
148         }
149
150         virtual void OnChannelDelete(Channel* chan)
151         {
152                 be->DoChannelDelete(chan);
153         }
154
155         virtual void OnRehash(User* user, const std::string &param)
156         {
157                 be->DoRehash();
158         }
159
160         virtual const char* OnRequest(Request* request)
161         {
162                 ListModeRequest* LM = (ListModeRequest*)request;
163                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
164                 {
165                         modelist* list;
166                         LM->chan->GetExt(be->GetInfoKey(), list);
167                         if (list)
168                         {
169                                 std::string mask = std::string(LM->user->nick) + "!" + LM->user->ident + "@" + LM->user->GetIPString();
170                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
171                                 {
172                                         if (InspIRCd::Match(LM->user->GetFullRealHost(), it->mask) || match(LM->user->GetFullHost(), it->mask) || (InspIRCd::Match(mask, it->mask, true)))
173                                         {
174                                                 // They match an entry
175                                                 return (char*)it->mask.c_str();
176                                         }
177                                 }
178                                 return NULL;
179                         }
180                 }
181                 return NULL;
182         }
183
184         virtual Version GetVersion()
185         {
186                 return Version(1, 2, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
187         }
188
189         virtual ~ModuleBanException()
190         {
191                 ServerInstance->Modes->DelMode(be);
192                 delete be;
193                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
194         }
195 };
196
197 MODULE_INIT(ModuleBanException)