]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Some more text fixes and improvements (#1618).
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2005, 2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *   Copyright (C) 2004 Christopher Hall <typobox43@gmail.com>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25 #include "modules/whois.h"
26
27 /** Handle user mode +W
28  */
29 class SeeWhois : public SimpleUserModeHandler
30 {
31  public:
32         SeeWhois(Module* Creator)
33                 : SimpleUserModeHandler(Creator, "showwhois", 'W')
34         {
35         }
36
37         void SetOperOnly(bool operonly)
38         {
39                 oper = operonly;
40         }
41 };
42
43 class WhoisNoticeCmd : public Command
44 {
45  public:
46         WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 2)
47         {
48                 flags_needed = FLAG_SERVERONLY;
49         }
50
51         void HandleFast(User* dest, User* src)
52         {
53                 dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
54                         src->GetHost(dest->HasPrivPermission("users/auspex")) +
55                         ") did a /whois on you");
56         }
57
58         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
59         {
60                 User* dest = ServerInstance->FindNick(parameters[0]);
61                 if (!dest)
62                         return CMD_FAILURE;
63
64                 User* source = ServerInstance->FindNick(parameters[1]);
65
66                 if (IS_LOCAL(dest) && source)
67                         HandleFast(dest, source);
68
69                 return CMD_SUCCESS;
70         }
71 };
72
73 class ModuleShowwhois : public Module, public Whois::EventListener
74 {
75         bool ShowWhoisFromOpers;
76         SeeWhois sw;
77         WhoisNoticeCmd cmd;
78
79  public:
80
81         ModuleShowwhois()
82                 : Whois::EventListener(this)
83                 , sw(this)
84                 , cmd(this)
85         {
86         }
87
88         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
89         {
90                 ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
91
92                 sw.SetOperOnly(tag->getBool("opersonly", true));
93                 ShowWhoisFromOpers = tag->getBool("showfromopers", true);
94         }
95
96         Version GetVersion() CXX11_OVERRIDE
97         {
98                 return Version("Provides user mode +W for opers to see when a user uses WHOIS on them", VF_OPTCOMMON|VF_VENDOR);
99         }
100
101         void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
102         {
103                 User* const source = whois.GetSource();
104                 User* const dest = whois.GetTarget();
105                 if (!dest->IsModeSet(sw) || whois.IsSelfWhois())
106                         return;
107
108                 if (!ShowWhoisFromOpers && source->IsOper())
109                         return;
110
111                 if (IS_LOCAL(dest))
112                 {
113                         cmd.HandleFast(dest, source);
114                 }
115                 else
116                 {
117                         CommandBase::Params params;
118                         params.push_back(dest->uuid);
119                         params.push_back(source->uuid);
120                         ServerInstance->PI->SendEncapsulatedData(dest->server->GetName(), cmd.name, params);
121                 }
122         }
123 };
124
125 MODULE_INIT(ModuleShowwhois)