2022-03-19 11:46:56 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-07-06 18:04:44 +01:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-03-19 11:46:56 +00:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2023-07-06 18:04:44 +01:00
|
|
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
2022-03-19 11:46:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-10 23:44:01 +01:00
|
|
|
#include "LaunchController.h"
|
2021-11-20 15:22:22 +00:00
|
|
|
#include "Application.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "minecraft/auth/AccountList.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
|
|
|
|
#include "ui/InstanceWindow.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "ui/MainWindow.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
#include "ui/dialogs/CustomMessageBox.h"
|
|
|
|
#include "ui/dialogs/EditAccountDialog.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "ui/dialogs/ProfileSelectDialog.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
#include "ui/dialogs/ProfileSetupDialog.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "ui/dialogs/ProgressDialog.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QHostAddress>
|
2021-06-19 02:15:21 +01:00
|
|
|
#include <QHostInfo>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QLineEdit>
|
2021-06-19 02:15:21 +01:00
|
|
|
#include <QList>
|
2021-12-30 20:26:29 +00:00
|
|
|
#include <QPushButton>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QStringList>
|
2021-11-22 02:55:16 +00:00
|
|
|
|
|
|
|
#include "BuildConfig.h"
|
|
|
|
#include "JavaCommon.h"
|
|
|
|
#include "launch/steps/TextPrint.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "minecraft/auth/AccountTask.h"
|
|
|
|
#include "tasks/Task.h"
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
LaunchController::LaunchController(QObject* parent) : Task(parent) {}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2015-10-23 23:57:54 +01:00
|
|
|
void LaunchController::executeTask()
|
2015-07-05 00:54:30 +01:00
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_instance) {
|
2019-09-15 04:31:13 +01:00
|
|
|
emitFailed(tr("No instance specified!"));
|
2018-07-15 13:51:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget)) {
|
2022-04-06 21:45:57 +01:00
|
|
|
emitFailed(tr("Invalid Java arguments specified. Please fix this first."));
|
|
|
|
return;
|
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
login();
|
2017-12-03 13:05:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 20:42:06 +00:00
|
|
|
void LaunchController::decideAccount()
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_accountToUse) {
|
2021-10-31 20:42:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// Find an account to use.
|
2021-11-20 15:22:22 +00:00
|
|
|
auto accounts = APPLICATION->accounts();
|
2023-08-02 17:35:35 +01:00
|
|
|
if (accounts->count() <= 0) {
|
2018-07-15 13:51:05 +01:00
|
|
|
// Tell the user they need to log in at least one account in order to play.
|
2023-08-02 17:35:35 +01:00
|
|
|
auto reply = CustomMessageBox::selectable(m_parentWidget, tr("No Accounts"),
|
2023-09-27 10:33:22 +01:00
|
|
|
tr("In order to play Minecraft, you must have at least one Microsoft "
|
2023-09-30 22:31:51 +01:00
|
|
|
"account which owns Minecraft logged in."
|
2023-08-02 17:35:35 +01:00
|
|
|
"Would you like to open the account manager to add an account now?"),
|
|
|
|
QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)
|
|
|
|
->exec();
|
|
|
|
|
|
|
|
if (reply == QMessageBox::Yes) {
|
2018-07-15 13:51:05 +01:00
|
|
|
// Open the account manager.
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->ShowGlobalSettings(m_parentWidget, "accounts");
|
2023-08-02 17:35:35 +01:00
|
|
|
} else if (reply == QMessageBox::No) {
|
2022-05-30 11:33:07 +01:00
|
|
|
// Do not open "profile select" dialog.
|
|
|
|
return;
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2021-07-26 20:44:11 +01:00
|
|
|
|
2022-12-27 22:00:15 +00:00
|
|
|
// Select the account to use. If the instance has a specific account set, that will be used. Otherwise, the default account will be used
|
|
|
|
auto instanceAccountId = m_instance->settings()->get("InstanceAccountId").toString();
|
|
|
|
auto instanceAccountIndex = accounts->findAccountByProfileId(instanceAccountId);
|
2023-01-02 18:16:09 +00:00
|
|
|
if (instanceAccountIndex == -1) {
|
2022-12-27 22:00:15 +00:00
|
|
|
m_accountToUse = accounts->defaultAccount();
|
2023-01-02 18:16:09 +00:00
|
|
|
} else {
|
2022-12-27 22:00:15 +00:00
|
|
|
m_accountToUse = accounts->at(instanceAccountIndex);
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_accountToUse) {
|
2018-07-15 13:51:05 +01:00
|
|
|
// If no default account is set, ask the user which one to use.
|
2023-08-02 17:35:35 +01:00
|
|
|
ProfileSelectDialog selectDialog(tr("Which account would you like to use?"), ProfileSelectDialog::GlobalDefaultCheckbox,
|
|
|
|
m_parentWidget);
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
selectDialog.exec();
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// Launch the instance with the selected account.
|
2021-10-31 20:42:06 +00:00
|
|
|
m_accountToUse = selectDialog.selectedAccount();
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// If the user said to use the account as default, do that.
|
2021-10-31 20:42:06 +00:00
|
|
|
if (selectDialog.useAsGlobalDefault() && m_accountToUse) {
|
2021-11-20 15:22:22 +00:00
|
|
|
accounts->setDefaultAccount(m_accountToUse);
|
2021-07-26 20:44:11 +01:00
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2021-10-31 20:42:06 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void LaunchController::login()
|
|
|
|
{
|
2021-10-31 20:42:06 +00:00
|
|
|
decideAccount();
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// if no account is selected, we bail
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_accountToUse) {
|
2019-09-15 04:31:13 +01:00
|
|
|
emitFailed(tr("No account selected for launch."));
|
2018-07-15 13:51:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// we loop until the user succeeds in logging in or gives up
|
|
|
|
bool tryagain = true;
|
2022-08-03 19:37:10 +01:00
|
|
|
unsigned int tries = 0;
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
while (tryagain) {
|
2022-08-03 19:37:10 +01:00
|
|
|
if (tries > 0 && tries % 3 == 0) {
|
2023-08-02 17:35:35 +01:00
|
|
|
auto result =
|
|
|
|
QMessageBox::question(m_parentWidget, tr("Continue launch?"),
|
|
|
|
tr("It looks like we couldn't launch after %1 tries. Do you want to continue trying?").arg(tries));
|
2022-08-03 19:37:10 +01:00
|
|
|
|
|
|
|
if (result == QMessageBox::No) {
|
2022-08-04 09:02:54 +01:00
|
|
|
emitAborted();
|
2022-08-03 19:37:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tries++;
|
2018-07-15 13:51:05 +01:00
|
|
|
m_session = std::make_shared<AuthSession>();
|
|
|
|
m_session->wants_online = m_online;
|
2022-07-11 19:46:11 +01:00
|
|
|
m_session->demo = m_demo;
|
2021-12-04 00:18:05 +00:00
|
|
|
m_accountToUse->fillSession(m_session);
|
2021-07-26 20:44:11 +01:00
|
|
|
|
2022-01-17 11:08:10 +00:00
|
|
|
// Launch immediately in true offline mode
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_accountToUse->isOffline()) {
|
2022-01-17 11:08:10 +00:00
|
|
|
launchInstance();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
switch (m_accountToUse->accountState()) {
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountState::Offline: {
|
2021-12-06 19:17:31 +00:00
|
|
|
m_session->wants_online = false;
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2023-06-08 00:37:54 +01:00
|
|
|
/* fallthrough */
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountState::Online: {
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_session->wants_online) {
|
2021-12-06 19:17:31 +00:00
|
|
|
// we ask the user for a player name
|
|
|
|
bool ok = false;
|
2022-07-11 19:46:11 +01:00
|
|
|
|
|
|
|
QString message = tr("Choose your offline mode player name.");
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_session->demo) {
|
2022-07-11 19:46:11 +01:00
|
|
|
message = tr("Choose your demo mode player name.");
|
|
|
|
}
|
|
|
|
|
2022-03-28 13:40:34 +01:00
|
|
|
QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString();
|
|
|
|
QString usedname = lastOfflinePlayerName.isEmpty() ? m_session->player_name : lastOfflinePlayerName;
|
2023-08-02 17:35:35 +01:00
|
|
|
QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), message, QLineEdit::Normal, usedname, &ok);
|
|
|
|
if (!ok) {
|
2021-12-06 19:17:31 +00:00
|
|
|
tryagain = false;
|
|
|
|
break;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
if (name.length()) {
|
2021-12-06 19:17:31 +00:00
|
|
|
usedname = name;
|
2022-03-28 13:40:34 +01:00
|
|
|
APPLICATION->settings()->set("LastOfflinePlayerName", usedname);
|
2021-12-06 19:17:31 +00:00
|
|
|
}
|
|
|
|
m_session->MakeOffline(usedname);
|
|
|
|
// offline flavored game from here :3
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_accountToUse->ownsMinecraft()) {
|
|
|
|
if (!m_accountToUse->hasProfile()) {
|
2021-12-30 20:26:29 +00:00
|
|
|
// Now handle setting up a profile name here...
|
|
|
|
ProfileSetupDialog dialog(m_accountToUse, m_parentWidget);
|
2023-08-02 17:35:35 +01:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2021-12-30 20:26:29 +00:00
|
|
|
tryagain = true;
|
|
|
|
continue;
|
2023-08-02 17:35:35 +01:00
|
|
|
} else {
|
2021-12-30 20:26:29 +00:00
|
|
|
emitFailed(tr("Received undetermined session status during login."));
|
|
|
|
return;
|
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
}
|
2021-12-30 20:26:29 +00:00
|
|
|
// we own Minecraft, there is a profile, it's all ready to go!
|
|
|
|
launchInstance();
|
|
|
|
return;
|
2023-08-02 17:35:35 +01:00
|
|
|
} else {
|
2021-12-30 20:26:29 +00:00
|
|
|
// play demo ?
|
|
|
|
QMessageBox box(m_parentWidget);
|
|
|
|
box.setWindowTitle(tr("Play demo?"));
|
2023-08-02 17:35:35 +01:00
|
|
|
box.setText(
|
|
|
|
tr("This account does not own Minecraft.\nYou need to purchase the game first to play it.\n\nDo you want to play "
|
|
|
|
"the demo?"));
|
2021-12-30 20:26:29 +00:00
|
|
|
box.setIcon(QMessageBox::Warning);
|
|
|
|
auto demoButton = box.addButton(tr("Play Demo"), QMessageBox::ButtonRole::YesRole);
|
|
|
|
auto cancelButton = box.addButton(tr("Cancel"), QMessageBox::ButtonRole::NoRole);
|
|
|
|
box.setDefaultButton(cancelButton);
|
|
|
|
|
|
|
|
box.exec();
|
2023-08-02 17:35:35 +01:00
|
|
|
if (box.clickedButton() == demoButton) {
|
2021-12-30 20:26:29 +00:00
|
|
|
// play demo here
|
|
|
|
m_session->MakeDemo();
|
|
|
|
launchInstance();
|
2023-08-02 17:35:35 +01:00
|
|
|
} else {
|
2021-12-30 20:26:29 +00:00
|
|
|
emitFailed(tr("Launch cancelled - account does not own Minecraft."));
|
|
|
|
}
|
2021-11-10 02:02:51 +00:00
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-05 02:48:07 +00:00
|
|
|
case AccountState::Errored:
|
|
|
|
// This means some sort of soft error that we can fix with a refresh ... so let's refresh.
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountState::Unchecked: {
|
|
|
|
m_accountToUse->refresh();
|
|
|
|
}
|
2023-06-08 00:37:54 +01:00
|
|
|
/* fallthrough */
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountState::Working: {
|
|
|
|
// refresh is in progress, we need to wait for it to finish to proceed.
|
|
|
|
ProgressDialog progDialog(m_parentWidget);
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_online) {
|
2021-12-04 00:18:05 +00:00
|
|
|
progDialog.setSkipButton(true, tr("Play Offline"));
|
2021-11-10 02:02:51 +00:00
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
auto task = m_accountToUse->currentTask();
|
|
|
|
progDialog.execWithTask(task.get());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// FIXME: this is missing - the meaning is that the account is queued for refresh and we should wait for that
|
|
|
|
/*
|
|
|
|
case AccountState::Queued: {
|
|
|
|
return;
|
2021-11-10 02:02:51 +00:00
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
*/
|
|
|
|
case AccountState::Expired: {
|
|
|
|
auto errorString = tr("The account has expired and needs to be logged into manually again.");
|
2023-08-02 17:35:35 +01:00
|
|
|
QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, QMessageBox::StandardButton::Ok,
|
|
|
|
QMessageBox::StandardButton::Ok);
|
2021-08-27 21:35:17 +01:00
|
|
|
emitFailed(errorString);
|
2021-07-26 20:44:11 +01:00
|
|
|
return;
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2022-02-18 11:26:52 +00:00
|
|
|
case AccountState::Disabled: {
|
2022-02-18 18:18:29 +00:00
|
|
|
auto errorString = tr("The launcher's client identification has changed. Please remove this account and add it again.");
|
2023-08-02 17:35:35 +01:00
|
|
|
QMessageBox::warning(m_parentWidget, tr("Client identification changed"), errorString, QMessageBox::StandardButton::Ok,
|
|
|
|
QMessageBox::StandardButton::Ok);
|
2022-02-18 11:26:52 +00:00
|
|
|
emitFailed(errorString);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountState::Gone: {
|
2023-08-02 17:35:35 +01:00
|
|
|
auto errorString =
|
|
|
|
tr("The account no longer exists on the servers. It may have been migrated, in which case please add the new account "
|
|
|
|
"you migrated this one to.");
|
|
|
|
QMessageBox::warning(m_parentWidget, tr("Account gone"), errorString, QMessageBox::StandardButton::Ok,
|
|
|
|
QMessageBox::StandardButton::Ok);
|
2021-08-29 18:58:35 +01:00
|
|
|
emitFailed(errorString);
|
|
|
|
return;
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
emitFailed(tr("Failed to launch."));
|
2015-07-05 00:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchController::launchInstance()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL");
|
|
|
|
Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL");
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_instance->reloadSettings()) {
|
2019-09-15 04:31:13 +01:00
|
|
|
QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Couldn't load the instance profile."));
|
2018-07-15 13:51:05 +01:00
|
|
|
emitFailed(tr("Couldn't load the instance profile."));
|
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2021-05-22 17:07:08 +01:00
|
|
|
m_launcher = m_instance->createLaunchTask(m_session, m_serverToJoin);
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_launcher) {
|
2018-07-15 13:51:05 +01:00
|
|
|
emitFailed(tr("Couldn't instantiate a launcher."));
|
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
auto console = qobject_cast<InstanceWindow*>(m_parentWidget);
|
2018-07-15 13:51:05 +01:00
|
|
|
auto showConsole = m_instance->settings()->get("ShowConsole").toBool();
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!console && showConsole) {
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->showInstanceWindow(m_instance);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch);
|
|
|
|
connect(m_launcher.get(), &LaunchTask::succeeded, this, &LaunchController::onSucceeded);
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(m_launcher.get(), &LaunchTask::failed, this, &LaunchController::onFailed);
|
2018-07-15 13:51:05 +01:00
|
|
|
connect(m_launcher.get(), &LaunchTask::requestProgress, this, &LaunchController::onProgressRequested);
|
2016-11-01 00:25:04 +00:00
|
|
|
|
2021-06-19 02:15:21 +01:00
|
|
|
// Prepend Online and Auth Status
|
|
|
|
QString online_mode;
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_session->wants_online) {
|
2021-06-19 02:15:21 +01:00
|
|
|
online_mode = "online";
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2021-06-19 02:15:21 +01:00
|
|
|
// Prepend Server Status
|
2023-08-02 17:35:35 +01:00
|
|
|
QStringList servers = { "authserver.mojang.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com" };
|
2021-06-19 02:15:21 +01:00
|
|
|
QString resolved_servers = "";
|
|
|
|
QHostInfo host_info;
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
for (QString server : servers) {
|
2021-06-19 02:15:21 +01:00
|
|
|
host_info = QHostInfo::fromName(server);
|
|
|
|
resolved_servers = resolved_servers + server + " resolves to:\n [";
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!host_info.addresses().isEmpty()) {
|
|
|
|
for (QHostAddress address : host_info.addresses()) {
|
2021-06-19 02:15:21 +01:00
|
|
|
resolved_servers = resolved_servers + address.toString();
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!host_info.addresses().endsWith(address)) {
|
2021-06-19 02:15:21 +01:00
|
|
|
resolved_servers = resolved_servers + ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resolved_servers = resolved_servers + "N/A";
|
|
|
|
}
|
|
|
|
resolved_servers = resolved_servers + "]\n\n";
|
|
|
|
}
|
2023-01-24 19:52:09 +00:00
|
|
|
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), resolved_servers, MessageLevel::Launcher));
|
2021-06-19 02:15:21 +01:00
|
|
|
} else {
|
2022-09-15 22:32:14 +01:00
|
|
|
online_mode = m_demo ? "demo" : "offline";
|
2021-06-19 02:15:21 +01:00
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
m_launcher->prependStep(
|
|
|
|
makeShared<TextPrint>(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));
|
2021-06-19 02:15:21 +01:00
|
|
|
|
|
|
|
// Prepend Version
|
2023-06-26 10:54:22 +01:00
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
auto versionString = QString("%1 version: %2 (%3)")
|
|
|
|
.arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString(), BuildConfig.BUILD_PLATFORM);
|
2023-06-26 10:54:22 +01:00
|
|
|
m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), versionString + "\n\n", MessageLevel::Launcher));
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
m_launcher->start();
|
2015-07-05 00:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchController::readyForLaunch()
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_profiler) {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_launcher->proceed();
|
|
|
|
return;
|
|
|
|
}
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
QString error;
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_profiler->check(&error)) {
|
2018-07-15 13:51:05 +01:00
|
|
|
m_launcher->abort();
|
2019-09-15 04:31:13 +01:00
|
|
|
emitFailed("Profiler startup failed!");
|
2023-07-06 18:04:44 +01:00
|
|
|
QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Profiler check for %1 failed: %2").arg(m_profiler->name(), error));
|
2018-07-15 13:51:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
BaseProfiler* profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this);
|
2015-07-05 00:54:30 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString& message) {
|
2023-07-06 18:04:44 +01:00
|
|
|
QMessageBox msg(m_parentWidget);
|
2018-07-15 13:51:05 +01:00
|
|
|
msg.setText(tr("The game launch is delayed until you press the "
|
2023-08-02 17:35:35 +01:00
|
|
|
"button. This is the right time to setup the profiler, as the "
|
|
|
|
"profiler server is running now.\n\n%1")
|
|
|
|
.arg(message));
|
2019-09-15 04:31:13 +01:00
|
|
|
msg.setWindowTitle(tr("Waiting."));
|
2018-07-15 13:51:05 +01:00
|
|
|
msg.setIcon(QMessageBox::Information);
|
2023-07-06 18:04:44 +01:00
|
|
|
msg.addButton(tr("&Launch"), QMessageBox::AcceptRole);
|
2018-07-15 13:51:05 +01:00
|
|
|
msg.exec();
|
|
|
|
m_launcher->proceed();
|
|
|
|
});
|
2023-08-02 17:35:35 +01:00
|
|
|
connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString& message) {
|
2018-07-15 13:51:05 +01:00
|
|
|
QMessageBox msg;
|
|
|
|
msg.setText(tr("Couldn't start the profiler: %1").arg(message));
|
|
|
|
msg.setWindowTitle(tr("Error"));
|
|
|
|
msg.setIcon(QMessageBox::Critical);
|
|
|
|
msg.addButton(QMessageBox::Ok);
|
|
|
|
msg.setModal(true);
|
|
|
|
msg.exec();
|
|
|
|
m_launcher->abort();
|
2019-09-15 04:31:13 +01:00
|
|
|
emitFailed("Profiler startup failed!");
|
2018-07-15 13:51:05 +01:00
|
|
|
});
|
|
|
|
profilerInstance->beginProfiling(m_launcher);
|
2015-07-05 00:54:30 +01:00
|
|
|
}
|
2016-11-01 00:25:04 +00:00
|
|
|
|
|
|
|
void LaunchController::onSucceeded()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
emitSucceeded();
|
2016-11-01 00:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchController::onFailed(QString reason)
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_instance->settings()->get("ShowConsoleOnError").toBool()) {
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->showInstanceWindow(m_instance, "console");
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
emitFailed(reason);
|
2016-11-01 00:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchController::onProgressRequested(Task* task)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
ProgressDialog progDialog(m_parentWidget);
|
|
|
|
progDialog.setSkipButton(true, tr("Abort"));
|
|
|
|
m_launcher->proceed();
|
|
|
|
progDialog.execWithTask(task);
|
2016-11-01 00:25:04 +00:00
|
|
|
}
|
2016-11-26 17:06:08 +00:00
|
|
|
|
|
|
|
bool LaunchController::abort()
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_launcher) {
|
2018-07-15 13:51:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!m_launcher->canAbort()) {
|
2018-07-15 13:51:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
auto response = CustomMessageBox::selectable(m_parentWidget, tr("Kill Minecraft?"),
|
|
|
|
tr("This can cause the instance to get corrupted and should only be used if Minecraft "
|
|
|
|
"is frozen for some reason"),
|
|
|
|
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)
|
|
|
|
->exec();
|
|
|
|
if (response == QMessageBox::Yes) {
|
2018-07-15 13:51:05 +01:00
|
|
|
return m_launcher->abort();
|
|
|
|
}
|
|
|
|
return false;
|
2016-11-26 17:06:08 +00:00
|
|
|
}
|