1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 static const char* dummy = "ON";
19 /* $ModDesc: Provides the NAMESX (CAP multi-prefix) capability. */
21 class ModuleNamesX : public Module
25 ModuleNamesX(InspIRCd* Me)
28 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
29 ServerInstance->Modules->Attach(eventlist, this, 5);
33 virtual ~ModuleNamesX()
37 void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
39 if ((displayable) && (extname == "NAMESX"))
40 proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
43 virtual Version GetVersion()
45 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
48 virtual void On005Numeric(std::string &output)
50 output.append(" NAMESX");
53 virtual int OnPreCommand(const std::string &command, const char* const* parameters, int pcnt, User *user, bool validated, const std::string &original_line)
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! :-)
63 if ((pcnt) && (!strcasecmp(parameters[0],"NAMESX")))
65 user->Extend("NAMESX",dummy);
72 virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick)
74 if (!issuer->GetExt("NAMESX"))
77 /* Some module hid this from being displayed, dont bother */
81 prefixes = channel->GetAllPrefixChars(user);
84 virtual void OnEvent(Event *ev)
86 if (ev->GetEventID() == "cap_req")
88 CapData *data = (CapData *) ev->GetData();
90 std::vector<std::string>::iterator it;
91 if ((it = std::find(data->wanted.begin(), data->wanted.end(), "multi-prefix")) != data->wanted.end())
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);
100 if (ev->GetEventID() == "cap_ls")
102 CapData *data = (CapData *) ev->GetData();
103 data->wanted.push_back("multi-prefix");
106 if (ev->GetEventID() == "cap_list")
108 CapData *data = (CapData *) ev->GetData();
110 if (data->user->GetExt("NAMESX"))
111 data->wanted.push_back("multi-prefix");
114 if (ev->GetEventID() == "cap_clear")
116 CapData *data = (CapData *) ev->GetData();
117 data->ack.push_back("-multi-prefix");
118 data->user->Shrink("NAMESX");
123 MODULE_INIT(ModuleNamesX)