]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
Some more to fix still, modules probably wont load correctly atm
[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                 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         void Implements(char* List)
38         {
39                 List[I_OnLocalTopicChange] = List[I_OnUserPreNick] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
40         }
41
42         int CheckRestricted(User *user, Channel *channel, const std::string &action)
43         {
44                 /* aren't local? we don't care. */
45                 if (!IS_LOCAL(user))
46                         return 0;
47
48                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
49                 {
50                         /* banned, boned. drop the message. */
51                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
52                         return 1;
53                 }
54
55                 return 0;
56         }
57
58         virtual int OnUserPreNick(User *user, const std::string &newnick)
59         {
60                 /* if they aren't local, we don't care */
61                 if (!IS_LOCAL(user))
62                         return 0;
63
64                 /* Allow changes to UID */
65                 if (isdigit(newnick[0]))
66                         return 0;
67
68                 /* bit of a special case. */
69                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
70                 {
71                         if (CheckRestricted(user, i->first, "change your nickname") == 1)
72                                 return 1;
73                 }
74
75                 return 0;
76         }
77
78         virtual int OnLocalTopicChange(User *user, Channel *channel, const std::string &topic)
79         {
80                 return CheckRestricted(user, channel, "change the topic");
81         }
82         
83         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
84         {
85                 return OnUserPreNotice(user,dest,target_type,text,status,exempt_list);
86         }
87
88         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
89         {
90                 if (target_type == TYPE_CHANNEL)
91                 {
92                         Channel *channel = (Channel *)dest;
93
94                         return CheckRestricted(user, channel, "message the channel");
95                 }
96
97                 return 0;
98         }
99 };
100
101 MODULE_INIT(ModuleRestrictBanned)