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