]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_restrictchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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;
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()
40                         {
41
42                 ReadConfig();
43                 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
44                 ServerInstance->Modules->Attach(eventlist, this, 2);
45         }
46
47         virtual void OnRehash(User* user)
48         {
49                 ReadConfig();
50         }
51
52
53         virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
54         {
55                 irc::string x = cname;
56                 if (!IS_LOCAL(user))
57                         return MOD_RES_PASSTHRU;
58
59                 // channel does not yet exist (record is null, about to be created IF we were to allow it)
60                 if (!chan)
61                 {
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                                 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname);
66                                 return MOD_RES_DENY;
67                         }
68                 }
69                 return MOD_RES_PASSTHRU;
70         }
71
72         virtual ~ModuleRestrictChans()
73         {
74         }
75
76         virtual Version GetVersion()
77         {
78                 return Version("Only opers may create new channels if this module is loaded",VF_VENDOR,API_VERSION);
79         }
80 };
81
82 MODULE_INIT(ModuleRestrictChans)