accept redirect messages
authoralfadur
Thu, 25 Apr 2019 23:59:50 +0300 (2019-04-25)
changeset 14843 bdb47255d7e4
parent 14842 5443e5e0faa3
child 14845 b02581c5b0c5
accept redirect messages
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/net/newnetclient.cpp
QTfrontend/net/newnetclient.h
--- a/QTfrontend/hwform.cpp	Thu Apr 25 21:25:16 2019 +0200
+++ b/QTfrontend/hwform.cpp	Thu Apr 25 23:59:50 2019 +0300
@@ -1366,6 +1366,7 @@
     GoToPage(ID_PAGE_CONNECTING);
 
     connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame()), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(redirected(quint16)), this, SLOT(NetRedirected(quint16)), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(connected()), this, SLOT(NetConnected()), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&)), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&)), Qt::QueuedConnection);
@@ -1715,6 +1716,23 @@
     }
 }
 
+void HWForm::NetRedirected(quint16 port)
+{
+    QMessageBox questionMsg(this);
+    questionMsg.setIcon(QMessageBox::Question);
+    questionMsg.setWindowTitle(QMessageBox::tr("Server redirection"));
+    questionMsg.setText(QMessageBox::tr("This server supports secure connections on port %1.\nWould you like to reconnect securely?").arg(port));
+    questionMsg.setTextFormat(Qt::PlainText);
+    questionMsg.setWindowModality(Qt::WindowModal);
+    questionMsg.addButton(QMessageBox::Yes);
+    questionMsg.addButton(QMessageBox::No);
+
+    if (questionMsg.exec() == QMessageBox::Yes)
+    {
+
+    }
+}
+
 void HWForm::NetConnected()
 {
     GoToPage(ID_PAGE_ROOMSLIST);
--- a/QTfrontend/hwform.h	Thu Apr 25 21:25:16 2019 +0200
+++ b/QTfrontend/hwform.h	Thu Apr 25 23:59:50 2019 +0300
@@ -103,6 +103,7 @@
         void NetConnectServer(const QString & host, quint16 port);
         void NetConnectOfficialServer();
         void NetStartServer();
+        void NetRedirected(quint16 port);
         void NetDisconnect();
         void NetConnected();
         void NetError(const QString & errmsg);
--- a/QTfrontend/net/newnetclient.cpp	Thu Apr 25 21:25:16 2019 +0200
+++ b/QTfrontend/net/newnetclient.cpp	Thu Apr 25 23:59:50 2019 +0300
@@ -296,6 +296,26 @@
         return;
     }
 
+    if (lst[0] == "REDIRECT")
+    {        
+        if (lst.size() < 2 || lst[1].toInt() == 0)
+        {
+            qWarning("Net: Malformed REDIRECT message");
+            return;            
+        }
+
+        quint16 port = lst[1].toInt();
+        if (port == 0) 
+        {
+            qWarning() << "Invalid redirection port";            
+        }
+        else 
+        {
+            emit redirected(port);
+        }
+        return;
+    }
+
     if (lst[0] == "CONNECTED")
     {
         if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion)
--- a/QTfrontend/net/newnetclient.h	Thu Apr 25 21:25:16 2019 +0200
+++ b/QTfrontend/net/newnetclient.h	Thu Apr 25 23:59:50 2019 +0300
@@ -98,6 +98,7 @@
         void AskForRunGame();
         void connected();
         void disconnected(const QString & reason);
+        void redirected(quint16 port);
         void Error(const QString & errmsg);
         void Warning(const QString & wrnmsg);
         void NickRegistered(const QString & nick);