]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
c37951eea3cbbf8369bcbadc0534f6df4fe3a586
[user/henk/code/inspircd.git] / src / modules / m_restrictbanned.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 "users.h"
20 #include "channels.h"
21 #include "modules.h"
22
23 #include "inspircd.h"
24
25 /* $ModDesc: Restricts banned users in a channel. May not speak, etc. */
26
27 class ModuleRestrictBanned : public Module
28 {
29  private:
30  public:
31         ModuleRestrictBanned(InspIRCd* Me) : Module::Module(Me)
32         {
33         }
34         
35         virtual ~ModuleRestrictBanned()
36         {
37         }
38         
39         virtual Version GetVersion()
40         {
41                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
42         }
43
44         void Implements(char* List)
45         {
46                 List[I_OnLocalTopicChange] = List[I_OnUserPreNick] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
47         }
48
49         int CheckRestricted(userrec *user, chanrec *channel, const std::string &action)
50         {
51                 /* aren't local? we don't care. */
52                 if (!IS_LOCAL(user))
53                         return 0;
54
55                 if (channel->IsBanned(user) && channel->GetStatus(user) < STATUS_VOICE)
56                 {
57                         /* banned, boned. drop the message. */
58                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
59                         return 1;
60                 }
61
62                 return 0;
63         }
64
65         virtual int OnUserPreNick(userrec *user, const std::string &newnick)
66         {
67                 /* if they aren't local, we don't care */
68                 if (!IS_LOCAL(user))
69                         return 0;
70
71                 /* bit of a special case. */
72                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
73                 {
74                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
75                                 return 1;
76                 }
77
78                 return 0;
79         }
80
81         virtual int OnLocalTopicChange(userrec *user, chanrec *channel, const std::string &topic)
82         {
83                 return CheckRestricted(user, channel, "change the topic");
84         }
85         
86         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
87         {
88                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
89         }
90
91         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
92         {
93                 if (target_type == TYPE_CHANNEL)
94                 {
95                         chanrec *channel = (chanrec *)dest;
96
97                         return CheckRestricted(user, channel, "message the channel");
98                 }
99
100                 return 0;
101         }
102 };
103
104
105 class ModuleRestrictBannedFactory : public ModuleFactory
106 {
107  public:
108         ModuleRestrictBannedFactory()
109         {
110         }
111         
112         ~ModuleRestrictBannedFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleRestrictBanned(Me);
119         }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleRestrictBannedFactory;
127 }
128