]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Add config <options:disablehmac> to support disabling of HMAC, and tidy up to detect...
[user/henk/code/inspircd.git] / src / modules / m_noctcp.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for unreal-style channel mode +c */
20
21
22
23 class NoCTCP : public ModeHandler
24 {
25  public:
26         NoCTCP(InspIRCd* Instance) : ModeHandler(Instance, 'C', 0, 0, false, MODETYPE_CHANNEL, false) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 if (adding)
31                 {
32                         if (!channel->IsModeSet('C'))
33                         {
34                                 channel->SetMode('C',true);
35                                 return MODEACTION_ALLOW;
36                         }
37                 }
38                 else
39                 {
40                         if (channel->IsModeSet('C'))
41                         {
42                                 channel->SetMode('C',false);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46
47                 return MODEACTION_DENY;
48         }
49 };
50
51 class ModuleNoCTCP : public Module
52 {
53         
54         NoCTCP* nc;
55         
56  public:
57  
58         ModuleNoCTCP(InspIRCd* Me)
59                 : Module::Module(Me)
60         {
61                 
62                 nc = new NoCTCP(ServerInstance);
63                 if (!ServerInstance->AddMode(nc, 'C'))
64                         throw ModuleException("Could not add new modes!");
65         }
66
67         void Implements(char* List)
68         {
69                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
70         }
71
72         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
73         {
74                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
75         }
76         
77         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
78         {
79                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
80                 {
81                         chanrec* c = (chanrec*)dest;
82                         if (c->IsModeSet('C'))
83                         {
84                                 if ((text.length()) && (text[0] == '\1'))
85                                 {
86                                         if (strncmp(text.c_str(),"\1ACTION ",8))
87                                         {
88                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
89                                                 return 1;
90                                         }
91                                 }
92                         }
93                 }
94                 return 0;
95         }
96
97         virtual ~ModuleNoCTCP()
98         {
99                 ServerInstance->Modes->DelMode(nc);
100                 DELETE(nc);
101         }
102
103         virtual Version GetVersion()
104         {
105                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
106         }
107 };
108
109
110 class ModuleNoCTCPFactory : public ModuleFactory
111 {
112  public:
113         ModuleNoCTCPFactory()
114         {
115         }
116         
117         ~ModuleNoCTCPFactory()
118         {
119         }
120         
121         virtual Module * CreateModule(InspIRCd* Me)
122         {
123                 return new ModuleNoCTCP(Me);
124         }
125         
126 };
127
128
129 extern "C" void * init_module( void )
130 {
131         return new ModuleNoCTCPFactory;
132 }
133