]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noinvite.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[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 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides support for unreal-style channel mode +V */
20
21 class NoInvite : public ModeHandler
22 {
23  public:
24         NoInvite(InspIRCd* Instance) : ModeHandler(Instance, 'V', 0, 0, false, MODETYPE_CHANNEL, false) { }
25
26         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
27         {
28                 if (adding)
29                 {
30                         if (!channel->IsModeSet('V'))
31                         {
32                                 channel->SetMode('V',true);
33                                 return MODEACTION_ALLOW;
34                         }
35                 }
36                 else
37                 {
38                         if (channel->IsModeSet('V'))
39                         {
40                                 channel->SetMode('V',false);
41                                 return MODEACTION_ALLOW;
42                         }
43                 }
44
45                 return MODEACTION_DENY;
46         }
47 };
48
49 class ModuleNoInvite : public Module
50 {
51         NoInvite *ni;
52  public:
53
54         ModuleNoInvite(InspIRCd* Me) : Module(Me)
55         {
56                 ni = new NoInvite(ServerInstance);
57                 if (!ServerInstance->AddMode(ni, 'V'))
58                         throw ModuleException("Could not add new modes!");
59         }
60
61         void Implements(char* List)
62         {
63                 List[I_OnUserPreInvite] = 1;
64         }
65
66         virtual int OnUserPreInvite(userrec* user,userrec* dest,chanrec* channel)
67         {
68                 if (channel->IsModeSet('V'))
69                 {
70                         user->WriteServ("492 %s %s :Can't invite %s to channel (+V set)",user->nick, channel->name, dest->nick);
71                         return 1;
72                 }
73                 return 0;
74         }
75
76         virtual ~ModuleNoInvite()
77         {
78                 ServerInstance->Modes->DelMode(ni);
79                 DELETE(ni);
80         }
81         
82         virtual Version GetVersion()
83         {
84                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
85         }
86 };
87
88 MODULE_INIT(ModuleNoInvite)