]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
d5a5baba164f76a26bf1e63aafeb50f589cad009
[user/henk/code/inspircd.git] / src / modules / m_restrictchans.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 using namespace std;
18
19 #include <stdio.h>
20 #include <map>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25 #include "inspircd.h"
26
27 /* $ModDesc: Only opers may create new channels if this module is loaded */
28
29 class ModuleRestrictChans : public Module
30 {
31         Server* Srv;
32
33         std::map<irc::string,int> allowchans;
34
35         void ReadConfig()
36         {
37                 ConfigReader* MyConf = new ConfigReader();
38                 allowchans.clear();
39                 for (int i = 0; i < MyConf->Enumerate("allowchannel"); i++)
40                 {
41                         std::string txt;
42                         txt = MyConf->ReadValue("allowchannel", "name", i);
43                         irc::string channel = txt.c_str();
44                         allowchans[channel] = 1;
45                 }
46                 DELETE(MyConf);
47         }
48
49  public:
50         ModuleRestrictChans(Server* Me)
51                 : Module::Module(Me)
52         {
53                 Srv = Me;
54                 ReadConfig();
55         }
56
57         virtual void OnRehash(const std::string &parameter)
58         {
59                 ReadConfig();
60         }
61
62         void Implements(char* List)
63         {
64                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
65         }
66         
67         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
68         {
69                 irc::string x = cname;
70                 // user is not an oper and its not in the allow list
71                 if ((!*user->oper) && (allowchans.find(x) == allowchans.end()))
72                 {
73                         // channel does not yet exist (record is null, about to be created IF we were to allow it)
74                         if (!chan)
75                         {
76                                 user->WriteServ("530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname);
77                                 return 1;
78                         }
79                 }
80                 return 0;
81         }
82         
83         virtual ~ModuleRestrictChans()
84         {
85         }
86         
87         virtual Version GetVersion()
88         {
89                 return Version(1,0,0,1,VF_VENDOR);
90         }
91 };
92
93
94 class ModuleRestrictChansFactory : public ModuleFactory
95 {
96  public:
97         ModuleRestrictChansFactory()
98         {
99         }
100         
101         ~ModuleRestrictChansFactory()
102         {
103         }
104         
105         virtual Module * CreateModule(Server* Me)
106         {
107                 return new ModuleRestrictChans(Me);
108         }
109         
110 };
111
112
113 extern "C" void * init_module( void )
114 {
115         return new ModuleRestrictChansFactory;
116 }
117