1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 *the file COPYING for details.
14 * ---------------------------------------------------
26 static const char* dummy = "ON";
28 /* $ModDesc: Provides aliases of commands. */
30 class ModuleNamesX : public Module
34 ModuleNamesX(InspIRCd* Me)
39 void Implements(char* List)
41 List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1;
44 virtual ~ModuleNamesX()
48 virtual Version GetVersion()
50 return Version(1,0,0,1,VF_VENDOR);
53 virtual void On005Numeric(std::string &output)
55 output.append(" NAMESX");
58 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated)
60 irc::string c = command.c_str();
61 /* We don't actually create a proper command handler class for PROTOCTL,
62 * because other modules might want to have PROTOCTL hooks too.
63 * Therefore, we just hook its as an unvalidated command therefore we
64 * can capture it even if it doesnt exist! :-)
68 if ((pcnt) && (!strcasecmp(parameters[0],"NAMESX")))
70 ServerInstance->Log(DEBUG,"Setting this user as NAMESX capable");
71 user->Extend("NAMESX",dummy);
78 virtual int OnUserList(userrec* user, chanrec* Ptr)
80 ServerInstance->Log(DEBUG,"NAMESX called for %s %s",user->nick,Ptr->name);
81 if (user->GetExt("NAMESX"))
83 ServerInstance->Log(DEBUG,"Using NAMESX user list code");
86 dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, Ptr->name);
88 char* ptr = list + dlen;
89 CUList *ulist= Ptr->GetUsers();
90 bool has_user = Ptr->HasUser(user);
91 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
93 if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
97 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", Ptr->GetAllPrefixChars(i->second), i->second->nick);
101 if (curlen > (480-NICKMAX))
103 /* list overflowed into multiple numerics */
104 ServerInstance->Log(DEBUG,"Send list 1");
105 user->WriteServ(list);
106 /* reset our lengths */
107 dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, Ptr->name);
113 /* if whats left in the list isnt empty, send it */
116 ServerInstance->Log(DEBUG,"Send list 2");
117 user->WriteServ(list);
119 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
120 ServerInstance->Log(DEBUG,"Returning 1");
124 ServerInstance->Log(DEBUG,"Returning 0");
130 class ModuleNamesXFactory : public ModuleFactory
133 ModuleNamesXFactory()
137 ~ModuleNamesXFactory()
141 virtual Module * CreateModule(InspIRCd* Me)
143 return new ModuleNamesX(Me);
148 extern "C" void * init_module( void )
150 return new ModuleNamesXFactory;