]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
Insert massive change here.
[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 "inspircd.h"
22 #include "mode.h"
23
24 /* $ModDesc: Provides support for channel mode +P to block all-CAPS channel messages and notices */
25
26
27 /** Handles the +P channel mode
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_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
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                                 user->WriteServ( "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                 ServerInstance->Modes->DelMode(bc);
107                 DELETE(bc);
108         }
109
110         virtual Version GetVersion()
111         {
112                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
113         }
114 };
115
116
117 class ModuleBlockCAPSFactory : public ModuleFactory
118 {
119  public:
120         ModuleBlockCAPSFactory()
121         {
122         }
123         
124         ~ModuleBlockCAPSFactory()
125         {
126         }
127         
128         virtual Module * CreateModule(InspIRCd* Me)
129         {
130                 return new ModuleBlockCAPS(Me);
131         }
132         
133 };
134
135
136 extern "C" void * init_module( void )
137 {
138         return new ModuleBlockCAPSFactory;
139 }