]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
Pedantic clean
[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(User *user, Channel *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(User *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                 /* Allow changes to UID */
63                 if (isdigit(newnick[0]))
64                         return 0;
65
66                 /* bit of a special case. */
67                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
68                 {
69                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
70                                 return 1;
71                 }
72
73                 return 0;
74         }
75
76         virtual int OnLocalTopicChange(User *user, Channel *channel, const std::string &topic)
77         {
78                 return CheckRestricted(user, channel, "change the topic");
79         }
80         
81         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
82         {
83                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
84         }
85
86         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
87         {
88                 if (target_type == TYPE_CHANNEL)
89                 {
90                         Channel *channel = (Channel *)dest;
91
92                         return CheckRestricted(user, channel, "message the channel");
93                 }
94
95                 return 0;
96         }
97 };
98
99 MODULE_INIT(ModuleRestrictBanned)