diff options
Diffstat (limited to 'src/modules/m_cap.h')
-rw-r--r-- | src/modules/m_cap.h | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/src/modules/m_cap.h b/src/modules/m_cap.h index ce5aec8ba..72c7a14a5 100644 --- a/src/modules/m_cap.h +++ b/src/modules/m_cap.h @@ -27,42 +27,53 @@ class CapData : public classbase Module* creator; }; -void GenericCapHandler(Event* ev, const std::string &extname, const std::string &cap) +class GenericCap { - if (ev->GetEventID() == "cap_req") + public: + LocalIntExt ext; + const std::string cap; + GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + cap, parent), cap(Cap) { - CapData *data = (CapData *) ev->GetData(); - - std::vector<std::string>::iterator it; - if ((it = std::find(data->wanted.begin(), data->wanted.end(), cap)) != data->wanted.end()) - { - // we can handle this, so ACK it, and remove it from the wanted list - data->ack.push_back(*it); - data->wanted.erase(it); - data->user->Extend(extname); - } + Extensible::Register(&ext); } - if (ev->GetEventID() == "cap_ls") + void HandleEvent(Event* ev) { - CapData *data = (CapData *) ev->GetData(); - data->wanted.push_back(cap); - } + if (ev->GetEventID() == "cap_req") + { + CapData *data = (CapData *) ev->GetData(); - if (ev->GetEventID() == "cap_list") - { - CapData *data = (CapData *) ev->GetData(); + std::vector<std::string>::iterator it; + if ((it = std::find(data->wanted.begin(), data->wanted.end(), cap)) != data->wanted.end()) + { + // 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, 1); + } + } - if (data->user->GetExt(extname)) + if (ev->GetEventID() == "cap_ls") + { + CapData *data = (CapData *) ev->GetData(); data->wanted.push_back(cap); - } + } - if (ev->GetEventID() == "cap_clear") - { - CapData *data = (CapData *) ev->GetData(); - data->ack.push_back("-" + cap); - data->user->Shrink(extname); + if (ev->GetEventID() == "cap_list") + { + CapData *data = (CapData *) ev->GetData(); + + if (ext.get(data->user)) + data->wanted.push_back(cap); + } + + if (ev->GetEventID() == "cap_clear") + { + CapData *data = (CapData *) ev->GetData(); + data->ack.push_back("-" + cap); + ext.set(data->user, 0); + } } -} +}; #endif |