]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_denychans.cpp
Change to IS_OPER, also modify to use short circuit evaluation (simple char check...
[user/henk/code/inspircd.git] / src / modules / m_denychans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "hashcomp.h"
18 #include "inspircd.h"
19 #include "wildcard.h"
20
21 /* $ModDesc: Implements config tags which allow blocking of joins to channels */
22
23 class ModuleDenyChannels : public Module
24 {
25  private:
26
27         
28         ConfigReader *Conf;
29
30  public:
31         ModuleDenyChannels(InspIRCd* Me) : Module::Module(Me)
32         {
33                 
34                 Conf = new ConfigReader(ServerInstance);
35         }
36         
37         virtual void OnRehash(userrec* user, const std::string &param)
38         {
39                 DELETE(Conf);
40                 Conf = new ConfigReader(ServerInstance);
41         }
42
43         virtual ~ModuleDenyChannels()
44         {
45                 DELETE(Conf);
46         }
47         
48         virtual Version GetVersion()
49         {
50                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
51         }
52
53         void Implements(char* List)
54         {
55                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
56         }
57
58         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
59         {
60                 for (int j =0; j < Conf->Enumerate("badchan"); j++)
61                 {
62                         if (match(cname, Conf->ReadValue("badchan","name",j).c_str()))
63                         {
64                                 if (IS_OPER(user) && Conf->ReadFlag("badchan","allowopers",j))
65                                 {
66                                         return 0;
67                                 }
68                                 else
69                                 {
70                                         std::string reason = Conf->ReadValue("badchan","reason",j);
71                                         user->WriteServ("926 %s %s :Channel %s is forbidden: %s",user->nick,cname,cname,reason.c_str());
72                                         return 1;
73                                 }
74                         }
75                 }
76                 return 0;
77         }
78 };
79
80 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
81
82 class ModuleDenyChannelsFactory : public ModuleFactory
83 {
84  public:
85         ModuleDenyChannelsFactory()
86         {
87         }
88         
89         ~ModuleDenyChannelsFactory()
90         {
91         }
92         
93         virtual Module * CreateModule(InspIRCd* Me)
94         {
95                 return new ModuleDenyChannels(Me);
96         }
97         
98 };
99
100
101 extern "C" void * init_module( void )
102 {
103         return new ModuleDenyChannelsFactory;
104 }
105