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/>.
23 #include "modules/whois.h"
28 RPL_WHOISSPECIAL = 320
33 const std::string name;
34 const std::string password;
35 const std::string hash;
36 const std::string host;
37 const std::string title;
38 const std::string vhost;
40 CustomTitle(const std::string& n, const std::string& p, const std::string& h, const std::string& hst, const std::string& t, const std::string& v)
50 bool MatchUser(User* user) const
52 const std::string userHost = user->ident + "@" + user->GetRealHost();
53 const std::string userIP = user->ident + "@" + user->GetIPString();
54 return InspIRCd::MatchMask(host, userHost, userIP);
57 bool CheckPass(User* user, const std::string& pass) const
59 return ServerInstance->PassCompare(user, password, pass, hash);
63 typedef std::multimap<std::string, CustomTitle> CustomVhostMap;
64 typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs;
68 class CommandTitle : public Command
72 CustomVhostMap configs;
74 CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
75 ctitle("ctitle", ExtensionItem::EXT_USER, Creator)
77 syntax = "<username> <password>";
80 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
82 MatchingConfigs matching = configs.equal_range(parameters[0]);
84 for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i)
86 CustomTitle config = i->second;
87 if (config.MatchUser(user) && config.CheckPass(user, parameters[1]))
89 ctitle.set(user, config.title);
91 ServerInstance->PI->SendMetaData(user, "ctitle", config.title);
93 if (!config.vhost.empty())
94 user->ChangeDisplayedHost(config.vhost);
96 user->WriteNotice("Custom title set to '" + config.title + "'");
102 user->WriteNotice("Invalid title credentials");
108 class ModuleCustomTitle : public Module, public Whois::LineEventListener
114 : Whois::LineEventListener(this)
119 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
121 ConfigTagList tags = ServerInstance->Config->ConfTags("title");
122 CustomVhostMap newtitles;
123 for (ConfigIter i = tags.first; i != tags.second; ++i)
125 reference<ConfigTag> tag = i->second;
126 std::string name = tag->getString("name", "", 1);
128 throw ModuleException("<title:name> is empty at " + tag->getTagLocation());
130 std::string pass = tag->getString("password");
132 throw ModuleException("<title:password> is empty at " + tag->getTagLocation());
134 std::string hash = tag->getString("hash");
135 std::string host = tag->getString("host", "*@*");
136 std::string title = tag->getString("title");
137 std::string vhost = tag->getString("vhost");
138 CustomTitle config(name, pass, hash, host, title, vhost);
139 newtitles.insert(std::make_pair(name, config));
141 cmd.configs.swap(newtitles);
144 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
145 ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
147 /* We use this and not OnWhois because this triggers for remote, too */
148 if (numeric.GetNumeric() == 312)
150 /* Insert our numeric before 312 */
151 const std::string* ctitle = cmd.ctitle.get(whois.GetTarget());
154 whois.SendLine(RPL_WHOISSPECIAL, ctitle);
157 /* Don't block anything */
158 return MOD_RES_PASSTHRU;
161 Version GetVersion() CXX11_OVERRIDE
163 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
167 MODULE_INIT(ModuleCustomTitle)