]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_noctcp.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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(Module* Creator) : ModeHandler(Creator, 'C', PARAM_NONE, MODETYPE_CHANNEL) { }
22
23         ModeAction OnModeChange(User* source, User* dest, Channel* 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()
54                 : nc(this)
55         {
56                 if (!ServerInstance->Modes->AddMode(&nc))
57                         throw ModuleException("Could not add new modes!");
58                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
59                 ServerInstance->Modules->Attach(eventlist, this, 3);
60         }
61
62         virtual ~ModuleNoCTCP()
63         {
64                 ServerInstance->Modes->DelMode(&nc);
65         }
66
67         virtual Version GetVersion()
68         {
69                 return Version("Provides support for unreal-style channel mode +C", VF_COMMON | VF_VENDOR, API_VERSION);
70         }
71
72         virtual ModResult OnUserPreMessage(User* 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 ModResult OnUserPreNotice(User* 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                         Channel* c = (Channel*)dest;
82
83                         if (CHANOPS_EXEMPT('C') && c->GetPrefixValue(user) == OP_VALUE)
84                         {
85                                 return MOD_RES_PASSTHRU;
86                         }
87
88                         if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet('C')))
89                         {
90                                 if ((text.length()) && (text[0] == '\1'))
91                                 {
92                                         if (strncmp(text.c_str(),"\1ACTION ",8))
93                                         {
94                                                 user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
95                                                 return MOD_RES_DENY;
96                                         }
97                                 }
98                         }
99                 }
100                 return MOD_RES_PASSTHRU;
101         }
102
103         virtual void On005Numeric(std::string &output)
104         {
105                 ServerInstance->AddExtBanChar('C');
106         }
107 };
108
109 MODULE_INIT(ModuleNoCTCP)