From ffd5dd948c8ebcd0d79e28097d65aa409334d2b9 Mon Sep 17 00:00:00 2001 From: Zakhar Afonin Date: Sun, 30 May 2021 16:03:22 +0300 Subject: [PATCH] Launching the game now possible. Feature parity with master branch --- api/logic/minecraft/auth/MojangAccount.cpp | 22 ++++++++++++++++++---- api/logic/minecraft/auth/MojangAccount.h | 6 ++++++ application/dialogs/LoginDialog.cpp | 8 +++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/api/logic/minecraft/auth/MojangAccount.cpp b/api/logic/minecraft/auth/MojangAccount.cpp index 2cf3a9eb..7e47e352 100644 --- a/api/logic/minecraft/auth/MojangAccount.cpp +++ b/api/logic/minecraft/auth/MojangAccount.cpp @@ -145,6 +145,17 @@ QJsonObject MojangAccount::saveToJson() const return json; } +bool MojangAccount::setLoginType(const QString &loginType) +{ + // TODO: Implement a cleaner validity check + if (loginType == "mojang" or loginType == "dummy") + { + m_loginType = loginType; + return true; + } + return false; +} + bool MojangAccount::setCurrentProfile(const QString &profileId) { for (int i = 0; i < m_profiles.length(); i++) @@ -180,9 +191,12 @@ std::shared_ptr MojangAccount::login(AuthSessionPtr session, QStr // Handling alternative account types if (m_loginType == "dummy") { - session->status = AuthSession::PlayableOffline; - session->auth_server_online = false; - fillSession(session); + if (session) + { + session->status = AuthSession::PlayableOnline; + session->auth_server_online = false; + fillSession(session); + } return nullptr; } @@ -292,7 +306,7 @@ void MojangAccount::fillSession(AuthSessionPtr session) } else { - session->player_name = "Player"; + session->player_name = m_username; session->session = "-"; } session->u = user(); diff --git a/api/logic/minecraft/auth/MojangAccount.h b/api/logic/minecraft/auth/MojangAccount.h index 1876e00c..96a9f46b 100644 --- a/api/logic/minecraft/auth/MojangAccount.h +++ b/api/logic/minecraft/auth/MojangAccount.h @@ -85,6 +85,12 @@ public: /* construction */ public: /* manipulation */ /** + * Overrides the login type on the account. + * Accepts "mojang" and "dummy". Returns false if other. + */ + bool setLoginType(const QString &loginType); + + /** * Sets the currently selected profile to the profile with the given ID string. * If profileId is not in the list of available profiles, the function will simply return * false. diff --git a/application/dialogs/LoginDialog.cpp b/application/dialogs/LoginDialog.cpp index 32f8a48f..74eb90e7 100644 --- a/application/dialogs/LoginDialog.cpp +++ b/application/dialogs/LoginDialog.cpp @@ -43,13 +43,19 @@ void LoginDialog::accept() // Setup the login task and start it m_account = MojangAccount::createFromUsername(ui->userTextBox->text()); + m_account->setLoginType("dummy"); // TODO: Add the login type selector m_loginTask = m_account->login(nullptr, ui->passTextBox->text()); connect(m_loginTask.get(), &Task::failed, this, &LoginDialog::onTaskFailed); connect(m_loginTask.get(), &Task::succeeded, this, &LoginDialog::onTaskSucceeded); connect(m_loginTask.get(), &Task::status, this, &LoginDialog::onTaskStatus); connect(m_loginTask.get(), &Task::progress, this, &LoginDialog::onTaskProgress); - m_loginTask->start(); + if (true) + { + onTaskSucceeded(); + } else { + m_loginTask->start(); + } } void LoginDialog::setUserInputsEnabled(bool enable)