]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
Merge pull request #514 from SaberUK/master+virtual-cleanup
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25 #include "listmode.h"
26
27 /* $ModDesc: Provides support for the +I channel mode */
28
29 /*
30  * Written by Om <om@inspircd.org>, April 2005.
31  * Based on m_exception, which was originally based on m_chanprotect and m_silence
32  *
33  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
34  * and if a user matches an entry on the +I list then they can join the channel,
35  * ignoring if +i is set on the channel
36  * Now supports CIDR and IP addresses -- Brain
37  */
38
39 /** Handles channel mode +I
40  */
41 class InviteException : public ListModeBase
42 {
43  public:
44         InviteException(Module* Creator) : ListModeBase(Creator, "invex", 'I', "End of Channel Invite Exception List", 346, 347, true) { }
45 };
46
47 class ModuleInviteException : public Module
48 {
49         bool invite_bypass_key;
50         InviteException ie;
51 public:
52         ModuleInviteException() : ie(this)
53         {
54         }
55
56         void init() CXX11_OVERRIDE
57         {
58                 ServerInstance->Modules->AddService(ie);
59
60                 OnRehash(NULL);
61                 ie.DoImplements(this);
62                 Implementation eventlist[] = { I_On005Numeric, I_OnCheckInvite, I_OnCheckKey, I_OnRehash };
63                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
64         }
65
66         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
67         {
68                 tokens["INVEX"] = "I";
69         }
70
71         ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
72         {
73                 ListModeBase::ModeList* list = ie.GetList(chan);
74                 if (list)
75                 {
76                         for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
77                         {
78                                 if (chan->CheckBan(user, it->mask))
79                                 {
80                                         return MOD_RES_ALLOW;
81                                 }
82                         }
83                 }
84
85                 return MOD_RES_PASSTHRU;
86         }
87
88         ModResult OnCheckKey(User* user, Channel* chan, const std::string& key) CXX11_OVERRIDE
89         {
90                 if (invite_bypass_key)
91                         return OnCheckInvite(user, chan);
92                 return MOD_RES_PASSTHRU;
93         }
94
95         void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
96         {
97                 ie.DoSyncChannel(chan, proto, opaque);
98         }
99
100         void OnRehash(User* user) CXX11_OVERRIDE
101         {
102                 invite_bypass_key = ServerInstance->Config->ConfValue("inviteexception")->getBool("bypasskey", true);
103                 ie.DoRehash();
104         }
105
106         Version GetVersion() CXX11_OVERRIDE
107         {
108                 return Version("Provides support for the +I channel mode", VF_VENDOR);
109         }
110 };
111
112 MODULE_INIT(ModuleInviteException)