]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_restrictbanned.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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                 Implementation eventlist[] = { I_OnLocalTopicChange, I_OnUserPreNick, I_OnUserPreNotice, I_OnUserPreMessage };
25                 ServerInstance->Modules->Attach(eventlist, this, 4);
26         }
27         
28         virtual ~ModuleRestrictBanned()
29         {
30         }
31         
32         virtual Version GetVersion()
33         {
34                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
35         }
36
37
38         int CheckRestricted(User *user, Channel *channel, const std::string &action)
39         {
40                 /* aren't local? we don't care. */
41                 if (!IS_LOCAL(user))
42                         return 0;
43
44                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
45                 {
46                         /* banned, boned. drop the message. */
47                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
48                         return 1;
49                 }
50
51                 return 0;
52         }
53
54         virtual int OnUserPreNick(User *user, const std::string &newnick)
55         {
56                 /* if they aren't local, we don't care */
57                 if (!IS_LOCAL(user))
58                         return 0;
59
60                 /* Allow changes to UID */
61                 if (isdigit(newnick[0]))
62                         return 0;
63
64                 /* bit of a special case. */
65                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
66                 {
67                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
68                                 return 1;
69                 }
70
71                 return 0;
72         }
73
74         virtual int OnLocalTopicChange(User *user, Channel *channel, const std::string &topic)
75         {
76                 return CheckRestricted(user, channel, "change the topic");
77         }
78         
79         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
80         {
81                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
82         }
83
84         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
85         {
86                 if (target_type == TYPE_CHANNEL)
87                 {
88                         Channel *channel = (Channel *)dest;
89
90                         return CheckRestricted(user, channel, "message the channel");
91                 }
92
93                 return 0;
94         }
95 };
96
97 MODULE_INIT(ModuleRestrictBanned)