]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
e0b3829bd07be092251ddbb8bed677c90a8bd550
[user/henk/code/inspircd.git] / src / modules / m_denychans.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 #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         void Implements(char* List)
52         {
53                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
54         }
55
56         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
57         {
58                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
59                 {
60                         if (match(cname, Conf->ReadValue("badchan","name",j).c_str()))
61                         {
62                                 if (IS_OPER(user) && Conf->ReadFlag("badchan","allowopers",j))
63                                 {
64                                         return 0;
65                                 }
66                                 else
67                                 {
68                                         std::string reason = Conf->ReadValue("badchan","reason",j);
69                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
70                                         return 1;
71                                 }
72                         }
73                 }
74                 return 0;
75         }
76 };
77
78 MODULE_INIT(ModuleDenyChannels)