2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2006-2007 John Brooks <john.brooks@dereferenced.net>
9 * Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
10 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
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/>.
31 RPL_WHOISSPECIAL = 320
36 class CommandSwhois : public Command
40 CommandSwhois(Module* Creator)
41 : Command(Creator, "SWHOIS", 2, 2)
42 , swhois("swhois", ExtensionItem::EXT_USER, Creator)
44 flags_needed = 'o'; syntax = "<nick> :<swhois>";
45 TRANSLATE2(TR_NICK, TR_TEXT);
48 CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
50 User* dest = ServerInstance->FindNick(parameters[0]);
52 if (!dest) // allow setting swhois using SWHOIS before reg
54 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
58 std::string* text = swhois.get(dest);
61 // We already had it set...
62 if (!user->server->IsULine())
63 // Ulines set SWHOISes silently
64 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());
66 else if (!user->server->IsULine())
68 // Ulines set SWHOISes silently
69 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());
72 if (parameters[1].empty())
75 swhois.set(dest, parameters[1]);
77 /* Bug #376 - feature request -
78 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
79 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
80 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
83 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
90 class ModuleSWhois : public Module, public Whois::LineEventListener
96 : Whois::LineEventListener(this)
101 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
102 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
104 /* We use this and not OnWhois because this triggers for remote, too */
105 if (numeric.GetNumeric() == 312)
107 /* Insert our numeric before 312 */
108 std::string* swhois = cmd.swhois.get(whois.GetTarget());
111 whois.SendLine(RPL_WHOISSPECIAL, *swhois);
115 /* Dont block anything */
116 return MOD_RES_PASSTHRU;
119 void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
124 std::string swhois = user->oper->getConfig("swhois");
126 if (!swhois.length())
129 cmd.swhois.set(user, swhois);
130 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
133 Version GetVersion() CXX11_OVERRIDE
135 return Version("Provides the SWHOIS command which allows setting of arbitrary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
139 MODULE_INIT(ModuleSWhois)