]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
If SVSNICK fails, attempt to change to UID, before quitting as a last resort (if...
[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
16 /* $ModDesc: Restricts banned users in a channel. May not speak, etc. */
17
18 class ModuleRestrictBanned : public Module
19 {
20  private:
21  public:
22         ModuleRestrictBanned(InspIRCd* Me) : Module(Me)
23         {
24         }
25         
26         virtual ~ModuleRestrictBanned()
27         {
28         }
29         
30         virtual Version GetVersion()
31         {
32                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
33         }
34
35         void Implements(char* List)
36         {
37                 List[I_OnLocalTopicChange] = List[I_OnUserPreNick] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
38         }
39
40         int CheckRestricted(userrec *user, chanrec *channel, const std::string &action)
41         {
42                 /* aren't local? we don't care. */
43                 if (!IS_LOCAL(user))
44                         return 0;
45
46                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
47                 {
48                         /* banned, boned. drop the message. */
49                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
50                         return 1;
51                 }
52
53                 return 0;
54         }
55
56         virtual int OnUserPreNick(userrec *user, const std::string &newnick)
57         {
58                 /* if they aren't local, we don't care */
59                 if (!IS_LOCAL(user))
60                         return 0;
61
62                 /* bit of a special case. */
63                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
64                 {
65                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
66                                 return 1;
67                 }
68
69                 return 0;
70         }
71
72         virtual int OnLocalTopicChange(userrec *user, chanrec *channel, const std::string &topic)
73         {
74                 return CheckRestricted(user, channel, "change the topic");
75         }
76         
77         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
78         {
79                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
80         }
81
82         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
83         {
84                 if (target_type == TYPE_CHANNEL)
85                 {
86                         chanrec *channel = (chanrec *)dest;
87
88                         return CheckRestricted(user, channel, "message the channel");
89                 }
90
91                 return 0;
92         }
93 };
94
95 MODULE_INIT(ModuleRestrictBanned)