]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_opermodes.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
12  *
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.
16  *
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
20  * details.
21  *
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/>.
24  */
25
26
27 #include "inspircd.h"
28
29 class ModuleModesOnOper : public Module
30 {
31  public:
32         Version GetVersion() CXX11_OVERRIDE
33         {
34                 return Version("Allows the server administrator to set user modes on server operators when they log into their server operator account.", VF_VENDOR);
35         }
36
37         void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
38         {
39                 if (!IS_LOCAL(user))
40                         return;
41
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())
47                 {
48                         ApplyModes(user, ThisOpersModes);
49                 }
50         }
51
52         void ApplyModes(User *u, std::string &smodes)
53         {
54                 char first = *(smodes.c_str());
55                 if ((first != '+') && (first != '-'))
56                         smodes = "+" + smodes;
57
58                 std::string buf;
59                 irc::spacesepstream ss(smodes);
60                 CommandBase::Params modes;
61
62                 modes.push_back(u->nick);
63                 // split into modes and mode params
64                 while (ss.GetToken(buf))
65                         modes.push_back(buf);
66
67                 ServerInstance->Parser.CallHandler("MODE", modes, u);
68         }
69 };
70
71 MODULE_INIT(ModuleModesOnOper)