]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Someone is getting slapped for this; the new hidesplits/hidebans behavior doesn't...
[user/henk/code/inspircd.git] / src / modules / m_restrictmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include <string>
16 #include <vector>
17 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20
21 #include "inspircd.h"
22
23 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
24
25
26 class ModuleRestrictMsg : public Module
27 {
28         
29  public:
30  
31         ModuleRestrictMsg(InspIRCd* Me)
32                 : Module::Module(Me)
33         {
34                 
35         }
36
37         void Implements(char* List)
38         {
39                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
40         }
41
42         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
43         {
44                 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
45                 {
46                         userrec* u = (userrec*)dest;
47                         if (*u->oper || *user->oper)
48                         {
49                                 // message allowed if:
50                                 // (1) the sender is opered
51                                 // (2) the recipient is opered
52                                 // (3) both are opered
53                                 // anything else, blocked.
54                                 return 0;
55                         }
56                         user->WriteServ("531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
57                         return 1;
58                 }
59                 // however, we must allow channel messages...
60                 return 0;
61         }
62
63         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
64         {
65                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
66         }
67
68         virtual ~ModuleRestrictMsg()
69         {
70         }
71         
72         virtual Version GetVersion()
73         {
74                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
75         }
76 };
77
78
79 class ModuleRestrictMsgFactory : public ModuleFactory
80 {
81  public:
82         ModuleRestrictMsgFactory()
83         {
84         }
85         
86         ~ModuleRestrictMsgFactory()
87         {
88         }
89         
90         virtual Module * CreateModule(InspIRCd* Me)
91         {
92                 return new ModuleRestrictMsg(Me);
93         }
94         
95 };
96
97
98 extern "C" void * init_module( void )
99 {
100         return new ModuleRestrictMsgFactory;
101 }
102