]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
Merge pull request #1139 from johanna-a/master
[user/henk/code/inspircd.git] / src / modules / m_hideoper.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handles user mode +H
25  */
26 class HideOper : public SimpleUserModeHandler
27 {
28  public:
29         HideOper(Module* Creator) : SimpleUserModeHandler(Creator, "hideoper", 'H')
30         {
31                 oper = true;
32         }
33 };
34
35 class ModuleHideOper : public Module, public Whois::LineEventListener
36 {
37         HideOper hm;
38  public:
39         ModuleHideOper()
40                 : Whois::LineEventListener(this)
41                 , hm(this)
42         {
43         }
44
45         Version GetVersion() CXX11_OVERRIDE
46         {
47                 return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
48         }
49
50         ModResult OnWhoisLine(Whois::Context& whois, unsigned int& numeric, std::string& text) CXX11_OVERRIDE
51         {
52                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
53                  * person doing the WHOIS is not an oper
54                  */
55                 if (numeric != 313)
56                         return MOD_RES_PASSTHRU;
57
58                 if (!whois.GetTarget()->IsModeSet(hm))
59                         return MOD_RES_PASSTHRU;
60
61                 if (!whois.GetSource()->HasPrivPermission("users/auspex"))
62                         return MOD_RES_DENY;
63
64                 return MOD_RES_PASSTHRU;
65         }
66
67         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, std::string& line) CXX11_OVERRIDE
68         {
69                 if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex"))
70                 {
71                         // hide the "*" that marks the user as an oper from the /WHO line
72                         std::string::size_type spcolon = line.find(" :");
73                         if (spcolon == std::string::npos)
74                                 return; // Another module hid the user completely
75                         std::string::size_type sp = line.rfind(' ', spcolon-1);
76                         std::string::size_type pos = line.find('*', sp);
77                         if (pos != std::string::npos)
78                                 line.erase(pos, 1);
79                         // hide the line completely if doing a "/who * o" query
80                         if (params.size() > 1 && params[1].find('o') != std::string::npos)
81                                 line.clear();
82                 }
83         }
84
85         ModResult OnStats(char symbol, User* user, string_list& results) CXX11_OVERRIDE
86         {
87                 if (symbol != 'P')
88                         return MOD_RES_PASSTHRU;
89
90                 unsigned int count = 0;
91                 const UserManager::OperList& opers = ServerInstance->Users->all_opers;
92                 for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i)
93                 {
94                         User* oper = *i;
95                         if (!oper->server->IsULine() && (user->IsOper() || !oper->IsModeSet(hm)))
96                         {
97                                 LocalUser* lu = IS_LOCAL(oper);
98                                 results.push_back("249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
99                                                 (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable"));
100                                 count++;
101                         }
102                 }
103                 results.push_back("249 "+user->nick+" :"+ConvToStr(count)+" OPER(s)");
104
105                 return MOD_RES_DENY;
106         }
107 };
108
109 MODULE_INIT(ModuleHideOper)