diff options
author | louiz’ <louiz@louiz.org> | 2020-08-16 16:09:13 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2020-08-16 16:09:13 +0200 |
commit | f548f63178508936e36ac42e39d7ca0f064dcfb1 (patch) | |
tree | 2f177e03a76ef05b0f279544d4196beb6f859da4 /src | |
parent | d016010333c7c093235f8d2cb8005109d205b2e1 (diff) | |
parent | b98434b5d04d1ada9b24475e17ee8947d96ad1e3 (diff) | |
download | biboumi-f548f63178508936e36ac42e39d7ca0f064dcfb1.tar.gz biboumi-f548f63178508936e36ac42e39d7ca0f064dcfb1.tar.bz2 biboumi-f548f63178508936e36ac42e39d7ca0f064dcfb1.tar.xz biboumi-f548f63178508936e36ac42e39d7ca0f064dcfb1.zip |
Merge branch 'v9'
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/irc_client.cpp | 25 | ||||
-rw-r--r-- | src/irc/irc_message.cpp | 39 | ||||
-rw-r--r-- | src/irc/irc_message.hpp | 4 |
3 files changed, 35 insertions, 33 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 3ae5ac6..5f0d9b9 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -1340,19 +1340,22 @@ long int IrcClient::get_throttle_limit() const void IrcClient::on_cap(const IrcMessage &message) { const auto& sub_command = message.arguments[1]; - const auto& cap = message.arguments[2]; - auto it = this->capabilities.find(cap); - if (it == this->capabilities.end()) + const auto& caps = utils::split(message.arguments[2], ' ', false); + for (const auto& cap: caps) { - log_warning("Received a CAP message for something we didn’t ask, or that we already handled."); - return; + auto it = this->capabilities.find(cap); + if (it == this->capabilities.end()) + { + log_warning("Received a CAP message for something we didn’t ask, or that we already handled: [", cap, "]"); + return; + } + Capability& capability = it->second; + if (sub_command == "ACK") + capability.on_ack(); + else if (sub_command == "NACK") + capability.on_nack(); + this->capabilities.erase(it); } - Capability& capability = it->second; - if (sub_command == "ACK") - capability.on_ack(); - else if (sub_command == "NACK") - capability.on_nack(); - this->capabilities.erase(it); if (this->capabilities.empty()) this->cap_end(); } diff --git a/src/irc/irc_message.cpp b/src/irc/irc_message.cpp index 14fdb0e..62fe9a7 100644 --- a/src/irc/irc_message.cpp +++ b/src/irc/irc_message.cpp @@ -1,33 +1,30 @@ #include <irc/irc_message.hpp> #include <iostream> -IrcMessage::IrcMessage(std::string&& line) +IrcMessage::IrcMessage(std::stringstream ss) { - std::string::size_type pos; - - // optional prefix - if (line[0] == ':') + if (ss.peek() == ':') { - pos = line.find(' '); - this->prefix = line.substr(1, pos - 1); - line = line.substr(pos + 1, std::string::npos); + ss.ignore(); + ss >> this->prefix; } - // command - pos = line.find(' '); - this->command = line.substr(0, pos); - line = line.substr(pos + 1, std::string::npos); - // arguments - do + ss >> this->command; + while (ss >> std::ws) { - if (line[0] == ':') + std::string arg; + if (ss.peek() == ':') + { + ss.ignore(); + std::getline(ss, arg); + } + else { - this->arguments.emplace_back(line.substr(1, std::string::npos)); - break ; + ss >> arg; + if (arg.empty()) + break; } - pos = line.find(' '); - this->arguments.emplace_back(line.substr(0, pos)); - line = line.substr(pos + 1, std::string::npos); - } while (pos != std::string::npos); + this->arguments.push_back(std::move(arg)); + } } IrcMessage::IrcMessage(std::string&& prefix, diff --git a/src/irc/irc_message.hpp b/src/irc/irc_message.hpp index 269a12a..5475fd2 100644 --- a/src/irc/irc_message.hpp +++ b/src/irc/irc_message.hpp @@ -4,11 +4,13 @@ #include <vector> #include <string> #include <ostream> +#include <sstream> class IrcMessage { public: - IrcMessage(std::string&& line); + IrcMessage(std::stringstream ss); + IrcMessage(std::string str): IrcMessage{std::stringstream{str}} {} IrcMessage(std::string&& prefix, std::string&& command, std::vector<std::string>&& args); IrcMessage(std::string&& command, std::vector<std::string>&& args); ~IrcMessage() = default; |