]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
Add sanity checks to the ssl modules so that theres no possibility of an out of range...
[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
16 /* $ModDesc: Only opers may create new channels if this module is loaded */
17
18 class ModuleRestrictChans : public Module
19 {
20         
21
22         std::map<irc::string,int> allowchans;
23
24         void ReadConfig()
25         {
26                 ConfigReader* MyConf = new ConfigReader(ServerInstance);
27                 allowchans.clear();
28                 for (int i = 0; i < MyConf->Enumerate("allowchannel"); i++)
29                 {
30                         std::string txt;
31                         txt = MyConf->ReadValue("allowchannel", "name", i);
32                         irc::string channel = txt.c_str();
33                         allowchans[channel] = 1;
34                 }
35                 DELETE(MyConf);
36         }
37
38  public:
39         ModuleRestrictChans(InspIRCd* Me)
40                 : Module(Me)
41         {
42                 
43                 ReadConfig();
44         }
45
46         virtual void OnRehash(userrec* user, const std::string &parameter)
47         {
48                 ReadConfig();
49         }
50
51         void Implements(char* List)
52         {
53                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
54         }
55         
56         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
57         {
58                 irc::string x = cname;
59                 // user is not an oper and its not in the allow list
60                 if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end()))
61                 {
62                         // channel does not yet exist (record is null, about to be created IF we were to allow it)
63                         if (!chan)
64                         {
65                                 user->WriteServ("530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname);
66                                 return 1;
67                         }
68                 }
69                 return 0;
70         }
71         
72         virtual ~ModuleRestrictChans()
73         {
74         }
75         
76         virtual Version GetVersion()
77         {
78                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
79         }
80 };
81
82 MODULE_INIT(ModuleRestrictChans)