]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_customtitle.cpp
Merge pull request #514 from SaberUK/master+virtual-cleanup
[user/henk/code/inspircd.git] / src / modules / m_customtitle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
25
26 /** Handle /TITLE
27  */
28 class CommandTitle : public Command
29 {
30  public:
31         StringExtItem ctitle;
32         CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
33                 ctitle("ctitle", Creator)
34         {
35                 syntax = "<user> <password>";
36         }
37
38         CmdResult Handle(const std::vector<std::string> &parameters, User* user)
39         {
40                 const std::string userHost = user->ident + "@" + user->host;
41                 const std::string userIP = user->ident + "@" + user->GetIPString();
42
43                 ConfigTagList tags = ServerInstance->Config->ConfTags("title");
44                 for (ConfigIter i = tags.first; i != tags.second; ++i)
45                 {
46                         std::string Name = i->second->getString("name");
47                         std::string pass = i->second->getString("password");
48                         std::string hash = i->second->getString("hash");
49                         std::string host = i->second->getString("host", "*@*");
50                         std::string title = i->second->getString("title");
51                         std::string vhost = i->second->getString("vhost");
52
53                         if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
54                                 InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
55                         {
56                                 ctitle.set(user, title);
57
58                                 ServerInstance->PI->SendMetaData(user, "ctitle", title);
59
60                                 if (!vhost.empty())
61                                         user->ChangeDisplayedHost(vhost.c_str());
62
63                                 user->WriteNotice("Custom title set to '" + title + "'");
64
65                                 return CMD_SUCCESS;
66                         }
67                 }
68
69                 user->WriteNotice("Invalid title credentials");
70                 return CMD_SUCCESS;
71         }
72
73 };
74
75 class ModuleCustomTitle : public Module
76 {
77         CommandTitle cmd;
78
79  public:
80         ModuleCustomTitle() : cmd(this)
81         {
82         }
83
84         void init() CXX11_OVERRIDE
85         {
86                 ServerInstance->Modules->AddService(cmd);
87                 ServerInstance->Modules->AddService(cmd.ctitle);
88                 ServerInstance->Modules->Attach(I_OnWhoisLine, this);
89         }
90
91         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
92         ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
93         {
94                 /* We use this and not OnWhois because this triggers for remote, too */
95                 if (numeric == 312)
96                 {
97                         /* Insert our numeric before 312 */
98                         const std::string* ctitle = cmd.ctitle.get(dest);
99                         if (ctitle)
100                         {
101                                 ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
102                         }
103                 }
104                 /* Don't block anything */
105                 return MOD_RES_PASSTHRU;
106         }
107
108         Version GetVersion() CXX11_OVERRIDE
109         {
110                 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
111         }
112 };
113
114 MODULE_INIT(ModuleCustomTitle)