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