]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
0bc03fab15b829836997d08967570b996cb999da
[user/henk/code/inspircd.git] / src / modules / m_restrictmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include <string>
21 #include <vector>
22 #include "users.h"
23 #include "channels.h"
24 #include "modules.h"
25 #include "helperfuncs.h"
26
27 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
28
29
30 class ModuleRestrictMsg : public Module
31 {
32         Server *Srv;
33  public:
34  
35         ModuleRestrictMsg(Server* Me)
36                 : Module::Module(Me)
37         {
38                 Srv = Me;
39         }
40
41         void Implements(char* List)
42         {
43                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
44         }
45
46         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
47         {
48                 if (target_type == TYPE_USER)
49                 {
50                         userrec* u = (userrec*)dest;
51                         if ((strchr(u->modes,'o')) || (strchr(user->modes,'o')))
52                         {
53                                 // message allowed if:
54                                 // (1) the sender is opered
55                                 // (2) the recipient is opered
56                                 // (3) both are opered
57                                 // anything else, blocked.
58                                 return 0;
59                         }
60                         WriteServ(user->fd,"531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
61                         return 1;
62                 }
63                 // however, we must allow channel messages...
64                 return 0;
65         }
66
67         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
68         {
69                 return this->OnUserPreMessage(user,dest,target_type,text);
70         }
71
72         virtual ~ModuleRestrictMsg()
73         {
74         }
75         
76         virtual Version GetVersion()
77         {
78                 return Version(1,0,0,1,VF_VENDOR);
79         }
80 };
81
82
83 class ModuleRestrictMsgFactory : public ModuleFactory
84 {
85  public:
86         ModuleRestrictMsgFactory()
87         {
88         }
89         
90         ~ModuleRestrictMsgFactory()
91         {
92         }
93         
94         virtual Module * CreateModule(Server* Me)
95         {
96                 return new ModuleRestrictMsg(Me);
97         }
98         
99 };
100
101
102 extern "C" void * init_module( void )
103 {
104         return new ModuleRestrictMsgFactory;
105 }
106