]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
eff6e64a4c28bd549a5af70234b7b5adffbda78e
[user/henk/code/inspircd.git] / src / modules / m_denychans.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 #include "wildcard.h"
16
17 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
18
19 class ModuleDenyChannels : public Module
20 {
21  private:
22
23         
24         ConfigReader *Conf;
25
26  public:
27         ModuleDenyChannels(InspIRCd* Me) : Module(Me)
28         {
29                 
30                 Conf = new ConfigReader(ServerInstance);
31                 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
32                 ServerInstance->Modules->Attach(eventlist, this, 2);
33         }
34         
35         virtual void OnRehash(User* user, const std::string &param)
36         {
37                 delete Conf;
38                 Conf = new ConfigReader(ServerInstance);
39         }
40
41         virtual ~ModuleDenyChannels()
42         {
43                 delete Conf;
44         }
45         
46         virtual Version GetVersion()
47         {
48                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
49         }
50
51
52         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
53         {
54                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
55                 {
56                         if (match(cname, Conf->ReadValue("badchan","name",j).c_str()))
57                         {
58                                 if (IS_OPER(user) && Conf->ReadFlag("badchan","allowopers",j))
59                                 {
60                                         return 0;
61                                 }
62                                 else
63                                 {
64                                         std::string reason = Conf->ReadValue("badchan","reason",j);
65                                         std::string redirect = Conf->ReadValue("badchan","redirect",j);
66
67                                         for (int j = 0; j < Conf->Enumerate("goodchan"); j++)
68                                         {
69                                                 if (match(cname, Conf->ReadValue("goodchan", "name", j).c_str()))
70                                                 {
71                                                         return 0;
72                                                 }
73                                         }
74                                         
75                                         if (ServerInstance->IsChannel(redirect.c_str()))
76                                         {
77                                                 user->WriteServ("926 %s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick,cname,cname,redirect.c_str(), reason.c_str());
78                                                 Channel::JoinUser(ServerInstance,user,redirect.c_str(),false,"",false,ServerInstance->Time(true));
79                                                 return 1;
80                                         }
81
82                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
83                                         return 1;
84                                 }
85                         }
86                 }
87                 return 0;
88         }
89 };
90
91 MODULE_INIT(ModuleDenyChannels)