]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
Header update: 2007 -> 2008
[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                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
66                                         return 1;
67                                 }
68                         }
69                 }
70                 return 0;
71         }
72 };
73
74 MODULE_INIT(ModuleDenyChannels)