]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_rmode.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_rmode.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
5  *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #include "inspircd.h"
24 #include "listmode.h"
25
26 /** Handle /RMODE
27  */
28 class CommandRMode : public Command
29 {
30  public:
31         CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
32         {
33                 allow_empty_last_param = false;
34                 syntax = "<channel> <mode> [<pattern>]";
35         }
36
37         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
38         {
39                 ModeHandler* mh;
40                 Channel* chan = ServerInstance->FindChan(parameters[0]);
41                 char modeletter = parameters[1][0];
42
43                 if (chan == NULL)
44                 {
45                         user->WriteNotice("The channel " + parameters[0] + " does not exist.");
46                         return CMD_FAILURE;
47                 }
48
49                 mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
50                 if (mh == NULL || parameters[1].size() > 1)
51                 {
52                         user->WriteNotice(parameters[1] + " is not a valid channel mode.");
53                         return CMD_FAILURE;
54                 }
55
56                 if (chan->GetPrefixValue(user) < mh->GetLevelRequired(false))
57                 {
58                         user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " +  chan->name + ".");
59                         return CMD_FAILURE;
60                 }
61
62                 std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
63                 PrefixMode* pm;
64                 ListModeBase* lm;
65                 ListModeBase::ModeList* ml;
66                 Modes::ChangeList changelist;
67
68                 if ((pm = mh->IsPrefixMode()))
69                 {
70                         // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
71                         const Channel::MemberMap& users = chan->GetUsers();
72                         for (Channel::MemberMap::const_iterator it = users.begin(); it != users.end(); ++it)
73                         {
74                                 if (!InspIRCd::Match(it->first->nick, pattern))
75                                         continue;
76                                 if (it->second->HasMode(pm) && !((it->first == user) && (pm->GetPrefixRank() > VOICE_VALUE)))
77                                         changelist.push_remove(mh, it->first->nick);
78                         }
79                 }
80                 else if ((lm = mh->IsListModeBase()) && ((ml = lm->GetList(chan)) != NULL))
81                 {
82                         for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
83                         {
84                                 if (!InspIRCd::Match(it->mask, pattern))
85                                         continue;
86                                 changelist.push_remove(mh, it->mask);
87                         }
88                 }
89                 else
90                 {
91                         if (chan->IsModeSet(mh))
92                                 changelist.push_remove(mh);
93                 }
94
95                 ServerInstance->Modes->Process(user, chan, NULL, changelist);
96                 return CMD_SUCCESS;
97         }
98 };
99
100 class ModuleRMode : public Module
101 {
102         CommandRMode cmd;
103
104  public:
105         ModuleRMode() : cmd(this) { }
106
107         Version GetVersion() CXX11_OVERRIDE
108         {
109                 return Version("Allows removal of channel list modes using glob patterns.", VF_VENDOR);
110         }
111 };
112
113 MODULE_INIT(ModuleRMode)