]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Remove dummy API_VERSION from Version constructor
[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, "noctcp", '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         }
65
66         virtual Version GetVersion()
67         {
68                 return Version("Provides support for unreal-style channel mode +C", VF_COMMON | VF_VENDOR);
69         }
70
71         virtual ModResult OnUserPreMessage(User* 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 ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77         {
78                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
79                 {
80                         Channel* c = (Channel*)dest;
81                         ModResult res;
82                         FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,c,"noctcp"));
83
84                         if (res == MOD_RES_ALLOW)
85                                 return MOD_RES_PASSTHRU;
86
87                         if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet('C')))
88                         {
89                                 if ((text.length()) && (text[0] == '\1'))
90                                 {
91                                         if (strncmp(text.c_str(),"\1ACTION ",8))
92                                         {
93                                                 user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
94                                                 return MOD_RES_DENY;
95                                         }
96                                 }
97                         }
98                 }
99                 return MOD_RES_PASSTHRU;
100         }
101
102         virtual void On005Numeric(std::string &output)
103         {
104                 ServerInstance->AddExtBanChar('C');
105         }
106 };
107
108 MODULE_INIT(ModuleNoCTCP)