]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Added remote rehash (even to a mask)
[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()
36         {
37                 Srv = new Server;
38         }
39
40         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
41         {
42                 if (target_type == TYPE_USER)
43                 {
44                         userrec* u = (userrec*)dest;
45                         if ((strchr(u->modes,'o')) || (strchr(user->modes,'o')))
46                         {
47                                 // message allowed if:
48                                 // (1) the sender is opered
49                                 // (2) the recipient is opered
50                                 // (3) both are opered
51                                 // anything else, blocked.
52                                 return 0;
53                         }
54                         WriteServ(user->fd,"531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
55                         return 1;
56                 }
57                 // however, we must allow channel messages...
58                 return 0;
59         }
60
61         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
62         {
63                 return this->OnUserPreMessage(user,dest,target_type,text);
64         }
65
66         virtual ~ModuleRestrictMsg()
67         {
68                 delete Srv;
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()
90         {
91                 return new ModuleRestrictMsg;
92         }
93         
94 };
95
96
97 extern "C" void * init_module( void )
98 {
99         return new ModuleRestrictMsgFactory;
100 }
101