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