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 Dennis Friis <peavey@inspircd.org>
10 * Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
11 * Copyright (C) 2005, 2007, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "modules/whois.h"
33 RPL_WHOISSPECIAL = 320
38 class CommandSwhois : public Command
41 LocalIntExt operblock;
43 CommandSwhois(Module* Creator)
44 : Command(Creator, "SWHOIS", 2, 2)
45 , operblock("swhois_operblock", ExtensionItem::EXT_USER, Creator)
46 , swhois("swhois", ExtensionItem::EXT_USER, Creator)
49 syntax = "<nick> :<swhois>";
50 TRANSLATE2(TR_NICK, TR_TEXT);
53 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
55 User* dest = ServerInstance->FindNick(parameters[0]);
57 if (!dest) // allow setting swhois using SWHOIS before reg
59 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
63 std::string* text = swhois.get(dest);
66 // We already had it set...
67 if (!user->server->IsULine())
68 // Ulines set SWHOISes silently
69 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());
71 else if (!user->server->IsULine())
73 // Ulines set SWHOISes silently
74 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());
77 operblock.set(user, 0);
78 if (parameters[1].empty())
81 swhois.set(dest, parameters[1]);
83 /* Bug #376 - feature request -
84 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
85 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
86 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
89 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
96 class ModuleSWhois : public Module, public Whois::LineEventListener
102 : Whois::LineEventListener(this)
107 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
108 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
110 /* We use this and not OnWhois because this triggers for remote, too */
111 if (numeric.GetNumeric() == 312)
113 /* Insert our numeric before 312 */
114 std::string* swhois = cmd.swhois.get(whois.GetTarget());
117 whois.SendLine(RPL_WHOISSPECIAL, *swhois);
121 /* Dont block anything */
122 return MOD_RES_PASSTHRU;
125 void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
130 std::string swhois = user->oper->getConfig("swhois");
132 if (!swhois.length())
135 cmd.operblock.set(user, 1);
136 cmd.swhois.set(user, swhois);
137 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
140 void OnPostDeoper(User* user) CXX11_OVERRIDE
142 std::string* swhois = cmd.swhois.get(user);
146 if (!cmd.operblock.get(user))
149 cmd.operblock.set(user, 0);
150 cmd.swhois.unset(user);
151 ServerInstance->PI->SendMetaData(user, "swhois", "");
154 void OnDecodeMetaData(Extensible* target, const std::string& extname, const std::string&) CXX11_OVERRIDE
156 User* dest = static_cast<User*>(target);
157 if (dest && (extname == "swhois"))
158 cmd.operblock.set(dest, 0);
161 Version GetVersion() CXX11_OVERRIDE
163 return Version("Adds the /SWHOIS command which adds custom lines to a user's WHOIS response.", VF_OPTCOMMON | VF_VENDOR);
167 MODULE_INIT(ModuleSWhois)