]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_namesx.cpp
Add support for CAP to this via multi-prefix. NOTE, the OnNamesList for this and...
[user/henk/code/inspircd.git] / src / modules / m_namesx.cpp
index 65fb6c6c22bc07203e7938cda88c13211f959cdb..a1ae48b7026acd7618c27b8738f5ca764b4b00ef 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -12,6 +12,7 @@
  */
 
 #include "inspircd.h"
+#include "m_cap.h"
 
 static const char* dummy = "ON";
 
@@ -24,12 +25,10 @@ class ModuleNamesX : public Module
        ModuleNamesX(InspIRCd* Me)
                : Module(Me)
        {
+               Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnPreCommand, I_OnUserList, I_On005Numeric, I_OnEvent };
+               ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnSyncUserMetaData] = List[I_OnPreCommand] = List[I_OnUserList] = List[I_On005Numeric] = 1;
-       }
 
        virtual ~ModuleNamesX()
        {
@@ -51,7 +50,7 @@ class ModuleNamesX : public Module
                output.append(" NAMESX");
        }
 
-       virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(const std::string &command, const char* const* parameters, int pcnt, User *user, bool validated, const std::string &original_line)
        {
                irc::string c = command.c_str();
                /* We don't actually create a proper command handler class for PROTOCTL,
@@ -119,6 +118,44 @@ class ModuleNamesX : public Module
                }
                return 0;               
        }
+
+       virtual void OnEvent(Event *ev)
+       {
+               if (ev->GetEventID() == "cap_req")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+
+                       std::vector<std::string>::iterator it;
+                       if ((it = std::find(data->wanted.begin(), data->wanted.end(), "multi-prefix")) != data->wanted.end())
+                       {
+                               // we can handle this, so ACK it, and remove it from the wanted list
+                               data->wanted.erase(it);
+                               data->ack.push_back(*it);
+                               data->user->Extend("NAMESX",dummy);
+                       }
+               }
+
+               if (ev->GetEventID() == "cap_ls")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+                       data->wanted.push_back("multi-prefix");
+               }
+
+               if (ev->GetEventID() == "cap_list")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+
+                       if (data->user->GetExt("NAMESX"))
+                               data->ack.push_back("multi-prefix");
+               }
+
+               if (ev->GetEventID() == "cap_clear")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+                       data->ack.push_back("-multi-prefix");
+                       data->user->Shrink("NAMESX");
+               }
+       }
 };
 
 MODULE_INIT(ModuleNamesX)