]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
a5a2ae5ff358bc20989ff2e133a78511ff8e4db2
[user/henk/code/inspircd.git] / src / modules / m_blockcaps.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *                <omster@gmail.com>
10  *     
11  * Written by Craig Edwards, Craig McLure, and others.
12  * This program is free but copyrighted software; see
13  *            the file COPYING for details.
14  *
15  * ---------------------------------------------------
16  */
17
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21
22 #include "inspircd.h"
23 #include "mode.h"
24
25 /* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
26
27
28
29 class BlockCaps : public ModeHandler
30 {
31  public:
32         BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
33
34         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
35         {
36                 if (adding)
37                 {
38                         if (!channel->IsModeSet('P'))
39                         {
40                                 channel->SetMode('P',true);
41                                 return MODEACTION_ALLOW;
42                         }
43                 }
44                 else
45                 {
46                         if (channel->IsModeSet('P'))
47                         {
48                                 channel->SetMode('P',false);
49                                 return MODEACTION_ALLOW;
50                         }
51                 }
52
53                 return MODEACTION_DENY;
54         }
55 };
56
57 class ModuleBlockCAPS : public Module
58 {
59         
60         BlockCaps* bc;
61 public:
62         
63         ModuleBlockCAPS(InspIRCd* Me) : Module::Module(Me)
64         {
65                 
66                 bc = new BlockCaps(ServerInstance);
67                 ServerInstance->AddMode(bc, 'P');
68         }
69
70         void Implements(char* List)
71         {
72                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
73         }
74
75         virtual void On005Numeric(std::string &output)
76         {
77         }
78
79         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
80         {
81                 if (target_type == TYPE_CHANNEL)
82                 {
83                         chanrec* c = (chanrec*)dest;
84
85                         if (c->IsModeSet('P'))
86                         {
87                                 const char* i = text.c_str();
88                                 for (; *i; i++)
89                                 {
90                                         if (((*i != ' ') && (*i != '\t')) && ((*i < 'A') || (*i > 'Z')))
91                                         {
92                                                 return 0;
93                                         }
94                                 }
95                                 
96                                 user->WriteServ( "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
97                                 return 1;
98                         }
99                 }
100                 return 0;
101         }
102         
103         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
104         {
105                 return OnUserPreMessage(user,dest,target_type,text,status);
106         }
107         
108         virtual ~ModuleBlockCAPS()
109         {
110                 DELETE(bc);
111         }
112         
113         virtual Version GetVersion()
114         {
115                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
116         }
117 };
118
119
120 class ModuleBlockCAPSFactory : public ModuleFactory
121 {
122  public:
123         ModuleBlockCAPSFactory()
124         {
125         }
126         
127         ~ModuleBlockCAPSFactory()
128         {
129         }
130         
131         virtual Module * CreateModule(InspIRCd* Me)
132         {
133                 return new ModuleBlockCAPS(Me);
134         }
135         
136 };
137
138
139 extern "C" void * init_module( void )
140 {
141         return new ModuleBlockCAPSFactory;
142 }