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 Dennis Friis <peavey@inspircd.org>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 RPL_WHOISSPECIAL = 320
32 class CommandTitle : public Command
36 CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
37 ctitle("ctitle", ExtensionItem::EXT_USER, Creator)
39 syntax = "<user> <password>";
42 CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
44 const std::string userHost = user->ident + "@" + user->GetRealHost();
45 const std::string userIP = user->ident + "@" + user->GetIPString();
47 ConfigTagList tags = ServerInstance->Config->ConfTags("title");
48 for (ConfigIter i = tags.first; i != tags.second; ++i)
50 std::string Name = i->second->getString("name");
51 std::string pass = i->second->getString("password");
52 std::string hash = i->second->getString("hash");
53 std::string host = i->second->getString("host", "*@*");
54 std::string title = i->second->getString("title");
55 std::string vhost = i->second->getString("vhost");
57 if (Name == parameters[0] && ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
58 InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
60 ctitle.set(user, title);
62 ServerInstance->PI->SendMetaData(user, "ctitle", title);
65 user->ChangeDisplayedHost(vhost);
67 user->WriteNotice("Custom title set to '" + title + "'");
73 user->WriteNotice("Invalid title credentials");
79 class ModuleCustomTitle : public Module, public Whois::LineEventListener
85 : Whois::LineEventListener(this)
90 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
91 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
93 /* We use this and not OnWhois because this triggers for remote, too */
94 if (numeric.GetNumeric() == 312)
96 /* Insert our numeric before 312 */
97 const std::string* ctitle = cmd.ctitle.get(whois.GetTarget());
100 whois.SendLine(RPL_WHOISSPECIAL, ctitle);
103 /* Don't block anything */
104 return MOD_RES_PASSTHRU;
107 Version GetVersion() CXX11_OVERRIDE
109 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
113 MODULE_INIT(ModuleCustomTitle)