]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Insert massive change here.
[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
26 #include "inspircd.h"
27
28 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
29
30
31 class ModuleRestrictMsg : public Module
32 {
33         
34  public:
35  
36         ModuleRestrictMsg(InspIRCd* Me)
37                 : Module::Module(Me)
38         {
39                 
40         }
41
42         void Implements(char* List)
43         {
44                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
45         }
46
47         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
48         {
49                 if (target_type == TYPE_USER)
50                 {
51                         userrec* u = (userrec*)dest;
52                         if (*u->oper || *user->oper)
53                         {
54                                 // message allowed if:
55                                 // (1) the sender is opered
56                                 // (2) the recipient is opered
57                                 // (3) both are opered
58                                 // anything else, blocked.
59                                 return 0;
60                         }
61                         user->WriteServ("531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
62                         return 1;
63                 }
64                 // however, we must allow channel messages...
65                 return 0;
66         }
67
68         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
69         {
70                 return this->OnUserPreMessage(user,dest,target_type,text,status);
71         }
72
73         virtual ~ModuleRestrictMsg()
74         {
75         }
76         
77         virtual Version GetVersion()
78         {
79                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
80         }
81 };
82
83
84 class ModuleRestrictMsgFactory : public ModuleFactory
85 {
86  public:
87         ModuleRestrictMsgFactory()
88         {
89         }
90         
91         ~ModuleRestrictMsgFactory()
92         {
93         }
94         
95         virtual Module * CreateModule(InspIRCd* Me)
96         {
97                 return new ModuleRestrictMsg(Me);
98         }
99         
100 };
101
102
103 extern "C" void * init_module( void )
104 {
105         return new ModuleRestrictMsgFactory;
106 }
107