Merge alfadur's commits
authorWuzzy <Wuzzy2@mail.ru>
Wed, 01 May 2019 00:13:23 +0200
changeset 14869 9078d787d491
parent 14868 349a87011080 (current diff)
parent 14866 e088bd03812d (diff)
child 14870 ce98c37826a7
Merge alfadur's commits
--- a/QTfrontend/hwform.cpp	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/hwform.cpp	Wed May 01 00:13:23 2019 +0200
@@ -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	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/hwform.h	Wed May 01 00:13:23 2019 +0200
@@ -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	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/net/newnetclient.cpp	Wed May 01 00:13:23 2019 +0200
@@ -80,12 +80,23 @@
     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;
     myhost = hostName + QString(":%1").arg(port);
-    NetSocket.connectToHost(hostName, port);
+    if (useTls)
+    {
+        NetSocket.connectToHostEncrypted(hostName, port);
+        if (!NetSocket.waitForEncrypted())
+        {
+            qWarning("Handshake failed");
+        }
+    }
+    else 
+    {
+        NetSocket.connectToHost(hostName, port);
+    }
 }
 
 void HWNewNet::Disconnect()
@@ -257,6 +268,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 +333,7 @@
         }
         else 
         {
+            netClientState = Redirected;
             emit redirected(port);
         }
         return;
@@ -328,11 +351,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	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/net/newnetclient.h	Wed May 01 00:13:23 2019 +0200
@@ -22,7 +22,7 @@
 
 #include <QObject>
 #include <QString>
-#include <QTcpSocket>
+#include <QSslSocket>
 #include <QMap>
 
 #include "team.h"
@@ -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);
@@ -68,7 +69,7 @@
         QString mynick;
         QString myroom;
         QString myhost;
-        QTcpSocket NetSocket;
+        QSslSocket NetSocket;
         QString seed;
         bool m_game_connected;
         bool m_nick_registered;
@@ -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	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/ui/page/pagenet.cpp	Wed May 01 00:13:23 2019 +0200
@@ -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	Wed May 01 00:11:36 2019 +0200
+++ b/QTfrontend/ui/page/pagenet.h	Wed May 01 00:13:23 2019 +0200
@@ -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();