]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uhnames.cpp
Merge pull request #1162 from SaberUK/insp20+fix-deinstall
[user/henk/code/inspircd.git] / src / modules / m_uhnames.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
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 #include "m_cap.h"
24
25 /* $ModDesc: Provides the UHNAMES facility. */
26
27 class ModuleUHNames : public Module
28 {
29  public:
30         GenericCap cap;
31
32         ModuleUHNames() : cap(this, "userhost-in-names")
33         {
34         }
35
36         void init()
37         {
38                 Implementation eventlist[] = { I_OnEvent, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric };
39                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
40         }
41
42         ~ModuleUHNames()
43         {
44         }
45
46         Version GetVersion()
47         {
48                 return Version("Provides the UHNAMES facility.",VF_VENDOR);
49         }
50
51         void On005Numeric(std::string &output)
52         {
53                 output.append(" UHNAMES");
54         }
55
56         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
57         {
58                 /* We don't actually create a proper command handler class for PROTOCTL,
59                  * because other modules might want to have PROTOCTL hooks too.
60                  * Therefore, we just hook its as an unvalidated command therefore we
61                  * can capture it even if it doesnt exist! :-)
62                  */
63                 if (command == "PROTOCTL")
64                 {
65                         if ((parameters.size()) && (!strcasecmp(parameters[0].c_str(),"UHNAMES")))
66                         {
67                                 cap.ext.set(user, 1);
68                                 return MOD_RES_DENY;
69                         }
70                 }
71                 return MOD_RES_PASSTHRU;
72         }
73
74         void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
75         {
76                 if (!cap.ext.get(issuer))
77                         return;
78
79                 if (nick.empty())
80                         return;
81
82                 nick = memb->user->GetFullHost();
83         }
84
85         void OnEvent(Event& ev)
86         {
87                 cap.HandleEvent(ev);
88         }
89 };
90
91 MODULE_INIT(ModuleUHNames)