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