]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
Removed a pointless check in ./configure --clean that made it only work with one...
[user/henk/code/inspircd.git] / src / modules / m_blockcaps.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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18 #include "mode.h"
19
20 /* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
21
22
23 /** Handles the +P channel mode
24  */
25 class BlockCaps : public ModeHandler
26 {
27  public:
28         BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
29
30         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
31         {
32                 if (adding)
33                 {
34                         if (!channel->IsModeSet('P'))
35                         {
36                                 channel->SetMode('P',true);
37                                 return MODEACTION_ALLOW;
38                         }
39                 }
40                 else
41                 {
42                         if (channel->IsModeSet('P'))
43                         {
44                                 channel->SetMode('P',false);
45                                 return MODEACTION_ALLOW;
46                         }
47                 }
48
49                 return MODEACTION_DENY;
50         }
51 };
52
53 class ModuleBlockCAPS : public Module
54 {
55         
56         BlockCaps* bc;
57 public:
58         
59         ModuleBlockCAPS(InspIRCd* Me) : Module::Module(Me)
60         {
61                 
62                 bc = new BlockCaps(ServerInstance);
63                 ServerInstance->AddMode(bc, 'P');
64         }
65
66         void Implements(char* List)
67         {
68                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
69         }
70
71         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
72         {
73                 if (target_type == TYPE_CHANNEL)
74                 {
75                         chanrec* c = (chanrec*)dest;
76
77                         if (c->IsModeSet('P'))
78                         {
79                                 const char* i = text.c_str();
80                                 for (; *i; i++)
81                                 {
82                                         if (((*i != ' ') && (*i != '\t')) && ((*i < 'A') || (*i > 'Z')))
83                                         {
84                                                 return 0;
85                                         }
86                                 }
87                                 
88                                 user->WriteServ( "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
89                                 return 1;
90                         }
91                 }
92                 return 0;
93         }
94
95         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
96         {
97                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
98         }
99
100         virtual ~ModuleBlockCAPS()
101         {
102                 ServerInstance->Modes->DelMode(bc);
103                 DELETE(bc);
104         }
105
106         virtual Version GetVersion()
107         {
108                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
109         }
110 };
111
112
113 class ModuleBlockCAPSFactory : public ModuleFactory
114 {
115  public:
116         ModuleBlockCAPSFactory()
117         {
118         }
119         
120         ~ModuleBlockCAPSFactory()
121         {
122         }
123         
124         virtual Module * CreateModule(InspIRCd* Me)
125         {
126                 return new ModuleBlockCAPS(Me);
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleBlockCAPSFactory;
135 }