From 0395474a0c3b40d4ef688e5d726a6519b3b2a620 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 28 Nov 2013 22:05:58 -0600 Subject: Nuke dead code --- CMakeLists.txt | 5 - gui/dialogs/LoginDialog.cpp | 216 -------------------------------- gui/dialogs/LoginDialog.h | 61 --------- gui/dialogs/LoginDialog.ui | 186 ---------------------------- logic/InstanceLauncher.cpp | 5 +- logic/net/LoginTask.cpp | 293 -------------------------------------------- logic/net/LoginTask.h | 76 ------------ 7 files changed, 3 insertions(+), 839 deletions(-) delete mode 100644 gui/dialogs/LoginDialog.cpp delete mode 100644 gui/dialogs/LoginDialog.h delete mode 100644 gui/dialogs/LoginDialog.ui delete mode 100644 logic/net/LoginTask.cpp delete mode 100644 logic/net/LoginTask.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a8038fff..dfce1fad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,8 +193,6 @@ gui/dialogs/CopyInstanceDialog.h gui/dialogs/CopyInstanceDialog.cpp gui/dialogs/dialogs/ gui/dialogs/NewInstanceDialog.cpp -gui/dialogs/LoginDialog.h -gui/dialogs/LoginDialog.cpp gui/dialogs/ProgressDialog.h gui/dialogs/ProgressDialog.cpp gui/dialogs/AboutDialog.h @@ -270,8 +268,6 @@ logic/net/NetJob.h logic/net/NetJob.cpp logic/net/HttpMetaCache.h logic/net/HttpMetaCache.cpp -logic/net/LoginTask.h -logic/net/LoginTask.cpp logic/net/S3ListBucket.h logic/net/S3ListBucket.cpp @@ -369,7 +365,6 @@ gui/ConsoleWindow.ui gui/dialogs/SettingsDialog.ui gui/dialogs/CopyInstanceDialog.ui gui/dialogs/NewInstanceDialog.ui -gui/dialogs/LoginDialog.ui gui/dialogs/AboutDialog.ui gui/dialogs/VersionSelectDialog.ui gui/dialogs/LwjglSelectDialog.ui diff --git a/gui/dialogs/LoginDialog.cpp b/gui/dialogs/LoginDialog.cpp deleted file mode 100644 index 28bbb1ee..00000000 --- a/gui/dialogs/LoginDialog.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LoginDialog.h" -#include "ui_LoginDialog.h" -#include "keyring.h" -#include "gui/Platform.h" -#include "MultiMC.h" -#include "logic/SkinUtils.h" - -#include -#include -#include -#include -#include "logic/net/HttpMetaCache.h" -#include "logger/QsLog.h" - -LoginDialog::LoginDialog(QWidget *parent, const QString &loginErrMsg) - : QDialog(parent), ui(new Ui::LoginDialog) -{ - MultiMCPlatform::fixWM_CLASS(this); - ui->setupUi(this); - - //: Use offline mode one time - offlineButton = new QPushButton(tr("Offline Once")); - - ui->loginButtonBox->addButton(offlineButton, QDialogButtonBox::ActionRole); - - blockToggles = false; - isOnline_ = true; - onlineForced = false; - - //: The username during login (placeholder) - ui->usernameTextBox->lineEdit()->setPlaceholderText(tr("Name")); - - connect(ui->usernameTextBox, SIGNAL(currentTextChanged(QString)), this, - SLOT(userTextChanged(QString))); - connect(ui->forgetButton, SIGNAL(clicked(bool)), this, SLOT(forgetCurrentUser())); - connect(offlineButton, SIGNAL(clicked(bool)), this, SLOT(launchOffline())); - - if (loginErrMsg.isEmpty()) - ui->loginErrorLabel->setVisible(false); - else - { - ui->loginErrorLabel->setVisible(true); - ui->loginErrorLabel->setText( - QString("%1").arg(loginErrMsg)); - } - - ui->lblFace->setVisible(false); - - resize(minimumSizeHint()); - layout()->setSizeConstraint(QLayout::SetFixedSize); - Keyring *k = Keyring::instance(); - QStringList accounts = k->getStoredAccounts("minecraft"); - ui->usernameTextBox->addItems(accounts); - - // TODO: restore last selected account here, if applicable - - int index = ui->usernameTextBox->currentIndex(); - if (index != -1) - { - ui->passwordTextBox->setFocus(Qt::OtherFocusReason); - } - - connect(ui->rememberUsernameCheckbox, SIGNAL(toggled(bool)), SLOT(usernameToggled(bool))); - connect(ui->rememberPasswordCheckbox, SIGNAL(toggled(bool)), SLOT(passwordToggled(bool))); -} - -LoginDialog::~LoginDialog() -{ - delete offlineButton; - delete ui; -} - -QString LoginDialog::getUsername() const -{ - return ui->usernameTextBox->currentText(); -} - -QString LoginDialog::getPassword() const -{ - return ui->passwordTextBox->text(); -} - -void LoginDialog::forgetCurrentUser() -{ - Keyring *k = Keyring::instance(); - QString acct = ui->usernameTextBox->currentText(); - k->removeStoredAccount("minecraft", acct); - ui->passwordTextBox->clear(); - int index = ui->usernameTextBox->findText(acct); - if (index != -1) - ui->usernameTextBox->removeItem(index); - if (!ui->usernameTextBox->count()) - { - blockToggles = true; - ui->rememberUsernameCheckbox->setChecked(false); - ui->rememberPasswordCheckbox->setChecked(false); - blockToggles = false; - } -} - -void LoginDialog::passwordToggled(bool state) -{ - // if toggled off - if (blockToggles) - return; - blockToggles = true; - if (!state) - { - QLOG_DEBUG() << "password disabled"; - } - else - { - if (!ui->rememberUsernameCheckbox->isChecked()) - { - ui->rememberUsernameCheckbox->setChecked(true); - } - QLOG_DEBUG() << "password enabled"; - } - blockToggles = false; -} - -void LoginDialog::usernameToggled(bool state) -{ - // if toggled off - if (blockToggles) - return; - blockToggles = true; - if (!state) - { - if (ui->rememberPasswordCheckbox->isChecked()) - { - ui->rememberPasswordCheckbox->setChecked(false); - } - QLOG_DEBUG() << "username disabled"; - } - else - { - QLOG_DEBUG() << "username enabled"; - } - blockToggles = false; -} - -void LoginDialog::userTextChanged(const QString &user) -{ - blockToggles = true; - Keyring *k = Keyring::instance(); - QStringList sl = k->getStoredAccounts("minecraft"); - bool gotFace = false; - - if (sl.contains(user)) - { - ui->rememberUsernameCheckbox->setChecked(true); - QString passwd = k->getPassword("minecraft", user); - ui->rememberPasswordCheckbox->setChecked(!passwd.isEmpty()); - ui->passwordTextBox->setText(passwd); - - QPixmap face = SkinUtils::getFaceFromCache(user); - gotFace = !face.isNull(); - - if(gotFace) ui->lblFace->setPixmap(face); - } - - ui->lblFace->setVisible(gotFace); - blockToggles = false; -} - -void LoginDialog::accept() -{ - bool saveName = ui->rememberUsernameCheckbox->isChecked(); - bool savePass = ui->rememberPasswordCheckbox->isChecked(); - Keyring *k = Keyring::instance(); - if (saveName) - { - if (savePass) - { - k->storePassword("minecraft", getUsername(), getPassword()); - } - else - { - k->storePassword("minecraft", getUsername(), QString()); - } - } - else - { - QString acct = ui->usernameTextBox->currentText(); - k->removeStoredAccount("minecraft", acct); - } - QDialog::accept(); -} - -void LoginDialog::launchOffline() -{ - isOnline_ = false; - QDialog::accept(); -} - -void LoginDialog::forceOnline() -{ - onlineForced = true; - offlineButton->setEnabled(false); -} diff --git a/gui/dialogs/LoginDialog.h b/gui/dialogs/LoginDialog.h deleted file mode 100644 index 73a92aab..00000000 --- a/gui/dialogs/LoginDialog.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -namespace Ui -{ -class LoginDialog; -} - -class LoginDialog : public QDialog -{ - Q_OBJECT - -public: - explicit LoginDialog(QWidget *parent = 0, const QString &loginErrMsg = ""); - ~LoginDialog(); - - QString getUsername() const; - QString getPassword() const; - - inline bool isOnline() - { - return isOnline_; - } - - void forceOnline(); - -public -slots: - virtual void accept(); - virtual void userTextChanged(const QString &user); - virtual void forgetCurrentUser(); -private -slots: - void usernameToggled(bool); - void passwordToggled(bool); - void launchOffline(); - -private: - Ui::LoginDialog *ui; - bool blockToggles; - QPushButton *offlineButton; - bool isOnline_; - bool onlineForced; -}; diff --git a/gui/dialogs/LoginDialog.ui b/gui/dialogs/LoginDialog.ui deleted file mode 100644 index 45f319ed..00000000 --- a/gui/dialogs/LoginDialog.ui +++ /dev/null @@ -1,186 +0,0 @@ - - - LoginDialog - - - - 0 - 0 - 496 - 168 - - - - Login - - - - - - <span style=" color:#ff0000;">Error</span> - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - - - - - 48 - 48 - - - - - 48 - 48 - - - - - 1 - 1 - - - - - - - :/icons/instances/steve - - - true - - - - - - - true - - - - - - - Username: - - - - - - - Password: - - - - - - - QLineEdit::Password - - - Password - - - - - - - - - - - - 1 - 0 - - - - &Remember Username? - - - - - - - - 1 - 0 - - - - R&emember Password? - - - - - - - - 0 - 0 - - - - Forget - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - - loginButtonBox - accepted() - LoginDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - loginButtonBox - rejected() - LoginDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp index 0ef0f045..c0079d80 100644 --- a/logic/InstanceLauncher.cpp +++ b/logic/InstanceLauncher.cpp @@ -19,10 +19,8 @@ #include "MultiMC.h" #include "gui/ConsoleWindow.h" -#include "gui/dialogs/LoginDialog.h" #include "gui/dialogs/ProgressDialog.h" -#include "logic/net/LoginTask.h" #include "logic/MinecraftProcess.h" #include "logic/lists/InstanceList.h" @@ -59,6 +57,8 @@ void InstanceLauncher::onLoginComplete() void InstanceLauncher::doLogin(const QString &errorMsg) { + // FIXME: Use new account system here... + /* LoginDialog *loginDlg = new LoginDialog(nullptr, errorMsg); loginDlg->exec(); if (loginDlg->result() == QDialog::Accepted) @@ -72,6 +72,7 @@ void InstanceLauncher::doLogin(const QString &errorMsg) Qt::QueuedConnection); tDialog->exec(loginTask); } + */ // onLoginComplete(LoginResponse("Offline","Offline", 1)); } diff --git a/logic/net/LoginTask.cpp b/logic/net/LoginTask.cpp deleted file mode 100644 index 5607447e..00000000 --- a/logic/net/LoginTask.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LoginTask.h" -#include "MultiMC.h" -#include - -#include - -#include -#include - -#include -#include -#include -#include - -LoginTask::LoginTask(const PasswordLogin &loginInfo, QObject *parent) - : Task(parent), loginInfo(loginInfo) -{ -} - -void LoginTask::executeTask() -{ - yggdrasilLogin(); -} - -void LoginTask::legacyLogin() -{ - setStatus(tr("Logging in...")); - auto worker = MMC->qnam(); - connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, - SLOT(processLegacyReply(QNetworkReply *))); - - QUrl loginURL("https://login.minecraft.net/"); - QNetworkRequest netRequest(loginURL); - netRequest.setHeader(QNetworkRequest::ContentTypeHeader, - "application/x-www-form-urlencoded"); - - QUrlQuery params; - params.addQueryItem("user", loginInfo.username); - params.addQueryItem("password", loginInfo.password); - params.addQueryItem("version", "13"); - - netReply = worker->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8()); -} - -void LoginTask::parseLegacyReply(QByteArray data) -{ - QString responseStr = QString::fromUtf8(data); - - QStringList strings = responseStr.split(":"); - if (strings.count() >= 4) - { - // strings[1] is the download ticket. It isn't used anymore. - QString username = strings[2]; - QString sessionID = strings[3]; - /* - struct LoginResponse - { - QString username; - QString session_id; - QString player_name; - QString player_id; - QString client_id; - }; - */ - result = {username, sessionID, username, QString()}; - emitSucceeded(); - } - else - { - if (responseStr.toLower() == "bad login") - emitFailed(tr("Invalid username or password.")); - else if (responseStr.toLower() == "old version") - emitFailed(tr("Launcher outdated, please update.")); - else - emitFailed(tr("Login failed: %1").arg(responseStr)); - } -} - -void LoginTask::processLegacyReply(QNetworkReply *reply) -{ - processReply(reply, &LoginTask::parseLegacyReply, &LoginTask::parseLegacyError); -} - -void LoginTask::processYggdrasilReply(QNetworkReply *reply) -{ - processReply(reply, &LoginTask::parseYggdrasilReply, &LoginTask::parseYggdrasilError); -} - -void LoginTask::processReply(QNetworkReply *reply, - std::function parser, - std::function errorHandler) -{ - if (netReply != reply) - return; - // Check for errors. - switch (reply->error()) - { - case QNetworkReply::NoError: - { - // Check the response code. - int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - switch (responseCode) - { - case 200: - parser(this, reply->readAll()); - break; - - default: - emitFailed(tr("Login failed: Unknown HTTP code %1 encountered.").arg(responseCode)); - break; - } - - break; - } - - case QNetworkReply::OperationCanceledError: - emitFailed(tr("Login canceled.")); - break; - - default: - emitFailed(errorHandler(this, reply)); - break; - } -} - -QString LoginTask::parseLegacyError(QNetworkReply *reply) -{ - int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - switch (responseCode) - { - case 403: - return tr("Invalid username or password."); - - case 503: - return tr("The login servers are currently unavailable. Check " - "http://help.mojang.com/ for more info."); - - default: - QLOG_DEBUG() << "Login failed with QNetworkReply code:" << reply->error(); - return tr("Login failed: %1").arg(reply->errorString()); - } -} - -QString LoginTask::parseYggdrasilError(QNetworkReply *reply) -{ - QByteArray data = reply->readAll(); - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - // If there are JSON errors fall back to using the legacy error handling using HTTP status - // codes - if (jsonError.error != QJsonParseError::NoError) - { - return parseLegacyError(reply); - } - - if (!jsonDoc.isObject()) - { - return parseLegacyError(reply); - } - - QJsonObject root = jsonDoc.object(); - - // QString error = root.value("error").toString(); - QString errorMessage = root.value("errorMessage").toString(); - - if (errorMessage.isEmpty()) - { - return parseLegacyError(reply); - } - - return tr("Login failed: ") + errorMessage; -} - -void LoginTask::yggdrasilLogin() -{ - setStatus(tr("Logging in...")); - auto worker = MMC->qnam(); - connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this, - SLOT(processYggdrasilReply(QNetworkReply *))); - - /* - { - // agent def. version might be incremented at some point - "agent":{"name":"Minecraft","version":1}, - "username": "mojang account name", - "password": "mojang account password", - // client token is optional. but we supply one anyway - "clientToken": "client identifier" - } - */ - - QUrl loginURL("https://authserver.mojang.com/authenticate"); - QNetworkRequest netRequest(loginURL); - netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - - auto settings = MMC->settings(); - QString clientToken = settings->get("YggdrasilClientToken").toString(); - // escape the {} - clientToken.remove('{'); - clientToken.remove('}'); - // create the request - QJsonObject root; - QJsonObject agent; - agent.insert("name", QString("Minecraft")); - agent.insert("version", QJsonValue(1)); - root.insert("agent", agent); - root.insert("username", loginInfo.username); - root.insert("password", loginInfo.password); - root.insert("clientToken", clientToken); - QJsonDocument requestDoc(root); - netReply = worker->post(netRequest, requestDoc.toJson()); -} - -/* -{ - "accessToken": "random access token", // hexadecimal - "clientToken": "client identifier", // identical to the one received - "availableProfiles": [ // only present if the agent field was received - { - "id": "profile identifier", // hexadecimal - "name": "player name" - } - ], - "selectedProfile": { // only present if the agent field was received - "id": "profile identifier", - "name": "player name" - } -} -*/ -void LoginTask::parseYggdrasilReply(QByteArray data) -{ - QJsonParseError jsonError; - QLOG_DEBUG() << data; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed(tr("Login failed: %1").arg(jsonError.errorString())); - return; - } - - if (!jsonDoc.isObject()) - { - emitFailed(tr("Login failed: BAD FORMAT #1")); - return; - } - - QJsonObject root = jsonDoc.object(); - - QString accessToken = root.value("accessToken").toString(); - QString clientToken = root.value("clientToken").toString(); - QString playerID; - QString playerName; - auto selectedProfile = root.value("selectedProfile"); - if (selectedProfile.isObject()) - { - auto selectedProfileO = selectedProfile.toObject(); - playerID = selectedProfileO.value("id").toString(); - playerName = selectedProfileO.value("name").toString(); - } - - QString sessionID = "token:" + accessToken + ":" + playerID; - /* - struct LoginResponse - { - QString username; - QString session_id; - QString player_name; - QString player_id; - QString client_id; - }; - */ - - result = {loginInfo.username, sessionID, playerName, playerID, accessToken}; - emitSucceeded(); -} diff --git a/logic/net/LoginTask.h b/logic/net/LoginTask.h deleted file mode 100644 index fe4e6d2f..00000000 --- a/logic/net/LoginTask.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "logic/tasks/Task.h" -#include - -struct PasswordLogin -{ - QString username; - QString password; -}; - -struct User -{ - QString id; - QMap properties; -}; - -struct LoginResponse -{ - QString username; - QString session_id; // session id is a combination of player id and the access token - QString player_name; - QString player_id; - QString access_token; - User user; // FIXME: no idea what this really is yet. anything relevant? -}; - -class QNetworkReply; - -class LoginTask : public Task -{ - Q_OBJECT -public: - explicit LoginTask(const PasswordLogin &loginInfo, QObject *parent = 0); - LoginResponse getResult() - { - return result; - } - -protected -slots: - void legacyLogin(); - void processLegacyReply(QNetworkReply *reply); - void parseLegacyReply(QByteArray data); - QString parseLegacyError(QNetworkReply *reply); - - void yggdrasilLogin(); - void processYggdrasilReply(QNetworkReply *reply); - void parseYggdrasilReply(QByteArray data); - QString parseYggdrasilError(QNetworkReply *reply); - - void processReply(QNetworkReply *reply, std::function, - std::function); - -protected: - void executeTask(); - - LoginResponse result; - QNetworkReply *netReply; - PasswordLogin loginInfo; -}; -- cgit v1.2.3