The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_namesx.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 #include "m_cap.h"
00016 
00017 /* $ModDesc: Provides the NAMESX (CAP multi-prefix) capability. */
00018 
00019 class ModuleNamesX : public Module
00020 {
00021  public:
00022 
00023         ModuleNamesX(InspIRCd* Me)
00024                 : Module(Me)
00025         {
00026                 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
00027                 ServerInstance->Modules->Attach(eventlist, this, 5);
00028         }
00029 
00030 
00031         virtual ~ModuleNamesX()
00032         {
00033         }
00034 
00035         void OnSyncUserMetaData(User* user, Module* proto,void* opaque, const std::string &extname, bool displayable)
00036         {
00037                 if ((displayable) && (extname == "NAMESX"))
00038                         proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, "Enabled");
00039         }
00040 
00041         virtual Version GetVersion()
00042         {
00043                 return Version("$Id: m_namesx.cpp 10291 2008-08-25 20:35:51Z w00t $",VF_VENDOR,API_VERSION);
00044         }
00045 
00046         virtual void On005Numeric(std::string &output)
00047         {
00048                 output.append(" NAMESX");
00049         }
00050 
00051         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
00052         {
00053                 irc::string c = command.c_str();
00054                 /* We don't actually create a proper command handler class for PROTOCTL,
00055                  * because other modules might want to have PROTOCTL hooks too.
00056                  * Therefore, we just hook its as an unvalidated command therefore we
00057                  * can capture it even if it doesnt exist! :-)
00058                  */
00059                 if (c == "PROTOCTL")
00060                 {
00061                         if ((parameters.size()) && (!strcasecmp(parameters[0].c_str(),"NAMESX")))
00062                         {
00063                                 user->Extend("NAMESX");
00064                                 return 1;
00065                         }
00066                 }
00067                 return 0;
00068         }
00069 
00070         virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick)
00071         {
00072                 if (!issuer->GetExt("NAMESX"))
00073                         return;
00074 
00075                 /* Some module hid this from being displayed, dont bother */
00076                 if (nick.empty())
00077                         return;
00078 
00079                 prefixes = channel->GetAllPrefixChars(user);
00080         }
00081 
00082         virtual void OnEvent(Event *ev)
00083         {
00084                 GenericCapHandler(ev, "NAMESX", "multi-prefix");
00085         }
00086 };
00087 
00088 MODULE_INIT(ModuleNamesX)