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