]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hideoper.cpp
Release v2.0.19
[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 SimpleUserModeHandler
29 {
30  public:
31         HideOper(Module* Creator) : SimpleUserModeHandler(Creator, "hideoper", 'H')
32         {
33                 oper = true;
34         }
35 };
36
37 class ModuleHideOper : public Module
38 {
39         HideOper hm;
40  public:
41         ModuleHideOper()
42                 : hm(this)
43         {
44         }
45
46         void init()
47         {
48                 ServerInstance->Modules->AddService(hm);
49                 Implementation eventlist[] = { I_OnWhoisLine, I_OnSendWhoLine, I_OnStats };
50                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
51         }
52
53
54         virtual ~ModuleHideOper()
55         {
56         }
57
58         virtual Version GetVersion()
59         {
60                 return Version("Provides support for hiding oper status with user mode +H", VF_VENDOR);
61         }
62
63         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
64         {
65                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
66                  * person doing the WHOIS is not an oper
67                  */
68                 if (numeric != 313)
69                         return MOD_RES_PASSTHRU;
70
71                 if (!dest->IsModeSet('H'))
72                         return MOD_RES_PASSTHRU;
73
74                 if (!user->HasPrivPermission("users/auspex"))
75                         return MOD_RES_DENY;
76
77                 return MOD_RES_PASSTHRU;
78         }
79
80         void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
81         {
82                 if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
83                 {
84                         // hide the "*" that marks the user as an oper from the /WHO line
85                         std::string::size_type spcolon = line.find(" :");
86                         if (spcolon == std::string::npos)
87                                 return; // Another module hid the user completely
88                         std::string::size_type sp = line.rfind(' ', spcolon-1);
89                         std::string::size_type pos = line.find('*', sp);
90                         if (pos != std::string::npos)
91                                 line.erase(pos, 1);
92                         // hide the line completely if doing a "/who * o" query
93                         if (params.size() > 1 && params[1].find('o') != std::string::npos)
94                                 line.clear();
95                 }
96         }
97
98         ModResult OnStats(char symbol, User* user, string_list &results)
99         {
100                 if (symbol != 'P')
101                         return MOD_RES_PASSTHRU;
102
103                 unsigned int count = 0;
104                 for (std::list<User*>::const_iterator i = ServerInstance->Users->all_opers.begin(); i != ServerInstance->Users->all_opers.end(); ++i)
105                 {
106                         User* oper = *i;
107                         if (!ServerInstance->ULine(oper->server) && (IS_OPER(user) || !oper->IsModeSet('H')))
108                         {
109                                 results.push_back(ServerInstance->Config->ServerName+" 249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
110                                                 (IS_LOCAL(oper) ? ConvToStr(ServerInstance->Time() - oper->idle_lastmsg) + " secs" : "unavailable"));
111                                 count++;
112                         }
113                 }
114                 results.push_back(ServerInstance->Config->ServerName+" 249 "+user->nick+" :"+ConvToStr(count)+" OPER(s)");
115
116                 return MOD_RES_DENY;
117         }
118 };
119
120
121 MODULE_INIT(ModuleHideOper)