]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Replace std::deque with std::vector in spanningtree and related modules
[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) : 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 public:
43         ModuleBanException(InspIRCd* Me) : Module(Me), be(Me)
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_OnCheckBan, I_OnCheckExtBan, I_OnCheckStringExtBan };
51                 Me->Modules->Attach(list, this, 6);
52
53         }
54
55         virtual void On005Numeric(std::string &output)
56         {
57                 output.append(" EXCEPTS=e");
58         }
59
60         virtual int OnCheckExtBan(User *user, Channel *chan, char type)
61         {
62                 if (chan != NULL)
63                 {
64                         modelist *list;
65                         chan->GetExt(be.GetInfoKey(), list);
66
67                         if (!list)
68                                 return 0;
69
70                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
71                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
72                         {
73                                 if (it->mask[0] != type || it->mask[1] != ':')
74                                         continue;
75
76                                 std::string maskptr = it->mask.substr(2);
77
78                                 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
79                                 {
80                                         // They match an entry on the list, so let them pass this.
81                                         return 1;
82                                 }
83                         }
84                 }
85
86                 return 0;
87         }
88
89         virtual int OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
90         {
91                 if (chan != NULL)
92                 {
93                         modelist *list;
94                         chan->GetExt(be.GetInfoKey(), list);
95
96                         if (!list)
97                                 return 0;
98                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
99                         {
100                                 if (it->mask[0] != type || it->mask[1] != ':')
101                                         continue;
102
103                                 std::string maskptr = it->mask.substr(2);
104                                 if (InspIRCd::Match(str, maskptr))
105                                         // They match an entry on the list, so let them in.
106                                         return 1;
107                         }
108                 }
109
110                 return 0;
111         }
112
113         virtual int OnCheckBan(User* user, Channel* chan)
114         {
115                 if (chan != NULL)
116                 {
117                         modelist* list;
118                         chan->GetExt(be.GetInfoKey(), list);
119
120                         if (!list)
121                         {
122                                 // No list, proceed normally
123                                 return 0;
124                         }
125
126                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
127                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
128                         {
129                                 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
130                                 {
131                                         // They match an entry on the list, so let them in.
132                                         return 1;
133                                 }
134                         }
135                 }
136                 return 0;
137         }
138
139         virtual void OnCleanup(int target_type, void* item)
140         {
141                 be.DoCleanup(target_type, item);
142         }
143
144         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
145         {
146                 be.DoSyncChannel(chan, proto, opaque);
147         }
148
149         virtual void OnChannelDelete(Channel* chan)
150         {
151                 be.DoChannelDelete(chan);
152         }
153
154         virtual void OnRehash(User* user)
155         {
156                 be.DoRehash();
157         }
158
159         virtual const char* OnRequest(Request* request)
160         {
161                 return be.DoOnRequest(request);
162         }
163
164         virtual Version GetVersion()
165         {
166                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
167         }
168
169         virtual ~ModuleBanException()
170         {
171                 ServerInstance->Modes->DelMode(&be);
172                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
173         }
174 };
175
176 MODULE_INIT(ModuleBanException)