1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
20 class CommandSwhois : public Command
24 CommandSwhois(Module* Creator) : Command(Creator,"SWHOIS", 2,2), swhois("swhois", Creator)
26 flags_needed = 'o'; syntax = "<nick> :<swhois>";
27 ServerInstance->Extensions.Register(&swhois);
28 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
31 CmdResult Handle(const std::vector<std::string> ¶meters, User* user)
33 User* dest = ServerInstance->FindNick(parameters[0]);
37 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
41 std::string* text = swhois.get(dest);
44 // We already had it set...
45 if (!ServerInstance->ULine(user->server))
46 // Ulines set SWHOISes silently
47 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());
49 else if (!ServerInstance->ULine(user->server))
51 // Ulines set SWHOISes silently
52 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());
55 if (parameters[1].empty())
58 swhois.set(dest, parameters[1]);
60 /* Bug #376 - feature request -
61 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
62 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
63 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
66 ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);
73 class ModuleSWhois : public Module
78 ModuleSWhois() : cmd(this)
80 ServerInstance->AddCommand(&cmd);
81 Implementation eventlist[] = { I_OnWhoisLine, I_OnPostCommand };
82 ServerInstance->Modules->Attach(eventlist, this, 2);
85 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
86 ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
88 /* We use this and not OnWhois because this triggers for remote, too */
91 /* Insert our numeric before 312 */
92 std::string* swhois = cmd.swhois.get(dest);
95 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), swhois->c_str());
99 /* Dont block anything */
100 return MOD_RES_PASSTHRU;
103 void OnPostCommand(const std::string &command, const std::vector<std::string> ¶ms, User *user, CmdResult result, const std::string &original_line)
105 if ((command != "OPER") || (result != CMD_SUCCESS))
109 std::string swhois = user->oper->getConfig("swhois");
111 if (!swhois.length())
114 cmd.swhois.set(user, swhois);
115 ServerInstance->PI->SendMetaData(user, "swhois", swhois);
124 return Version("Provides the SWHOIS command which allows setting of arbitary WHOIS lines", VF_OPTCOMMON | VF_VENDOR);
128 MODULE_INIT(ModuleSWhois)