]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
- More formatting changes
[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                 bool isoper = strchr(user->modes,'o') ? true : false;
63
64                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
65                 {
66                         irc::string cn = Conf->ReadValue("badchan","name",j).c_str();
67                         irc::string thischan = cname;
68                         if (thischan == cn)
69                         {
70                                 if ((Conf->ReadFlag("badchan","allowopers",j)) && isoper == true)
71                                 {
72                                         return 0;
73                                 }
74                                 else
75                                 {
76                                         std::string reason = Conf->ReadValue("badchan","reason",j);
77                                         WriteServ(user->fd,"926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
78                                         return 1;
79                                 }
80                         }
81                 }
82                 return 0;
83         }
84 };
85
86 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
87
88 class ModuleDenyChannelsFactory : public ModuleFactory
89 {
90  public:
91         ModuleDenyChannelsFactory()
92         {
93         }
94         
95         ~ModuleDenyChannelsFactory()
96         {
97         }
98         
99         virtual Module * CreateModule(Server* Me)
100         {
101                 return new ModuleDenyChannels(Me);
102         }
103         
104 };
105
106
107 extern "C" void * init_module( void )
108 {
109         return new ModuleDenyChannelsFactory;
110 }
111