]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Add support for LOCKSERV/UNLOCKSERV to block/open for new connections. Thanks to...
[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                 ServerInstance->AddMode(nc, 'C');
64         }
65
66         void Implements(char* List)
67         {
68                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
69         }
70
71         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
72         {
73                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
74         }
75         
76         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77         {
78                 if (target_type == TYPE_CHANNEL)
79                 {
80                         chanrec* c = (chanrec*)dest;
81                         if (c->IsModeSet('C'))
82                         {
83                                 if ((text.length()) && (text[0] == '\1'))
84                                 {
85                                         if (strncmp(text.c_str(),"\1ACTION ",8))
86                                         {
87                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
88                                                 return 1;
89                                         }
90                                 }
91                         }
92                 }
93                 return 0;
94         }
95
96         virtual ~ModuleNoCTCP()
97         {
98                 ServerInstance->Modes->DelMode(nc);
99                 DELETE(nc);
100         }
101
102         virtual Version GetVersion()
103         {
104                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
105         }
106 };
107
108
109 class ModuleNoCTCPFactory : public ModuleFactory
110 {
111  public:
112         ModuleNoCTCPFactory()
113         {
114         }
115         
116         ~ModuleNoCTCPFactory()
117         {
118         }
119         
120         virtual Module * CreateModule(InspIRCd* Me)
121         {
122                 return new ModuleNoCTCP(Me);
123         }
124         
125 };
126
127
128 extern "C" void * init_module( void )
129 {
130         return new ModuleNoCTCPFactory;
131 }
132