+ CapEvent(Module* sender, User* u, CapEventType capevtype) : Event(sender, "cap_request"), type(capevtype), user(u) {}
+};
+
+class GenericCap
+{
+ public:
+ LocalIntExt ext;
+ const std::string cap;
+ GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
+ {
+ ServerInstance->Modules->AddService(ext);
+ }
+
+ void HandleEvent(Event& ev)
+ {
+ if (ev.id != "cap_request")
+ return;
+
+ CapEvent *data = static_cast<CapEvent*>(&ev);
+ if (data->type == CapEvent::CAPEVENT_REQ)
+ {
+ for (std::vector<std::string>::iterator it = data->wanted.begin(); it != data->wanted.end(); ++it)
+ {
+ if (it->empty())
+ continue;
+ bool enablecap = ((*it)[0] != '-');
+ if (((enablecap) && (*it == cap)) || (*it == "-" + cap))
+ {
+ // 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, enablecap ? 1 : 0);
+ break;
+ }
+ }
+ }
+ else if (data->type == CapEvent::CAPEVENT_LS)
+ {
+ data->wanted.push_back(cap);
+ }
+ else if (data->type == CapEvent::CAPEVENT_LIST)
+ {
+ if (ext.get(data->user))
+ data->wanted.push_back(cap);
+ }
+ else if (data->type == CapEvent::CAPEVENT_CLEAR)
+ {
+ data->ack.push_back("-" + cap);
+ ext.set(data->user, 0);
+ }
+ }