]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
Now with binary versioning goodness
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*     +------------------------------------+
2  *     | Inspire Internet Relay Chat Daemon |
3  *     +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                    E-mail:
7  *             <brain@chatspike.net>
8  *             <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  * the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include <vector>
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "mode.h"
23 #include "u_listmode.h"
24
25 /* $ModDesc: Provides support for the +I channel mode */
26
27 /*
28  * Written by Om <om@inspircd.org>, April 2005.
29  * Based on m_exception, which was originally based on m_chanprotect and m_silence
30  *
31  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
32  * and if a user matches an entry on the +I list then they can join the channel,
33  * ignoring if +i is set on the channel
34  * Now supports CIDR and IP addresses -- Brain
35  */
36
37 class InspIRCd* ServerInstance;
38
39 /** Handles channel mode +I
40  */
41 class InviteException : public ListModeBase
42 {
43  public:
44         InviteException(InspIRCd* Instance) : ListModeBase(Instance, 'I', "End of Channel Invite Exception List", "346", "347", true) { }
45 };
46
47 class ModuleInviteException : public Module
48 {
49         InviteException* ie;
50 public:
51         ModuleInviteException(InspIRCd* Me) : Module(Me)
52         {
53                 ie = new InviteException(ServerInstance);
54                 ServerInstance->AddMode(ie, 'I');
55         }
56         
57         virtual void Implements(char* List)
58         {
59                 ie->DoImplements(List);
60                 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 void OnCleanup(int target_type, void* item)
94         {
95                 ie->DoCleanup(target_type, item);
96         }
97
98         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
99         {
100                 ie->DoSyncChannel(chan, proto, opaque);
101         }
102
103         virtual void OnChannelDelete(chanrec* chan)
104         {
105                 ie->DoChannelDelete(chan);
106         }
107
108         virtual void OnRehash(const std::string &param)
109         {
110                 ie->DoRehash();
111         }
112                 
113         virtual Version GetVersion()
114         {
115                 return Version(1, 0, 0, 3, VF_VENDOR | VF_COMMON, API_VERSION);
116         }
117
118         ~ModuleInviteException()
119         {
120                 ServerInstance->Modes->DelMode(ie);
121                 DELETE(ie);
122         }
123 };
124
125
126 class ModuleInviteExceptionFactory : public ModuleFactory
127 {
128  public:
129         ModuleInviteExceptionFactory()
130         {
131         }
132         
133         ~ModuleInviteExceptionFactory()
134         {
135         }
136         
137         virtual Module * CreateModule(InspIRCd* Me)
138         {
139                 return new ModuleInviteException(Me);
140         }
141         
142 };
143
144
145 extern "C" void * init_module( void )
146 {
147         return new ModuleInviteExceptionFactory;
148 }