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/>.
30 class CommandSwhois : public Command
34 CommandSwhois(Module* Creator) : Command(Creator,"SWHOIS", 2,2), swhois("swhois", Creator)
36 flags_needed = 'o'; syntax = "<nick> :<swhois>";
37 TRANSLATE2(TR_NICK, TR_TEXT);
40 CmdResult Handle(const std::vector<std::string> ¶meters, User* user)
42 User* dest = ServerInstance->FindNick(parameters[0]);
44 if ((!dest) || (IS_SERVER(dest))) // allow setting swhois using SWHOIS before reg
46 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
50 std::string* text = swhois.get(dest);
53 // We already had it set...
54 if (!user->server->IsULine())
55 // Ulines set SWHOISes silently
56 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());
58 else if (!user->server->IsULine())
60 // Ulines set SWHOISes silently
61 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());
64 if (parameters[1].empty())
67 swhois.set(dest, parameters[1]);
69 /* Bug #376 - feature request -
70 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
71 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
72 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
75 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
82 class ModuleSWhois : public Module
87 ModuleSWhois() : cmd(this)
91 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
92 ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
94 /* We use this and not OnWhois because this triggers for remote, too */
97 /* Insert our numeric before 312 */
98 std::string* swhois = cmd.swhois.get(dest);
101 ServerInstance->SendWhoisLine(user, dest, 320, "%s :%s", dest->nick.c_str(), swhois->c_str());
105 /* Dont block anything */
106 return MOD_RES_PASSTHRU;
109 void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE
114 std::string swhois = user->oper->getConfig("swhois");
116 if (!swhois.length())
119 cmd.swhois.set(user, swhois);
120 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
123 Version GetVersion() CXX11_OVERRIDE
125 return Version("Provides the SWHOIS command which allows setting of arbitrary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
129 MODULE_INIT(ModuleSWhois)