add argument flag for tls connections
authoralfadur
Wed, 01 May 2019 00:01:56 +0300
changeset 14865 90cf07c60feb
parent 14864 0c231b5184c5
child 14866 e088bd03812d
add argument flag for tls connections
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/net/newnetclient.cpp
QTfrontend/net/newnetclient.h
QTfrontend/ui/page/pagenet.cpp
QTfrontend/ui/page/pagenet.h
--- a/QTfrontend/hwform.cpp	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/hwform.cpp	Wed May 01 00:01:56 2019 +0300
@@ -294,7 +294,7 @@
     connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
     pageSwitchMapper->setMapping(ui.pageNet->BtnNetSvrStart, ID_PAGE_NETSERVER);
 
-    connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16)));
+    connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16, bool)), this, SLOT(NetConnectServer(const QString &, quint16, bool)));
 
     connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
 
@@ -1155,18 +1155,18 @@
 void HWForm::NetConnectQuick(const QString & host, quint16 port)
 {
     GoToPage(ID_PAGE_MAIN);
-    NetConnectServer(host, port);
+    NetConnectServer(host, port, false);
 }
 
-void HWForm::NetConnectServer(const QString & host, quint16 port)
+void HWForm::NetConnectServer(const QString & host, quint16 port, bool useTls)
 {
     qDebug("connecting to %s:%d", qPrintable(host), port);
-    _NetConnect(host, port, ui.pageOptions->editNetNick->text().trimmed());
+    _NetConnect(host, port, useTls, ui.pageOptions->editNetNick->text().trimmed());
 }
 
 void HWForm::NetConnectOfficialServer()
 {
-    NetConnectServer(NETGAME_DEFAULT_SERVER, NETGAME_DEFAULT_PORT);
+    NetConnectServer(NETGAME_DEFAULT_SERVER, NETGAME_DEFAULT_PORT, false);
 }
 
 void HWForm::NetPassword(const QString & nick)
@@ -1261,7 +1261,7 @@
         if (retry && hwnet) {
             if (hwnet->m_private_game) {
                 QStringList list = hwnet->getHost().split(":");
-                NetConnectServer(list.at(0), list.at(1).toShort());
+                NetConnectServer(list.at(0), list.at(1).toShort(), false);
             } else
                 NetConnectOfficialServer();
         }
@@ -1350,7 +1350,7 @@
         ui.pageRoomsList->displayWarning(wrnmsg);
 }
 
-void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
+void HWForm::_NetConnect(const QString & hostName, quint16 port, bool useTls, QString nick)
 {
     Q_UNUSED(nick);
 
@@ -1531,7 +1531,7 @@
     ui.pageRoomsList->setUser(nickname);
     ui.pageNetGame->setUser(nickname);
 
-    hwnet->Connect(hostName, port, nickname);
+    hwnet->Connect(hostName, port, useTls, nickname);
 }
 
 int HWForm::AskForNickAndPwd(void)
@@ -1585,7 +1585,7 @@
                 if (retry) {
                     if (hwnet->m_private_game) {
                         QStringList list = hwnet->getHost().split(":");
-                        NetConnectServer(list.at(0), list.at(1).toShort());
+                        NetConnectServer(list.at(0), list.at(1).toShort(), false);
                     } else
                         NetConnectOfficialServer();
                 }
@@ -1631,7 +1631,7 @@
         delete netHost;
         netHost = new QString(hpd->leHost->text());
         netPort = hpd->sbPort->value();
-        NetConnectServer(*netHost, netPort);
+        NetConnectServer(*netHost, netPort, false);
     }
     delete hpd;
 }
@@ -1659,7 +1659,7 @@
 
 void HWForm::AsyncNetServerStart()
 {
-    NetConnectServer("localhost", pnetserver->getRunningPort());
+    NetConnectServer("localhost", pnetserver->getRunningPort(), false);
 }
 
 void HWForm::NetDisconnect()
@@ -1688,7 +1688,7 @@
         if (retry) {
             if (hwnet->m_private_game) {
                 QStringList list = hwnet->getHost().split(":");
-                NetConnectServer(list.at(0), list.at(1).toUInt());
+                NetConnectServer(list.at(0), list.at(1).toUInt(), false);
             } else
                 NetConnectOfficialServer();
         }
@@ -1728,8 +1728,13 @@
     questionMsg.addButton(QMessageBox::No);
 
     if (questionMsg.exec() == QMessageBox::Yes)
+    {        
+        QString host = hwnet->getHost().split(":").at(0);
+        NetConnectServer(host, port, true);
+    }
+    else if (hwnet)
     {
-
+        hwnet->ContinueConnection();
     }
 }
 
