X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fctcphandler.cpp;h=6a28f5e9be0c7ae2d7ee31cfb5a20633f4619de7;hb=a18fc9cf59a6329cb67d4eb7bd0197fceacdf7d8;hp=2b606f6ba833241db0e69d7d2164b6ca4e3db9f0;hpb=ac374ec32612798c230d54665f6bce7faf416602;p=quassel.git diff --git a/src/core/ctcphandler.cpp b/src/core/ctcphandler.cpp index 2b606f6b..6a28f5e9 100644 --- a/src/core/ctcphandler.cpp +++ b/src/core/ctcphandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-10 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -26,7 +26,7 @@ #include "coreignorelistmanager.h" CtcpHandler::CtcpHandler(CoreNetwork *parent) - : BasicHandler(parent), + : CoreBasicHandler(parent), XDELIM("\001"), _ignoreListManager(parent->ignoreListManager()) { @@ -162,6 +162,9 @@ void CtcpHandler::parse(Message::Type messageType, const QString &prefix, const } QByteArray CtcpHandler::pack(const QByteArray &ctcpTag, const QByteArray &message) { + if(message.isEmpty()) + return XDELIM + ctcpTag + XDELIM; + return XDELIM + ctcpTag + ' ' + xdelimQuote(message) + XDELIM; } @@ -185,43 +188,74 @@ void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const Q emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix); } +void CtcpHandler::handleClientinfo(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { + Q_UNUSED(target) + if(ctcptype == CtcpQuery) { + if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "CLIENTINFO")) + return; + reply(nickFromMask(prefix), "CLIENTINFO", QString("ACTION CLIENTINFO PING TIME VERSION")); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP CLIENTINFO request from %1").arg(prefix)); + } else { + // display clientinfo answer + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP CLIENTINFO answer from %1: %2") + .arg(nickFromMask(prefix)).arg(param)); + } +} + void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { Q_UNUSED(target) if(ctcptype == CtcpQuery) { - if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING")) { - reply(nickFromMask(prefix), "PING", param); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix)); - } + if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING")) + return; + reply(nickFromMask(prefix), "PING", param); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix)); } else { // display ping answer uint now = QDateTime::currentDateTime().toTime_t(); uint then = QDateTime().fromTime_t(param.toInt()).toTime_t(); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING answer from %1 with %2 seconds round trip time").arg(prefix).arg(now-then)); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING answer from %1 with %2 seconds round trip time") + .arg(nickFromMask(prefix)).arg(now-then)); } } void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { Q_UNUSED(target) if(ctcptype == CtcpQuery) { - if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION")) { - reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org") + if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION")) + return; + reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org") .arg(Quassel::buildInfo().plainVersionString) .arg(Quassel::buildInfo().buildDate)); - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix)); - } + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix)); } else { // display Version answer - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION answer from %1: %2").arg(prefix).arg(param)); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION answer from %1: %2") + .arg(nickFromMask(prefix)).arg(param)); + } +} + +void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { + Q_UNUSED(target) + if(ctcptype == CtcpQuery) { + if(_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "TIME")) + return; + reply(nickFromMask(prefix), "TIME", QDateTime::currentDateTime().toString()); + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME request by %1").arg(prefix)); + } + else { + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP TIME answer from %1: %2") + .arg(nickFromMask(prefix)).arg(param)); } } void CtcpHandler::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { Q_UNUSED(ctcptype); Q_UNUSED(target); - Q_UNUSED(param); if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) { - emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix)); + QString str = tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix); + if(!param.isEmpty()) + str.append(tr(" with arguments: %1").arg(param)); + emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", str); } } -