]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
99774563d3d827a7b7612210afb8eb8962c7e87d
[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
26 /** Handle user mode +W
27  */
28 class SeeWhois : public SimpleUserModeHandler
29 {
30  public:
31         SeeWhois(Module* Creator)
32                 : SimpleUserModeHandler(Creator, "showwhois", 'W')
33         {
34         }
35
36         void SetOperOnly(bool operonly)
37         {
38                 oper = operonly;
39         }
40 };
41
42 class WhoisNoticeCmd : public Command
43 {
44  public:
45         WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 2)
46         {
47                 flags_needed = FLAG_SERVERONLY;
48         }
49
50         void HandleFast(User* dest, User* src)
51         {
52                 dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
53                         src->GetHost(dest->HasPrivPermission("users/auspex")) + 
54                         ") did a /whois on you");
55         }
56
57         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
58         {
59                 User* dest = ServerInstance->FindNick(parameters[0]);
60                 if (!dest)
61                         return CMD_FAILURE;
62
63                 User* source = ServerInstance->FindNick(parameters[1]);
64
65                 if (IS_LOCAL(dest) && source)
66                         HandleFast(dest, source);
67
68                 return CMD_SUCCESS;
69         }
70 };
71
72 class ModuleShowwhois : public Module, public Whois::EventListener
73 {
74         bool ShowWhoisFromOpers;
75         SeeWhois sw;
76         WhoisNoticeCmd cmd;
77
78  public:
79
80         ModuleShowwhois()
81                 : Whois::EventListener(this)
82                 , sw(this)
83                 , cmd(this)
84         {
85         }
86
87         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
88         {
89                 ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
90
91                 sw.SetOperOnly(tag->getBool("opersonly", true));
92                 ShowWhoisFromOpers = tag->getBool("showfromopers", true);
93         }
94
95         Version GetVersion() CXX11_OVERRIDE
96         {
97                 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
98         }
99
100         void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
101         {
102                 User* const source = whois.GetSource();
103                 User* const dest = whois.GetTarget();
104                 if (!dest->IsModeSet(sw) || whois.IsSelfWhois())
105                         return;
106
107                 if (!ShowWhoisFromOpers && source->IsOper())
108                         return;
109
110                 if (IS_LOCAL(dest))
111                 {
112                         cmd.HandleFast(dest, source);
113                 }
114                 else
115                 {
116                         std::vector<std::string> params;
117                         params.push_back(dest->uuid);
118                         params.push_back(source->uuid);
119                         ServerInstance->PI->SendEncapsulatedData(dest->server->GetName(), cmd.name, params);
120                 }
121         }
122 };
123
124 MODULE_INIT(ModuleShowwhois)