]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Update copyrights for 2009.
[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://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(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
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->Modes->AddMode(nc))
59                         throw ModuleException("Could not add new modes!");
60                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
61                 ServerInstance->Modules->Attach(eventlist, this, 2);
62         }
63
64         virtual ~ModuleNoCTCP()
65         {
66                 ServerInstance->Modes->DelMode(nc);
67                 delete nc;
68         }
69
70         virtual Version GetVersion()
71         {
72                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
73         }
74
75         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
76         {
77                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
78         }
79
80         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
81         {
82                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
83                 {
84                         Channel* c = (Channel*)dest;
85
86                         if (CHANOPS_EXEMPT(ServerInstance, 'C') && c->GetStatus(user) == STATUS_OP)
87                         {
88                                 return 0;
89                         }
90
91                         if (c->IsModeSet('C') || c->IsExtBanned(user, 'C'))
92                         {
93                                 if ((text.length()) && (text[0] == '\1'))
94                                 {
95                                         if (strncmp(text.c_str(),"\1ACTION ",8))
96                                         {
97                                                 user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
98                                                 return 1;
99                                         }
100                                 }
101                         }
102                 }
103                 return 0;
104         }
105
106         virtual void On005Numeric(std::string &output)
107         {
108                 ServerInstance->AddExtBanChar('C');
109         }
110 };
111
112 MODULE_INIT(ModuleNoCTCP)