]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
1ecec735e0ac69ef00fd1556940f1692774253c3
[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 "u_listmode.h"
26
27 /* $ModDesc: Provides support for the +I channel mode */
28 /* $ModDep: ../../include/u_listmode.h */
29
30 /*
31  * Written by Om <om@inspircd.org>, April 2005.
32  * Based on m_exception, which was originally based on m_chanprotect and m_silence
33  *
34  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
35  * and if a user matches an entry on the +I list then they can join the channel,
36  * ignoring if +i is set on the channel
37  * Now supports CIDR and IP addresses -- Brain
38  */
39
40 /** Handles channel mode +I
41  */
42 class InviteException : public ListModeBase
43 {
44  public:
45         InviteException(Module* Creator) : ListModeBase(Creator, "invex", '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() : ie(this)
53         {
54                 if (!ServerInstance->Modes->AddMode(&ie))
55                         throw ModuleException("Could not add new modes!");
56
57                 ie.DoImplements(this);
58                 Implementation eventlist[] = { I_On005Numeric, I_OnCheckInvite, I_OnCheckKey };
59                 ServerInstance->Modules->Attach(eventlist, this, 3);
60         }
61
62         void On005Numeric(std::string &output)
63         {
64                 output.append(" INVEX=I");
65         }
66
67         ModResult OnCheckInvite(User* user, Channel* chan)
68         {
69                 if(chan != NULL)
70                 {
71                         modelist* list = ie.extItem.get(chan);
72                         if (list)
73                         {
74                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
75                                 {
76                                         if (chan->CheckBan(user, it->mask))
77                                         {
78                                                 return MOD_RES_ALLOW;
79                                         }
80                                 }
81                         }
82                 }
83
84                 return MOD_RES_PASSTHRU;
85         }
86
87         ModResult OnCheckKey(User* user, Channel* chan, const std::string& key)
88         {
89                 if (ServerInstance->Config->ConfValue("inviteexception")->getBool("bypasskey", true))
90                         return OnCheckInvite(user, chan);
91                 return MOD_RES_PASSTHRU;
92         }
93
94         void OnCleanup(int target_type, void* item)
95         {
96                 ie.DoCleanup(target_type, item);
97         }
98
99         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
100         {
101                 ie.DoSyncChannel(chan, proto, opaque);
102         }
103
104         void OnRehash(User* user)
105         {
106                 ie.DoRehash();
107         }
108
109         Version GetVersion()
110         {
111                 return Version("Provides support for the +I channel mode", VF_VENDOR);
112         }
113 };
114
115 MODULE_INIT(ModuleInviteException)