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/>.
24 /* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
28 class CommandTitle : public Command
32 CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
33 ctitle("ctitle", Creator)
35 syntax = "<user> <password>";
38 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
40 std::stringstream hl(hostlist);
44 if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
52 CmdResult Handle(const std::vector<std::string> ¶meters, User* user)
57 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
58 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
60 ConfigTagList tags = ServerInstance->Config->ConfTags("title");
61 for (ConfigIter i = tags.first; i != tags.second; ++i)
63 std::string Name = i->second->getString("name");
64 std::string pass = i->second->getString("password");
65 std::string hash = i->second->getString("hash");
66 std::string host = i->second->getString("host", "*@*");
67 std::string title = i->second->getString("title");
68 std::string vhost = i->second->getString("vhost");
70 if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
72 ctitle.set(user, title);
74 ServerInstance->PI->SendMetaData(user, "ctitle", title);
77 user->ChangeDisplayedHost(vhost.c_str());
79 user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
85 user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
91 class ModuleCustomTitle : public Module
96 ModuleCustomTitle() : cmd(this)
102 ServerInstance->Modules->AddService(cmd);
103 ServerInstance->Modules->AddService(cmd.ctitle);
104 ServerInstance->Modules->Attach(I_OnWhoisLine, this);
107 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
108 ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
110 /* We use this and not OnWhois because this triggers for remote, too */
113 /* Insert our numeric before 312 */
114 const std::string* ctitle = cmd.ctitle.get(dest);
117 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
120 /* Don't block anything */
121 return MOD_RES_PASSTHRU;
130 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
134 MODULE_INIT(ModuleCustomTitle)