]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
Add Base64 encode/decode functions to the core
[user/henk/code/inspircd.git] / src / modules / m_restrictchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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         std::set<irc::string> allowchans;
21
22         void ReadConfig()
23         {
24                 allowchans.clear();
25                 ConfigTagList tags = ServerInstance->Config->ConfTags("allowchannel");
26                 for(ConfigIter i = tags.first; i != tags.second; ++i)
27                 {
28                         ConfigTag* tag = i->second;
29                         std::string txt = tag->getString("name");
30                         allowchans.insert(txt.c_str());
31                 }
32         }
33
34  public:
35         ModuleRestrictChans()
36         {
37                 ReadConfig();
38                 Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash };
39                 ServerInstance->Modules->Attach(eventlist, this, 2);
40         }
41
42         virtual void OnRehash(User* user)
43         {
44                 ReadConfig();
45         }
46
47
48         virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
49         {
50                 irc::string x = cname;
51                 if (!IS_LOCAL(user))
52                         return MOD_RES_PASSTHRU;
53
54                 // channel does not yet exist (record is null, about to be created IF we were to allow it)
55                 if (!chan)
56                 {
57                         // user is not an oper and its not in the allow list
58                         if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end()))
59                         {
60                                 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Only IRC operators may create new channels",user->nick.c_str(),cname);
61                                 return MOD_RES_DENY;
62                         }
63                 }
64                 return MOD_RES_PASSTHRU;
65         }
66
67         virtual ~ModuleRestrictChans()
68         {
69         }
70
71         virtual Version GetVersion()
72         {
73                 return Version("Only opers may create new channels if this module is loaded",VF_VENDOR);
74         }
75 };
76
77 MODULE_INIT(ModuleRestrictChans)