]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_allowinvite.cpp
Dynamically determine the size of the eventlist[] passed to Attach()
[user/henk/code/inspircd.git] / src / modules / m_allowinvite.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 /* $ModDesc: Provides support for channel mode +A, allowing /invite freely on a channel (and extban A to allow specific users it) */
23
24 class AllowInvite : public SimpleChannelModeHandler
25 {
26  public:
27         AllowInvite(Module* Creator) : SimpleChannelModeHandler(Creator, "allowinvite", 'A') { }
28 };
29
30 class ModuleAllowInvite : public Module
31 {
32         AllowInvite ni;
33  public:
34
35         ModuleAllowInvite() : ni(this)
36         {
37         }
38
39         void init()
40         {
41                 if (!ServerInstance->Modes->AddMode(&ni))
42                         throw ModuleException("Could not add new modes!");
43                 Implementation eventlist[] = { I_OnUserPreInvite, I_On005Numeric };
44                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
45         }
46
47         virtual void On005Numeric(std::string &output)
48         {
49                 ServerInstance->AddExtBanChar('A');
50         }
51
52         virtual ModResult OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout)
53         {
54                 if (IS_LOCAL(user))
55                 {
56                         ModResult res = channel->GetExtBanStatus(user, 'A');
57                         if (res == MOD_RES_DENY)
58                         {
59                                 // Matching extban, explicitly deny /invite
60                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You are banned from using INVITE", user->nick.c_str(), channel->name.c_str());
61                                 return res;
62                         }
63                         if (channel->IsModeSet('A') || res == MOD_RES_ALLOW)
64                         {
65                                 // Explicitly allow /invite
66                                 return MOD_RES_ALLOW;
67                         }
68                 }
69
70                 return MOD_RES_PASSTHRU;
71         }
72
73         virtual ~ModuleAllowInvite()
74         {
75         }
76
77         virtual Version GetVersion()
78         {
79                 return Version("Provides support for channel mode +A, allowing /invite freely on a channel (and extban A to allow specific users it)",VF_VENDOR);
80         }
81 };
82
83 MODULE_INIT(ModuleAllowInvite)