]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
1b72c52c3789bfa314f689d0ee70c91963de8acc
[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         }
32         
33         virtual void OnRehash(userrec* user, const std::string &param)
34         {
35                 DELETE(Conf);
36                 Conf = new ConfigReader(ServerInstance);
37         }
38
39         virtual ~ModuleDenyChannels()
40         {
41                 DELETE(Conf);
42         }
43         
44         virtual Version GetVersion()
45         {
46                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
47         }
48
49         void Implements(char* List)
50         {
51                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
52         }
53
54         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
55         {
56                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
57                 {
58                         if (match(cname, Conf->ReadValue("badchan","name",j).c_str()))
59                         {
60                                 if (IS_OPER(user) && Conf->ReadFlag("badchan","allowopers",j))
61                                 {
62                                         return 0;
63                                 }
64                                 else
65                                 {
66                                         std::string reason = Conf->ReadValue("badchan","reason",j);
67                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
68                                         return 1;
69                                 }
70                         }
71                 }
72                 return 0;
73         }
74 };
75
76 MODULE_INIT(ModuleDenyChannels)