]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_allowinvite.cpp
ModResult conversion: Change return type of all module functions
[user/henk/code/inspircd.git] / src / modules / m_allowinvite.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
16 /* $ModDesc: Provides support for channel mode +A, allowing /invite freely on a channel (and extban A to allow specific users it) */
17
18 class AllowInvite : public SimpleChannelModeHandler
19 {
20  public:
21         AllowInvite(InspIRCd* Instance, Module* Creator) : SimpleChannelModeHandler(Instance, Creator, 'A') { }
22 };
23
24 class ModuleAllowInvite : public Module
25 {
26         AllowInvite ni;
27  public:
28
29         ModuleAllowInvite(InspIRCd* Me) : Module(Me), ni(Me, this)
30         {
31                 if (!ServerInstance->Modes->AddMode(&ni))
32                         throw ModuleException("Could not add new modes!");
33                 Implementation eventlist[] = { I_OnUserPreInvite, I_On005Numeric };
34                 ServerInstance->Modules->Attach(eventlist, this, 2);
35         }
36
37         virtual void On005Numeric(std::string &output)
38         {
39                 ServerInstance->AddExtBanChar('A');
40         }
41
42         virtual ModResult OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout)
43         {
44                 if (IS_LOCAL(user))
45                 {
46                         ModResult res = channel->GetExtBanStatus(user, 'A');
47                         if (res == MOD_RES_DENY)
48                         {
49                                 // Matching extban, explicitly deny /invite
50                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You are banned from using INVITE", user->nick.c_str(), channel->name.c_str());
51                                 return res;
52                         }
53                         if (channel->IsModeSet('A') || res == MOD_RES_ALLOW)
54                         {
55                                 // Explicitly allow /invite
56                                 return MOD_RES_ALLOW;
57                         }
58                 }
59
60                 return MOD_RES_PASSTHRU;
61         }
62
63         virtual ~ModuleAllowInvite()
64         {
65                 ServerInstance->Modes->DelMode(&ni);
66         }
67
68         virtual Version GetVersion()
69         {
70                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
71         }
72 };
73
74 MODULE_INIT(ModuleAllowInvite)