The complete source code of IdealIRC http://www.idealirc.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
idealirc/IRCClient/Commands/cmdV3Cap.cpp

56 lines
1.8 KiB

/*
* 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::string>(std::istream_iterator<std::string>{ss},
std::istream_iterator<std::string>());
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.
}
}