]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noinvite.cpp
2cf3954fe908640302bbb07295133dc403efb2da
[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 #include "helperfuncs.h"
24 #include "inspircd.h"
25
26 /* $ModDesc: Provides support for unreal-style channel mode +V */
27
28 class NoInvite : public ModeHandler
29 {
30  public:
31         NoInvite() : ModeHandler('V', 0, 0, false, MODETYPE_CHANNEL, false) { }
32
33         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
34         {
35                 if (adding)
36                 {
37                         if (!channel->IsModeSet('V'))
38                         {
39                                 channel->SetMode('V',true);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43                 else
44                 {
45                         if (channel->IsModeSet('V'))
46                         {
47                                 channel->SetMode('V',false);
48                                 return MODEACTION_ALLOW;
49                         }
50                 }
51
52                 return MODEACTION_DENY;
53         }
54 };
55
56 class ModuleNoInvite : public Module
57 {
58         Server *Srv;
59         NoInvite *ni;
60         
61         public:
62  
63                 ModuleNoInvite(Server* Me) : Module::Module(Me)
64                 {
65                         Srv = Me;
66                         ni = new NoInvite();
67                         Srv->AddMode(ni, 'V');
68                 }
69
70                 void Implements(char* List)
71                 {
72                         List[I_On005Numeric] = List[I_OnUserPreInvite] = 1;
73                 }
74
75                 virtual void On005Numeric(std::string &output)
76                 {
77                         InsertMode(output,"V",4);
78                 }
79
80
81                 virtual int OnUserPreInvite(userrec* user,userrec* dest,chanrec* channel)
82                 {
83                         if (channel->IsModeSet('V'))
84                         {
85                                 user->WriteServ("492 %s %s :Can't invite %s to channel (+V set)",user->nick, channel->name, dest->nick);
86                                 return 1;
87                         }
88                         return 0;
89                 }
90
91                 virtual ~ModuleNoInvite()
92                 {
93                         DELETE(ni);
94                 }
95         
96                 virtual Version GetVersion()
97                 {
98                         return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
99                 }
100 };
101
102
103 class ModuleNoInviteFactory : public ModuleFactory
104 {
105         public:
106                 ModuleNoInviteFactory()
107                 {
108                 }
109         
110                 ~ModuleNoInviteFactory()
111                 {
112                 }
113         
114                 virtual Module * CreateModule(Server* Me)
115                 {
116                         return new ModuleNoInvite(Me);
117                 }
118         
119 };
120
121
122 extern "C" void * init_module( void )
123 {
124         return new ModuleNoInviteFactory;
125 }
126