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