]> Some of my projects - anidbudpclient.git/commitdiff
If UDP API returns UNKNOWN_COMMAND while using encryption, assume the API key is...
authorAPTX <marek321@gmail.com>
Sun, 17 Jun 2012 15:57:37 +0000 (17:57 +0200)
committerAPTX <marek321@gmail.com>
Sun, 17 Jun 2012 15:57:37 +0000 (17:57 +0200)
client.cpp
client.h

index 466b890297781c92e26405f0141ede068b23997f..775fd9da3880ed94a97f783efe05e16f8a321457 100644 (file)
@@ -45,6 +45,7 @@ qDebug() << "Api instance init!";
        authenticatingStarted = false;
        encryptionStarted = false;
        usingEncryption = false;
+       firstEncryptedCommand = false;
        commandsTimedOut = 0;
 
        socket = new QUdpSocket(this);
@@ -432,6 +433,7 @@ qDebug() << "success!";
 #endif
                m_salt = encryptReply->salt();
                usingEncryption = true;
+               firstEncryptedCommand = true;
                emit encryptionEstablished();
                return;
        }
@@ -638,13 +640,20 @@ qDebug() << QString("Recieved datagram from [%1]:%2\nRaw datagram contents:%3")
                                                emit connectionError();
                                                goto endLoop;
                                        case UNKNOWN_COMMAND:
-                                               if (usingEncryption)
+                                               if (usingEncryption && firstEncryptedCommand)
                                                {
                                                        m_error = EncryptionError;
                                                        m_errorString = tr("Server did not recognize encrypted command. Make sure the API Key is correct.");
+                                                       firstEncryptedCommand = false;
                                                        emit connectionError();
                                                        goto endLoop;
                                                }
+                                               else if (usingEncryption && !firstEncryptedCommand)
+                                               {
+                                                       usingEncryption = false;
+                                                       m_salt.clear();
+                                                       m_sessionId.clear();
+                                               }
                                        break;
                                        default:
                                                if (replyCode > 601 && replyCode < 700)
@@ -659,6 +668,8 @@ qDebug() << QString("Recieved datagram from [%1]:%2\nRaw datagram contents:%3")
                        }
                }
 
+               firstEncryptedCommand = false;
+
                QByteArray commandId = tmp.mid(0, 5);
 
                commandsTimedOut = 0;
index a66b4fe6d8aa5f44d446d9d0fbc967da878ccadb..0631a5dc120157ffde674b4a3ff3cac177b4c8f3 100644 (file)
--- a/client.h
+++ b/client.h
@@ -200,6 +200,7 @@ private:
        bool authenticatingStarted;
        bool encryptionStarted;
        bool usingEncryption;
+       bool firstEncryptedCommand;
 
        int commandsTimedOut;