]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
03a2fbc7c59d4ae91cd9f722f6a28bf2d4fe1ebf
[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 /*
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 /** Handles channel mode +I
38  */
39 class InviteException : public ListModeBase
40 {
41  public:
42         InviteException(Module* Creator)
43                 : ListModeBase(Creator, "invex", 'I', "End of Channel Invite Exception List", 346, 347, true)
44         {
45                 syntax = "<mask>";
46         }
47 };
48
49 class ModuleInviteException : public Module
50 {
51         bool invite_bypass_key;
52         InviteException ie;
53 public:
54         ModuleInviteException() : ie(this)
55         {
56         }
57
58         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
59         {
60                 tokens["INVEX"] = ConvToStr(ie.GetModeChar());
61         }
62
63         ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
64         {
65                 ListModeBase::ModeList* list = ie.GetList(chan);
66                 if (list)
67                 {
68                         for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
69                         {
70                                 if (chan->CheckBan(user, it->mask))
71                                 {
72                                         return MOD_RES_ALLOW;
73                                 }
74                         }
75                 }
76
77                 return MOD_RES_PASSTHRU;
78         }
79
80         ModResult OnCheckKey(User* user, Channel* chan, const std::string& key) CXX11_OVERRIDE
81         {
82                 if (invite_bypass_key)
83                         return OnCheckInvite(user, chan);
84                 return MOD_RES_PASSTHRU;
85         }
86
87         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
88         {
89                 ie.DoRehash();
90                 invite_bypass_key = ServerInstance->Config->ConfValue("inviteexception")->getBool("bypasskey", true);
91         }
92
93         Version GetVersion() CXX11_OVERRIDE
94         {
95                 return Version("Provides channel mode +I, invite exceptions", VF_VENDOR);
96         }
97 };
98
99 MODULE_INIT(ModuleInviteException)