2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2004-2005 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
27 class CommandSamode : public Command
33 CommandSamode(Module* Creator) : Command(Creator,"SAMODE", 2)
35 allow_empty_last_param = false;
36 flags_needed = 'o'; syntax = "<target> (+|-)<modes> [<mode-parameters>]";
40 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
42 if (parameters[0].c_str()[0] != '#')
44 User* target = ServerInstance->FindNickOnly(parameters[0]);
45 if ((!target) || (target->registered != REG_ALL))
47 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
51 // Changing the modes of another user requires a special permission
52 if ((target != user) && (!user->HasPrivPermission("users/samode-usermodes", true)))
56 // XXX: Make ModeParser clear LastParse
57 Modes::ChangeList emptychangelist;
58 ServerInstance->Modes->ProcessSingle(ServerInstance->FakeClient, NULL, ServerInstance->FakeClient, emptychangelist);
62 ServerInstance->Parser.CallHandler("MODE", parameters, user);
67 // If we haven't logged anything yet then the client queried the list of a listmode
68 // (e.g. /SAMODE #chan b), which was handled internally by the MODE command handler.
70 // Viewing the modes of a user or a channel could also result in this, but
71 // that is not possible with /SAMODE because we require at least 2 parameters.
72 LogUsage(user, stdalgo::string::join(parameters));
78 void LogUsage(const User* user, const std::string& text)
81 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SAMODE: " + text);
85 class ModuleSaMode : public Module
94 Version GetVersion() CXX11_OVERRIDE
96 return Version("Provides command SAMODE to allow opers to change modes on channels and users", VF_VENDOR);
99 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
102 return MOD_RES_ALLOW;
103 return MOD_RES_PASSTHRU;
106 void OnMode(User* user, User* destuser, Channel* destchan, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) CXX11_OVERRIDE
111 std::string logtext = (destuser ? destuser->nick : destchan->name);
112 logtext.push_back(' ');
113 logtext += ClientProtocol::Messages::Mode::ToModeLetters(modes);
115 for (Modes::ChangeList::List::const_iterator i = modes.getlist().begin(); i != modes.getlist().end(); ++i)
117 const Modes::Change& item = *i;
118 if (!item.param.empty())
119 logtext.append(1, ' ').append(item.param);
122 cmd.LogUsage(user, logtext);
125 void Prioritize() CXX11_OVERRIDE
127 Module* disable = ServerInstance->Modules->Find("m_disable.so");
128 ServerInstance->Modules->SetPriority(this, I_OnRawMode, PRIORITY_BEFORE, disable);
130 Module *override = ServerInstance->Modules->Find("m_override.so");
131 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_BEFORE, override);
135 MODULE_INIT(ModuleSaMode)