/***************************************************************************
- * 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 *
#include "coreignorelistmanager.h"
CtcpHandler::CtcpHandler(CoreNetwork *parent)
- : BasicHandler(parent),
+ : CoreBasicHandler(parent),
XDELIM("\001"),
_ignoreListManager(parent->ignoreListManager())
{
int xdelimPos = -1;
int xdelimEndPos = -1;
int spacePos = -1;
+ QList<QByteArray> replies;
while((xdelimPos = dequotedMessage.indexOf(XDELIM)) != -1) {
if(xdelimPos > 0)
displayMsg(messageType, target, userDecode(target, dequotedMessage.left(xdelimPos)), prefix, flags);
ctcpparam = QString();
}
- handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), ctcpcmd.toUpper())) {
+ QString reply_;
+ handle(ctcpcmd, Q_ARG(CtcpType, ctcptype), Q_ARG(QString, prefix), Q_ARG(QString, target), Q_ARG(QString, ctcpparam), Q_ARG(QString, reply_));
+ if(ctcptype == CtcpQuery && !reply_.isNull()) {
+ replies << lowLevelQuote(pack(serverEncode(ctcpcmd), userEncode(nickFromMask(prefix), reply_)));
+ }
+ }
+ }
+ if(ctcptype == CtcpQuery && !replies.isEmpty()) {
+ packedReply(nickFromMask(prefix), replies);
}
if(!dequotedMessage.isEmpty())
}
QByteArray CtcpHandler::pack(const QByteArray &ctcpTag, const QByteArray &message) {
+ if(message.isEmpty())
+ return XDELIM + ctcpTag + XDELIM;
+
return XDELIM + ctcpTag + ' ' + xdelimQuote(message) + XDELIM;
}
emit putCmd("NOTICE", params);
}
+void CtcpHandler::packedReply(const QString &bufname, const QList<QByteArray> &replies) {
+ QList<QByteArray> params;
+
+ int answerSize = 0;
+ for(int i = 0; i < replies.count(); i++) {
+ answerSize += replies.at(i).size();
+ }
+
+ QByteArray quotedReply(answerSize, 0);
+ int nextPos = 0;
+ QByteArray &reply = quotedReply;
+ for(int i = 0; i < replies.count(); i++) {
+ reply = replies.at(i);
+ quotedReply.replace(nextPos, reply.size(), reply);
+ nextPos += reply.size();
+ }
+
+ params << serverEncode(bufname) << quotedReply;
+ emit putCmd("NOTICE", params);
+}
+
//******************************/
// CTCP HANDLER
//******************************/
-void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleAction(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &/*reply*/) {
Q_UNUSED(ctcptype)
emit displayMsg(Message::Action, typeByTarget(target), target, param, prefix);
}
-void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
+void CtcpHandler::handleClientinfo(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
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));
+ QStringList supportedHandlers;
+ foreach(QString handler, providesHandlers()) {
+ supportedHandlers << handler.toUpper();
}
+ reply = supportedHandlers.join(" ");
+ 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, QString &reply) {
+ Q_UNUSED(target)
+ if(ctcptype == CtcpQuery) {
+ reply = 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) {
+void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
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")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
- emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
- }
+ reply = 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));
} 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::defaultHandler(const QString &cmd, CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
- Q_UNUSED(ctcptype);
- Q_UNUSED(target);
- if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
- 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);
+void CtcpHandler::handleTime(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m, QString &reply) {
+ Q_UNUSED(target)
+ if(ctcptype == CtcpQuery) {
+ reply = 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, QString &reply) {
+ Q_UNUSED(ctcptype);
+ Q_UNUSED(target);
+ Q_UNUSED(reply);
+ 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);
+}