]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Just to mess with om's head, remove helperfuncs.h from everywhere
[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
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
22
23 class BanException : public ListModeBase
24 {
25  public:
26         BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }
27 };
28
29
30 class ModuleBanException : public Module
31 {
32         BanException* be;
33         
34
35 public:
36         ModuleBanException(InspIRCd* Me)
37         : Module::Module(Me)
38         {
39                 be = new BanException(ServerInstance);
40                 ServerInstance->AddMode(be, 'e');
41         }
42         
43         virtual void Implements(char* List)
44         {
45                 be->DoImplements(List);
46                 List[I_On005Numeric] = List[I_OnCheckBan] = 1;
47         }
48         
49         virtual void On005Numeric(std::string &output)
50         {
51                 output.append(" EXCEPTS=e");
52                 ServerInstance->Modes->InsertMode(output, "e", 1);
53         }
54
55         virtual int OnCheckBan(userrec* user, chanrec* chan)
56         {
57                 if(chan != NULL)
58                 {
59                         modelist* list;
60                         chan->GetExt(be->GetInfoKey(), list);
61                         
62                         if(list)
63                         {
64                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
65                                         if(ServerInstance->MatchText(user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(user->GetFullHost(), it->mask))
66                                                 // They match an entry on the list, so let them in.
67                                                 return 1;
68                                 return 0;
69                         }
70                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
71                 }
72                 return 0;       
73         }
74
75         virtual void OnCleanup(int target_type, void* item)
76         {
77                 be->DoCleanup(target_type, item);
78         }
79
80         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
81         {
82                 be->DoSyncChannel(chan, proto, opaque);
83         }
84
85         virtual void OnChannelDelete(chanrec* chan)
86         {
87                 be->DoChannelDelete(chan);
88         }
89
90         virtual void OnRehash(const std::string &param)
91         {
92                 be->DoRehash();
93         }
94         
95         virtual Version GetVersion()
96         {
97                 return Version(1, 0, 0, 3, VF_STATIC | VF_VENDOR);
98         }
99         
100         virtual ~ModuleBanException()
101         {
102                 DELETE(be);     
103         }
104 };
105
106 class ModuleBanExceptionFactory : public ModuleFactory
107 {
108  public:
109         ModuleBanExceptionFactory()
110         {
111         }
112         
113         ~ModuleBanExceptionFactory()
114         {
115         }
116         
117         virtual Module* CreateModule(InspIRCd* Me)
118         {
119                 return new ModuleBanException(Me);
120         }
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleBanExceptionFactory;
127 }