QTfrontend/hwform.cpp
changeset 8720 5603527f9803
parent 8716 e09633d10f16
child 8722 2dead6b84bca
--- a/QTfrontend/hwform.cpp	Mon Mar 11 12:21:37 2013 -0400
+++ b/QTfrontend/hwform.cpp	Tue Mar 12 01:32:39 2013 +0100
@@ -1002,6 +1002,7 @@
 
 void HWForm::NetConnectQuick(const QString & host, quint16 port)
 {
+    GoToPage(ID_PAGE_MAIN);
     NetConnectServer(host, port);
 }
 
@@ -1103,10 +1104,14 @@
     if (!ok || newNick.isEmpty())
     {
         //ForcedDisconnect(tr("No nickname supplied."));
-    bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
-    GoBack();
+        bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
+        GoBack();
         if (retry) {
-            NetConnectOfficialServer();
+            if (hwnet->m_private_game) {
+                QStringList list = hwnet->getHost().split(":");
+                NetConnectServer(list.at(0), list.at(1).toShort());
+            } else
+                NetConnectOfficialServer();
         }
         return;
     }
@@ -1189,11 +1194,11 @@
 {
     Q_UNUSED(nick);
 
-    if(hwnet)
-    {
+    if (hwnet) {
+        // destroy old connection
         hwnet->Disconnect();
         delete hwnet;
-        hwnet=0;
+        hwnet = NULL;
     }
 
     hwnet = new HWNewNet();
@@ -1337,8 +1342,22 @@
     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
 
-//nick and pass stuff
+    //nick and pass stuff
+    QString nickname = config->value("net/nick", "").toString();
+
+    hwnet->m_private_game = !(hostName == "netserver.hedgewars.org" && port == NETGAME_DEFAULT_PORT);
+    if (hwnet->m_private_game == false)
+        if (AskForNickAndPwd() != 0)
+            return;
 
+    ui.pageRoomsList->setUser(nickname);
+    ui.pageNetGame->setUser(nickname);
+
+    hwnet->Connect(hostName, port, nickname);
+}
+
+int HWForm::AskForNickAndPwd(void)
+{
     //remove temppasswordhash just in case
     config->clearTempHash();
 
@@ -1369,7 +1388,7 @@
             if (pwDialog->exec() != QDialog::Accepted) {
                 delete pwDialog;
                 GoBack();
-                return;
+                return -1;
             }
 
             //set nick and pass from the dialog
@@ -1382,9 +1401,13 @@
                 GoBack();
                 delete pwDialog;
                 if (retry) {
-                    NetConnectOfficialServer();
-                }
-                return;
+                    if (hwnet->m_private_game) {
+                        QStringList list = hwnet->getHost().split(":");
+                        NetConnectServer(list.at(0), list.at(1).toShort());
+                    } else
+                        NetConnectOfficialServer();
+                    }
+                return -1;
             }
 
             if (!password.isEmpty()) {
@@ -1421,15 +1444,9 @@
             nickname = config->value("net/nick", "").toString();
         }
     }
-
-    ui.pageRoomsList->setUser(nickname);
-    ui.pageNetGame->setUser(nickname);
-
-    hwnet->Connect(hostName, port, nickname);
+    return 0;
 }
 
-
-
 void HWForm::NetConnect()
 {
     HWHostPortDialog * hpd = new HWHostPortDialog(this);
@@ -1497,7 +1514,11 @@
     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
         if (retry) {
-            NetConnectOfficialServer();
+            if (hwnet->m_private_game) {
+                QStringList list = hwnet->getHost().split(":");
+                NetConnectServer(list.at(0), list.at(1).toShort());
+            } else
+                NetConnectOfficialServer();
         }
         else {
             while (ui.Pages->currentIndex() != ID_PAGE_NET
@@ -1510,8 +1531,7 @@
     }
     if (pnetserver)
         return; // we have server - let it care of all things
-    if (hwnet)
-    {
+    if (hwnet) {
         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
         MessageDialog::ShowErrorMessage(errorStr, this);
     }