]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_namesx.cpp
MetaData rework
[user/henk/code/inspircd.git] / src / modules / m_namesx.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 NAMESX (CAP multi-prefix) capability. */
18
19 class ModuleNamesX : public Module
20 {
21  public:
22
23         ModuleNamesX(InspIRCd* Me)
24                 : Module(Me)
25         {
26                 Implementation eventlist[] = { I_OnSyncUser, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
27                 ServerInstance->Modules->Attach(eventlist, this, 5);
28         }
29
30
31         virtual ~ModuleNamesX()
32         {
33         }
34
35         void OnSyncUser(User* user, Module* proto,void* opaque)
36         {
37                 if (proto->ProtoTranslate(NULL) == "?" && user->GetExt("NAMESX"))
38                         proto->ProtoSendMetaData(opaque, user, "NAMESX", "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(" NAMESX");
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(),"NAMESX")))
62                         {
63                                 user->Extend("NAMESX");
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("NAMESX"))
73                         return;
74
75                 /* Some module hid this from being displayed, dont bother */
76                 if (nick.empty())
77                         return;
78
79                 prefixes = channel->GetAllPrefixChars(user);
80         }
81
82         virtual void OnEvent(Event *ev)
83         {
84                 GenericCapHandler(ev, "NAMESX", "multi-prefix");
85         }
86 };
87
88 MODULE_INIT(ModuleNamesX)