]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_allowinvite.cpp
Use Utils->ServerUser instead of ServerInstance->FakeClient in m_spanningtree
[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) : 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->GetExtBanStatus(user, 'A') == -1)
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 1;
52                         }
53                         if (channel->IsModeSet('A') || channel->GetExtBanStatus(user, 'A') == 1)
54                         {
55                                 // Explicitly allow /invite
56                                 return -1;
57                         }
58                 }
59
60                 return 0;
61         }
62
63         virtual ~ModuleAllowInvite()
64         {
65                 ServerInstance->Modes->DelMode(ni);
66                 delete ni;
67         }
68
69         virtual Version GetVersion()
70         {
71                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
72         }
73 };
74
75 MODULE_INIT(ModuleAllowInvite)