this should prevent the password prompt from appearing on local games (issue 548)
authorkoda
Tue, 12 Mar 2013 01:32:39 +0100
changeset 8720 5603527f9803
parent 8719 0f55bcfe7f36
child 8721 4cc2b2cd4184
this should prevent the password prompt from appearing on local games (issue #548)
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/net/newnetclient.cpp
QTfrontend/net/newnetclient.h
--- 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);
     }
--- a/QTfrontend/hwform.h	Mon Mar 11 12:21:37 2013 -0400
+++ b/QTfrontend/hwform.h	Tue Mar 12 01:32:39 2013 +0100
@@ -145,6 +145,7 @@
 
     private:
         void _NetConnect(const QString & hostName, quint16 port, QString nick);
+        int  AskForNickAndPwd(void);
         void UpdateTeamsLists();
         void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo);
         void closeEvent(QCloseEvent *event);
--- a/QTfrontend/net/newnetclient.cpp	Mon Mar 11 12:21:37 2013 -0400
+++ b/QTfrontend/net/newnetclient.cpp	Tue Mar 12 01:32:39 2013 +0100
@@ -311,7 +311,7 @@
         QStringList tmp = lst;
         tmp.removeFirst();
         m_roomsListModel->setRoomsList(tmp);
-        if (m_nick_registered == false)
+        if (m_private_game == false && m_nick_registered == false)
         {
             emit NickNotRegistered(mynick);
         }
--- a/QTfrontend/net/newnetclient.h	Mon Mar 11 12:21:37 2013 -0400
+++ b/QTfrontend/net/newnetclient.h	Tue Mar 12 01:32:39 2013 +0100
@@ -61,6 +61,7 @@
         QAbstractItemModel * lobbyPlayersModel();
         QAbstractItemModel * roomPlayersModel();
         bool allPlayersReady();
+        bool m_private_game;
 
     private:
         bool isChief;