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