2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
27 #include "modules/whois.h"
29 /** Handle user mode +W
31 class SeeWhois : public SimpleUserModeHandler
34 SeeWhois(Module* Creator)
35 : SimpleUserModeHandler(Creator, "showwhois", 'W')
39 void SetOperOnly(bool operonly)
45 class WhoisNoticeCmd : public Command
48 WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 2)
50 flags_needed = FLAG_SERVERONLY;
53 void HandleFast(User* dest, User* src)
55 dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
56 src->GetHost(dest->HasPrivPermission("users/auspex")) +
57 ") did a /whois on you");
60 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
62 User* dest = ServerInstance->FindNick(parameters[0]);
66 User* source = ServerInstance->FindNick(parameters[1]);
68 if (IS_LOCAL(dest) && source)
69 HandleFast(dest, source);
75 class ModuleShowwhois : public Module, public Whois::EventListener
77 bool ShowWhoisFromOpers;
84 : Whois::EventListener(this)
90 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
92 ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
94 sw.SetOperOnly(tag->getBool("opersonly", true));
95 ShowWhoisFromOpers = tag->getBool("showfromopers", true);
98 Version GetVersion() CXX11_OVERRIDE
100 return Version("Provides user mode +W for opers to see when a user uses WHOIS on them", VF_OPTCOMMON|VF_VENDOR);
103 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
105 User* const source = whois.GetSource();
106 User* const dest = whois.GetTarget();
107 if (!dest->IsModeSet(sw) || whois.IsSelfWhois())
110 if (!ShowWhoisFromOpers && source->IsOper())
115 cmd.HandleFast(dest, source);
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);
127 MODULE_INIT(ModuleShowwhois)