]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
b2d15f9d7b0e80ed9be398e982e0584e02e688ed
[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 "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style channel mode +c */
17
18 class NoCTCP : public ModeHandler
19 {
20  public:
21         NoCTCP(InspIRCd* Instance) : ModeHandler(Instance, 'C', 0, 0, false, MODETYPE_CHANNEL, false) { }
22
23         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
24         {
25                 if (adding)
26                 {
27                         if (!channel->IsModeSet('C'))
28                         {
29                                 channel->SetMode('C',true);
30                                 return MODEACTION_ALLOW;
31                         }
32                 }
33                 else
34                 {
35                         if (channel->IsModeSet('C'))
36                         {
37                                 channel->SetMode('C',false);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41
42                 return MODEACTION_DENY;
43         }
44 };
45
46 class ModuleNoCTCP : public Module
47 {
48         
49         NoCTCP* nc;
50         
51  public:
52  
53         ModuleNoCTCP(InspIRCd* Me)
54                 : Module(Me)
55         {
56                 
57                 nc = new NoCTCP(ServerInstance);
58                 if (!ServerInstance->AddMode(nc, 'C'))
59                         throw ModuleException("Could not add new modes!");
60         }
61
62         void Implements(char* List)
63         {
64                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
65         }
66
67         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
68         {
69                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
70         }
71         
72         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
73         {
74                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
75                 {
76                         chanrec* c = (chanrec*)dest;
77                         if (c->IsModeSet('C'))
78                         {
79                                 if ((text.length()) && (text[0] == '\1'))
80                                 {
81                                         if (strncmp(text.c_str(),"\1ACTION ",8))
82                                         {
83                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
84                                                 return 1;
85                                         }
86                                 }
87                         }
88                 }
89                 return 0;
90         }
91
92         virtual ~ModuleNoCTCP()
93         {
94                 ServerInstance->Modes->DelMode(nc);
95                 delete nc;
96         }
97
98         virtual Version GetVersion()
99         {
100                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
101         }
102 };
103
104 MODULE_INIT(ModuleNoCTCP)