]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
11add8046d49b1c42a40a0ac87cfd9628934c933
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "mode.h"
19 #include "u_listmode.h"
20
21 /* $ModDesc: Provides support for the +I channel mode */
22 /* $ModDep: ../../include/u_listmode.h */
23
24 /*
25  * Written by Om <om@inspircd.org>, April 2005.
26  * Based on m_exception, which was originally based on m_chanprotect and m_silence
27  *
28  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
29  * and if a user matches an entry on the +I list then they can join the channel,
30  * ignoring if +i is set on the channel
31  * Now supports CIDR and IP addresses -- Brain
32  */
33
34 class InspIRCd* ServerInstance;
35
36 /** Handles channel mode +I
37  */
38 class InviteException : public ListModeBase
39 {
40  public:
41         InviteException(InspIRCd* Instance) : ListModeBase(Instance, 'I', "End of Channel Invite Exception List", "346", "347", true) { }
42 };
43
44 class ModuleInviteException : public Module
45 {
46         InviteException* ie;
47 public:
48         ModuleInviteException(InspIRCd* Me) : Module(Me)
49         {
50                 ie = new InviteException(ServerInstance);
51                 if (!ServerInstance->AddMode(ie, 'I'))
52                         throw ModuleException("Could not add new modes!");
53                 ServerInstance->PublishInterface("ChannelBanList", this);
54         }
55
56         virtual void Implements(char* List)
57         {
58                 ie->DoImplements(List);
59                 List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckInvite] = 1;
60         }
61         
62         virtual void On005Numeric(std::string &output)
63         {
64                 output.append(" INVEX=I");
65         }
66          
67         virtual int OnCheckInvite(userrec* user, chanrec* chan)
68         {
69                 if(chan != NULL)
70                 {
71                         modelist* list;
72                         chan->GetExt(ie->GetInfoKey(), list);
73                         if (list)
74                         {
75                                 char mask[MAXBUF];
76                                 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
77                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
78                                 {
79                                         if(match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
80                                         {
81                                                 // They match an entry on the list, so let them in.
82                                                 return 1;
83                                         }
84                                 }
85                         }
86                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
87                 }
88
89                 return 0;               
90         }
91
92         virtual char* OnRequest(Request* request)
93         {
94                 ListModeRequest* LM = (ListModeRequest*)request;
95                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
96                 {
97                         modelist* list;
98                         LM->chan->GetExt(ie->GetInfoKey(), list);
99                         if (list)
100                         {
101                                 char mask[MAXBUF];
102                                 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
103                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
104                                 {
105                                         if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
106                                         {
107                                                 // They match an entry
108                                                 return (char*)it->mask.c_str();
109                                         }
110                                 }
111                                 return NULL;
112                         }
113                 }
114                 return NULL;
115         }
116
117         virtual void OnCleanup(int target_type, void* item)
118         {
119                 ie->DoCleanup(target_type, item);
120         }
121
122         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
123         {
124                 ie->DoSyncChannel(chan, proto, opaque);
125         }
126
127         virtual void OnChannelDelete(chanrec* chan)
128         {
129                 ie->DoChannelDelete(chan);
130         }
131
132         virtual void OnRehash(userrec* user, const std::string &param)
133         {
134                 ie->DoRehash();
135         }
136                 
137         virtual Version GetVersion()
138         {
139                 return Version(1, 1, 0, 3, VF_VENDOR | VF_COMMON, API_VERSION);
140         }
141
142         ~ModuleInviteException()
143         {
144                 ServerInstance->Modes->DelMode(ie);
145                 DELETE(ie);
146                 ServerInstance->UnpublishInterface("ChannelBanList", this);
147         }
148 };
149
150
151 class ModuleInviteExceptionFactory : public ModuleFactory
152 {
153  public:
154         ModuleInviteExceptionFactory()
155         {
156         }
157         
158         ~ModuleInviteExceptionFactory()
159         {
160         }
161         
162         virtual Module * CreateModule(InspIRCd* Me)
163         {
164                 return new ModuleInviteException(Me);
165         }
166         
167 };
168
169
170 extern "C" DllExport void * init_module( void )
171 {
172         return new ModuleInviteExceptionFactory;
173 }