2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2005, 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/>.
29 class ModuleModesOnOper : public Module
32 Version GetVersion() CXX11_OVERRIDE
34 return Version("Allows the server administrator to set user modes on server operators when they log into their server operator account.", VF_VENDOR);
37 void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
42 // whenever a user opers, go through the oper types, find their <type:modes>,
43 // and if they have one apply their modes. The mode string can contain +modes
44 // to add modes to the user or -modes to take modes from the user.
45 std::string ThisOpersModes = user->oper->getConfig("modes");
46 if (!ThisOpersModes.empty())
48 ApplyModes(user, ThisOpersModes);
52 void ApplyModes(User *u, std::string &smodes)
54 char first = *(smodes.c_str());
55 if ((first != '+') && (first != '-'))
56 smodes = "+" + smodes;
59 irc::spacesepstream ss(smodes);
60 CommandBase::Params modes;
62 modes.push_back(u->nick);
63 // split into modes and mode params
64 while (ss.GetToken(buf))
67 ServerInstance->Parser.CallHandler("MODE", modes, u);
71 MODULE_INIT(ModuleModesOnOper)