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