]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
cbd7368691c218c3528280b68f6ac15ced17174c
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "hashcomp.h"
18
19 #include "inspircd.h"
20
21 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
22
23 class ModuleDenyChannels : public Module
24 {
25  private:
26
27         
28         ConfigReader *Conf;
29
30  public:
31         ModuleDenyChannels(InspIRCd* Me) : Module::Module(Me)
32         {
33                 
34                 Conf = new ConfigReader(ServerInstance);
35         }
36         
37         virtual void OnRehash(userrec* user, const std::string &param)
38         {
39                 DELETE(Conf);
40                 Conf = new ConfigReader(ServerInstance);
41         }
42
43         virtual ~ModuleDenyChannels()
44         {
45                 DELETE(Conf);
46         }
47         
48         virtual Version GetVersion()
49         {
50                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
51         }
52
53         void Implements(char* List)
54         {
55                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
56         }
57
58         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
59         {
60                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
61                 {
62                         irc::string cn = Conf->ReadValue("badchan","name",j).c_str();
63                         irc::string thischan = cname;
64                         if (thischan == cn)
65                         {
66                                 if ((Conf->ReadFlag("badchan","allowopers",j)) && *user->oper)
67                                 {
68                                         return 0;
69                                 }
70                                 else
71                                 {
72                                         std::string reason = Conf->ReadValue("badchan","reason",j);
73                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
74                                         return 1;
75                                 }
76                         }
77                 }
78                 return 0;
79         }
80 };
81
82 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
83
84 class ModuleDenyChannelsFactory : public ModuleFactory
85 {
86  public:
87         ModuleDenyChannelsFactory()
88         {
89         }
90         
91         ~ModuleDenyChannelsFactory()
92         {
93         }
94         
95         virtual Module * CreateModule(InspIRCd* Me)
96         {
97                 return new ModuleDenyChannels(Me);
98         }
99         
100 };
101
102
103 extern "C" void * init_module( void )
104 {
105         return new ModuleDenyChannelsFactory;
106 }
107