1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 
25 #include "inspircd.h"
26 #include "commands.h"
27 #include "treeserver.h"
28 #include "utils.h"
29 
30 /** Because the core won't let users or even SERVERS set +o,
31  * we use the OPERTYPE command to do this.
32  */
HandleRemote(RemoteUser * u,CommandBase::Params & params)33 CmdResult CommandOpertype::HandleRemote(RemoteUser* u, CommandBase::Params& params)
34 {
35 	const std::string& opertype = params[0];
36 	if (!u->IsOper())
37 		ServerInstance->Users->all_opers.push_back(u);
38 
39 	ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
40 	if (opermh)
41 		u->SetMode(opermh, true);
42 
43 	ServerConfig::OperIndex::const_iterator iter = ServerInstance->Config->OperTypes.find(opertype);
44 	if (iter != ServerInstance->Config->OperTypes.end())
45 		u->oper = iter->second;
46 	else
47 		u->oper = new OperInfo(opertype);
48 
49 	if (Utils->quiet_bursts)
50 	{
51 		/*
52 		 * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
53 		 * then do nothing. -- w00t
54 		 */
55 		TreeServer* remoteserver = TreeServer::Get(u);
56 		if (remoteserver->IsBehindBursting() || remoteserver->IsSilentULine())
57 			return CMD_SUCCESS;
58 	}
59 
60 	ServerInstance->SNO->WriteToSnoMask('O', "From %s: User %s (%s@%s) is now a server operator of type %s", u->server->GetName().c_str(), u->nick.c_str(),u->ident.c_str(), u->GetRealHost().c_str(), opertype.c_str());
61 	return CMD_SUCCESS;
62 }
63 
Builder(User * user)64 CommandOpertype::Builder::Builder(User* user)
65 	: CmdBuilder(user, "OPERTYPE")
66 {
67 	push_last(user->oper->name);
68 }
69