]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uhnames.cpp
b0e096baaf80999f5b3c043155af5167785e628e
[user/henk/code/inspircd.git] / src / modules / m_uhnames.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "m_cap.h"
16
17 /* $ModDesc: Provides the UHNAMES facility. */
18
19 class ModuleUHNames : public Module
20 {
21         CUList nl;
22  public:
23
24         ModuleUHNames(InspIRCd* Me)
25                 : Module(Me)
26         {
27                 Implementation eventlist[] = { I_OnEvent, I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric };
28                 ServerInstance->Modules->Attach(eventlist, this, 5);
29         }
30
31         virtual ~ModuleUHNames()
32         {
33         }
34
35         void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
36         {
37                 if ((displayable) && (extname == "UHNAMES"))
38                         proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
39         }
40
41         virtual Version GetVersion()
42         {
43                 return Version("$Id$",VF_VENDOR,API_VERSION);
44         }
45
46         virtual void On005Numeric(std::string &output)
47         {
48                 output.append(" UHNAMES");
49         }
50
51         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
52         {
53                 irc::string c = command.c_str();
54                 /* We don't actually create a proper command handler class for PROTOCTL,
55                  * because other modules might want to have PROTOCTL hooks too.
56                  * Therefore, we just hook its as an unvalidated command therefore we
57                  * can capture it even if it doesnt exist! :-)
58                  */
59                 if (c == "PROTOCTL")
60                 {
61                         if ((parameters.size()) && (!strcasecmp(parameters[0].c_str(),"UHNAMES")))
62                         {
63                                 user->Extend("UHNAMES");
64                                 return 1;
65                         }
66                 }
67                 return 0;
68         }
69
70         virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick)
71         {
72                 if (!issuer->GetExt("UHNAMES"))
73                         return;
74
75                 if (nick.empty())
76                         return;
77
78                 nick = user->GetFullHost();
79         }
80
81         virtual void OnEvent(Event* ev)
82         {
83                 GenericCapHandler(ev, "UHNAMES", "userhost-in-names");
84         }
85 };
86
87 MODULE_INIT(ModuleUHNames)