]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cap.h
Move destruction logic for User and Spanningtree into cull()
[user/henk/code/inspircd.git] / src / modules / m_cap.h
index 1c0ea49fcce540ff398ce9d445206cfe22bd627e..a375801264218bf345543b95c8fa1979d5ff77ff 100644 (file)
@@ -2,11 +2,11 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 #include <map>
 #include <string>
 
-class CapData
+class CapData : public classbase
 {
  public:
        irc::string type;
        std::vector<std::string> wanted;
        std::vector<std::string> ack;
-       std::vector<std::string> nak;
        User* user;
        Module* creator;
 };
 
+class GenericCap
+{
+ public:
+       LocalIntExt ext;
+       const std::string cap;
+       GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
+       {
+               Extensible::Register(&ext);
+       }
+
+       void HandleEvent(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(), cap)) != data->wanted.end())
+                       {
+                               // we can handle this, so ACK it, and remove it from the wanted list
+                               data->ack.push_back(*it);
+                               data->wanted.erase(it);
+                               ext.set(data->user, 1);
+                       }
+               }
+
+               if (ev->GetEventID() == "cap_ls")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+                       data->wanted.push_back(cap);
+               }
+
+               if (ev->GetEventID() == "cap_list")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+
+                       if (ext.get(data->user))
+                               data->wanted.push_back(cap);
+               }
+
+               if (ev->GetEventID() == "cap_clear")
+               {
+                       CapData *data = (CapData *) ev->GetData();
+                       data->ack.push_back("-" + cap);
+                       ext.set(data->user, 0);
+               }
+       }
+};
+
 #endif