]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_namesx.cpp
d4e5def632d4dffdce74cac4fe7085075730b6b2
[user/henk/code/inspircd.git] / src / modules / m_namesx.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 static const char* dummy = "ON";
18
19 /* $ModDesc: Provides the NAMESX (CAP multi-prefix) capability. */
20
21 class ModuleNamesX : public Module
22 {
23  public:
24         
25         ModuleNamesX(InspIRCd* Me)
26                 : Module(Me)
27         {
28                 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
29                 ServerInstance->Modules->Attach(eventlist, this, 5);
30         }
31
32
33         virtual ~ModuleNamesX()
34         {
35         }
36
37         void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
38         {
39                 if ((displayable) && (extname == "NAMESX"))
40                         proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
41         }
42
43         virtual Version GetVersion()
44         {
45                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
46         }
47
48         virtual void On005Numeric(std::string &output)
49         {
50                 output.append(" NAMESX");
51         }
52
53         virtual int OnPreCommand(const std::string &command, const char* const* parameters, int pcnt, User *user, bool validated, const std::string &original_line)
54         {
55                 irc::string c = command.c_str();
56                 /* We don't actually create a proper command handler class for PROTOCTL,
57                  * because other modules might want to have PROTOCTL hooks too.
58                  * Therefore, we just hook its as an unvalidated command therefore we
59                  * can capture it even if it doesnt exist! :-)
60                  */
61                 if (c == "PROTOCTL")
62                 {
63                         if ((pcnt) && (!strcasecmp(parameters[0],"NAMESX")))
64                         {
65                                 user->Extend("NAMESX",dummy);
66                                 return 1;
67                         }
68                 }
69                 return 0;
70         }
71
72         virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick)
73         {
74                 if (!issuer->GetExt("NAMESX"))
75                         return;
76
77                 /* Some module hid this from being displayed, dont bother */
78                 if (nick.empty())
79                         return;
80
81                 prefixes = channel->GetAllPrefixChars(user);
82         }
83
84         virtual void OnEvent(Event *ev)
85         {
86                 if (ev->GetEventID() == "cap_req")
87                 {
88                         CapData *data = (CapData *) ev->GetData();
89
90                         std::vector<std::string>::iterator it;
91                         if ((it = std::find(data->wanted.begin(), data->wanted.end(), "multi-prefix")) != data->wanted.end())
92                         {
93                                 // we can handle this, so ACK it, and remove it from the wanted list
94                                 data->ack.push_back(*it);
95                                 data->wanted.erase(it);
96                                 data->user->Extend("NAMESX",dummy);
97                         }
98                 }
99
100                 if (ev->GetEventID() == "cap_ls")
101                 {
102                         CapData *data = (CapData *) ev->GetData();
103                         data->wanted.push_back("multi-prefix");
104                 }
105
106                 if (ev->GetEventID() == "cap_list")
107                 {
108                         CapData *data = (CapData *) ev->GetData();
109
110                         if (data->user->GetExt("NAMESX"))
111                                 data->wanted.push_back("multi-prefix");
112                 }
113
114                 if (ev->GetEventID() == "cap_clear")
115                 {
116                         CapData *data = (CapData *) ev->GetData();
117                         data->ack.push_back("-multi-prefix");
118                         data->user->Shrink("NAMESX");
119                 }
120         }
121 };
122
123 MODULE_INIT(ModuleNamesX)