]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Tons of module versionflags stuff, and checks for it in /UNLOADMODULE
[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 #include <stdio.h>
18 #include <string>
19 #include <vector>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23
24 /* $ModDesc: Forbids users from messaging each other. Users may still message opers and opers may message other opers. */
25
26
27 class ModuleRestrictMsg : public Module
28 {
29         Server *Srv;
30  public:
31  
32         ModuleRestrictMsg()
33         {
34                 Srv = new Server;
35         }
36
37         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
38         {
39                 if (target_type == TYPE_USER)
40                 {
41                         userrec* u = (userrec*)dest;
42                         if ((strchr(u->modes,'o')) || (strchr(user->modes,'o')))
43                         {
44                                 // message allowed if:
45                                 // (1) the sender is opered
46                                 // (2) the recipient is opered
47                                 // (3) both are opered
48                                 // anything else, blocked.
49                                 return 0;
50                         }
51                         WriteServ(user->fd,"531 %s %s :You are not permitted to send private messages to this user",user->nick,u->nick);
52                         return 1;
53                 }
54                 // however, we must allow channel messages...
55                 return 0;
56         }
57
58         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
59         {
60                 return this->OnUserPreMessage(user,dest,target_type,text);
61         }
62
63         virtual ~ModuleRestrictMsg()
64         {
65                 delete Srv;
66         }
67         
68         virtual Version GetVersion()
69         {
70                 return Version(1,0,0,1,VF_VENDOR);
71         }
72 };
73
74
75 class ModuleRestrictMsgFactory : public ModuleFactory
76 {
77  public:
78         ModuleRestrictMsgFactory()
79         {
80         }
81         
82         ~ModuleRestrictMsgFactory()
83         {
84         }
85         
86         virtual Module * CreateModule()
87         {
88                 return new ModuleRestrictMsg;
89         }
90         
91 };
92
93
94 extern "C" void * init_module( void )
95 {
96         return new ModuleRestrictMsgFactory;
97 }
98