2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
6 * Copyright (C) 2012-2016, 2018 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class CommandSamode : public Command
37 CommandSamode(Module* Creator) : Command(Creator,"SAMODE", 2)
39 allow_empty_last_param = false;
41 syntax = "<target> (+|-)<modes> [<mode-parameters>]";
45 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
47 if (parameters[0].c_str()[0] != '#')
49 User* target = ServerInstance->FindNickOnly(parameters[0]);
50 if ((!target) || (target->registered != REG_ALL))
52 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
56 // Changing the modes of another user requires a special permission
57 if ((target != user) && (!user->HasPrivPermission("users/samode-usermodes")))
59 user->WriteNotice("*** You are not allowed to /SAMODE other users (the privilege users/samode-usermodes is needed to /SAMODE others).");
64 // XXX: Make ModeParser clear LastParse
65 Modes::ChangeList emptychangelist;
66 ServerInstance->Modes->ProcessSingle(ServerInstance->FakeClient, NULL, ServerInstance->FakeClient, emptychangelist);
70 ServerInstance->Parser.CallHandler("MODE", parameters, user);
75 // If we haven't logged anything yet then the client queried the list of a listmode
76 // (e.g. /SAMODE #chan b), which was handled internally by the MODE command handler.
78 // Viewing the modes of a user or a channel could also result in this, but
79 // that is not possible with /SAMODE because we require at least 2 parameters.
80 LogUsage(user, stdalgo::string::join(parameters));
86 void LogUsage(const User* user, const std::string& text)
89 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SAMODE: " + text);
93 class ModuleSaMode : public Module
102 Version GetVersion() CXX11_OVERRIDE
104 return Version("Adds the /SAMODE command which allows server operators to change the modes of a target (channel, user) that they would not otherwise have the privileges to change.", VF_VENDOR);
107 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
110 return MOD_RES_ALLOW;
111 return MOD_RES_PASSTHRU;
114 void OnMode(User* user, User* destuser, Channel* destchan, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) CXX11_OVERRIDE
119 std::string logtext = (destuser ? destuser->nick : destchan->name);
120 logtext.push_back(' ');
121 logtext += ClientProtocol::Messages::Mode::ToModeLetters(modes);
123 for (Modes::ChangeList::List::const_iterator i = modes.getlist().begin(); i != modes.getlist().end(); ++i)
125 const Modes::Change& item = *i;
126 if (!item.param.empty())
127 logtext.append(1, ' ').append(item.param);
130 cmd.LogUsage(user, logtext);
133 void Prioritize() CXX11_OVERRIDE
135 Module* disable = ServerInstance->Modules->Find("m_disable.so");
136 ServerInstance->Modules->SetPriority(this, I_OnRawMode, PRIORITY_BEFORE, disable);
138 Module *override = ServerInstance->Modules->Find("m_override.so");
139 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_BEFORE, override);
143 MODULE_INIT(ModuleSaMode)