]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictbanned.cpp
Test stuff to fix remote stats brokage
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17
18 #include "inspircd.h"
19
20 /* $ModDesc: Restricts banned users in a channel. May not speak, etc. */
21
22 class ModuleRestrictBanned : public Module
23 {
24  private:
25  public:
26         ModuleRestrictBanned(InspIRCd* Me) : Module::Module(Me)
27         {
28         }
29         
30         virtual ~ModuleRestrictBanned()
31         {
32         }
33         
34         virtual Version GetVersion()
35         {
36                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
37         }
38
39         void Implements(char* List)
40         {
41                 List[I_OnLocalTopicChange] = List[I_OnUserPreNick] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
42         }
43
44         int CheckRestricted(userrec *user, chanrec *channel, const std::string &action)
45         {
46                 /* aren't local? we don't care. */
47                 if (!IS_LOCAL(user))
48                         return 0;
49
50                 if (channel->GetStatus(user) < STATUS_VOICE && channel->IsBanned(user))
51                 {
52                         /* banned, boned. drop the message. */
53                         user->WriteServ("NOTICE "+std::string(user->nick)+" :*** You may not " + action + ", as you are banned on channel " + channel->name);
54                         return 1;
55                 }
56
57                 return 0;
58         }
59
60         virtual int OnUserPreNick(userrec *user, const std::string &newnick)
61         {
62                 /* if they aren't local, we don't care */
63                 if (!IS_LOCAL(user))
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(userrec *user, chanrec *channel, const std::string &topic)
77         {
78                 return CheckRestricted(user, channel, "change the topic");
79         }
80         
81         virtual int OnUserPreMessage(userrec* 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(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
87         {
88                 if (target_type == TYPE_CHANNEL)
89                 {
90                         chanrec *channel = (chanrec *)dest;
91
92                         return CheckRestricted(user, channel, "message the channel");
93                 }
94
95                 return 0;
96         }
97 };
98
99
100 class ModuleRestrictBannedFactory : public ModuleFactory
101 {
102  public:
103         ModuleRestrictBannedFactory()
104         {
105         }
106         
107         ~ModuleRestrictBannedFactory()
108         {
109         }
110         
111         virtual Module * CreateModule(InspIRCd* Me)
112         {
113                 return new ModuleRestrictBanned(Me);
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleRestrictBannedFactory;
122 }
123