]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Fix remote bursting with quietbursts, before QA actually test it :P (thanks HiroP)
[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
48                         // message allowed if:
49                         // (1) the sender is opered
50                         // (2) the recipient is opered
51                         // anything else, blocked.
52                         if (IS_OPER(u) || IS_OPER(user))
53                         {
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
60                 // however, we must allow channel messages...
61                 return 0;
62         }
63
64         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
65         {
66                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
67         }
68
69         virtual ~ModuleRestrictMsg()
70         {
71         }
72         
73         virtual Version GetVersion()
74         {
75                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
76         }
77 };
78
79
80 class ModuleRestrictMsgFactory : public ModuleFactory
81 {
82  public:
83         ModuleRestrictMsgFactory()
84         {
85         }
86         
87         ~ModuleRestrictMsgFactory()
88         {
89         }
90         
91         virtual Module * CreateModule(InspIRCd* Me)
92         {
93                 return new ModuleRestrictMsg(Me);
94         }
95         
96 };
97
98
99 extern "C" void * init_module( void )
100 {
101         return new ModuleRestrictMsgFactory;
102 }
103