]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
Converted more stuff to 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_denychans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "hashcomp.h"
24 #include "helperfuncs.h"
25
26 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
27
28 class ModuleDenyChannels : public Module
29 {
30  private:
31
32         Server *Srv;
33         ConfigReader *Conf;
34
35  public:
36         ModuleDenyChannels(Server* Me)
37                 : Module::Module(Me)
38         {
39                 Srv = Me;
40                 Conf = new ConfigReader;
41         }
42         
43         virtual ~ModuleDenyChannels()
44         {
45                 delete Conf;
46         }
47         
48         virtual Version GetVersion()
49         {
50                 return Version(1,0,0,1,VF_VENDOR);
51         }
52
53         void Implements(char* List)
54         {
55                 List[I_OnUserPreJoin] = 1;
56         }
57
58         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
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)) && (strchr(user->modes,'o')))
67                                 {
68                                         return 0;
69                                 }
70                                 else
71                                 {
72                                         std::string reason = Conf->ReadValue("badchan","reason",j);
73                                         WriteServ(user->fd,"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(Server* 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