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 aliases of commands. */
21 class ModuleNamesX : public Module
25 ModuleNamesX(InspIRCd* Me)
28 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnUserList, 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 int OnUserList(User* user, Channel* Ptr, CUList* &ulist)
74 if (user->GetExt("NAMESX"))
78 dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, Ptr->IsModeSet('s') ? '@' : Ptr->IsModeSet('p') ? '*' : '=', Ptr->name);
80 char* ptr = list + dlen;
83 ulist = Ptr->GetUsers();
85 bool has_user = Ptr->HasUser(user);
86 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
88 if ((!has_user) && (i->first->IsModeSet('i')))
91 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
94 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", Ptr->GetAllPrefixChars(i->first), i->second.c_str());
95 /* OnUserList can change this - reset it back to normal */
96 i->second = i->first->nick;
100 if (curlen > (480-NICKMAX))
102 /* list overflowed into multiple numerics */
103 user->WriteServ(std::string(list));
104 /* reset our lengths */
105 dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, Ptr->IsModeSet('s') ? '@' : Ptr->IsModeSet('p') ? '*' : '=', Ptr->name);
111 /* if whats left in the list isnt empty, send it */
114 user->WriteServ(std::string(list));
116 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
122 virtual void OnEvent(Event *ev)
124 if (ev->GetEventID() == "cap_req")
126 CapData *data = (CapData *) ev->GetData();
128 std::vector<std::string>::iterator it;
129 if ((it = std::find(data->wanted.begin(), data->wanted.end(), "multi-prefix")) != data->wanted.end())
131 // we can handle this, so ACK it, and remove it from the wanted list
132 data->wanted.erase(it);
133 data->ack.push_back(*it);
134 data->user->Extend("NAMESX",dummy);
138 if (ev->GetEventID() == "cap_ls")
140 CapData *data = (CapData *) ev->GetData();
141 data->wanted.push_back("multi-prefix");
144 if (ev->GetEventID() == "cap_list")
146 CapData *data = (CapData *) ev->GetData();
148 if (data->user->GetExt("NAMESX"))
149 data->ack.push_back("multi-prefix");
152 if (ev->GetEventID() == "cap_clear")
154 CapData *data = (CapData *) ev->GetData();
155 data->ack.push_back("-multi-prefix");
156 data->user->Shrink("NAMESX");
161 MODULE_INIT(ModuleNamesX)