]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
Note: FOR THE MOMENT, this is BROKEN. It wont run right until im done.
[user/henk/code/inspircd.git] / src / modules / m_denychans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20 #include "hashcomp.h"
21 #include "helperfuncs.h"
22 #include "inspircd.h"
23
24 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
25
26 class ModuleDenyChannels : public Module
27 {
28  private:
29
30         Server *Srv;
31         ConfigReader *Conf;
32
33  public:
34         ModuleDenyChannels(InspIRCd* Me) : Module::Module(Me)
35         {
36                 
37                 Conf = new ConfigReader;
38         }
39         
40         virtual void OnRehash(const std::string &param)
41         {
42                 DELETE(Conf);
43                 Conf = new ConfigReader;
44         }
45         
46         virtual ~ModuleDenyChannels()
47         {
48                 DELETE(Conf);
49         }
50         
51         virtual Version GetVersion()
52         {
53                 return Version(1,0,0,1,VF_VENDOR);
54         }
55
56         void Implements(char* List)
57         {
58                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
59         }
60
61         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
62         {
63                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
64                 {
65                         irc::string cn = Conf->ReadValue("badchan","name",j).c_str();
66                         irc::string thischan = cname;
67                         if (thischan == cn)
68                         {
69                                 if ((Conf->ReadFlag("badchan","allowopers",j)) && *user->oper)
70                                 {
71                                         return 0;
72                                 }
73                                 else
74                                 {
75                                         std::string reason = Conf->ReadValue("badchan","reason",j);
76                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
77                                         return 1;
78                                 }
79                         }
80                 }
81                 return 0;
82         }
83 };
84
85 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
86
87 class ModuleDenyChannelsFactory : public ModuleFactory
88 {
89  public:
90         ModuleDenyChannelsFactory()
91         {
92         }
93         
94         ~ModuleDenyChannelsFactory()
95         {
96         }
97         
98         virtual Module * CreateModule(InspIRCd* Me)
99         {
100                 return new ModuleDenyChannels(Me);
101         }
102         
103 };
104
105
106 extern "C" void * init_module( void )
107 {
108         return new ModuleDenyChannelsFactory;
109 }
110