From b39afed6242836f67b14d07281af9a1d335446c1 Mon Sep 17 00:00:00 2001 From: Tomatix Date: Tue, 17 Nov 2020 18:08:40 +0100 Subject: [PATCH] Fixed broken CTCP --- ICommand/Internal/ctcp.cpp | 2 +- ICommand/Internal/me.cpp | 2 +- IRCClient/IRCBase.cpp | 32 +++++++++++++++++++++----------- IRCClient/IRCBase.h | 3 ++- IdealIRC/IRC.cpp | 5 +++-- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ICommand/Internal/ctcp.cpp b/ICommand/Internal/ctcp.cpp index c2d1e1b..6e41bb7 100644 --- a/ICommand/Internal/ctcp.cpp +++ b/ICommand/Internal/ctcp.cpp @@ -10,5 +10,5 @@ void ICommandPriv::cmd_ctcp(const std::string& target, const std::string& comman .arg(qmsg) .arg(target.c_str())); - connection.ctcp(target, command, message); + connection.ctcpRequest(target, command, message); } diff --git a/ICommand/Internal/me.cpp b/ICommand/Internal/me.cpp index cde1174..8957fc0 100644 --- a/ICommand/Internal/me.cpp +++ b/ICommand/Internal/me.cpp @@ -6,7 +6,7 @@ using namespace Command::Internal; void ICommandPriv::cmd_me(const std::string& target, const std::string& message) { - connection.ctcp(target, ACTION, message); + connection.ctcpRequest(target, ACTION, message); std::string mynick = connection.getNickname(); IWin* cw = status.getActiveWindow(); diff --git a/IRCClient/IRCBase.cpp b/IRCClient/IRCBase.cpp index 9311899..647e9d4 100644 --- a/IRCClient/IRCBase.cpp +++ b/IRCClient/IRCBase.cpp @@ -324,6 +324,20 @@ struct IRCBasePriv sock->write_some(asio::buffer(out)); } + void ctcp(const std::string& messageType, const std::string& target, const std::string& command, const std::string& message = "") + { + if (!isConnected) + return; + + std::string ctcpdata; + ctcpdata.push_back(CTCPflag); + ctcpdata.append(command); + if (!message.empty()) + ctcpdata.append(" " + message); + ctcpdata.push_back(CTCPflag); + write(messageType, { target }, ctcpdata); + } + void addMemberToChannel(const IRCPrefix& prefix, const std::string& channel) { auto member = super.getMember(prefix.nickname()); @@ -468,7 +482,7 @@ struct IRCBasePriv return IRCError::NoError; } - void parseChannelModeMessage(std::shared_ptr chan, const std::string& modes, const std::vector& args) + void parseChannelModeMessage(std::shared_ptr chan, const std::string& modes, const std::vector& args) const { char sign; // + or - int argidx = 0; @@ -681,18 +695,14 @@ void IRCBase::raw(const std::string& data) mp->writeNoMsg(data, {}); } -void IRCBase::ctcp(const std::string& target, const std::string& command, const std::string& message) +void IRCBase::ctcpRequest(const std::string& target, const std::string& command, const std::string& message) { - if (!mp->isConnected) - return; + mp->ctcp(Command::IRC::PRIVMSG, target, command, message); +} - std::string ctcpdata; - ctcpdata.push_back(CTCPflag); - ctcpdata.append(command); - if (!message.empty()) - ctcpdata.append(" " + message); - ctcpdata.push_back(CTCPflag); - mp->write(Command::IRC::PRIVMSG, { target }, ctcpdata); +void IRCBase::ctcpResponse(const std::string& target, const std::string& command, const std::string& message) +{ + mp->ctcp(Command::IRC::NOTICE, target, command, message); } void IRCBase::setManualKeepalive(std::chrono::seconds freq) diff --git a/IRCClient/IRCBase.h b/IRCClient/IRCBase.h index b8f772f..e5a919b 100644 --- a/IRCClient/IRCBase.h +++ b/IRCClient/IRCBase.h @@ -56,7 +56,8 @@ public: void command(const std::string& command, const std::string& msg); void raw(const std::string& data); - void ctcp(const std::string& target, const std::string& command, const std::string& message = ""); + void ctcpRequest(const std::string& target, const std::string& command, const std::string& message = ""); + void ctcpResponse(const std::string& target, const std::string& command, const std::string& message = ""); //! Set to >0 to enable, =0 to disable. void setManualKeepalive(std::chrono::seconds freq = std::chrono::seconds(30)); diff --git a/IdealIRC/IRC.cpp b/IdealIRC/IRC.cpp index 9d3aaf2..7d8d82d 100644 --- a/IdealIRC/IRC.cpp +++ b/IdealIRC/IRC.cpp @@ -611,7 +611,7 @@ void IRC::onMsgCTCPRequest(const IRCPrefix& sender, const std::string& target, c msg = fmt::format("[CTCP {}] from {}", command, sender.nickname()); } - /* Sent to channel */ + /* Sent to channel */ else { msg = fmt::format("[CTCP {}]:{} from {}", command, target, sender.nickname()); } @@ -621,7 +621,8 @@ void IRC::onMsgCTCPRequest(const IRCPrefix& sender, const std::string& target, c } if (command == "VERSION") { - ctcp(sender.nickname(), "VERSION", fmt::format("IdealIRC {} by Tomatix - http://idealirc.org/", VERSION_STRING)); + ctcpResponse(sender.nickname(), "VERSION", + fmt::format("IdealIRC {} by Tomatix - http://www.idealirc.org/", VERSION_STRING)); } contextualScriptEvent(&m_status, ScriptEvent::CtcpRequest, sender.toString(), target, command, message);