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