]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noinvite.cpp
158dec8b2ba07920649e74ed8386d3507606b1d2
[user/henk/code/inspircd.git] / src / modules / m_noinvite.cpp
1 /*   +------------------------------------+
2  *   | Inspire Internet Relay Chat Daemon |
3  *   +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                   E-mail:
7  *            <brain@chatspike.net>
8  *            <Craig@chatspike.net>
9  * 
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  * the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23
24 #include "inspircd.h"
25
26 /* $ModDesc: Provides support for unreal-style channel mode +V */
27
28
29
30 class NoInvite : public ModeHandler
31 {
32  public:
33         NoInvite(InspIRCd* Instance) : ModeHandler(Instance, 'V', 0, 0, false, MODETYPE_CHANNEL, false) { }
34
35         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
36         {
37                 if (adding)
38                 {
39                         if (!channel->IsModeSet('V'))
40                         {
41                                 channel->SetMode('V',true);
42                                 return MODEACTION_ALLOW;
43                         }
44                 }
45                 else
46                 {
47                         if (channel->IsModeSet('V'))
48                         {
49                                 channel->SetMode('V',false);
50                                 return MODEACTION_ALLOW;
51                         }
52                 }
53
54                 return MODEACTION_DENY;
55         }
56 };
57
58 class ModuleNoInvite : public Module
59 {
60         
61         NoInvite *ni;
62         
63         public:
64  
65                 ModuleNoInvite(InspIRCd* Me) : Module::Module(Me)
66                 {
67                         
68                         ni = new NoInvite(ServerInstance);
69                         ServerInstance->AddMode(ni, 'V');
70                 }
71
72                 void Implements(char* List)
73                 {
74                         List[I_On005Numeric] = List[I_OnUserPreInvite] = 1;
75                 }
76
77                 virtual void On005Numeric(std::string &output)
78                 {
79                 }
80
81
82                 virtual int OnUserPreInvite(userrec* user,userrec* dest,chanrec* channel)
83                 {
84                         if (channel->IsModeSet('V'))
85                         {
86                                 user->WriteServ("492 %s %s :Can't invite %s to channel (+V set)",user->nick, channel->name, dest->nick);
87                                 return 1;
88                         }
89                         return 0;
90                 }
91
92                 virtual ~ModuleNoInvite()
93                 {
94                         DELETE(ni);
95                 }
96         
97                 virtual Version GetVersion()
98                 {
99                         return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
100                 }
101 };
102
103
104 class ModuleNoInviteFactory : public ModuleFactory
105 {
106         public:
107                 ModuleNoInviteFactory()
108                 {
109                 }
110         
111                 ~ModuleNoInviteFactory()
112                 {
113                 }
114         
115                 virtual Module * CreateModule(InspIRCd* Me)
116                 {
117                         return new ModuleNoInvite(Me);
118                 }
119         
120 };
121
122
123 extern "C" void * init_module( void )
124 {
125         return new ModuleNoInviteFactory;
126 }
127