]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noinvite.cpp
So much stuff changed in this one, i forgot most of it.
[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 extern InspIRCd* ServerInstance;
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         Server *Srv;
61         NoInvite *ni;
62         
63         public:
64  
65                 ModuleNoInvite(Server* Me) : Module::Module(Me)
66                 {
67                         Srv = Me;
68                         ni = new NoInvite(ServerInstance);
69                         Srv->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                         ServerInstance->ModeGrok->InsertMode(output,"V",4);
80                 }
81
82
83                 virtual int OnUserPreInvite(userrec* user,userrec* dest,chanrec* channel)
84                 {
85                         if (channel->IsModeSet('V'))
86                         {
87                                 user->WriteServ("492 %s %s :Can't invite %s to channel (+V set)",user->nick, channel->name, dest->nick);
88                                 return 1;
89                         }
90                         return 0;
91                 }
92
93                 virtual ~ModuleNoInvite()
94                 {
95                         DELETE(ni);
96                 }
97         
98                 virtual Version GetVersion()
99                 {
100                         return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
101                 }
102 };
103
104
105 class ModuleNoInviteFactory : public ModuleFactory
106 {
107         public:
108                 ModuleNoInviteFactory()
109                 {
110                 }
111         
112                 ~ModuleNoInviteFactory()
113                 {
114                 }
115         
116                 virtual Module * CreateModule(Server* Me)
117                 {
118                         return new ModuleNoInvite(Me);
119                 }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleNoInviteFactory;
127 }
128