2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** Handles user mode +H
26 class HideOper : public SimpleUserModeHandler
31 HideOper(Module* Creator) : SimpleUserModeHandler(Creator, "hideoper", 'H')
37 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding)
39 if (SimpleUserModeHandler::OnModeChange(source, dest, channel, parameter, adding) == MODEACTION_DENY)
40 return MODEACTION_DENY;
47 return MODEACTION_ALLOW;
51 class ModuleHideOper : public Module, public Whois::LineEventListener
57 : Whois::LineEventListener(this)
63 Version GetVersion() CXX11_OVERRIDE
65 return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
68 void OnUserQuit(User* user, const std::string&, const std::string&) CXX11_OVERRIDE
70 if (user->IsModeSet(hm))
74 ModResult OnNumeric(User* user, const Numeric::Numeric& numeric) CXX11_OVERRIDE
76 if (numeric.GetNumeric() != 252 || active || user->HasPrivPermission("users/auspex"))
77 return MOD_RES_PASSTHRU;
79 // If there are no visible operators then we shouldn't send the numeric.
80 size_t opercount = ServerInstance->Users->all_opers.size() - hm.opercount;
84 user->WriteNumeric(252, opercount, "operator(s) online");
90 ModResult OnWhoisLine(Whois::Context& whois, unsigned int& numeric, std::string& text) CXX11_OVERRIDE
92 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
93 * person doing the WHOIS is not an oper
96 return MOD_RES_PASSTHRU;
98 if (!whois.GetTarget()->IsModeSet(hm))
99 return MOD_RES_PASSTHRU;
101 if (!whois.GetSource()->HasPrivPermission("users/auspex"))
104 return MOD_RES_PASSTHRU;
107 void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, std::string& line) CXX11_OVERRIDE
109 if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex"))
111 // hide the "*" that marks the user as an oper from the /WHO line
112 std::string::size_type spcolon = line.find(" :");
113 if (spcolon == std::string::npos)
114 return; // Another module hid the user completely
115 std::string::size_type sp = line.rfind(' ', spcolon-1);
116 std::string::size_type pos = line.find('*', sp);
117 if (pos != std::string::npos)
119 // hide the line completely if doing a "/who * o" query
120 if (params.size() > 1 && params[1].find('o') != std::string::npos)
125 ModResult OnStats(char symbol, User* user, string_list& results) CXX11_OVERRIDE
128 return MOD_RES_PASSTHRU;
130 unsigned int count = 0;
131 const UserManager::OperList& opers = ServerInstance->Users->all_opers;
132 for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i)
135 if (!oper->server->IsULine() && (user->IsOper() || !oper->IsModeSet(hm)))
137 LocalUser* lu = IS_LOCAL(oper);
138 results.push_back("249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
139 (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable"));
143 results.push_back("249 "+user->nick+" :"+ConvToStr(count)+" OPER(s)");
149 MODULE_INIT(ModuleHideOper)