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