From f822d4da8e2a3148a7c83f6e5f3d89d605411238 Mon Sep 17 00:00:00 2001
From: "danil.martynenko" <danil.martynenko@demlabs.net>
Date: Mon, 10 Feb 2025 18:57:10 +0300
Subject: [PATCH] [*] fixed key activation and connection

---
 vpn/client/DapCmdHandlers/DapCmdConnect.cpp        | 12 +++++-------
 vpn/client/DapCmdHandlers/DapCmdResetSerialKey.cpp |  3 +++
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/vpn/client/DapCmdHandlers/DapCmdConnect.cpp b/vpn/client/DapCmdHandlers/DapCmdConnect.cpp
index 241164c25..fe9b4ffd0 100644
--- a/vpn/client/DapCmdHandlers/DapCmdConnect.cpp
+++ b/vpn/client/DapCmdHandlers/DapCmdConnect.cpp
@@ -80,17 +80,15 @@ void DapCmdConnect::handle(const QJsonObject* params)
     }
 
     bool updateRouteTable = mandatoryConnParams[UPDATE_ROUTE_TABLE].toBool(true);
-    QString serialKey;
+    QString serialKey = "";
 
     if (params->contains("serial")) {
         serialKey = params->value("serial").toString().remove('-');
-        if (serialKey.isEmpty()) {
-            serialKey = DapServiceDataLocal::instance()->serialKeyData()->serialKey().remove('-');
-        }
-    } else {
+    }
+
+    if (serialKey.isEmpty()) {
         serialKey = DapServiceDataLocal::instance()->serialKeyData()->serialKey().remove('-');
     }
-    serialKey = QString(DapServiceDataLocal::instance()->serialKeyData()->serialKey()).remove('-');
 
     uint16_t port = uint16_t(mandatoryConnParams[PORT_KEY].toInt());
     QString address = mandatoryConnParams[ADDRESS_KEY].toString();
@@ -101,7 +99,7 @@ void DapCmdConnect::handle(const QJsonObject* params)
     if (!serialKey.isEmpty()) {
         emit sigConnect(serialKey, "", "", address, port, updateRouteTable);
     } else {
-        emit sigConnectNoAuth(address, port);
+        sendCmdError("No serial key provided");
     }
 }
 
diff --git a/vpn/client/DapCmdHandlers/DapCmdResetSerialKey.cpp b/vpn/client/DapCmdHandlers/DapCmdResetSerialKey.cpp
index 973e4a204..8b4d7f641 100644
--- a/vpn/client/DapCmdHandlers/DapCmdResetSerialKey.cpp
+++ b/vpn/client/DapCmdHandlers/DapCmdResetSerialKey.cpp
@@ -7,14 +7,17 @@ DapCmdResetSerialKey::DapCmdResetSerialKey(QObject *parent)
 
 void DapCmdResetSerialKey::handle(const QJsonObject *params)
 {
+    qDebug() << "Handling reset serial key command...";
     DapCmdServiceAbstract::handle(params);
 
     connect(this, &DapCmdResetSerialKey::sigResetSerialKeyReplied, [&] (const QString& reply) {
+        qDebug() << "Received signal: sigResetSerialKeyReplied with reply:" << reply;
         QJsonObject l_obj;
         l_obj["reset_reply"] = reply;
         sendCmd(&l_obj);
     });
 
+    qDebug() << "Emitting sigResetRequestSent signal...";
     emit sigResetRequestSent();
 }
 
-- 
GitLab