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