]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
Untested! New m_watch that should be hundreds of times faster (im not joking either)
[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 (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
73                 {
74                         if (((ucrec*)(*i))->channel != NULL)
75                         {
76                                 chanrec *channel = ((ucrec*)(*i))->channel;
77
78                                 if (CheckRestricted(user, channel, "change your nickname") == 1)
79                                         return 1;
80                         }
81                 }
82
83                 return 0;
84         }
85
86         virtual int OnLocalTopicChange(userrec *user, chanrec *channel, const std::string &topic)
87         {
88                 return CheckRestricted(user, channel, "change the topic");
89         }
90         
91         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
92         {
93                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
94         }
95
96         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
97         {
98                 if (target_type == TYPE_CHANNEL)
99                 {
100                         chanrec *channel = (chanrec *)dest;
101
102                         return CheckRestricted(user, channel, "message the channel");
103                 }
104
105                 return 0;
106         }
107 };
108
109
110 class ModuleRestrictBannedFactory : public ModuleFactory
111 {
112  public:
113         ModuleRestrictBannedFactory()
114         {
115         }
116         
117         ~ModuleRestrictBannedFactory()
118         {
119         }
120         
121         virtual Module * CreateModule(InspIRCd* Me)
122         {
123                 return new ModuleRestrictBanned(Me);
124         }
125         
126 };
127
128
129 extern "C" void * init_module( void )
130 {
131         return new ModuleRestrictBannedFactory;
132 }
133