From: APTX Date: Sun, 17 Jun 2012 15:57:37 +0000 (+0200) Subject: If UDP API returns UNKNOWN_COMMAND while using encryption, assume the API key is... X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=d500593b8a03ba57a356d7c304e689af027a97a1;p=anidbudpclient.git If UDP API returns UNKNOWN_COMMAND while using encryption, assume the API key is wrong on the first command and assume the session expired instead. --- diff --git a/client.cpp b/client.cpp index 466b890..775fd9d 100644 --- a/client.cpp +++ b/client.cpp @@ -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; diff --git a/client.h b/client.h index a66b4fe..0631a5d 100644 --- a/client.h +++ b/client.h @@ -200,6 +200,7 @@ private: bool authenticatingStarted; bool encryptionStarted; bool usingEncryption; + bool firstEncryptedCommand; int commandsTimedOut;