Give more feedback for YggdrasilTask network errors.
This commit is contained in:
@ -71,7 +71,7 @@ QJsonObject AuthenticateTask::getRequestContent() const
|
||||
return req;
|
||||
}
|
||||
|
||||
bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
void AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
{
|
||||
// Read the response data. We need to get the client token, access token, and the selected
|
||||
// profile.
|
||||
@ -84,16 +84,13 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
if (clientToken.isEmpty())
|
||||
{
|
||||
// Fail if the server gave us an empty client token
|
||||
// TODO: Set an error properly to display to the user.
|
||||
QLOG_ERROR() << "Server didn't send a client token.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't send a client token."));
|
||||
return;
|
||||
}
|
||||
if (!m_account->m_clientToken.isEmpty() && clientToken != m_account->m_clientToken)
|
||||
{
|
||||
// The server changed our client token! Obey its wishes, but complain. That's what I do
|
||||
// for my parents, so...
|
||||
QLOG_WARN() << "Server changed our client token to '" << clientToken
|
||||
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server attempted to change the client token. This isn't supported."));
|
||||
return;
|
||||
}
|
||||
// Set the client token.
|
||||
m_account->m_clientToken = clientToken;
|
||||
@ -104,8 +101,8 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
if (accessToken.isEmpty())
|
||||
{
|
||||
// Fail if the server didn't give us an access token.
|
||||
// TODO: Set an error properly to display to the user.
|
||||
QLOG_ERROR() << "Server didn't send an access token.";
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't send an access token."));
|
||||
return;
|
||||
}
|
||||
// Set the access token.
|
||||
m_account->m_accessToken = accessToken;
|
||||
@ -149,16 +146,13 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
QString currentProfileId = currentProfile.value("id").toString("");
|
||||
if (currentProfileId.isEmpty())
|
||||
{
|
||||
// TODO: Set an error to display to the user.
|
||||
QLOG_ERROR() << "Server didn't specify a currently selected profile.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't specify a currently selected profile. The account exists, but likely isn't premium."));
|
||||
return;
|
||||
}
|
||||
if (!m_account->setCurrentProfile(currentProfileId))
|
||||
{
|
||||
// TODO: Set an error to display to the user.
|
||||
QLOG_ERROR() << "Server specified a selected profile that wasn't in the available "
|
||||
"profiles list.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server specified a selected profile that wasn't in the available profiles list."));
|
||||
return;
|
||||
}
|
||||
|
||||
// this is what the vanilla launcher passes to the userProperties launch param
|
||||
@ -181,7 +175,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
// We've made it through the minefield of possible errors. Return true to indicate that
|
||||
// we've succeeded.
|
||||
QLOG_DEBUG() << "Finished reading authentication response.";
|
||||
return true;
|
||||
changeState(STATE_SUCCEEDED);
|
||||
}
|
||||
|
||||
QString AuthenticateTask::getEndpoint() const
|
||||
@ -189,15 +183,15 @@ QString AuthenticateTask::getEndpoint() const
|
||||
return "authenticate";
|
||||
}
|
||||
|
||||
QString AuthenticateTask::getStateMessage(const YggdrasilTask::State state) const
|
||||
QString AuthenticateTask::getStateMessage() const
|
||||
{
|
||||
switch (state)
|
||||
switch (m_state)
|
||||
{
|
||||
case STATE_SENDING_REQUEST:
|
||||
return tr("Authenticating: Sending request...");
|
||||
case STATE_PROCESSING_RESPONSE:
|
||||
return tr("Authenticating: Processing response...");
|
||||
default:
|
||||
return YggdrasilTask::getStateMessage(state);
|
||||
return YggdrasilTask::getStateMessage();
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,13 @@ public:
|
||||
AuthenticateTask(MojangAccount *account, const QString &password, QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual QJsonObject getRequestContent() const;
|
||||
virtual QJsonObject getRequestContent() const override;
|
||||
|
||||
virtual QString getEndpoint() const;
|
||||
virtual QString getEndpoint() const override;
|
||||
|
||||
virtual bool processResponse(QJsonObject responseData);
|
||||
virtual void processResponse(QJsonObject responseData) override;
|
||||
|
||||
QString getStateMessage(const YggdrasilTask::State state) const;
|
||||
virtual QString getStateMessage() const override;
|
||||
|
||||
private:
|
||||
QString m_password;
|
||||
|
@ -60,7 +60,7 @@ QJsonObject RefreshTask::getRequestContent() const
|
||||
return req;
|
||||
}
|
||||
|
||||
bool RefreshTask::processResponse(QJsonObject responseData)
|
||||
void RefreshTask::processResponse(QJsonObject responseData)
|
||||
{
|
||||
// Read the response data. We need to get the client token, access token, and the selected
|
||||
// profile.
|
||||
@ -73,17 +73,13 @@ bool RefreshTask::processResponse(QJsonObject responseData)
|
||||
if (clientToken.isEmpty())
|
||||
{
|
||||
// Fail if the server gave us an empty client token
|
||||
// TODO: Set an error properly to display to the user.
|
||||
QLOG_ERROR() << "Server didn't send a client token.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't send a client token."));
|
||||
return;
|
||||
}
|
||||
if (!m_account->m_clientToken.isEmpty() && clientToken != m_account->m_clientToken)
|
||||
{
|
||||
// The server changed our client token! Obey its wishes, but complain. That's what I do
|
||||
// for my parents, so...
|
||||
QLOG_ERROR() << "Server changed our client token to '" << clientToken
|
||||
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server attempted to change the client token. This isn't supported."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, we set the access token.
|
||||
@ -92,9 +88,8 @@ bool RefreshTask::processResponse(QJsonObject responseData)
|
||||
if (accessToken.isEmpty())
|
||||
{
|
||||
// Fail if the server didn't give us an access token.
|
||||
// TODO: Set an error properly to display to the user.
|
||||
QLOG_ERROR() << "Server didn't send an access token.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't send an access token."));
|
||||
return;
|
||||
}
|
||||
|
||||
// we validate that the server responded right. (our current profile = returned current
|
||||
@ -103,9 +98,8 @@ bool RefreshTask::processResponse(QJsonObject responseData)
|
||||
QString currentProfileId = currentProfile.value("id").toString("");
|
||||
if (m_account->currentProfile()->id != currentProfileId)
|
||||
{
|
||||
// TODO: Set an error to display to the user.
|
||||
QLOG_ERROR() << "Server didn't specify the same selected profile as ours.";
|
||||
return false;
|
||||
changeState(STATE_FAILED_HARD, tr("Authentication server didn't specify the same prefile as expected."));
|
||||
return;
|
||||
}
|
||||
|
||||
// this is what the vanilla launcher passes to the userProperties launch param
|
||||
@ -130,7 +124,7 @@ bool RefreshTask::processResponse(QJsonObject responseData)
|
||||
QLOG_DEBUG() << "Finished reading refresh response.";
|
||||
// Reset the access token.
|
||||
m_account->m_accessToken = accessToken;
|
||||
return true;
|
||||
changeState(STATE_SUCCEEDED);
|
||||
}
|
||||
|
||||
QString RefreshTask::getEndpoint() const
|
||||
@ -138,15 +132,15 @@ QString RefreshTask::getEndpoint() const
|
||||
return "refresh";
|
||||
}
|
||||
|
||||
QString RefreshTask::getStateMessage(const YggdrasilTask::State state) const
|
||||
QString RefreshTask::getStateMessage() const
|
||||
{
|
||||
switch (state)
|
||||
switch (m_state)
|
||||
{
|
||||
case STATE_SENDING_REQUEST:
|
||||
return tr("Refreshing login token...");
|
||||
case STATE_PROCESSING_RESPONSE:
|
||||
return tr("Refreshing login token: Processing response...");
|
||||
default:
|
||||
return YggdrasilTask::getStateMessage(state);
|
||||
return YggdrasilTask::getStateMessage();
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ public:
|
||||
RefreshTask(MojangAccount * account);
|
||||
|
||||
protected:
|
||||
virtual QJsonObject getRequestContent() const;
|
||||
virtual QJsonObject getRequestContent() const override;
|
||||
|
||||
virtual QString getEndpoint() const;
|
||||
virtual QString getEndpoint() const override;
|
||||
|
||||
virtual bool processResponse(QJsonObject responseData);
|
||||
virtual void processResponse(QJsonObject responseData) override;
|
||||
|
||||
QString getStateMessage(const YggdrasilTask::State state) const;
|
||||
virtual QString getStateMessage() const override;
|
||||
};
|
||||
|
||||
|
@ -38,11 +38,10 @@ QJsonObject ValidateTask::getRequestContent() const
|
||||
return req;
|
||||
}
|
||||
|
||||
bool ValidateTask::processResponse(QJsonObject responseData)
|
||||
void ValidateTask::processResponse(QJsonObject responseData)
|
||||
{
|
||||
// Assume that if processError wasn't called, then the request was successful.
|
||||
emitSucceeded();
|
||||
return true;
|
||||
changeState(YggdrasilTask::STATE_SUCCEEDED);
|
||||
}
|
||||
|
||||
QString ValidateTask::getEndpoint() const
|
||||
@ -50,15 +49,15 @@ QString ValidateTask::getEndpoint() const
|
||||
return "validate";
|
||||
}
|
||||
|
||||
QString ValidateTask::getStateMessage(const YggdrasilTask::State state) const
|
||||
QString ValidateTask::getStateMessage() const
|
||||
{
|
||||
switch (state)
|
||||
switch (m_state)
|
||||
{
|
||||
case STATE_SENDING_REQUEST:
|
||||
case YggdrasilTask::STATE_SENDING_REQUEST:
|
||||
return tr("Validating access token: Sending request...");
|
||||
case STATE_PROCESSING_RESPONSE:
|
||||
case YggdrasilTask::STATE_PROCESSING_RESPONSE:
|
||||
return tr("Validating access token: Processing response...");
|
||||
default:
|
||||
return YggdrasilTask::getStateMessage(state);
|
||||
return YggdrasilTask::getStateMessage();
|
||||
}
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ public:
|
||||
ValidateTask(MojangAccount *account, QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual QJsonObject getRequestContent() const;
|
||||
virtual QJsonObject getRequestContent() const override;
|
||||
|
||||
virtual QString getEndpoint() const;
|
||||
virtual QString getEndpoint() const override;
|
||||
|
||||
virtual bool processResponse(QJsonObject responseData);
|
||||
virtual void processResponse(QJsonObject responseData) override;
|
||||
|
||||
QString getStateMessage(const YggdrasilTask::State state) const;
|
||||
virtual QString getStateMessage() const override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
Reference in New Issue
Block a user