2013-11-04 07:23:05 +05:30
|
|
|
/* 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 07:30:58 +05:30
|
|
|
#include "InstanceLauncher.h"
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
#include "gui/ConsoleWindow.h"
|
|
|
|
#include "gui/dialogs/LoginDialog.h"
|
|
|
|
#include "gui/dialogs/ProgressDialog.h"
|
|
|
|
|
2013-09-23 03:53:50 +05:30
|
|
|
#include "logic/net/LoginTask.h"
|
2013-09-07 07:30:58 +05:30
|
|
|
#include "logic/MinecraftProcess.h"
|
2013-11-04 07:23:05 +05:30
|
|
|
#include "logic/lists/InstanceList.h"
|
2013-09-07 07:30:58 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
InstanceLauncher::InstanceLauncher(QString instId) : QObject(), instId(instId)
|
|
|
|
{
|
|
|
|
}
|
2013-09-07 07:30:58 +05:30
|
|
|
|
|
|
|
void InstanceLauncher::onTerminated()
|
|
|
|
{
|
|
|
|
std::cout << "Minecraft exited" << std::endl;
|
|
|
|
MMC->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceLauncher::onLoginComplete()
|
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
LoginTask *task = (LoginTask *)QObject::sender();
|
2013-09-07 07:30:58 +05:30
|
|
|
auto result = task->getResult();
|
|
|
|
auto instance = MMC->instances()->getInstanceById(instId);
|
2013-11-04 07:23:05 +05:30
|
|
|
proc = instance->prepareForLaunch(result);
|
|
|
|
if (!proc)
|
2013-09-07 07:30:58 +05:30
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
// FIXME: report error
|
2013-09-07 07:30:58 +05:30
|
|
|
return;
|
|
|
|
}
|
2013-09-08 19:55:02 +05:30
|
|
|
console = new ConsoleWindow(proc);
|
2013-09-07 07:30:58 +05:30
|
|
|
console->show();
|
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
|
|
|
|
connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console,
|
|
|
|
SLOT(write(QString, MessageLevel::Enum)));
|
2013-09-07 07:30:58 +05:30
|
|
|
|
|
|
|
proc->launch();
|
|
|
|
}
|
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
void InstanceLauncher::doLogin(const QString &errorMsg)
|
2013-09-07 07:30:58 +05:30
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
LoginDialog *loginDlg = new LoginDialog(nullptr, errorMsg);
|
2013-09-07 07:30:58 +05:30
|
|
|
loginDlg->exec();
|
2013-11-04 07:23:05 +05:30
|
|
|
if (loginDlg->result() == QDialog::Accepted)
|
2013-09-07 07:30:58 +05:30
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()};
|
2013-09-07 07:30:58 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
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 07:30:58 +05:30
|
|
|
}
|
2013-11-04 07:23:05 +05:30
|
|
|
// onLoginComplete(LoginResponse("Offline","Offline", 1));
|
2013-09-07 07:30:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int InstanceLauncher::launch()
|
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
std::cout << "Launching Instance '" << qPrintable(instId) << "'" << std::endl;
|
2013-09-07 07:30:58 +05:30
|
|
|
auto instance = MMC->instances()->getInstanceById(instId);
|
2013-11-04 07:23:05 +05:30
|
|
|
if (!instance)
|
2013-09-07 07:30:58 +05:30
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
std::cout << "Could not find instance requested. note that you have to specify the ID, "
|
|
|
|
"not the NAME" << std::endl;
|
2013-09-07 07:30:58 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "Logging in..." << std::endl;
|
2013-11-04 07:23:05 +05:30
|
|
|
doLogin("");
|
2013-09-07 07:30:58 +05:30
|
|
|
|
|
|
|
return MMC->exec();
|
|
|
|
}
|