Bug 131399

Summary: Finding unused nicks doesn't nick maximum nick length into account
Product: [Applications] konversation Reporter: Gábor Lehel <illissius>
Component: generalAssignee: Konversation Developers <konversation-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Gábor Lehel 2006-07-26 16:55:49 UTC
Version:           0.19+ #3114 (using KDE KDE 3.5.2)
Installed from:    Compiled From Sources
Compiler:          GCC 4.1.0 
OS:                Linux

If your nickname is 9 characters on a network with 9 characters as the maximum allowed length for nicknames (such as EFNet), Konversation keeps trying to append _ characters to the nick, failing each time (the server, I assume, just discards them past the 9th), and keeps doing this until it is disconnected or the original nick becomes available. Accompanied by high CPU usage and general interface lagginess.

An excerpt:

[16:48:39] *** You are now known as illissius`__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________.
[16:48:40] [Nick] Nickname already in use. Trying illissius`__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________.
[16:48:40] *** You are now known as illissius`___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________.
[16:48:41] [Nick] Nickname already in use. Trying illissius`___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________.
Comment 1 Eike Hein 2006-07-26 23:40:58 UTC
SVN commit 566733 by hein:

Retire the "append underscore to last used nick after unsuccessfully
going through the identity's list of nicknames" behavior, which even-
tually runs into the NICKLEN wall. Instead, ask the user to enter a
new nick, or cancel the connection attempt on opt-out. 
Patch by Raphael Kubo da Costa, and mentored by me.
BUG:131399


 M  +33 -18    inputfilter.cpp  
 M  +7 -3      server.cpp  


--- trunk/extragear/network/konversation/src/inputfilter.cpp #566732:566733
@@ -716,7 +716,6 @@
                     else
                     {
                         property = *it;
-                        // value = "";
                     }
                     if (property=="PREFIX")
                     {
@@ -724,7 +723,7 @@
                         if(pos==-1)
                         {
                             server->setPrefixes (QString::null, value);
-                                                  // XXX if ) isn't in the string, NOTHING should be there. anyone got a server
+                            // XXX if ) isn't in the string, NOTHING should be there. anyone got a server
                             if (value.length() || property.length())
                                 server->appendStatusMessage("","XXX Server sent bad PREFIX in RPL_ISUPPORT, please report.");
                         }
@@ -740,9 +739,7 @@
                     else if (property == "CAPAB")
                     {
                         // Disable as we don't use this for anything yet
-#if 0
-                        server->queue("CAPAB IDENTIFY-MSG");
-#endif
+                        //server->queue("CAPAB IDENTIFY-MSG");
                     }
                     else
                     {
@@ -969,15 +966,24 @@
                 }
                 else                              // not connected yet, so try to find a nick that's not in use
                 {
-                    // Get the next nick from the list
-                    QString newNick=server->getNextNickname();
-                    // Update Server window
-                    server->obtainNickInfo(server->getNickname()) ;
-                    server->renameNick(server->getNickname(), newNick);
-                    // Show message
-                    server->appendMessageToFrontmost(i18n("Nick"),i18n("Nickname already in use. Trying %1.").arg(newNick));
-                    // Send nickchange request to the server
-                    server->queue("NICK "+newNick);
+                    // Get the next nick from the list or ask for a new one
+                    QString newNick = server->getNextNickname();
+
+                    // The user chose to disconnect
+                    if (newNick.isNull())
+                    {
+                        server->disconnect();
+                    }
+                    else
+                    {
+                        // Update Server window
+                        server->obtainNickInfo(server->getNickname()) ;
+                        server->renameNick(server->getNickname(), newNick);
+                        // Show message
+                        server->appendMessageToFrontmost(i18n("Nick"), i18n("Nickname already in use. Trying %1.").arg(newNick));
+                        // Send nickchange request to the server
+                        server->queue("NICK "+newNick);
+                    }
                 }
                 break;
             }
@@ -990,10 +996,19 @@
                 else                              // Find a new nick as in ERR_NICKNAMEINUSE
                 {
                     QString newNick = server->getNextNickname();
-                    server->obtainNickInfo(server->getNickname()) ;
-                    server->renameNick(server->getNickname(), newNick);
-                    server->appendMessageToFrontmost(i18n("Nick"), i18n("Erroneus nickname. Changing nick to %1." ).arg(newNick)) ;
-                    server->queue("NICK "+newNick);
+
+                    // The user chose to disconnect
+                    if (newNick.isNull())
+                    {
+                        server->disconnect();
+                    }
+                    else
+                    {
+                        server->obtainNickInfo(server->getNickname()) ;
+                        server->renameNick(server->getNickname(), newNick);
+                        server->appendMessageToFrontmost(i18n("Nick"), i18n("Erroneus nickname. Changing nick to %1." ).arg(newNick)) ;
+                        server->queue("NICK "+newNick);
+                    }
                 }
                 break;
             }
--- trunk/extragear/network/konversation/src/server.cpp #566732:566733
@@ -23,6 +23,7 @@
 #include <klocale.h>
 #include <kdebug.h>
 #include <kfiledialog.h>
+#include <kinputdialog.h>
 #include <kmessagebox.h>
 #include <kresolver.h>
 #include <ksocketdevice.h>
@@ -926,10 +927,13 @@
 QString Server::getNextNickname()
 {
     QString newNick = getIdentity()->getNickname(++tryNickNumber);
+    
+    if (newNick.isNull())
+    {
+        QString inputText = i18n("No nicknames from the \"%1\" identity were accepted by the connection \"%2\".\nPlease enter a new one or press Cancel to disconnect:").arg(getIdentity()->getName()).arg(getServerGroup());
+        newNick = KInputDialog::getText(i18n("Nickname error"), inputText, QString::null);
+    }
 
-    if(newNick.isEmpty())
-       newNick = getNickname()+'_';
-
     return newNick;
 }