]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
Just to mess with om's head, remove helperfuncs.h from everywhere
[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                 ServerInstance->Modes->InsertMode(output, "P", 4);
78         }
79
80         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
81         {
82                 if (target_type == TYPE_CHANNEL)
83                 {
84                         chanrec* c = (chanrec*)dest;
85
86                         if (c->IsModeSet('P'))
87                         {
88                                 const char* i = text.c_str();
89                                 for (; *i; i++)
90                                 {
91                                         if (((*i != ' ') && (*i != '\t')) && ((*i < 'A') || (*i > 'Z')))
92                                         {
93                                                 return 0;
94                                         }
95                                 }
96                                 
97                                 user->WriteServ( "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
98                                 return 1;
99                         }
100                 }
101                 return 0;
102         }
103         
104         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
105         {
106                 return OnUserPreMessage(user,dest,target_type,text,status);
107         }
108         
109         virtual ~ModuleBlockCAPS()
110         {
111                 DELETE(bc);
112         }
113         
114         virtual Version GetVersion()
115         {
116                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
117         }
118 };
119
120
121 class ModuleBlockCAPSFactory : public ModuleFactory
122 {
123  public:
124         ModuleBlockCAPSFactory()
125         {
126         }
127         
128         ~ModuleBlockCAPSFactory()
129         {
130         }
131         
132         virtual Module * CreateModule(InspIRCd* Me)
133         {
134                 return new ModuleBlockCAPS(Me);
135         }
136         
137 };
138
139
140 extern "C" void * init_module( void )
141 {
142         return new ModuleBlockCAPSFactory;
143 }