]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
Merge pull request #131 from attilamolnar/insp20+hideroperwhofix
[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 /* $ModDesc: Provides support for hiding oper status with user mode +H */
25
26 /** Handles user mode +H
27  */
28 class HideOper : public ModeHandler
29 {
30  public:
31         HideOper(Module* Creator) : ModeHandler(Creator, "hideoper", 'H', PARAM_NONE, MODETYPE_USER)
32         {
33                 oper = true;
34         }
35
36         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
37         {
38                 if (adding)
39                 {
40                         if (!dest->IsModeSet('H'))
41                         {
42                                 dest->SetMode('H',true);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46                 else
47                 {
48                         if (dest->IsModeSet('H'))
49                         {
50                                 dest->SetMode('H',false);
51                                 return MODEACTION_ALLOW;
52                         }
53                 }
54
55                 return MODEACTION_DENY;
56         }
57 };
58
59 class ModuleHideOper : public Module
60 {
61         HideOper hm;
62  public:
63         ModuleHideOper()
64                 : hm(this)
65         {
66                 if (!ServerInstance->Modes->AddMode(&hm))
67                         throw ModuleException("Could not add new modes!");
68                 Implementation eventlist[] = { I_OnWhoisLine, I_OnSendWhoLine };
69                 ServerInstance->Modules->Attach(eventlist, this, 2);
70         }
71
72
73         virtual ~ModuleHideOper()
74         {
75         }
76
77         virtual Version GetVersion()
78         {
79                 return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
80         }
81
82         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
83         {
84                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
85                  * person doing the WHOIS is not an oper
86                  */
87                 if (numeric != 313)
88                         return MOD_RES_PASSTHRU;
89
90                 if (!dest->IsModeSet('H'))
91                         return MOD_RES_PASSTHRU;
92
93                 if (!user->HasPrivPermission("users/auspex"))
94                         return MOD_RES_DENY;
95
96                 return MOD_RES_PASSTHRU;
97         }
98
99         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
100         {
101                 if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
102                 {
103                         // hide the "*" that marks the user as an oper from the /WHO line
104                         std::string::size_type pos = line.find("*");
105                         if (pos != std::string::npos)
106                                 line.erase(pos, 1);
107                         // hide the line completely if doing a "/who * o" query
108                         if (params.size() > 1 && params[1].find('o') != std::string::npos)
109                                 line.clear();
110                 }
111         }
112 };
113
114
115 MODULE_INIT(ModuleHideOper)