#121 Added capability to enable/disable IRCv3 extensions for IRCClient.

master
Tomatix 4 years ago
parent 34efc87086
commit 505231f9b2
  1. 4
      IRCClient/Commands/cmdV3Cap.cpp
  2. 37
      IRCClient/IRCBase.cpp
  3. 10
      IRCClient/IRCBase.h
  4. 2
      IRCClient/IRCBasePriv.h

@ -23,8 +23,8 @@ void IRCBasePriv::cmdV3Cap(const IRCMessage& ircmessage)
std::istream_iterator<std::string>());
for (const auto& cap : serverV3support) {
auto myIt = std::find(V3Support.begin(), V3Support.end(), cap);
if (myIt != V3Support.end())
auto myIt = std::find(ircv3enabled.begin(), ircv3enabled.end(), cap);
if (myIt != ircv3enabled.end())
registeredV3support.push_back(cap);
}

@ -21,7 +21,9 @@
IRCBase::IRCBase()
: mp(new IRCBasePriv(*this))
{}
{
std::copy(V3Support.begin(), V3Support.end(), std::back_inserter(mp->ircv3enabled));
}
IRCBase::IRCBase(IRCBase&& other) noexcept
: mp(std::move(other.mp))
@ -369,6 +371,11 @@ const std::vector<std::string>& IRCBase::clientV3Support()
return V3Support;
}
const std::vector<std::string>& IRCBase::enabledV3Support() const
{
return mp->ircv3enabled;
}
const std::vector<std::string>& IRCBase::registeredV3Support() const
{
return mp->registeredV3support;
@ -419,3 +426,31 @@ const IRCMessage* IRCBase::getCurrentMessageRaw() const
{
return mp->currentMessage;
}
void IRCBase::enableIRCv3Features(const std::vector<std::string>& features)
{
auto isFeatureSupported = [](const std::string& feature) {
return std::find(V3Support.begin(), V3Support.end(), feature) == V3Support.end();
};
auto isFeatureEnabled = [this](const std::string& feature) {
return std::find(mp->ircv3enabled.begin(), mp->ircv3enabled.end(), feature) != mp->ircv3enabled.end();
};
for (const auto& feature : features) {
if (!isFeatureSupported(feature) || isFeatureEnabled(feature))
continue;
else
mp->ircv3enabled.emplace_back(feature);
}
}
void IRCBase::disableIRCv3Features(const std::vector<std::string>& features)
{
for (const auto& feature : features) {
auto it = std::find(mp->ircv3enabled.begin(), mp->ircv3enabled.end(), feature);
if (it != mp->ircv3enabled.end()) {
mp->ircv3enabled.erase(it);
}
}
}

@ -107,6 +107,7 @@ public:
[[nodiscard]] bool isSSL() const;
[[nodiscard]] static const std::vector<std::string>& clientV3Support();
[[nodiscard]] const std::vector<std::string>& enabledV3Support() const;
[[nodiscard]] const std::vector<std::string>& registeredV3Support() const;
[[nodiscard]] const std::vector<std::string>& serverV3Support() const;
[[nodiscard]] const std::unordered_map<std::string,std::string>& isupport() const;
@ -120,6 +121,15 @@ public:
[[nodiscard]] const IRCMessage* getCurrentMessageRaw() const;
/**
* Enables a set of IRCv3 features. The keys are strings as described by the standard (eg. account-notify, away-notify, etc.)
* If a feature given is not actually supported by the client, it's ignored. See 'V3Support' in IRCBasePriv.h.
*/
void enableIRCv3Features(const std::vector<std::string>& features);
/// Disables a set of IRCv3 features. The keys are strings as described by the standard (eg. account-notify, away-notify, etc.)
void disableIRCv3Features(const std::vector<std::string>& features);
protected:
virtual void onConnected() {}
virtual void onConnectedWithSSLExceptions(const std::vector<IRCError>& codes) {}

@ -111,6 +111,8 @@ struct IRCBasePriv
IRCMessage* currentMessage{ nullptr };
std::vector<std::string> ircv3enabled;
/*
* Various helper functions for the IRC client implementation.
*/

Loading…
Cancel
Save