2013-11-04 01:53:05 +00:00
|
|
|
/* 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 <iostream>
|
|
|
|
|
2013-09-07 02:00:58 +00:00
|
|
|
#include "InstanceLauncher.h"
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
#include "gui/ConsoleWindow.h"
|
|
|
|
#include "gui/dialogs/LoginDialog.h"
|
|
|
|
#include "gui/dialogs/ProgressDialog.h"
|
|
|
|
|
2013-09-22 22:23:50 +00:00
|
|
|
#include "logic/net/LoginTask.h"
|
2013-09-07 02:00:58 +00:00
|
|
|
#include "logic/MinecraftProcess.h"
|
2013-11-04 01:53:05 +00:00
|
|
|
#include "logic/lists/InstanceList.h"
|
2013-09-07 02:00:58 +00:00
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
InstanceLauncher::InstanceLauncher(QString instId) : QObject(), instId(instId)
|
|
|
|
{
|
|
|
|
}
|
2013-09-07 02:00:58 +00:00
|
|
|
|
|
|
|
void InstanceLauncher::onTerminated()
|
|
|
|
{
|
|
|
|
std::cout << "Minecraft exited" << std::endl;
|
|
|
|
MMC->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceLauncher::onLoginComplete()
|
|
|
|
{
|
2013-11-21 00:31:15 +00:00
|
|
|
// TODO: Fix this.
|
|
|
|
/*
|
2013-11-04 01:53:05 +00:00
|
|
|
LoginTask *task = (LoginTask *)QObject::sender();
|
2013-09-07 02:00:58 +00:00
|
|
|
auto result = task->getResult();
|
|
|
|
auto instance = MMC->instances()->getInstanceById(instId);
|
2013-11-04 01:53:05 +00:00
|
|
|
proc = instance->prepareForLaunch(result);
|
|
|
|
if (!proc)
|
2013-09-07 02:00:58 +00:00
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
// FIXME: report error
|
2013-09-07 02:00:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-08 14:25:02 +00:00
|
|
|
console = new ConsoleWindow(proc);
|
2013-11-23 00:41:28 +00:00
|
|
|
connect(console, SIGNAL(isClosing()), this, SLOT(onTerminated()));
|
2013-09-07 02:00:58 +00:00
|
|
|
|
2013-11-23 00:41:28 +00:00
|
|
|
proc->setLogin(result.username, result.session_id);
|
2013-09-07 02:00:58 +00:00
|
|
|
proc->launch();
|
2013-11-21 00:31:15 +00:00
|
|
|
*/
|
2013-09-07 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
void InstanceLauncher::doLogin(const QString &errorMsg)
|
2013-09-07 02:00:58 +00:00
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
LoginDialog *loginDlg = new LoginDialog(nullptr, errorMsg);
|
2013-09-07 02:00:58 +00:00
|
|
|
loginDlg->exec();
|
2013-11-04 01:53:05 +00:00
|
|
|
if (loginDlg->result() == QDialog::Accepted)
|
2013-09-07 02:00:58 +00:00
|
|
|
{
|
2013-11-22 00:04:14 +00:00
|
|
|
PasswordLogin uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
|
2013-09-07 02:00:58 +00:00
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
ProgressDialog *tDialog = new ProgressDialog(nullptr);
|
|
|
|
LoginTask *loginTask = new LoginTask(uInfo, tDialog);
|
|
|
|
connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection);
|
|
|
|
connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)),
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
tDialog->exec(loginTask);
|
2013-09-07 02:00:58 +00:00
|
|
|
}
|
2013-11-04 01:53:05 +00:00
|
|
|
// onLoginComplete(LoginResponse("Offline","Offline", 1));
|
2013-09-07 02:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int InstanceLauncher::launch()
|
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
std::cout << "Launching Instance '" << qPrintable(instId) << "'" << std::endl;
|
2013-09-07 02:00:58 +00:00
|
|
|
auto instance = MMC->instances()->getInstanceById(instId);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (!instance)
|
2013-09-07 02:00:58 +00:00
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
std::cout << "Could not find instance requested. note that you have to specify the ID, "
|
|
|
|
"not the NAME" << std::endl;
|
2013-09-07 02:00:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Logging in..." << std::endl;
|
2013-11-04 01:53:05 +00:00
|
|
|
doLogin("");
|
2013-09-07 02:00:58 +00:00
|
|
|
|
|
|
|
return MMC->exec();
|
|
|
|
}
|