2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
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.
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
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/>.
24 class CapEvent : public Event
36 std::vector<std::string> wanted;
37 std::vector<std::string> ack;
39 CapEvent(Module* sender, User* u, CapEventType capevtype) : Event(sender, "cap_request"), type(capevtype), user(u) {}
46 const std::string cap;
47 GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
49 ServerInstance->Modules->AddService(ext);
52 void HandleEvent(Event& ev)
54 if (ev.id != "cap_request")
57 CapEvent *data = static_cast<CapEvent*>(&ev);
58 if (data->type == CapEvent::CAPEVENT_REQ)
60 for (std::vector<std::string>::iterator it = data->wanted.begin(); it != data->wanted.end(); ++it)
64 bool enablecap = ((*it)[0] != '-');
65 if (((enablecap) && (*it == cap)) || (*it == "-" + cap))
67 // we can handle this, so ACK it, and remove it from the wanted list
68 data->ack.push_back(*it);
69 data->wanted.erase(it);
70 ext.set(data->user, enablecap ? 1 : 0);
75 else if (data->type == CapEvent::CAPEVENT_LS)
77 data->wanted.push_back(cap);
79 else if (data->type == CapEvent::CAPEVENT_LIST)
81 if (ext.get(data->user))
82 data->wanted.push_back(cap);
84 else if (data->type == CapEvent::CAPEVENT_CLEAR)
86 data->ack.push_back("-" + cap);
87 ext.set(data->user, 0);