]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Change Extensible to use strongly typed entries
[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_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 ModResult OnCheckExtBan(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                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
70                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
71                         {
72                                 if (it->mask[0] != type || it->mask[1] != ':')
73                                         continue;
74
75                                 std::string maskptr = it->mask.substr(2);
76
77                                 if (InspIRCd::Match(user->GetFullRealHost(), maskptr) || InspIRCd::Match(user->GetFullHost(), maskptr) || (InspIRCd::MatchCIDR(mask, maskptr)))
78                                 {
79                                         // They match an entry on the list, so let them pass this.
80                                         return MOD_RES_ALLOW;
81                                 }
82                         }
83                 }
84
85                 return MOD_RES_PASSTHRU;
86         }
87
88         virtual ModResult OnCheckStringExtBan(const std::string &str, Channel *chan, char type)
89         {
90                 if (chan != NULL)
91                 {
92                         modelist *list = be.extItem.get(chan);
93
94                         if (!list)
95                                 return MOD_RES_PASSTHRU;
96                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
97                         {
98                                 if (it->mask[0] != type || it->mask[1] != ':')
99                                         continue;
100
101                                 std::string maskptr = it->mask.substr(2);
102                                 if (InspIRCd::Match(str, maskptr))
103                                         // They match an entry on the list, so let them in.
104                                         return MOD_RES_ALLOW;
105                         }
106                 }
107
108                 return MOD_RES_PASSTHRU;
109         }
110
111         virtual ModResult OnCheckBan(User* user, Channel* chan)
112         {
113                 if (chan != NULL)
114                 {
115                         modelist *list = be.extItem.get(chan);
116
117                         if (!list)
118                         {
119                                 // No list, proceed normally
120                                 return MOD_RES_PASSTHRU;
121                         }
122
123                         std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
124                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
125                         {
126                                 if (InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
127                                 {
128                                         // They match an entry on the list, so let them in.
129                                         return MOD_RES_ALLOW;
130                                 }
131                         }
132                 }
133                 return MOD_RES_PASSTHRU;
134         }
135
136         virtual void OnCleanup(int target_type, void* item)
137         {
138                 be.DoCleanup(target_type, item);
139         }
140
141         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
142         {
143                 be.DoSyncChannel(chan, proto, opaque);
144         }
145
146         virtual void OnRehash(User* user)
147         {
148                 be.DoRehash();
149         }
150
151         virtual const char* OnRequest(Request* request)
152         {
153                 return be.DoOnRequest(request);
154         }
155
156         virtual Version GetVersion()
157         {
158                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
159         }
160
161         virtual ~ModuleBanException()
162         {
163                 ServerInstance->Modes->DelMode(&be);
164                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
165         }
166 };
167
168 MODULE_INIT(ModuleBanException)