]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
fc7ede256f983757145e5de8c2768fbdf371be67
[user/henk/code/inspircd.git] / src / modules / m_noctcp.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 +c */
27
28 extern InspIRCd* ServerInstance;
29
30 class NoCTCP : public ModeHandler
31 {
32  public:
33         NoCTCP(InspIRCd* Instance) : ModeHandler(Instance, 'C', 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('C'))
40                         {
41                                 channel->SetMode('C',true);
42                                 return MODEACTION_ALLOW;
43                         }
44                 }
45                 else
46                 {
47                         if (channel->IsModeSet('C'))
48                         {
49                                 channel->SetMode('C',false);
50                                 return MODEACTION_ALLOW;
51                         }
52                 }
53
54                 return MODEACTION_DENY;
55         }
56 };
57
58 class ModuleNoCTCP : public Module
59 {
60         Server *Srv;
61         NoCTCP* nc;
62         
63  public:
64  
65         ModuleNoCTCP(Server* Me)
66                 : Module::Module(Me)
67         {
68                 Srv = Me;
69                 nc = new NoCTCP(ServerInstance);
70                 Srv->AddMode(nc, 'C');
71         }
72
73         void Implements(char* List)
74         {
75                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
76         }
77
78         virtual void On005Numeric(std::string &output)
79         {
80                 ServerInstance->ModeGrok->InsertMode(output,"C",4);
81         }
82         
83         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
84         {
85                 return OnUserPreNotice(user,dest,target_type,text,status);
86         }
87         
88         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
89         {
90                 if (target_type == TYPE_CHANNEL)
91                 {
92                         chanrec* c = (chanrec*)dest;
93                         if (c->IsModeSet('C'))
94                         {
95                                 if ((text.length()) && (text[0] == '\1'))
96                                 {
97                                         if (strncmp(text.c_str(),"\1ACTION ",8))
98                                         {
99                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
100                                                 return 1;
101                                         }
102                                 }
103                         }
104                 }
105                 return 0;
106         }
107
108         virtual ~ModuleNoCTCP()
109         {
110                 DELETE(nc);
111         }
112
113         virtual Version GetVersion()
114         {
115                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
116         }
117 };
118
119
120 class ModuleNoCTCPFactory : public ModuleFactory
121 {
122  public:
123         ModuleNoCTCPFactory()
124         {
125         }
126         
127         ~ModuleNoCTCPFactory()
128         {
129         }
130         
131         virtual Module * CreateModule(Server* Me)
132         {
133                 return new ModuleNoCTCP(Me);
134         }
135         
136 };
137
138
139 extern "C" void * init_module( void )
140 {
141         return new ModuleNoCTCPFactory;
142 }
143