]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
GnuTLS: Send SSL client certificate when requested
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 "u_listmode.h"
16
17 /* $ModDesc: Provides support for the +I channel mode */
18 /* $ModDep: ../../include/u_listmode.h */
19
20 /*
21  * Written by Om <om@inspircd.org>, April 2005.
22  * Based on m_exception, which was originally based on m_chanprotect and m_silence
23  *
24  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
25  * and if a user matches an entry on the +I list then they can join the channel,
26  * ignoring if +i is set on the channel
27  * Now supports CIDR and IP addresses -- Brain
28  */
29
30 class InspIRCd* ServerInstance;
31
32 /** Handles channel mode +I
33  */
34 class InviteException : public ListModeBase
35 {
36  public:
37         InviteException(InspIRCd* Instance, Module* Creator) : ListModeBase(Instance, Creator, 'I', "End of Channel Invite Exception List", 346, 347, true) { }
38 };
39
40 class ModuleInviteException : public Module
41 {
42         InviteException ie;
43 public:
44         ModuleInviteException(InspIRCd* Me) : Module(Me), ie(Me, this)
45         {
46                 if (!ServerInstance->Modes->AddMode(&ie))
47                         throw ModuleException("Could not add new modes!");
48                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
49
50                 ie.DoImplements(this);
51                 Implementation eventlist[] = { I_OnRequest, I_On005Numeric, I_OnCheckInvite };
52                 ServerInstance->Modules->Attach(eventlist, this, 3);
53         }
54
55         void On005Numeric(std::string &output)
56         {
57                 output.append(" INVEX=I");
58         }
59
60         ModResult OnCheckInvite(User* user, Channel* chan)
61         {
62                 if(chan != NULL)
63                 {
64                         modelist* list = ie.extItem.get(chan);
65                         if (list)
66                         {
67                                 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
68                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
69                                 {
70                                         if(InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
71                                         {
72                                                 // They match an entry on the list, so let them in.
73                                                 return MOD_RES_DENY;
74                                         }
75                                 }
76                         }
77                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
78                 }
79
80                 return MOD_RES_PASSTHRU;
81         }
82
83         const char* OnRequest(Request* request)
84         {
85                 return ie.DoOnRequest(request);
86         }
87
88         void OnCleanup(int target_type, void* item)
89         {
90                 ie.DoCleanup(target_type, item);
91         }
92
93         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
94         {
95                 ie.DoSyncChannel(chan, proto, opaque);
96         }
97
98         void OnRehash(User* user)
99         {
100                 ie.DoRehash();
101         }
102
103         Version GetVersion()
104         {
105                 return Version("$Id$", VF_VENDOR | VF_COMMON, API_VERSION);
106         }
107
108         ~ModuleInviteException()
109         {
110                 ServerInstance->Modes->DelMode(&ie);
111                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
112         }
113 };
114
115 MODULE_INIT(ModuleInviteException)