]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cap.h
Merge pull request #193 from attilamolnar/insp20+newlinefix
[user/henk/code/inspircd.git] / src / modules / m_cap.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #ifndef M_CAP_H
22 #define M_CAP_H
23
24 #include <map>
25 #include <string>
26
27 class CapEvent : public Event
28 {
29  public:
30         irc::string type;
31         std::vector<std::string> wanted;
32         std::vector<std::string> ack;
33         User* user;
34         Module* creator;
35         CapEvent(Module* sender, const std::string& t) : Event(sender, t) {}
36 };
37
38 class GenericCap
39 {
40  public:
41         LocalIntExt ext;
42         const std::string cap;
43         GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
44         {
45                 ServerInstance->Extensions.Register(&ext);
46         }
47
48         void HandleEvent(Event& ev)
49         {
50                 CapEvent *data = static_cast<CapEvent*>(&ev);
51                 if (ev.id == "cap_req")
52                 {
53                         std::vector<std::string>::iterator it;
54                         if ((it = std::find(data->wanted.begin(), data->wanted.end(), cap)) != data->wanted.end())
55                         {
56                                 // we can handle this, so ACK it, and remove it from the wanted list
57                                 data->ack.push_back(*it);
58                                 data->wanted.erase(it);
59                                 ext.set(data->user, 1);
60                         }
61                 }
62                 else if (ev.id == "cap_ls")
63                 {
64                         data->wanted.push_back(cap);
65                 }
66                 else if (ev.id == "cap_list")
67                 {
68                         if (ext.get(data->user))
69                                 data->wanted.push_back(cap);
70                 }
71                 else if (ev.id == "cap_clear")
72                 {
73                         data->ack.push_back("-" + cap);
74                         ext.set(data->user, 0);
75                 }
76         }
77 };
78
79 #endif