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