]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_allowinvite.cpp
f137598e2b40facc95c3c7d13f2b521350e14635
[user/henk/code/inspircd.git] / src / modules / m_allowinvite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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) : SimpleChannelModeHandler(Instance, 'A') { }
22 };
23
24 class ModuleAllowInvite : public Module
25 {
26         AllowInvite *ni;
27  public:
28
29         ModuleAllowInvite(InspIRCd* Me) : Module(Me)
30         {
31                 ni = new AllowInvite(ServerInstance);
32                 if (!ServerInstance->Modes->AddMode(ni))
33                         throw ModuleException("Could not add new modes!");
34                 Implementation eventlist[] = { I_OnUserPreInvite, I_On005Numeric };
35                 ServerInstance->Modules->Attach(eventlist, this, 2);
36         }
37
38         virtual void On005Numeric(std::string &output)
39         {
40                 ServerInstance->AddExtBanChar('A');
41         }
42
43         virtual int OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout)
44         {
45                 if (IS_LOCAL(user))
46                 {
47                         if (channel->IsModeSet('A') || channel->IsExtBanned(user, 'A'))
48                         {
49                                 // Explicitly allow /invite
50                                 return -1;
51                         }
52                 }
53
54                 return 0;
55         }
56
57         virtual ~ModuleAllowInvite()
58         {
59                 ServerInstance->Modes->DelMode(ni);
60                 delete ni;
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
66         }
67 };
68
69 MODULE_INIT(ModuleAllowInvite)