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