]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
Fix to allow for OnRehash to know what user initiated the rehash
[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         }
55         
56         virtual void Implements(char* List)
57         {
58                 ie->DoImplements(List);
59                 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 void OnCleanup(int target_type, void* item)
93         {
94                 ie->DoCleanup(target_type, item);
95         }
96
97         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
98         {
99                 ie->DoSyncChannel(chan, proto, opaque);
100         }
101
102         virtual void OnChannelDelete(chanrec* chan)
103         {
104                 ie->DoChannelDelete(chan);
105         }
106
107         virtual void OnRehash(userrec* user, const std::string &param)
108         {
109                 ie->DoRehash();
110         }
111                 
112         virtual Version GetVersion()
113         {
114                 return Version(1, 1, 0, 3, VF_VENDOR | VF_COMMON, API_VERSION);
115         }
116
117         ~ModuleInviteException()
118         {
119                 ServerInstance->Modes->DelMode(ie);
120                 DELETE(ie);
121         }
122 };
123
124
125 class ModuleInviteExceptionFactory : public ModuleFactory
126 {
127  public:
128         ModuleInviteExceptionFactory()
129         {
130         }
131         
132         ~ModuleInviteExceptionFactory()
133         {
134         }
135         
136         virtual Module * CreateModule(InspIRCd* Me)
137         {
138                 return new ModuleInviteException(Me);
139         }
140         
141 };
142
143
144 extern "C" void * init_module( void )
145 {
146         return new ModuleInviteExceptionFactory;
147 }