]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
90abd79e9370ea52233c41c5d5e527436dd91f07
[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 "helperfuncs.h"
8 #include "u_listmode.h"
9
10 /* $ModDesc: Provides support for the +I channel mode */
11
12 /* Written by Om<om@inspircd.org>, April 2005. */
13 /* Based on m_exception, which was originally based on m_chanprotect and m_silence */
14
15 // The +I channel mode takes a nick!ident@host, glob patterns allowed,
16 // and if a user matches an entry on the +I list then they can join the channel, ignoring if +i is set on the channel
17
18 class ModuleInviteException : public ListModeBaseModule
19 {
20 public:
21         ModuleInviteException(Server* serv) : ListModeBaseModule::ListModeBaseModule(serv, 'I', "End of Channel Invite Exception List", "346", "347")
22         {
23         }
24         
25         virtual void Implements(char* List)
26         {
27                 this->DoImplements(List);
28                 List[I_On005Numeric] = List[I_OnCheckInvite] = 1;
29         }
30         
31         virtual void On005Numeric(std::string &output)
32         {
33                 output.append(" INVEX=999");
34                 output.insert(output.find("CHANMODES=", 0)+10, "I");
35         }
36          
37         virtual int OnCheckInvite(userrec* user, chanrec* chan)
38         {
39                 if(chan != NULL)
40                 {
41                         modelist* list = (modelist*)chan->GetExt(infokey);
42                         Srv->Log(DEBUG, std::string(user->nick)+" is trying to join "+std::string(chan->name)+", checking for invite exceptions");
43                         if (list)
44                         {
45                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
46                                 {
47                                         if(Srv->MatchText(user->GetFullRealHost(), it->mask) || Srv->MatchText(user->GetFullHost(), it->mask))
48                                         {
49                                                 // They match an entry on the list, so let them in.
50                                                 return 1;
51                                         }
52                                 }
53                         }
54                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
55                 }
56
57                 return 0;               
58         }
59                 
60         virtual Version GetVersion()
61         {
62                 return Version(1, 0, 0, 2, VF_STATIC);
63         }
64 };
65
66
67 class ModuleInviteExceptionFactory : public ModuleFactory
68 {
69  public:
70         ModuleInviteExceptionFactory()
71         {
72         }
73         
74         ~ModuleInviteExceptionFactory()
75         {
76         }
77         
78         virtual Module * CreateModule(Server* serv)
79         {
80                 return new ModuleInviteException(serv);
81         }
82         
83 };
84
85
86 extern "C" void * init_module( void )
87 {
88         return new ModuleInviteExceptionFactory;
89 }