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