]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
Mode +b stuff, probably wont work yet
[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 ModuleBlockCAPS : public Module
26 {
27         Server *Srv;
28 public:
29         
30         ModuleBlockCAPS(Server* Me) : Module::Module(Me)
31         {
32                 Srv = Me;
33                 Srv->AddExtendedMode('P', MT_CHANNEL, false, 0, 0);
34         }
35
36         void Implements(char* List)
37         {
38                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1;
39         }
40
41         virtual void On005Numeric(std::string &output)
42         {
43                 InsertMode(output, "P", 4);
44         }
45
46         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
47         {
48                 if (target_type == TYPE_CHANNEL)
49                 {
50                         chanrec* c = (chanrec*)dest;
51
52                         if (c->IsModeSet('P'))
53                         {
54                                 const char* i = text.c_str();
55                                 for (; *i; i++)
56                                 {
57                                         if (((*i != ' ') && (*i != '\t')) && ((*i < 'A') || (*i > 'Z')))
58                                         {
59                                                 return 0;
60                                         }
61                                 }
62                                 
63                                 WriteServ(user->fd, "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
64                                 return 1;
65                         }
66                 }
67                 return 0;
68         }
69         
70         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
71         {
72                 return OnUserPreMessage(user,dest,target_type,text,status);
73         }
74         
75         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
76         {
77                 // check if this is our mode character...
78                 if ((modechar == 'P') && (type == MT_CHANNEL))
79                 {
80                         log(DEBUG,"Allowing P change");
81                         return 1;
82                 }
83                 else
84                 {
85                         return 0;
86                 }
87         }
88
89         virtual ~ModuleBlockCAPS()
90         {
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
96         }
97 };
98
99
100 class ModuleBlockCAPSFactory : public ModuleFactory
101 {
102  public:
103         ModuleBlockCAPSFactory()
104         {
105         }
106         
107         ~ModuleBlockCAPSFactory()
108         {
109         }
110         
111         virtual Module * CreateModule(Server* Me)
112         {
113                 return new ModuleBlockCAPS(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleBlockCAPSFactory;
122 }