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