Ask for another nickname on collision. Works only with new server.
authorunc0rr
Sat, 29 Jan 2011 17:40:49 +0300
changeset 4879 55f939e2c19c
parent 4878 c310bab60b94
child 4880 07e9849c6a70
Ask for another nickname on collision. Works only with new server.
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/newnetclient.cpp	Sat Jan 29 15:39:04 2011 +0300
+++ b/QTfrontend/newnetclient.cpp	Sat Jan 29 17:40:49 2011 +0300
@@ -489,6 +489,26 @@
         return;
     }
 
+    if (lst[0] == "NOTICE") {
+        if(lst.size() < 2)
+        {
+            qWarning("Net: Bad NOTICE message");
+            return;
+        }
+
+        bool ok;
+        int n = lst[1].toInt(&ok);
+        if(!ok)
+        {
+            qWarning("Net: Bad NOTICE message");
+            return;
+        }
+
+        handleNotice(n);
+
+        return;
+    }
+
     if (lst[0] == "TEAM_ACCEPTED") {
         if (lst.size() != 2)
         {
@@ -752,3 +772,28 @@
 {
     RawSendNet(QString("GET_SERVER_VAR"));
 }
+
+void HWNewNet::handleNotice(int n)
+{
+    switch(n)
+    {
+        case 0:
+        {
+            bool ok = false;
+            QString newNick = QInputDialog::getText(0, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(mynick), QLineEdit::Normal, mynick, &ok);
+
+            if (!ok || newNick.isEmpty()) {
+                Disconnect();
+                emit Disconnected();
+                return;
+            }
+
+            config->setValue("net/nick", newNick);
+            mynick = newNick;
+
+            RawSendNet(QString("NICK%1%2").arg(delimeter).arg(newNick));
+
+            break;
+        }
+    }
+}
--- a/QTfrontend/newnetclient.h	Sat Jan 29 15:39:04 2011 +0300
+++ b/QTfrontend/newnetclient.h	Sat Jan 29 17:40:49 2011 +0300
@@ -86,6 +86,7 @@
   void RawSendNet(const QString & buf);
   void RawSendNet(const QByteArray & buf);
   void ParseCmd(const QStringList & lst);
+  void handleNotice(int n);
 
   int loginStep;
   int netClientState;
@@ -161,7 +162,7 @@
   void ClientRead();
   void OnConnect();
   void OnDisconnect();
-  void displayError(QAbstractSocket::SocketError socketError);
+  void displayError(QAbstractSocket::SocketError socketError); 
 };
 
 #endif // _NEW_NETCLIENT_INCLUDED