1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 TITLE command which allows setting of CUSTOM WHOIS TITLE line */
20 class CommandTitle : public Command
24 CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
25 ctitle("ctitle", Creator)
27 syntax = "<user> <password>";
28 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
31 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
33 std::stringstream hl(hostlist);
37 if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
45 CmdResult Handle(const std::vector<std::string> ¶meters, User* user)
50 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
51 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
54 for (int i=0; i<Conf.Enumerate("title"); i++)
56 std::string Name = Conf.ReadValue("title", "name", "", i);
57 std::string pass = Conf.ReadValue("title", "password", "", i);
58 std::string hash = Conf.ReadValue("title", "hash", "", i);
59 std::string host = Conf.ReadValue("title", "host", "*@*", i);
60 std::string title = Conf.ReadValue("title", "title", "", i);
61 std::string vhost = Conf.ReadValue("title", "vhost", "", i);
63 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())
65 ctitle.set(user, title);
67 ServerInstance->PI->SendMetaData(user, "ctitle", title);
70 user->ChangeDisplayedHost(vhost.c_str());
72 user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
78 user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
84 class ModuleCustomTitle : public Module
89 ModuleCustomTitle() : cmd(this)
91 ServerInstance->AddCommand(&cmd);
92 ServerInstance->Extensions.Register(&cmd.ctitle);
93 ServerInstance->Modules->Attach(I_OnWhoisLine, this);
96 // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
97 ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
99 /* We use this and not OnWhois because this triggers for remote, too */
102 /* Insert our numeric before 312 */
103 const std::string* ctitle = cmd.ctitle.get(dest);
106 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
109 /* Don't block anything */
110 return MOD_RES_PASSTHRU;
119 return Version("Custom Title for users", VF_COMMON | VF_VENDOR);
123 MODULE_INIT(ModuleCustomTitle)