]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_customtitle.cpp
2a08592ea16bef9b3aa5fd7caed51c3338f6793e
[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 /** Handle /TITLE
25  */
26 class CommandTitle : public Command
27 {
28  public:
29         StringExtItem ctitle;
30         CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
31                 ctitle("ctitle", ExtensionItem::EXT_USER, Creator)
32         {
33                 syntax = "<user> <password>";
34         }
35
36         CmdResult Handle(const std::vector<std::string> &parameters, User* user)
37         {
38                 const std::string userHost = user->ident + "@" + user->GetRealHost();
39                 const std::string userIP = user->ident + "@" + user->GetIPString();
40
41                 ConfigTagList tags = ServerInstance->Config->ConfTags("title");
42                 for (ConfigIter i = tags.first; i != tags.second; ++i)
43                 {
44                         std::string Name = i->second->getString("name");
45                         std::string pass = i->second->getString("password");
46                         std::string hash = i->second->getString("hash");
47                         std::string host = i->second->getString("host", "*@*");
48                         std::string title = i->second->getString("title");
49                         std::string vhost = i->second->getString("vhost");
50
51                         if (Name == parameters[0] && ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
52                                 InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
53                         {
54                                 ctitle.set(user, title);
55
56                                 ServerInstance->PI->SendMetaData(user, "ctitle", title);
57
58                                 if (!vhost.empty())
59                                         user->ChangeDisplayedHost(vhost);
60
61                                 user->WriteNotice("Custom title set to '" + title + "'");
62
63                                 return CMD_SUCCESS;
64                         }
65                 }
66
67                 user->WriteNotice("Invalid title credentials");
68                 return CMD_SUCCESS;
69         }
70
71 };
72
73 class ModuleCustomTitle : public Module, public Whois::LineEventListener
74 {
75         CommandTitle cmd;
76
77  public:
78         ModuleCustomTitle()
79                 : Whois::LineEventListener(this)
80                 , cmd(this)
81         {
82         }
83
84         // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
85         ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
86         {
87                 /* We use this and not OnWhois because this triggers for remote, too */
88                 if (numeric.GetNumeric() == 312)
89                 {
90                         /* Insert our numeric before 312 */
91                         const std::string* ctitle = cmd.ctitle.get(whois.GetTarget());
92                         if (ctitle)
93                         {
94                                 whois.SendLine(320, ctitle);
95                         }
96                 }
97                 /* Don't block anything */
98                 return MOD_RES_PASSTHRU;
99         }
100
101         Version GetVersion() CXX11_OVERRIDE
102         {
103                 return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
104         }
105 };
106
107 MODULE_INIT(ModuleCustomTitle)