]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcaps.cpp
Auto loading of commands as shared objects via dlsym (very lightweight interface...
[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
28 class BlockCaps : public ModeHandler
29 {
30  public:
31         BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
32
33         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
34         {
35                 if (adding)
36                 {
37                         if (!channel->IsModeSet('P'))
38                         {
39                                 channel->SetMode('P',true);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43                 else
44                 {
45                         if (channel->IsModeSet('P'))
46                         {
47                                 channel->SetMode('P',false);
48                                 return MODEACTION_ALLOW;
49                         }
50                 }
51
52                 return MODEACTION_DENY;
53         }
54 };
55
56 class ModuleBlockCAPS : public Module
57 {
58         
59         BlockCaps* bc;
60 public:
61         
62         ModuleBlockCAPS(InspIRCd* Me) : Module::Module(Me)
63         {
64                 
65                 bc = new BlockCaps(ServerInstance);
66                 ServerInstance->AddMode(bc, 'P');
67         }
68
69         void Implements(char* List)
70         {
71                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
72         }
73
74         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
75         {
76                 if (target_type == TYPE_CHANNEL)
77                 {
78                         chanrec* c = (chanrec*)dest;
79
80                         if (c->IsModeSet('P'))
81                         {
82                                 const char* i = text.c_str();
83                                 for (; *i; i++)
84                                 {
85                                         if (((*i != ' ') && (*i != '\t')) && ((*i < 'A') || (*i > 'Z')))
86                                         {
87                                                 return 0;
88                                         }
89                                 }
90                                 
91                                 user->WriteServ( "404 %s %s :Can't send all-CAPS to channel (+P set)", user->nick, c->name);
92                                 return 1;
93                         }
94                 }
95                 return 0;
96         }
97
98         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
99         {
100                 return OnUserPreMessage(user,dest,target_type,text,status);
101         }
102
103         virtual ~ModuleBlockCAPS()
104         {
105                 ServerInstance->Modes->DelMode(bc);
106                 DELETE(bc);
107         }
108
109         virtual Version GetVersion()
110         {
111                 return Version(1,0,0,0,VF_COMMON|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(InspIRCd* 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 }