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