]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Added ability to send and receive a challenge, dont do anything with it yet
[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                 ServerInstance->PublishInterface("ChannelBanList", this);
58         }
59         
60         virtual void Implements(char* List)
61         {
62                 be->DoImplements(List);
63                 List[I_OnRequest] = 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 (match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (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(userrec* user, const std::string &param)
113         {
114                 be->DoRehash();
115         }
116
117         virtual char* OnRequest(Request* request)
118         {
119                 ListModeRequest* LM = (ListModeRequest*)request;
120                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
121                 {
122                         modelist* list;
123                         LM->chan->GetExt(be->GetInfoKey(), list);
124                         if (list)
125                         {
126                                 char mask[MAXBUF];
127                                 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
128                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
129                                 {
130                                         if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
131                                         {
132                                                 // They match an entry
133                                                 return (char*)it->mask.c_str();
134                                         }
135                                 }
136                                 return NULL;
137                         }
138                 }
139                 return NULL;
140         }
141
142         virtual Version GetVersion()
143         {
144                 return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
145         }
146         
147         virtual ~ModuleBanException()
148         {
149                 ServerInstance->Modes->DelMode(be);
150                 DELETE(be);
151                 ServerInstance->UnpublishInterface("ChannelBanList", this);
152         }
153 };
154
155 class ModuleBanExceptionFactory : public ModuleFactory
156 {
157  public:
158         ModuleBanExceptionFactory()
159         {
160         }
161         
162         ~ModuleBanExceptionFactory()
163         {
164         }
165         
166         virtual Module* CreateModule(InspIRCd* Me)
167         {
168                 return new ModuleBanException(Me);
169         }
170 };
171
172
173 extern "C" void * init_module( void )
174 {
175         return new ModuleBanExceptionFactory;
176 }