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