]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
14dc3199ed9c8d064cde3bacff3ed2d67cce35cb
[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 "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides support for unreal-style channel mode +c */
25
26
27
28 class NoCTCP : public ModeHandler
29 {
30  public:
31         NoCTCP(InspIRCd* Instance) : ModeHandler(Instance, '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         
59         NoCTCP* nc;
60         
61  public:
62  
63         ModuleNoCTCP(InspIRCd* Me)
64                 : Module::Module(Me)
65         {
66                 
67                 nc = new NoCTCP(ServerInstance);
68                 ServerInstance->AddMode(nc, 'C');
69         }
70
71         void Implements(char* List)
72         {
73                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
74         }
75
76         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
77         {
78                 return OnUserPreNotice(user,dest,target_type,text,status);
79         }
80         
81         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
82         {
83                 if (target_type == TYPE_CHANNEL)
84                 {
85                         chanrec* c = (chanrec*)dest;
86                         if (c->IsModeSet('C'))
87                         {
88                                 if ((text.length()) && (text[0] == '\1'))
89                                 {
90                                         if (strncmp(text.c_str(),"\1ACTION ",8))
91                                         {
92                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
93                                                 return 1;
94                                         }
95                                 }
96                         }
97                 }
98                 return 0;
99         }
100
101         virtual ~ModuleNoCTCP()
102         {
103                 ServerInstance->Modes->DelMode(nc);
104                 DELETE(nc);
105         }
106
107         virtual Version GetVersion()
108         {
109                 return Version(1,0,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
110         }
111 };
112
113
114 class ModuleNoCTCPFactory : public ModuleFactory
115 {
116  public:
117         ModuleNoCTCPFactory()
118         {
119         }
120         
121         ~ModuleNoCTCPFactory()
122         {
123         }
124         
125         virtual Module * CreateModule(InspIRCd* Me)
126         {
127                 return new ModuleNoCTCP(Me);
128         }
129         
130 };
131
132
133 extern "C" void * init_module( void )
134 {
135         return new ModuleNoCTCPFactory;
136 }
137