fixes #391 - appending underscores if all nicknames of the identity are unavailable
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 14 Feb 2009 01:17:11 +0000 (02:17 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 14 Feb 2009 01:17:11 +0000 (02:17 +0100)
src/core/corenetwork.cpp
src/core/ircserverhandler.cpp
src/core/ircserverhandler.h

index c023385..32888ec 100644 (file)
@@ -205,7 +205,7 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason, bool
   else
     _quitReason = reason;
 
   else
     _quitReason = reason;
 
-  displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : reason));
+  displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting. (%1)").arg((!requested && !withReconnect) ? tr("Core Shutdown") : _quitReason));
   switch(socket.state()) {
   case QAbstractSocket::ConnectedState:
     userInputHandler()->issueQuit(_quitReason);
   switch(socket.state()) {
   case QAbstractSocket::ConnectedState:
     userInputHandler()->issueQuit(_quitReason);
index 34573d9..5bd4dc4 100644 (file)
@@ -88,10 +88,12 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) {
   uint num = cmd.toUInt();
   if(num > 0) {
     if(params.count() == 0) {
   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;
     }
       return;
     }
-    params.removeFirst();
+    _target = serverDecode(params.takeFirst());
+  } else {
+    _target = QString();
   }
 
   // note that the IRC server is still alive
   }
 
   // note that the IRC server is still alive
@@ -935,20 +937,19 @@ void IrcServerHandler::handle369(const QString &prefix, const QList<QByteArray>
 void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix);
 
 void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> &params) {
   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
   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 {
   } 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 */
 }
 
 /* ERR_NICKNAMEINUSE */
@@ -975,14 +976,21 @@ void IrcServerHandler::handle433(const QString &prefix, const QList<QByteArray>
 
 /* */
 
 
 /* */
 
-void IrcServerHandler::tryNextNick(const QString &errnick) {
+void IrcServerHandler::tryNextNick(const QString &errnick, bool erroneus) {
   QStringList desiredNicks = coreSession()->identity(network()->identity())->nicks();
   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 {
   } 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> &params, int minParams) {
 }
 
 bool IrcServerHandler::checkParamCount(const QString &methodName, const QList<QByteArray> &params, int minParams) {
index a0b088b..b06a6b6 100644 (file)
@@ -81,9 +81,14 @@ public slots:
   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);
 
 private:
   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);
 
 private:
-  void tryNextNick(const QString &errnick);
+  void tryNextNick(const QString &errnick, bool erroneus = false);
   bool checkParamCount(const QString &methodName, const QList<QByteArray> &params, int minParams);
   bool checkParamCount(const QString &methodName, const QList<QByteArray> &params, int minParams);
+
+  // holds the target for numeric replies or is invalid otherwise
+  inline const QString &target() const { return _target; }
+
   bool _whois;
   bool _whois;
+  QString _target;
 };
 
 
 };