]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Review and optimize
[user/henk/code/inspircd.git] / src / modules / m_restrictmsg.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
42         {
43                 if (target_type == TYPE_USER)
44                 {
45                         userrec* u = (userrec*)dest;
46                         if ((strchr(u->modes,'o')) || (strchr(user->modes,'o')))
47                         {
48                                 // message allowed if:
49                                 // (1) the sender is opered
50                                 // (2) the recipient is opered
51                                 // (3) both are opered
52                                 // anything else, blocked.
53                                 return 0;
54                         }
55                         WriteServ(user->fd,"531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
56                         return 1;
57                 }
58                 // however, we must allow channel messages...
59                 return 0;
60         }
61
62         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
63         {
64                 return this->OnUserPreMessage(user,dest,target_type,text);
65         }
66
67         virtual ~ModuleRestrictMsg()
68         {
69         }
70         
71         virtual Version GetVersion()
72         {
73                 return Version(1,0,0,1,VF_VENDOR);
74         }
75 };
76
77
78 class ModuleRestrictMsgFactory : public ModuleFactory
79 {
80  public:
81         ModuleRestrictMsgFactory()
82         {
83         }
84         
85         ~ModuleRestrictMsgFactory()
86         {
87         }
88         
89         virtual Module * CreateModule(Server* Me)
90         {
91                 return new ModuleRestrictMsg(Me);
92         }
93         
94 };
95
96
97 extern "C" void * init_module( void )
98 {
99         return new ModuleRestrictMsgFactory;
100 }
101