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