]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cap.h
Allow multiple autoconnects in a single <autoconnect> tag, fix infinite failover
[user/henk/code/inspircd.git] / src / modules / m_cap.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __CAP_H__
15 #define __CAP_H__
16
17 #include <map>
18 #include <string>
19
20 class CapData : public classbase
21 {
22  public:
23         irc::string type;
24         std::vector<std::string> wanted;
25         std::vector<std::string> ack;
26         User* user;
27         Module* creator;
28 };
29
30 class GenericCap
31 {
32  public:
33         LocalIntExt ext;
34         const std::string cap;
35         GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
36         {
37                 Extensible::Register(&ext);
38         }
39
40         void HandleEvent(Event* ev)
41         {
42                 if (ev->GetEventID() == "cap_req")
43                 {
44                         CapData *data = (CapData *) ev->GetData();
45
46                         std::vector<std::string>::iterator it;
47                         if ((it = std::find(data->wanted.begin(), data->wanted.end(), cap)) != data->wanted.end())
48                         {
49                                 // we can handle this, so ACK it, and remove it from the wanted list
50                                 data->ack.push_back(*it);
51                                 data->wanted.erase(it);
52                                 ext.set(data->user, 1);
53                         }
54                 }
55
56                 if (ev->GetEventID() == "cap_ls")
57                 {
58                         CapData *data = (CapData *) ev->GetData();
59                         data->wanted.push_back(cap);
60                 }
61
62                 if (ev->GetEventID() == "cap_list")
63                 {
64                         CapData *data = (CapData *) ev->GetData();
65
66                         if (ext.get(data->user))
67                                 data->wanted.push_back(cap);
68                 }
69
70                 if (ev->GetEventID() == "cap_clear")
71                 {
72                         CapData *data = (CapData *) ev->GetData();
73                         data->ack.push_back("-" + cap);
74                         ext.set(data->user, 0);
75                 }
76         }
77 };
78
79 #endif