]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Describe module purpose in /MODULES output
[user/henk/code/inspircd.git] / src / modules / m_restrictmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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
16 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
17
18
19 class ModuleRestrictMsg : public Module
20 {
21
22  public:
23
24         ModuleRestrictMsg(InspIRCd* Me)
25                 : Module(Me)
26         {
27
28                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
29                 ServerInstance->Modules->Attach(eventlist, this, 2);
30         }
31
32
33         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
34         {
35                 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
36                 {
37                         User* u = (User*)dest;
38
39                         // message allowed if:
40                         // (1) the sender is opered
41                         // (2) the recipient is opered
42                         // anything else, blocked.
43                         if (IS_OPER(u) || IS_OPER(user))
44                         {
45                                 return MOD_RES_PASSTHRU;
46                         }
47                         user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user",user->nick.c_str(),u->nick.c_str());
48                         return MOD_RES_DENY;
49                 }
50
51                 // however, we must allow channel messages...
52                 return MOD_RES_PASSTHRU;
53         }
54
55         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
56         {
57                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
58         }
59
60         virtual ~ModuleRestrictMsg()
61         {
62         }
63
64         virtual Version GetVersion()
65         {
66                 return Version("Forbids users from messaging each other. Users may still message opers and opers may message other opers.",VF_VENDOR,API_VERSION);
67         }
68 };
69
70 MODULE_INIT(ModuleRestrictMsg)