]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_exemptchanops.cpp
Update the cloaks of connected users when their IP address changes.
[user/henk/code/inspircd.git] / src / modules / m_exemptchanops.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "listmode.h"
22 #include "modules/exemption.h"
23
24 /** Handles channel mode +X
25  */
26 class ExemptChanOps : public ListModeBase
27 {
28  public:
29         ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
30
31         bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE {
32                 std::string::size_type p = word.find(':');
33                 if (p == std::string::npos)
34                 {
35                         user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Invalid exemptchanops entry, format is <restriction>:<prefix>"));
36                         return false;
37                 }
38
39                 std::string restriction(word, 0, p);
40                 // If there is a '-' in the restriction string ignore it and everything after it
41                 // to support "auditorium-vis" and "auditorium-see" in m_auditorium
42                 p = restriction.find('-');
43                 if (p != std::string::npos)
44                         restriction.erase(p);
45
46                 if (!ServerInstance->Modes->FindMode(restriction, MODETYPE_CHANNEL))
47                 {
48                         user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction"));
49                         return false;
50                 }
51
52                 return true;
53         }
54 };
55
56 class ExemptHandler : public CheckExemption::EventListener
57 {
58  public:
59         ExemptChanOps ec;
60         ExemptHandler(Module* me)
61                 : CheckExemption::EventListener(me)
62                 , ec(me)
63         {
64         }
65
66         PrefixMode* FindMode(const std::string& mid)
67         {
68                 if (mid.length() == 1)
69                         return ServerInstance->Modes->FindPrefixMode(mid[0]);
70
71                 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
72                 return mh ? mh->IsPrefixMode() : NULL;
73         }
74
75         ModResult OnCheckExemption(User* user, Channel* chan, const std::string& restriction) CXX11_OVERRIDE
76         {
77                 unsigned int mypfx = chan->GetPrefixValue(user);
78                 std::string minmode;
79
80                 ListModeBase::ModeList* list = ec.GetList(chan);
81
82                 if (list)
83                 {
84                         for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
85                         {
86                                 std::string::size_type pos = (*i).mask.find(':');
87                                 if (pos == std::string::npos)
88                                         continue;
89                                 if (!i->mask.compare(0, pos, restriction))
90                                         minmode.assign(i->mask, pos + 1, std::string::npos);
91                         }
92                 }
93
94                 PrefixMode* mh = FindMode(minmode);
95                 if (mh && mypfx >= mh->GetPrefixRank())
96                         return MOD_RES_ALLOW;
97                 if (mh || minmode == "*")
98                         return MOD_RES_DENY;
99
100                 return MOD_RES_PASSTHRU;
101         }
102 };
103
104 class ModuleExemptChanOps : public Module
105 {
106         ExemptHandler eh;
107
108  public:
109         ModuleExemptChanOps() : eh(this)
110         {
111         }
112
113         Version GetVersion() CXX11_OVERRIDE
114         {
115                 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
116         }
117
118         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
119         {
120                 eh.ec.DoRehash();
121         }
122 };
123
124 MODULE_INIT(ModuleExemptChanOps)