]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Some more to fix still, modules probably wont load correctly atm
[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
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         void Implements(char* List)
33         {
34                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
35         }
36
37         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
38         {
39                 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
40                 {
41                         User* u = (User*)dest;
42
43                         // message allowed if:
44                         // (1) the sender is opered
45                         // (2) the recipient is opered
46                         // anything else, blocked.
47                         if (IS_OPER(u) || IS_OPER(user))
48                         {
49                                 return 0;
50                         }
51                         user->WriteServ("531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
52                         return 1;
53                 }
54
55                 // however, we must allow channel messages...
56                 return 0;
57         }
58
59         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
60         {
61                 return this->OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
62         }
63
64         virtual ~ModuleRestrictMsg()
65         {
66         }
67         
68         virtual Version GetVersion()
69         {
70                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
71         }
72 };
73
74 MODULE_INIT(ModuleRestrictMsg)