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>";
36 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
39 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
41 std::stringstream hl(hostlist);
45 if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
53 CmdResult Handle(const std::vector<std::string> ¶meters, User* user)
58 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
59 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
62 for (int i=0; i<Conf.Enumerate("title"); i++)
64 std::string Name = Conf.ReadValue("title", "name", "", i);
65 std::string pass = Conf.ReadValue("title", "password", "", i);
66 std::string hash = Conf.ReadValue("title", "hash", "", i);
67 std::string host = Conf.ReadValue("title", "host", "*@*", i);
68 std::string title = Conf.ReadValue("title", "title", "", i);
69 std::string vhost = Conf.ReadValue("title", "vhost", "", i);
71 if (!strcmp(Name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
73 ctitle.set(user, title);
75 ServerInstance->PI->SendMetaData(user, "ctitle", title);
78 user->ChangeDisplayedHost(vhost.c_str());
80 user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
86 user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
92 class ModuleCustomTitle : public Module
97 ModuleCustomTitle() : cmd(this)
99 ServerInstance->AddCommand(&cmd);
100 ServerInstance->Extensions.Register(&cmd.ctitle);
101 ServerInstance->Modules->Attach(I_OnWhoisLine, this);
104 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
105 ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
107 /* We use this and not OnWhois because this triggers for remote, too */
110 /* Insert our numeric before 312 */
111 const std::string* ctitle = cmd.ctitle.get(dest);
114 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
117 /* Don't block anything */
118 return MOD_RES_PASSTHRU;
127 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
131 MODULE_INIT(ModuleCustomTitle)