]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cap.h
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_cap.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 CapEvent : public Event
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         CapEvent(Module* sender, const std::string& t) : Event(sender, t) {}
29 };
30
31 class GenericCap
32 {
33  public:
34         LocalIntExt ext;
35         const std::string cap;
36         GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
37         {
38                 ServerInstance->Extensions.Register(&ext);
39         }
40
41         void HandleEvent(Event& ev)
42         {
43                 CapEvent *data = static_cast<CapEvent*>(&ev);
44                 if (ev.id == "cap_req")
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.id == "cap_ls")
57                 {
58                         data->wanted.push_back(cap);
59                 }
60
61                 if (ev.id == "cap_list")
62                 {
63                         if (ext.get(data->user))
64                                 data->wanted.push_back(cap);
65                 }
66
67                 if (ev.id == "cap_clear")
68                 {
69                         data->ack.push_back("-" + cap);
70                         ext.set(data->user, 0);
71                 }
72         }
73 };
74
75 #endif