]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[user/henk/code/inspircd.git] / src / modules / m_restrictbanned.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Restricts banned users in a channel. May not speak, etc. */
20
21 class ModuleRestrictBanned : public Module
22 {
23  private:
24  public:
25         ModuleRestrictBanned(InspIRCd* Me) : Module(Me)
26         {
27         }
28         
29         virtual ~ModuleRestrictBanned()
30         {
31         }
32         
33         virtual Version GetVersion()
34         {
35                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
36         }
37
38         void Implements(char* List)
39         {
40                 List[I_OnLocalTopicChange] = List[I_OnUserPreNick] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
41         }
42
43         int CheckRestricted(userrec *user, chanrec *channel, const std::string &action)
44         {
45                 /* aren't local? we don't care. */
46                 if (!IS_LOCAL(user))
47                         return 0;
48
49                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
50                 {
51                         /* banned, boned. drop the message. */
52                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
53                         return 1;
54                 }
55
56                 return 0;
57         }
58
59         virtual int OnUserPreNick(userrec *user, const std::string &newnick)
60         {
61                 /* if they aren't local, we don't care */
62                 if (!IS_LOCAL(user))
63                         return 0;
64
65                 /* bit of a special case. */
66                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
67                 {
68                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
69                                 return 1;
70                 }
71
72                 return 0;
73         }
74
75         virtual int OnLocalTopicChange(userrec *user, chanrec *channel, const std::string &topic)
76         {
77                 return CheckRestricted(user, channel, "change the topic");
78         }
79         
80         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
81         {
82                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
83         }
84
85         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
86         {
87                 if (target_type == TYPE_CHANNEL)
88                 {
89                         chanrec *channel = (chanrec *)dest;
90
91                         return CheckRestricted(user, channel, "message the channel");
92                 }
93
94                 return 0;
95         }
96 };
97
98 MODULE_INIT(ModuleRestrictBanned)