2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2012-2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
9 * Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
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"
32 RPL_WHOISSPECIAL = 320
37 class CommandSwhois : public Command
40 LocalIntExt operblock;
42 CommandSwhois(Module* Creator)
43 : Command(Creator, "SWHOIS", 2, 2)
44 , operblock("swhois_operblock", ExtensionItem::EXT_USER, Creator)
45 , swhois("swhois", ExtensionItem::EXT_USER, Creator)
48 syntax = "<nick> :<swhois>";
49 TRANSLATE2(TR_NICK, TR_TEXT);
52 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
54 User* dest = ServerInstance->FindNick(parameters[0]);
56 if (!dest) // allow setting swhois using SWHOIS before reg
58 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
62 std::string* text = swhois.get(dest);
65 // We already had it set...
66 if (!user->server->IsULine())
67 // Ulines set SWHOISes silently
68 ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick.c_str(), dest->nick.c_str(), text->c_str(), parameters[1].c_str());
70 else if (!user->server->IsULine())
72 // Ulines set SWHOISes silently
73 ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois to '%s'", user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str());
76 operblock.set(user, 0);
77 if (parameters[1].empty())
80 swhois.set(dest, parameters[1]);
82 /* Bug #376 - feature request -
83 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
84 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
85 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
88 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
95 class ModuleSWhois : public Module, public Whois::LineEventListener
101 : Whois::LineEventListener(this)
106 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
107 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
109 /* We use this and not OnWhois because this triggers for remote, too */
110 if (numeric.GetNumeric() == 312)
112 /* Insert our numeric before 312 */
113 std::string* swhois = cmd.swhois.get(whois.GetTarget());
116 whois.SendLine(RPL_WHOISSPECIAL, *swhois);
120 /* Dont block anything */
121 return MOD_RES_PASSTHRU;
124 void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
129 std::string swhois = user->oper->getConfig("swhois");
131 if (!swhois.length())
134 cmd.operblock.set(user, 1);
135 cmd.swhois.set(user, swhois);
136 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
139 void OnPostDeoper(User* user) CXX11_OVERRIDE
141 std::string* swhois = cmd.swhois.get(user);
145 if (!cmd.operblock.get(user))
148 cmd.operblock.set(user, 0);
149 cmd.swhois.unset(user);
150 ServerInstance->PI->SendMetaData(user, "swhois", "");
153 void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string&) CXX11_OVERRIDE
155 User* dest = static_cast<User*>(target);
156 if (dest && (extname == "swhois"))
157 cmd.operblock.set(dest, 0);
160 Version GetVersion() CXX11_OVERRIDE
162 return Version("Adds the /SWHOIS command which adds custom lines to a user's WHOIS response.", VF_OPTCOMMON | VF_VENDOR);
166 MODULE_INIT(ModuleSWhois)