// 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);
+ if(msg.length() > idx + 2)
+ trailing = msg.mid(idx + 2);
msg = msg.left(idx);
}
// OK, now it is safe to split...
QList<QByteArray> params = msg.split(' ');
+
+ // This could still contain empty elements due to (faulty?) ircds sending multiple spaces in a row
+ // Also, QByteArray is not nearly as convenient to work with as QString for such things :)
+ QList<QByteArray>::iterator iter = params.begin();
+ while(iter != params.end()) {
+ if(iter->isEmpty())
+ iter = params.erase(iter);
+ else
+ ++iter;
+ }
+
if(!trailing.isEmpty()) params << trailing;
if(params.count() < 1) {
qWarning() << "Received invalid string from server!";
uint num = cmd.toUInt();
if(num > 0) {
if(params.count() == 0) {
- qWarning() << "Message received from server violates RFC and is ignored!";
+ qWarning() << "Message received from server violates RFC and is ignored!" << msg;
return;
}
- params.removeFirst();
+ _target = serverDecode(params.takeFirst());
+ } else {
+ _target = QString();
}
// note that the IRC server is still alive
handleMode(prefix, params);
}
+/* RPL_??? - "<channel> <homepage> */
+void IrcServerHandler::handle328(const QString &prefix, const QList<QByteArray> ¶ms) {
+ Q_UNUSED(prefix);
+ if(!checkParamCount("IrcServerHandler::handle328()", params, 2))
+ return;
+
+ QString channel = serverDecode(params[0]);
+ QString homepage = serverDecode(params[1]);
+
+ emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Homepage for %1 is %2").arg(channel, homepage));
+}
+
+
/* RPL_??? - "<channel> <creation time (unix)>" */
void IrcServerHandler::handle329(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
- Q_UNUSED(params)
-#ifdef __GNUC__
-# warning "Implement handle329 (Channel creation time)"
-#endif
- // FIXME implement this...
+ if(!checkParamCount("IrcServerHandler::handle329()", params, 2))
+ return;
+
+ QString channel = serverDecode(params[0]);
+ uint unixtime = params[1].toUInt();
+ if(!unixtime) {
+ qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << params[1];
+ return;
+ }
+ QDateTime time = QDateTime::fromTime_t(unixtime);
+
+ emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Channel %1 created on %2").arg(channel, time.toString()));
}
/* RPL_NOTOPIC */
void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> ¶ms) {
Q_UNUSED(prefix);
+ QString errnick;
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, BufferInfo::StatusBuffer, "", tr("There is a nickname in your identity's nicklist which contains illegal characters"));
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", 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, BufferInfo::StatusBuffer, "", tr("Please use: /nick <othernick> to continue or clean up your nicklist"));
+ errnick = target();
} else {
- QString errnick = params[0];
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick %1 contains illegal characters").arg(errnick));
- tryNextNick(errnick);
+ errnick = params[0];
}
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick %1 contains illegal characters").arg(errnick));
+ tryNextNick(errnick, true /* erroneus */);
}
/* ERR_NICKNAMEINUSE */
/* */
-void IrcServerHandler::tryNextNick(const QString &errnick) {
+void IrcServerHandler::tryNextNick(const QString &errnick, bool erroneus) {
QStringList desiredNicks = coreSession()->identity(network()->identity())->nicks();
- int nextNick = desiredNicks.indexOf(errnick) + 1;
- if(desiredNicks.size() > nextNick) {
- putCmd("NICK", serverEncode(desiredNicks[nextNick]));
+ int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
+ QString nextNick;
+ if(nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
+ nextNick = desiredNicks[nextNickIdx];
} else {
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"));
+ if(erroneus) {
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"));
+ return;
+ } else {
+ nextNick = errnick + "_";
+ }
}
+ putCmd("NICK", serverEncode(nextNick));
}
bool IrcServerHandler::checkParamCount(const QString &methodName, const QList<QByteArray> ¶ms, int minParams) {