]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
bc0d7f009ea5602e41f59537f86a5f488d43e182
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 <string>
15 #include <vector>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "mode.h"
20 #include "inspircd.h"
21 #include "u_listmode.h"
22 #include "wildcard.h"
23
24 /* $ModDesc: Provides support for the +e channel mode */
25 /* $ModDep: ../../include/u_listmode.h */
26
27 /* Written by Om<om@inspircd.org>, April 2005. */
28 /* Rewritten to use the listmode utility by Om, December 2005 */
29 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
30
31 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
32 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
33 // Now supports CIDR and IP addresses -- Brain
34
35
36 /** Handles +e channel mode
37  */
38 class BanException : public ListModeBase
39 {
40  public:
41         BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }
42 };
43
44
45 class ModuleBanException : public Module
46 {
47         BanException* be;
48         
49
50 public:
51         ModuleBanException(InspIRCd* Me)
52         : Module::Module(Me)
53         {
54                 be = new BanException(ServerInstance);
55                 if (!ServerInstance->AddMode(be, 'e'))
56                         throw ModuleException("Could not add new modes!");
57         }
58         
59         virtual void Implements(char* List)
60         {
61                 be->DoImplements(List);
62                 List[I_On005Numeric] = List[I_OnCheckBan] = 1;
63         }
64         
65         virtual void On005Numeric(std::string &output)
66         {
67                 output.append(" EXCEPTS=e");
68         }
69
70         virtual int OnCheckBan(userrec* user, chanrec* chan)
71         {
72                 if (chan != NULL)
73                 {
74                         modelist* list;
75                         chan->GetExt(be->GetInfoKey(), list);
76                         
77                         if (list)
78                         {
79                                 char mask[MAXBUF];
80                                 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
81                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
82                                 {
83                                         if (ServerInstance->MatchText(user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(user->GetFullHost(), it->mask) || (match(mask, it->mask.c_str(), true)))
84                                         {
85                                                 // They match an entry on the list, so let them in.
86                                                 return 1;
87                                         }
88                                 }
89                                 return 0;
90                         }
91                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
92                 }
93                 return 0;       
94         }
95
96         virtual void OnCleanup(int target_type, void* item)
97         {
98                 be->DoCleanup(target_type, item);
99         }
100
101         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
102         {
103                 be->DoSyncChannel(chan, proto, opaque);
104         }
105
106         virtual void OnChannelDelete(chanrec* chan)
107         {
108                 be->DoChannelDelete(chan);
109         }
110
111         virtual void OnRehash(const std::string &param)
112         {
113                 be->DoRehash();
114         }
115         
116         virtual Version GetVersion()
117         {
118                 return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
119         }
120         
121         virtual ~ModuleBanException()
122         {
123                 ServerInstance->Modes->DelMode(be);
124                 DELETE(be);     
125         }
126 };
127
128 class ModuleBanExceptionFactory : public ModuleFactory
129 {
130  public:
131         ModuleBanExceptionFactory()
132         {
133         }
134         
135         ~ModuleBanExceptionFactory()
136         {
137         }
138         
139         virtual Module* CreateModule(InspIRCd* Me)
140         {
141                 return new ModuleBanException(Me);
142         }
143 };
144
145
146 extern "C" void * init_module( void )
147 {
148         return new ModuleBanExceptionFactory;
149 }