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