/* * IdealIRC Core - Internet Relay Chat API * Copyright (C) 2021 Tom-Andre Barstad. * This software is licensed under the Software Attribution License. * See LICENSE for more information. */ #include "../IRCBase.h" #include "../IRCBasePriv.h" #include "../Commands.h" void IRCBasePriv::cmdV3Cap(const IRCMessage& ircmessage) { using namespace Command::IRC; /* * List of IRCv3 capabilities from the server. * Match it with what we support and request those. */ if (ircmessage[1] == Command::IRCv3::LS) { std::istringstream ss(ircmessage.getMessage()); serverV3support = std::vector(std::istream_iterator{ss}, std::istream_iterator()); for (const auto& cap : serverV3support) { auto myIt = std::find(ircv3enabled.begin(), ircv3enabled.end(), cap); if (myIt != ircv3enabled.end()) registeredV3support.push_back(cap); } std::string requestStr; for (const auto& cap : registeredV3support) { if (!requestStr.empty()) requestStr += ' '; requestStr += cap; } write(Command::IRCv3::CAP, { Command::IRCv3::REQ }, requestStr); } /* * Server accepted our desires. */ else if (ircmessage[1] == Command::IRCv3::ACK) { writeNoMsg(Command::IRCv3::CAP, { Command::IRCv3::END }); } /* * Server replied NAK on our IRCv3 capabilities, even though it seems it supported them... * Resetting and continuing with our lives. */ else if (ircmessage[1] == Command::IRCv3::NAK) { registeredV3support.clear(); writeNoMsg(Command::IRCv3::CAP, { Command::IRCv3::END }); // TODO erase the offending modules instead. } }