]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
Return a Membership* from get_first_visible_channel() in cmd_who and pass that to...
[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
36 {
37         HideOper hm;
38  public:
39         ModuleHideOper()
40                 : hm(this)
41         {
42         }
43
44         Version GetVersion() CXX11_OVERRIDE
45         {
46                 return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
47         }
48
49         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
50         {
51                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
52                  * person doing the WHOIS is not an oper
53                  */
54                 if (numeric != 313)
55                         return MOD_RES_PASSTHRU;
56
57                 if (!dest->IsModeSet(hm))
58                         return MOD_RES_PASSTHRU;
59
60                 if (!user->HasPrivPermission("users/auspex"))
61                         return MOD_RES_DENY;
62
63                 return MOD_RES_PASSTHRU;
64         }
65
66         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, std::string& line) CXX11_OVERRIDE
67         {
68                 if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex"))
69                 {
70                         // hide the "*" that marks the user as an oper from the /WHO line
71                         std::string::size_type pos = line.find("*");
72                         if (pos != std::string::npos)
73                                 line.erase(pos, 1);
74                         // hide the line completely if doing a "/who * o" query
75                         if (params.size() > 1 && params[1].find('o') != std::string::npos)
76                                 line.clear();
77                 }
78         }
79 };
80
81 MODULE_INIT(ModuleHideOper)