--- a/QTfrontend/hwform.h	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/hwform.h	Wed May 01 00:01:56 2019 +0300
@@ -100,7 +100,7 @@
         void startTraining(const QString&, const QString&);
         void StartCampaign();
         void NetConnect();
-        void NetConnectServer(const QString & host, quint16 port);
+        void NetConnectServer(const QString & host, quint16 port, bool useTls);
         void NetConnectOfficialServer();
         void NetStartServer();
         void NetRedirected(quint16 port);
@@ -159,7 +159,7 @@
         void FromNetProxySlot(const QByteArray &);
 
     private:
-        void _NetConnect(const QString & hostName, quint16 port, QString nick);
+        void _NetConnect(const QString & hostName, quint16 port, bool useTls, QString nick);
         int  AskForNickAndPwd(void);
         void UpdateTeamsLists();
         void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo);
--- a/QTfrontend/net/newnetclient.cpp	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/net/newnetclient.cpp	Wed May 01 00:01:56 2019 +0300
@@ -80,7 +80,7 @@
     NetSocket.flush();
 }
 
-void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
+void HWNewNet::Connect(const QString & hostName, quint16 port, bool useTls, const QString & nick)
 {
     netClientState = Connecting;
     mynick = nick;
@@ -257,6 +257,17 @@
     maybeSendPassword();
 }
 
+void HWNewNet::ContinueConnection()
+{
+    if (netClientState == Connected)    
+    {
+        RawSendNet(QString("NICK%1%2").arg(delimiter).arg(mynick));
+        RawSendNet(QString("PROTO%1%2").arg(delimiter).arg(*cProtoVer));    
+        m_game_connected = true;
+        emit adminAccess(false);
+    }
+}
+
 void HWNewNet::ParseCmd(const QStringList & lst)
 {
     qDebug() << "Server: " << lst;
@@ -311,6 +322,7 @@
         }
         else 
         {
+            netClientState = Redirected;
             emit redirected(port);
         }
         return;
@@ -328,11 +340,12 @@
             return;
         }
 
-        RawSendNet(QString("NICK%1%2").arg(delimiter).arg(mynick));
-        RawSendNet(QString("PROTO%1%2").arg(delimiter).arg(*cProtoVer));
-        netClientState = Connected;
-        m_game_connected = true;
-        emit adminAccess(false);
+        ClientState lastState = netClientState;
+        netClientState = Connected;      
+        if (lastState != Redirected)
+        {
+            ContinueConnection();
+        }
         return;
     }
 
--- a/QTfrontend/net/newnetclient.h	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/net/newnetclient.h	Wed May 01 00:01:56 2019 +0300
@@ -43,11 +43,12 @@
         Q_OBJECT
 
     public:
-        enum ClientState { Disconnected, Connecting, Connected, InLobby, InRoom, InGame };
+        enum ClientState { Disconnected, Connecting, Redirected, Connected, InLobby, InRoom, InGame };
 
         HWNewNet();
         ~HWNewNet();
-        void Connect(const QString & hostName, quint16 port, const QString & nick);
+        void Connect(const QString & hostName, quint16 port, bool useTls, const QString & nick);
+        void ContinueConnection();
         void Disconnect();
         void SendPasswordHash(const QString & hash);
         void NewNick(const QString & nick);
@@ -87,7 +88,7 @@
         int  ByteLength(const QString & str);
         void RawSendNet(const QString & buf);
         void RawSendNet(const QByteArray & buf);
-        void ParseCmd(const QStringList & lst);
+        void ParseCmd(const QStringList & lst);        
         void handleNotice(int n);
 
         void maybeSendPassword();
--- a/QTfrontend/ui/page/pagenet.cpp	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/ui/page/pagenet.cpp	Wed May 01 00:01:56 2019 +0300
@@ -128,5 +128,5 @@
     QString host = model->index(mi.row(), 1).data().toString();
     quint16 port = model->index(mi.row(), 2).data().toUInt();
 
-    emit connectClicked(host, port);
+    emit connectClicked(host, port, false);
 }
--- a/QTfrontend/ui/page/pagenet.h	Tue Apr 30 22:43:48 2019 +0200
+++ b/QTfrontend/ui/page/pagenet.h	Wed May 01 00:01:56 2019 +0300
@@ -38,7 +38,7 @@
         void updateServersList();
 
     signals:
-        void connectClicked(const QString & host, quint16 port);
+        void connectClicked(const QString & host, quint16 port, bool useTls);
 
     private:
         QLayout * bodyLayoutDefinition();