/***************************************************************************
- * Copyright (C) 2005-07 by The Quassel Team *
+ * Copyright (C) 2005-08 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#include "util.h"
-#include "server.h"
-#include "networkinfo.h"
+#include "coresession.h"
+#include "networkconnection.h"
+#include "network.h"
+#include "identity.h"
#include "ctcphandler.h"
#include "ircuser.h"
#include <QDebug>
-IrcServerHandler::IrcServerHandler(Server *parent)
- : BasicHandler(parent) {
+IrcServerHandler::IrcServerHandler(NetworkConnection *parent)
+ : BasicHandler(parent),
+ networkConnection(parent) {
+ _whowas = false;
}
IrcServerHandler::~IrcServerHandler() {
+
+}
+
+QString IrcServerHandler::serverDecode(const QByteArray &string) {
+ return networkConnection->serverDecode(string);
+}
+
+QStringList IrcServerHandler::serverDecode(const QList<QByteArray> &stringlist) {
+ QStringList list;
+ foreach(QByteArray s, stringlist) list << networkConnection->serverDecode(s);
+ return list;
+}
+
+QString IrcServerHandler::bufferDecode(const QString &bufferName, const QByteArray &string) {
+ return networkConnection->bufferDecode(bufferName, string);
+}
+
+QStringList IrcServerHandler::bufferDecode(const QString &bufferName, const QList<QByteArray> &stringlist) {
+ QStringList list;
+ foreach(QByteArray s, stringlist) list << networkConnection->bufferDecode(bufferName, s);
+ return list;
+}
+
+QString IrcServerHandler::userDecode(const QString &userNick, const QByteArray &string) {
+ return networkConnection->userDecode(userNick, string);
+}
+
+QStringList IrcServerHandler::userDecode(const QString &userNick, const QList<QByteArray> &stringlist) {
+ QStringList list;
+ foreach(QByteArray s, stringlist) list << networkConnection->userDecode(userNick, s);
+ return list;
}
/*! Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */
-void IrcServerHandler::handleServerMsg(QByteArray rawmsg) {
+void IrcServerHandler::handleServerMsg(QByteArray msg) {
try {
- if(rawmsg.isEmpty()) {
+ if(msg.isEmpty()) {
qWarning() << "Received empty string from server!";
return;
}
- // TODO Implement encoding conversion
- /* At this point, we have a raw message as a byte array. This needs to be converted to a QString somewhere.
- * Problem is, that at this point we don't know which encoding to use for the various parts of the message.
- * This is something the command handler needs to take care of (e.g. PRIVMSG needs to first parse for CTCP,
- * and then convert the raw strings into the correct encoding.
- * We _can_ safely assume Server encoding for prefix and cmd, but not for the params. Therefore, we need to
- * change from a QStringList to a QList<QByteArray> in all the handlers, and have the handlers call decodeString
- * where needed...
- */
- QString msg = QString::fromLatin1(rawmsg);
-
- // OK, first we split the raw message into its various parts...
+
+ // Now we split the raw message into its various parts...
QString prefix = "";
+ QByteArray trailing;
QString cmd;
- QStringList params;
- // a colon as the first chars indicates the existance of a prefix
- if(msg[0] == ':') {
- msg.remove(0,1);
- prefix = msg.section(' ', 0, 0);
- msg = msg.section(' ', 1);
+ // First, check for a trailing parameter introduced by " :", since this might screw up splitting the msg
+ // NOTE: This assumes that this is true in raw encoding, but well, hopefully there are no servers running in japanese on protocol level...
+ int idx = msg.indexOf(" :");
+ if(idx >= 0) {
+ if(msg.length() > idx + 2) trailing = msg.mid(idx + 2);
+ msg = msg.left(idx);
}
-
- // next string without a whitespace is the command
- cmd = msg.section(' ', 0, 0).toUpper();
- msg = msg.mid(cmd.length());
-
- // get the parameters
- QString trailing = "";
- if(msg.contains(" :")) {
- trailing = msg.section(" :", 1);
- msg = msg.section(" :", 0, 0);
- }
- if(!msg.isEmpty()) {
- params << msg.split(' ', QString::SkipEmptyParts);
+ // OK, now it is safe to split...
+ QList<QByteArray> params = msg.split(' ');
+ if(!trailing.isEmpty()) params << trailing;
+ if(params.count() < 1) {
+ qWarning() << "Received invalid string from server!";
+ return;
}
- if(!trailing.isEmpty()) {
- params << trailing;
+
+ QString foo = serverDecode(params.takeFirst());
+
+ // a colon as the first chars indicates the existence of a prefix
+ if(foo[0] == ':') {
+ foo.remove(0, 1);
+ prefix = foo;
+ if(params.count() < 1) {
+ qWarning() << "Received invalid string from server!";
+ return;
+ }
+ foo = serverDecode(params.takeFirst());
}
+ // next string without a whitespace is the command
+ cmd = foo.trimmed().toUpper();
+
// numeric replies have the target as first param (RFC 2812 - 2.4). this is usually our own nick. Remove this!
uint num = cmd.toUInt();
if(num > 0) {
- Q_ASSERT(params.count() > 0); // Violation to RFC
+ if(params.count() == 0) {
+ qWarning() << "Message received from server violates RFC and is ignored!";
+ return;
+ }
params.removeFirst();
}
// Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-)
- handle(cmd, Q_ARG(QString, prefix), Q_ARG(QStringList, params));
+ handle(cmd, Q_ARG(QString, prefix), Q_ARG(QList<QByteArray>, params));
//handle(cmd, Q_ARG(QString, prefix));
} catch(Exception e) {
emit displayMsg(Message::Error, "", e.msg());
}
-void IrcServerHandler::defaultHandler(QString cmd, QString prefix, QStringList params) {
+void IrcServerHandler::defaultHandler(QString cmd, QString prefix, QList<QByteArray> rawparams) {
+ // we assume that all this happens in server encoding
+ QStringList params;
+ foreach(QByteArray r, rawparams) params << serverDecode(r);
uint num = cmd.toUInt();
if(num) {
// A lot of server messages don't really need their own handler because they don't do much.
//******************************/
// IRC SERVER HANDLER
//******************************/
-void IrcServerHandler::handleJoin(QString prefix, QStringList params) {
+void IrcServerHandler::handleJoin(QString prefix, QList<QByteArray> params) {
Q_ASSERT(params.count() == 1);
- QString channel = params[0];
- IrcUser *ircuser = networkInfo()->updateNickFromMask(prefix);
+ QString channel = serverDecode(params[0]);
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
emit displayMsg(Message::Join, channel, channel, prefix);
- qDebug() << "IrcServerHandler::handleJoin()" << prefix << params;
+ //qDebug() << "IrcServerHandler::handleJoin()" << prefix << params;
ircuser->joinChannel(channel);
}
-void IrcServerHandler::handleKick(QString prefix, QStringList params) {
- networkInfo()->updateNickFromMask(prefix);
- IrcUser *victim = networkInfo()->ircUser(params[1]);
- QString channel = params[0];
+void IrcServerHandler::handleKick(QString prefix, QList<QByteArray> params) {
+ network()->updateNickFromMask(prefix);
+ IrcUser *victim = network()->ircUser(serverDecode(params[1]));
+ QString channel = serverDecode(params[0]);
Q_ASSERT(victim);
victim->partChannel(channel);
QString msg;
if(params.count() > 2) // someone got a reason!
- msg = QString("%1 %2").arg(victim->nick()).arg(params[2]);
+ msg = QString("%1 %2").arg(victim->nick()).arg(bufferDecode(channel, params[2]));
else
msg = victim->nick();
-
- emit displayMsg(Message::Kick, params[0], msg, prefix);
+
+ emit displayMsg(Message::Kick, channel, msg, prefix);
}
-void IrcServerHandler::handleMode(QString prefix, QStringList params) {
- Q_UNUSED(prefix)
- Q_UNUSED(params)
+void IrcServerHandler::handleMode(QString prefix, QList<QByteArray> params) {
+ if(params.count() < 2) {
+ emit displayMsg(Message::Error, "", tr("Received invalid MODE from %s: %s").arg(prefix).arg(serverDecode(params).join(" ")));
+ return;
+ }
+
+ if(network()->isChannelName(params[0])) {
+ // Channel Modes
+ emit displayMsg(Message::Mode, serverDecode(params[0]), serverDecode(params).join(" "), prefix);
+
+ IrcChannel *channel = network()->ircChannel(params.takeFirst());
+ // FIXME: currently the IrcChannels only support PREFIX-Modes for users
+ // This cannot be fixed unless the SignalProxy() doesn't rely on methodIds anymore
+ QString modes = params.takeFirst();
+ bool add = true;
+ int modeIndex = 0;
+ for(int c = 0; c < modes.length(); c++) {
+ if(modes[c] == '+') {
+ add = true;
+ continue;
+ }
+ if(modes[c] == '-') {
+ add = false;
+ continue;
+ }
+
+ // this is the part where we restrict the mode changes to PREFIXES:
+ if(network()->prefixModes().contains(modes[c]) && modeIndex < params.count()) {
+ IrcUser *ircUser = network()->ircUser(params[modeIndex]);
+ if(add)
+ channel->addUserMode(ircUser, QString(modes[c]));
+ else
+ channel->removeUserMode(ircUser, QString(modes[c]));
+ }
+ modeIndex++;
+ }
-// if(isChannelName(params[0])) {
-// // TODO only channel-user modes supported by now
-// QString prefixes = serverSupports["PrefixModes"].toString();
-// QString modes = params[1];
-// int p = 2;
-// int m = 0;
-// bool add = true;
-// while(m < modes.length()) {
-// if(modes[m] == '+') { add = true; m++; continue; }
-// if(modes[m] == '-') { add = false; m++; continue; }
-// if(prefixes.contains(modes[m])) { // it's a user channel mode
-// Q_ASSERT(params.count() > m);
-// QString nick = params[p++];
-// if(nicks.contains(nick)) { // sometimes, a server might try to set a MODE on a nick that is no longer there
-// QVariantMap n = nicks[nick]; QVariantMap clist = n["Channels"].toMap(); QVariantMap chan = clist[params[0]].toMap();
-// QString mstr = chan["Mode"].toString();
-// add ? mstr += modes[m] : mstr.remove(modes[m]);
-// chan["Mode"] = mstr; clist[params[0]] = chan; n["Channels"] = clist; nicks[nick] = n;
-// emit nickUpdated(network, nick, n);
-// }
-// m++;
-// } else {
-// // TODO add more modes
-// m++;
-// }
-// }
-// emit displayMsg(Message::Mode, params[0], params.join(" "), prefix);
-// } else {
-// //Q_ASSERT(nicks.contains(params[0]));
-// //QVariantMap n = nicks[params[0]].toMap();
-// //QString mode = n["Mode"].toString();
-// emit displayMsg(Message::Mode, "", params.join(" "));
-// }
-}
-
-void IrcServerHandler::handleNick(QString prefix, QStringList params) {
- IrcUser *ircuser = networkInfo()->updateNickFromMask(prefix);
+ } else {
+ // pure User Modes
+ emit displayMsg(Message::Mode, "", serverDecode(params).join(" "), prefix);
+ }
+}
+
+void IrcServerHandler::handleNick(QString prefix, QList<QByteArray> params) {
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
Q_ASSERT(ircuser);
- QString newnick = params[0];
+ QString newnick = serverDecode(params[0]);
QString oldnick = ircuser->nick();
foreach(QString channel, ircuser->channels()) {
- if(networkInfo()->isMyNick(oldnick)) {
+ if(network()->isMyNick(oldnick)) {
emit displayMsg(Message::Nick, channel, newnick, newnick);
} else {
emit displayMsg(Message::Nick, channel, newnick, prefix);
ircuser->setNick(newnick);
}
-void IrcServerHandler::handleNotice(QString prefix, QStringList params) {
- if(networkInfo()->currentServer().isEmpty() || networkInfo()->currentServer() == prefix)
- emit displayMsg(Message::Server, "", params[1], prefix);
+void IrcServerHandler::handleNotice(QString prefix, QList<QByteArray> params) {
+ if(network()->currentServer().isEmpty() || network()->currentServer() == prefix)
+ emit displayMsg(Message::Server, "", serverDecode(params[1]), prefix);
else
- emit displayMsg(Message::Notice, "", params[1], prefix);
+ emit displayMsg(Message::Notice, "", userDecode(prefix, params[1]), prefix);
}
-void IrcServerHandler::handlePart(QString prefix, QStringList params) {
- IrcUser *ircuser = networkInfo()->updateNickFromMask(prefix);
- QString channel = params[0];
+void IrcServerHandler::handlePart(QString prefix, QList<QByteArray> params) {
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
+ QString channel = serverDecode(params[0]);
Q_ASSERT(ircuser);
-
+
ircuser->partChannel(channel);
-
+
QString msg;
if(params.count() > 1)
- msg = params[1];
-
- emit displayMsg(Message::Part, params[0], msg, prefix);
+ msg = userDecode(ircuser->nick(), params[1]);
+
+ emit displayMsg(Message::Part, channel, msg, prefix);
}
-void IrcServerHandler::handlePing(QString prefix, QStringList params) {
- Q_UNUSED(prefix)
- emit putCmd("PONG", params);
+void IrcServerHandler::handlePing(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+ emit putCmd("PONG", serverDecode(params));
}
-void IrcServerHandler::handlePrivmsg(QString prefix, QStringList params) {
- networkInfo()->updateNickFromMask(prefix);
- if(params.count()<2)
- params << QString("");
-
- // it's possible to pack multiple privmsgs into one param using ctcp
- QStringList messages = server->ctcpHandler()->parse(CtcpHandler::CtcpQuery, prefix, params[0], params[1]);
-
+void IrcServerHandler::handlePrivmsg(QString prefix, QList<QByteArray> params) {
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
+ Q_ASSERT(ircuser);
+ if(params.count() < 2)
+ params << QByteArray("");
+
+ QString target = serverDecode(params[0]);
+
// are we the target or is it a channel?
- if(networkInfo()->isMyNick(params[0])) {
+ if(network()->isMyNick(target)) {
+ // it's possible to pack multiple privmsgs into one param using ctcp
+ QStringList messages = networkConnection->ctcpHandler()->parse(CtcpHandler::CtcpQuery, prefix, target, userDecode(ircuser->nick(), params[1]));
+ quint8 flags;
foreach(QString message, messages) {
- if(!message.isEmpty()) {
- emit displayMsg(Message::Plain, "", message, prefix, Message::PrivMsg);
- }
+ flags = Message::PrivMsg;
+ if(message.contains(network()->myNick()))
+ flags |= Message::Highlight;
+ emit displayMsg(Message::Plain, "", message, prefix, flags);
}
-
} else {
- Q_ASSERT(isChannelName(params[0])); // should be channel!
+ // so it's probably a channel..
+ if(!isChannelName(target)) {
+ qWarning() << "received PRIVMSG with target" << target << "which is neither us nor a channel!";
+ return;
+ }
+
+ QStringList messages = networkConnection->ctcpHandler()->parse(CtcpHandler::CtcpQuery, prefix, target, bufferDecode(target, params[1]));
+ quint8 flags;
foreach(QString message, messages) {
- if(!message.isEmpty()) {
- emit displayMsg(Message::Plain, params[0], message, prefix);
- }
+ flags = Message::None;
+ if(message.contains(network()->myNick()))
+ flags |= Message::Highlight;
+ emit displayMsg(Message::Plain, target, message, prefix, flags);
}
}
}
-void IrcServerHandler::handleQuit(QString prefix, QStringList params) {
- IrcUser *ircuser = networkInfo()->updateNickFromMask(prefix);
+void IrcServerHandler::handleQuit(QString prefix, QList<QByteArray> params) {
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
Q_ASSERT(ircuser);
- qDebug() << "IrcServerHandler:handleQuit" << prefix << params;
QString msg;
if(params.count())
- msg = params[0];
-
+ msg = userDecode(ircuser->nick(), params[0]);
+
foreach(QString channel, ircuser->channels())
emit displayMsg(Message::Quit, channel, msg, prefix);
-
- networkInfo()->removeIrcUser(nickFromMask(prefix));
+
+ network()->removeIrcUser(nickFromMask(prefix));
}
-void IrcServerHandler::handleTopic(QString prefix, QStringList params) {
- IrcUser *ircuser = networkInfo()->updateNickFromMask(prefix);
- QString channel = params[0];
- QString topic = params[1];
+void IrcServerHandler::handleTopic(QString prefix, QList<QByteArray> params) {
+ IrcUser *ircuser = network()->updateNickFromMask(prefix);
+ QString channel = serverDecode(params[0]);
+ QString topic = bufferDecode(channel, params[1]);
Q_ASSERT(ircuser);
- networkInfo()->ircChannel(channel)->setTopic(topic);
+ network()->ircChannel(channel)->setTopic(topic);
- emit displayMsg(Message::Server, params[0], tr("%1 has changed topic for %2 to: \"%3\"").arg(ircuser->nick()).arg(channel).arg(topic));
+ emit displayMsg(Message::Server, channel, tr("%1 has changed topic for %2 to: \"%3\"").arg(ircuser->nick()).arg(channel).arg(topic));
}
/* RPL_WELCOME */
-void IrcServerHandler::handle001(QString prefix, QStringList params) {
+void IrcServerHandler::handle001(QString prefix, QList<QByteArray> params) {
// there should be only one param: "Welcome to the Internet Relay Network <nick>!<user>@<host>"
- QString myhostmask = params[0].section(' ', -1, -1);
- networkInfo()->setCurrentServer(prefix);
- networkInfo()->setMyNick(nickFromMask(myhostmask));
-
- emit displayMsg(Message::Server, "", params[0], prefix);
+ QString param = serverDecode(params[0]);
+ QString myhostmask = param.section(' ', -1, -1);
+ network()->setCurrentServer(prefix);
+ network()->setMyNick(nickFromMask(myhostmask));
- // TODO: reimplement perform List!
- //// send performlist
- //QStringList performList = networkSettings["Perform"].toString().split( "\n" );
- //int count = performList.count();
- //for(int a = 0; a < count; a++) {
- // if(!performList[a].isEmpty() ) {
- // userInput(network, "", performList[a]);
- // }
- //}
+ emit displayMsg(Message::Server, "", param, prefix);
}
/* RPL_ISUPPORT */
// TODO Complete 005 handling, also use sensible defaults for non-sent stuff
-void IrcServerHandler::handle005(QString prefix, QStringList params) {
+void IrcServerHandler::handle005(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
- QString rpl_isupport_suffix = params.takeLast();
+ QString rpl_isupport_suffix = serverDecode(params.takeLast());
if(rpl_isupport_suffix.toLower() != QString("are supported by this server")) {
qWarning() << "Received invalid RPL_ISUPPORT! Suffix is:" << rpl_isupport_suffix << "Excpected: are supported by this server";
return;
}
- foreach(QString param, params) {
+ foreach(QString param, serverDecode(params)) {
QString key = param.section("=", 0, 0);
QString value = param.section("=", 1);
- networkInfo()->addSupport(key, value);
+ network()->addSupport(key, value);
}
}
-/* RPL_NOTOPIC */
-void IrcServerHandler::handle331(QString prefix, QStringList params) {
+/*
+WHOIS-Message:
+ Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
+ and 301 (RPL_AWAY)
+ "<nick> :<away message>"
+WHO-Message:
+ Replies 352 and 315 paired are used to answer a WHO message.
+
+WHOWAS-Message:
+ Replies 314 and 369 are responses to a WHOWAS message.
+
+*/
+
+
+/* RPL_AWAY - "<nick> :<away message>" */
+void IrcServerHandler::handle301(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
- networkInfo()->ircChannel(params[0])->setTopic(QString());
- emit displayMsg(Message::Server, params[0], tr("No topic is set for %1.").arg(params[0]));
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
+ if(ircuser) {
+ ircuser->setAwayMessage(serverDecode(params.last()));
+ ircuser->setAway(true);
+ }
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
}
-/* RPL_TOPIC */
-void IrcServerHandler::handle332(QString prefix, QStringList params) {
+/* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
+void IrcServerHandler::handle311(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
+ if(ircuser) {
+ ircuser->setUser(serverDecode(params[1]));
+ ircuser->setHost(serverDecode(params[2]));
+ ircuser->setRealName(serverDecode(params.last()));
+ }
+ emit displayMsg(Message::Server, "", tr("[Whois] %1")
+ .arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
+void IrcServerHandler::handle312(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
+ if(ircuser) {
+ ircuser->setServer(serverDecode(params[1]));
+ }
+ if(_whowas) {
+ emit displayMsg(Message::Server, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
+ } else {
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
+ }
+}
+
+/* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
+void IrcServerHandler::handle313(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
+ if(ircuser) {
+ ircuser->setIrcOperator(params.last());
+ }
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_WHOWASUSER - "<nick> <user> <host> * :<real name>" */
+void IrcServerHandler::handle314(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ _whowas = true;
+ emit displayMsg(Message::Server, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_ENDOFWHO: "<name> :End of WHO list" */
+void IrcServerHandler::handle315(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ emit displayMsg(Message::Server, "", tr("[Who] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_WHOISIDLE - "<nick> <integer> :seconds idle" */
+void IrcServerHandler::handle317(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
+ if(ircuser) {
+ QDateTime now = QDateTime::currentDateTime();
+ int idleSecs = serverDecode(params[1]).toInt();
+ idleSecs *= -1;
+ ircuser->setIdleTime(now.addSecs(idleSecs));
+ emit displayMsg(Message::Server, "", tr("[Whois] %1 %2").arg(ircuser->nick()).arg(ircuser->idleTime().secsTo(now)));
+ } else {
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
+ }
+}
+
+/* RPL_ENDOFWHOIS - "<nick> :End of WHOIS list" */
+void IrcServerHandler::handle318(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
- networkInfo()->ircChannel(params[0])->setTopic(params[1]);
- emit displayMsg(Message::Server, params[0], tr("Topic for %1 is \"%2\"").arg(params[0]).arg(params[1]));
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_WHOISCHANNELS - "<nick> :*( ( "@" / "+" ) <channel> " " )" */
+void IrcServerHandler::handle319(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix)
+ emit displayMsg(Message::Server, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* RPL_NOTOPIC */
+void IrcServerHandler::handle331(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+ QString channel = serverDecode(params[0]);
+ network()->ircChannel(channel)->setTopic(QString());
+ emit displayMsg(Message::Server, channel, tr("No topic is set for %1.").arg(channel));
+}
+
+/* RPL_TOPIC */
+void IrcServerHandler::handle332(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+ QString channel = serverDecode(params[0]);
+ QString topic = bufferDecode(channel, params[1]);
+ network()->ircChannel(channel)->setTopic(topic);
+ emit displayMsg(Message::Server, channel, tr("Topic for %1 is \"%2\"").arg(channel, topic));
}
/* Topic set by... */
-void IrcServerHandler::handle333(QString prefix, QStringList params) {
+void IrcServerHandler::handle333(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+ QString channel = serverDecode(params[0]);
+ emit displayMsg(Message::Server, channel, tr("Topic set by %1 on %2")
+ .arg(bufferDecode(channel, params[1]), QDateTime::fromTime_t(bufferDecode(channel, params[2]).toUInt()).toString()));
+}
+
+/* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
+ ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
+void IrcServerHandler::handle352(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
- emit displayMsg(Message::Server, params[0], tr("Topic set by %1 on %2").arg(params[1]).arg(QDateTime::fromTime_t(params[2].toUInt()).toString()));
+ QString channel = serverDecode(params[0]);
+ IrcUser *ircuser = network()->ircUser(serverDecode(params[4]));
+ ircuser->setUser(serverDecode(params[1]));
+ ircuser->setHost(serverDecode(params[2]));
+
+ bool away = serverDecode(params[5]).startsWith("G") ? true : false;
+ ircuser->setAway(away);
+ ircuser->setServer(serverDecode(params[3]));
+ ircuser->setRealName(serverDecode(params.last()).section(" ", 1));
+
+ emit displayMsg(Message::Server, "", tr("[Who] %1").arg(serverDecode(params).join(" ")));
}
/* RPL_NAMREPLY */
-void IrcServerHandler::handle353(QString prefix, QStringList params) {
+void IrcServerHandler::handle353(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
params.removeFirst(); // either "=", "*" or "@" indicating a public, private or secret channel
- QString channelname = params.takeFirst();
+ QString channelname = serverDecode(params.takeFirst());
- foreach(QString nick, params.takeFirst().split(' ')) {
+ foreach(QString nick, serverDecode(params.takeFirst()).split(' ')) {
QString mode = QString();
- if(networkInfo()->prefixes().contains(nick[0])) {
- mode = networkInfo()->prefixToMode(nick[0]);
+ if(network()->prefixes().contains(nick[0])) {
+ mode = network()->prefixToMode(nick[0]);
nick = nick.mid(1);
}
- IrcUser *ircuser = networkInfo()->newIrcUser(nick);
+ IrcUser *ircuser = network()->newIrcUser(nick);
ircuser->joinChannel(channelname);
if(!mode.isNull())
- networkInfo()->ircChannel(channelname)->addUserMode(ircuser, mode);
+ network()->ircChannel(channelname)->addUserMode(ircuser, mode);
}
}
-/* ERR_ERRONEUSNICKNAME */
-void IrcServerHandler::handle432(QString prefix, QStringList params) {
+/* RPL_ENDOFWHOWAS - "<nick> :End of WHOWAS" */
+void IrcServerHandler::handle369(QString prefix, QList<QByteArray> params) {
Q_UNUSED(prefix)
- Q_UNUSED(params)
- emit displayMsg(Message::Error, "", tr("Your desired nickname contains illegal characters!"));
- emit displayMsg(Message::Error, "", tr("Please use /nick <othernick> to continue your IRC-Session!"));
- // FIXME!
-
-// if(params.size() < 2) {
-// // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
-// // nick @@@
-// // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
-// // correct server reply:
-// // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
-// emit displayMsg(Message::Error, "", tr("There is a nickname in your identity's nicklist which contains illegal characters"));
-// emit displayMsg(Message::Error, "", tr("Due to a bug in Unreal IRCd (and maybe other irc-servers too) we're unable to determine the erroneous nick"));
-// emit displayMsg(Message::Error, "", tr("Please use: /nick <othernick> to continue or clean up your nicklist"));
-// } else {
-// QString errnick = params[0];
-// emit displayMsg(Message::Error, "", tr("Nick %1 contains illegal characters").arg(errnick));
-// // if there is a problem while connecting to the server -> we handle it
-// // TODO rely on another source...
-// if(currentServer.isEmpty()) {
-// QStringList desiredNicks = identity["NickList"].toStringList();
-// int nextNick = desiredNicks.indexOf(errnick) + 1;
-// if (desiredNicks.size() > nextNick) {
-// putCmd("NICK", QStringList(desiredNicks[nextNick]));
-// } else {
-// emit displayMsg(Message::Error, "", tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"));
-// }
-// }
-// }
+ _whowas = false;
+ emit displayMsg(Message::Server, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
+}
+
+/* ERR_ERRONEUSNICKNAME */
+void IrcServerHandler::handle432(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+
+ if(params.size() < 2) {
+ // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
+ // nick @@@
+ // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
+ // correct server reply:
+ // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
+ emit displayMsg(Message::Error, "", tr("There is a nickname in your identity's nicklist which contains illegal characters"));
+ emit displayMsg(Message::Error, "", tr("Due to a bug in Unreal IRCd (and maybe other irc-servers too) we're unable to determine the erroneous nick"));
+ emit displayMsg(Message::Error, "", tr("Please use: /nick <othernick> to continue or clean up your nicklist"));
+ } else {
+ QString errnick = params[0];
+ emit displayMsg(Message::Error, "", tr("Nick %1 contains illegal characters").arg(errnick));
+ tryNextNick(errnick);
+ }
}
/* ERR_NICKNAMEINUSE */
-void IrcServerHandler::handle433(QString prefix, QStringList params) {
- Q_UNUSED(prefix)
- QString errnick = params[0];
- emit displayMsg(Message::Error, "", tr("Nick %1 is already taken").arg(errnick));
- emit displayMsg(Message::Error, "", tr("Please use /nick <othernick> to continue your IRC-Session!"));
- // FIXME!
-
-// // if there is a problem while connecting to the server -> we handle it
-// // TODO rely on another source...
-// if(currentServer.isEmpty()) {
-// QStringList desiredNicks = identity["NickList"].toStringList();
-// int nextNick = desiredNicks.indexOf(errnick) + 1;
-// if (desiredNicks.size() > nextNick) {
-// putCmd("NICK", QStringList(desiredNicks[nextNick]));
-// } else {
-// emit displayMsg(Message::Error, "", tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"));
-// }
-// }
+void IrcServerHandler::handle433(QString prefix, QList<QByteArray> params) {
+ Q_UNUSED(prefix);
+
+ QString errnick = serverDecode(params[0]);
+ emit displayMsg(Message::Error, "", tr("Nick already in use: %1").arg(errnick));
+
+ // if there is a problem while connecting to the server -> we handle it
+ // but only if our connection has not been finished yet...
+ if(!networkConnection->network()->currentServer().isEmpty())
+ return;
+
+ tryNextNick(errnick);
}
+void IrcServerHandler::tryNextNick(const QString &errnick) {
+ QStringList desiredNicks = networkConnection->coreSession()->identity(networkConnection->network()->identity())->nicks();
+ int nextNick = desiredNicks.indexOf(errnick) + 1;
+ if(desiredNicks.size() > nextNick) {
+ putCmd("NICK", QStringList(desiredNicks[nextNick]));
+ } else {
+ emit displayMsg(Message::Error, "", tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"));
+ }
+}
+
+
/***********************************************************************************/