CTCP Ping. Some CTCP fixes also.

master
Tomatix 5 years ago
parent a6dc2684c5
commit 7552c851ff
  1. 2
      ICommand/ICommandPriv.h
  2. 8
      ICommand/Internal/ctcp.cpp
  3. 6
      ICommand/Internal/ctcpreply.cpp
  4. 31
      IdealIRC/IRC.cpp

@ -22,7 +22,7 @@ struct ICommandPriv
void cmd_privmsg(const std::string& target, const std::string& message);
void cmd_notice(const std::string& target, const std::string& message);
void cmd_ctcp(const std::string& target, const std::string& command, const std::string& message);
void cmd_ctcp(const std::string& target, const std::string& command, std::string message);
void cmd_ctcpreply(const std::string& target, const std::string& command, const std::string& message);
void cmd_me(const std::string& target, const std::string& message);
void cmd_echo(const std::string& arg1, const std::string& arg2, const std::string& text);

@ -1,9 +1,13 @@
#include "ICommand/ICommandPriv.h"
#include <QDateTime>
void ICommandPriv::cmd_ctcp(const std::string& target, const std::string& command, const std::string& message)
void ICommandPriv::cmd_ctcp(const std::string& target, const std::string& command, std::string message)
{
if (command == "PING")
message = std::to_string( QDateTime::currentMSecsSinceEpoch() );
QString qmsg = QString::fromStdString(command);
if (!message.empty())
if (!message.empty() && command != "PING")
qmsg += " " + QString::fromStdString(message);
status.printToActive(PrintType::CTCP, QStringLiteral("Sending [CTCP %1] to %2")

@ -6,9 +6,9 @@ void ICommandPriv::cmd_ctcpreply(const std::string& target, const std::string& c
if (!message.empty())
qmsg += " " + QString::fromStdString(message);
status.printToActive(PrintType::CTCP, QStringLiteral("Sending [CTCP REPLY %1] to %2")
.arg(qmsg)
.arg(target.c_str()));
status.print(PrintType::CTCP, QStringLiteral("Sending [CTCP REPLY %1] to %2")
.arg(qmsg)
.arg(target.c_str()));
connection.ctcpResponse(target, command, message);
}

@ -761,44 +761,59 @@ void IRC::onMsgCTCPRequest(const IRCPrefix& sender, const std::string& target, c
win->print(PrintType::Action, msg.c_str());
}
else if (!ignoreVerbosity(Command::Internal::CTCP)) {
std::string msg;
std::string printmsg;
std::string cmdMsg;
if (!message.empty() && command != "PING")
cmdMsg = fmt::format("{} {}", command, message);
else
cmdMsg = command;
/* Sent private */
if (std::find(chantypes.begin(), chantypes.end(), target[0]) == chantypes.end()) {
msg = fmt::format("[CTCP {}] from {}", command, sender.nickname());
printmsg = fmt::format("[CTCP {}] from {}", cmdMsg, sender.nickname());
}
/* Sent to channel */
else {
msg = fmt::format("[CTCP {}]:{} from {}", command, target, sender.nickname());
printmsg = fmt::format("[CTCP {}]:{} from {}", cmdMsg, target, sender.nickname());
}
auto* win = getStatus().getActiveWindow();
win->print(PrintType::CTCP, msg.c_str());
getStatus().print(PrintType::CTCP, printmsg.c_str());
}
if (command == "VERSION") {
ctcpResponse(sender.nickname(), "VERSION",
fmt::format("IdealIRC {} by Tomatix - http://www.idealirc.org/", VERSION_STRING));
}
else if (command == "PING") {
ctcpResponse(sender.toString(), command, message);
}
contextualScriptEvent(&m_status, ScriptEvent::CtcpRequest, sender.toString(), target, command, message);
}
void IRC::onMsgCTCPResponse(const IRCPrefix& sender, const std::string& target, const std::string& command, const std::string& message)
{
std::string msg = message;
if (command == "PING") {
const qint64 curr = QDateTime::currentMSecsSinceEpoch();
const qint64 prev = std::stoll(message);
const qint64 diffMs = curr - prev;
msg = fmt::format("{}ms", diffMs);
}
if (!ignoreVerbosity(Command::Internal::CTCP)) {
std::string printmsg;
if (message.empty())
printmsg = fmt::format("[CTCP {}] reply from {}", command, sender.nickname());
else
printmsg = fmt::format("[CTCP {}] reply from {}: {}", command, sender.nickname(), message);
printmsg = fmt::format("[CTCP {}] reply from {}: {}", command, sender.nickname(), msg);
auto* win = getStatus().getActiveWindow();
win->print(PrintType::CTCP, printmsg.c_str());
}
contextualScriptEvent(&m_status, ScriptEvent::CtcpReply, sender.toString(), target, command, message);
contextualScriptEvent(&m_status, ScriptEvent::CtcpReply, sender.toString(), target, command, msg);
}
void IRC::onMsgDCCRequest(std::shared_ptr<DCC> dcc, const IRCPrefix& sender, const std::string& target, const std::string& type, const std::string& message)

Loading…
Cancel
Save