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