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