]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Fix all typos (not as fun as 'kill all humans' but meh, beggers cant be choosers)
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
1 #include <stdio.h>
2 #include <string>
3 #include <vector>
4 #include "users.h"
5 #include "channels.h"
6 #include "modules.h"
7 #include "mode.h"
8 #include "helperfuncs.h"
9 #include "u_listmode.h"
10
11 /* $ModDesc: Provides support for the +e channel mode */
12
13 /* Written by Om<om@inspircd.org>, April 2005. */
14 /* Rewritten to use the listmode utility by Om, December 2005 */
15 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
16
17 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
18 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
19
20 class BanException : public ListModeBase
21 {
22  public:
23         BanException(Server* serv) : ListModeBase(serv, 'e', "End of Channel Exception List", "348", "349") { }
24 };
25
26
27 class ModuleBanException : public Module
28 {
29         BanException* be;
30         Server* Srv;
31
32 public:
33         ModuleBanException(Server* serv) : Module(serv)
34         {
35                 be = new BanException(serv);
36                 Srv = serv;
37         }
38         
39         virtual void Implements(char* List)
40         {
41                 be->DoImplements(List);
42                 List[I_On005Numeric] = List[I_OnCheckBan] = 1;
43         }
44         
45         virtual void On005Numeric(std::string &output)
46         {
47                 output.append(" EXCEPTS=e");
48                 InsertMode(output, "e", 1);
49         }
50
51         virtual int OnCheckBan(userrec* user, chanrec* chan)
52         {
53                 if(chan != NULL)
54                 {
55                         modelist* list = (modelist*)chan->GetExt(be->GetInfoKey());
56                         Srv->Log(DEBUG, std::string(user->nick)+" is trying to join "+std::string(chan->name)+", checking for ban exceptions");
57                         
58                         if(list)
59                         {
60                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
61                                         if(Srv->MatchText(user->GetFullRealHost(), it->mask) || Srv->MatchText(user->GetFullHost(), it->mask))
62                                                 // They match an entry on the list, so let them in.
63                                                 return 1;
64                                 return 0;
65                         }
66                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
67                 }
68                 return 0;       
69         }
70
71         virtual void OnCleanup(int target_type, void* item)
72         {
73                 be->DoCleanup(target_type, item);
74         }
75
76         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
77         {
78                 be->DoSyncChannel(chan, proto, opaque);
79         }
80
81         virtual void OnChannelDelete(chanrec* chan)
82         {
83                 be->DoChannelDelete(chan);
84         }
85
86         virtual void OnRehash(const std::string &param)
87         {
88                 be->DoRehash();
89         }
90         
91         virtual Version GetVersion()
92         {
93                 return Version(1, 0, 0, 3, VF_STATIC | VF_VENDOR);
94         }
95 };
96
97 class ModuleBanExceptionFactory : public ModuleFactory
98 {
99  public:
100         ModuleBanExceptionFactory()
101         {
102         }
103         
104         ~ModuleBanExceptionFactory()
105         {
106         }
107         
108         virtual Module* CreateModule(Server* serv)
109         {
110                 return new ModuleBanException(serv);
111         }
112         
113 };
114
115
116 extern "C" void * init_module( void )
117 {
118         return new ModuleBanExceptionFactory;
119 }