]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noinvite.cpp
More AddModes fixes
[user/henk/code/inspircd.git] / src / modules / m_noinvite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 unreal-style channel mode +V */
17
18 class NoInvite : public ModeHandler
19 {
20  public:
21         NoInvite(InspIRCd* Instance) : ModeHandler(Instance, 'V', 0, 0, false, MODETYPE_CHANNEL, false) { }
22
23         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
24         {
25                 if (adding)
26                 {
27                         if (!channel->IsModeSet('V'))
28                         {
29                                 channel->SetMode('V',true);
30                                 return MODEACTION_ALLOW;
31                         }
32                 }
33                 else
34                 {
35                         if (channel->IsModeSet('V'))
36                         {
37                                 channel->SetMode('V',false);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41
42                 return MODEACTION_DENY;
43         }
44 };
45
46 class ModuleNoInvite : public Module
47 {
48         NoInvite *ni;
49  public:
50
51         ModuleNoInvite(InspIRCd* Me) : Module(Me)
52         {
53                 ni = new NoInvite(ServerInstance);
54                 if (!ServerInstance->AddMode(ni, 'V'))
55                         throw ModuleException("Could not add new modes!");
56         }
57
58         void Implements(char* List)
59         {
60                 List[I_OnUserPreInvite] = 1;
61         }
62
63         virtual int OnUserPreInvite(User* user,User* dest,Channel* channel)
64         {
65                 if (channel->IsModeSet('V'))
66                 {
67                         user->WriteServ("492 %s %s :Can't invite %s to channel (+V set)",user->nick, channel->name, dest->nick);
68                         return 1;
69                 }
70                 return 0;
71         }
72
73         virtual ~ModuleNoInvite()
74         {
75                 ServerInstance->Modes->DelMode(ni);
76                 DELETE(ni);
77         }
78         
79         virtual Version GetVersion()
80         {
81                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
82         }
83 };
84
85 MODULE_INIT(ModuleNoInvite)