]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Remove InspIRCd* parameters and fields
[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()
25                         {
26
27                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
28                 ServerInstance->Modules->Attach(eventlist, this, 2);
29         }
30
31
32         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
33         {
34                 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
35                 {
36                         User* u = (User*)dest;
37
38                         // message allowed if:
39                         // (1) the sender is opered
40                         // (2) the recipient is opered
41                         // anything else, blocked.
42                         if (IS_OPER(u) || IS_OPER(user))
43                         {
44                                 return MOD_RES_PASSTHRU;
45                         }
46                         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());
47                         return MOD_RES_DENY;
48                 }
49
50                 // however, we must allow channel messages...
51                 return MOD_RES_PASSTHRU;
52         }
53
54         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
55         {
56                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
57         }
58
59         virtual ~ModuleRestrictMsg()
60         {
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version("Forbids users from messaging each other. Users may still message opers and opers may message other opers.",VF_VENDOR,API_VERSION);
66         }
67 };
68
69 MODULE_INIT(ModuleRestrictMsg)