]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
faa272b131bd6ed9fe6c7991daf79b5b7d3b9790
[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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
20
21
22 class ModuleRestrictMsg : public Module
23 {
24         
25  public:
26  
27         ModuleRestrictMsg(InspIRCd* Me)
28                 : Module(Me)
29         {
30                 
31         }
32
33         void Implements(char* List)
34         {
35                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
36         }
37
38         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
39         {
40                 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
41                 {
42                         userrec* u = (userrec*)dest;
43
44                         // message allowed if:
45                         // (1) the sender is opered
46                         // (2) the recipient is opered
47                         // anything else, blocked.
48                         if (IS_OPER(u) || IS_OPER(user))
49                         {
50                                 return 0;
51                         }
52                         user->WriteServ("531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
53                         return 1;
54                 }
55
56                 // however, we must allow channel messages...
57                 return 0;
58         }
59
60         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
61         {
62                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
63         }
64
65         virtual ~ModuleRestrictMsg()
66         {
67         }
68         
69         virtual Version GetVersion()
70         {
71                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
72         }
73 };
74
75 MODULE_INIT(ModuleRestrictMsg);