2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Craig Edwards <brain@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 * Originally by Chernov-Phoenix Alexey (Phoenix@RusNet) mailto:phoenix /email address separator/ pravmail.ru
32 #define OPERPREFIX_VALUE 1000000
34 class OperPrefixMode : public PrefixMode
37 OperPrefixMode(Module* Creator)
38 : PrefixMode(Creator, "operprefix", 'y', OPERPREFIX_VALUE)
40 prefix = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!", 1, 1)[0];
41 ranktoset = ranktounset = UINT_MAX;
45 class ModuleOperPrefixMode;
46 class HideOperWatcher : public ModeWatcher
48 ModuleOperPrefixMode* parentmod;
51 HideOperWatcher(ModuleOperPrefixMode* parent);
52 void AfterMode(User* source, User* dest, Channel* channel, const std::string ¶meter, bool adding) CXX11_OVERRIDE;
55 class ModuleOperPrefixMode : public Module
58 HideOperWatcher hideoperwatcher;
59 UserModeReference hideopermode;
62 ModuleOperPrefixMode()
63 : opm(this), hideoperwatcher(this)
64 , hideopermode(this, "hideoper")
66 /* To give clients a chance to learn about the new prefix we don't give +y to opers
67 * right now. That means if the module was loaded after opers have joined channels
68 * they need to rejoin them in order to get the oper prefix.
72 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
74 if ((user->IsOper()) && (!user->IsModeSet(hideopermode)))
76 return MOD_RES_PASSTHRU;
79 void OnPostJoin(Membership* memb) CXX11_OVERRIDE
81 if ((!IS_LOCAL(memb->user)) || (!memb->user->IsOper()) || (memb->user->IsModeSet(hideopermode)))
84 if (memb->HasMode(&opm))
87 // The user was force joined and OnUserPreJoin() did not run. Set the operprefix now.
88 Modes::ChangeList changelist;
89 changelist.push_add(&opm, memb->user->nick);
90 ServerInstance->Modes.Process(ServerInstance->FakeClient, memb->chan, NULL, changelist);
93 void SetOperPrefix(User* user, bool add)
95 Modes::ChangeList changelist;
96 changelist.push(&opm, add, user->nick);
97 for (User::ChanList::iterator v = user->chans.begin(); v != user->chans.end(); v++)
98 ServerInstance->Modes->Process(ServerInstance->FakeClient, (*v)->chan, NULL, changelist);
101 void OnPostOper(User* user, const std::string& opername, const std::string& opertype) CXX11_OVERRIDE
103 if (IS_LOCAL(user) && (!user->IsModeSet(hideopermode)))
104 SetOperPrefix(user, true);
107 Version GetVersion() CXX11_OVERRIDE
109 return Version("Adds the server operator-only y (operprefix) channel prefix mode.", VF_VENDOR);
112 void Prioritize() CXX11_OVERRIDE
114 // m_opermodes may set +H on the oper to hide him, we don't want to set the oper prefix in that case
115 Module* opermodes = ServerInstance->Modules->Find("m_opermodes.so");
116 ServerInstance->Modules->SetPriority(this, I_OnPostOper, PRIORITY_AFTER, opermodes);
120 HideOperWatcher::HideOperWatcher(ModuleOperPrefixMode* parent)
121 : ModeWatcher(parent, "hideoper", MODETYPE_USER)
126 void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding)
128 // If hideoper is being unset because the user is deopering, don't set +y
129 if (IS_LOCAL(dest) && dest->IsOper())
130 parentmod->SetOperPrefix(dest, !adding);
133 MODULE_INIT(ModuleOperPrefixMode)