Implement basic yggdrasil auth.
No fancy login token saving involved.
This commit is contained in:
parent
eb4ed3734f
commit
984c36e571
@ -226,6 +226,8 @@ logic/net/DownloadJob.h
|
||||
logic/net/DownloadJob.cpp
|
||||
logic/net/HttpMetaCache.h
|
||||
logic/net/HttpMetaCache.cpp
|
||||
logic/net/LoginTask.h
|
||||
logic/net/LoginTask.cpp
|
||||
|
||||
# legacy instances
|
||||
logic/LegacyInstance.h
|
||||
@ -281,8 +283,7 @@ logic/EnabledItemFilter.cpp
|
||||
logic/tasks/ProgressProvider.h
|
||||
logic/tasks/Task.h
|
||||
logic/tasks/Task.cpp
|
||||
logic/tasks/LoginTask.h
|
||||
logic/tasks/LoginTask.cpp
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
88
MultiMC.cpp
88
MultiMC.cpp
@ -16,7 +16,6 @@
|
||||
#include "logic/InstanceLauncher.h"
|
||||
#include "logic/net/HttpMetaCache.h"
|
||||
|
||||
|
||||
#include "pathutils.h"
|
||||
#include "cmdutils.h"
|
||||
#include <inisettingsobject.h>
|
||||
@ -25,8 +24,7 @@
|
||||
#include "config.h"
|
||||
using namespace Util::Commandline;
|
||||
|
||||
MultiMC::MultiMC ( int& argc, char** argv )
|
||||
:QApplication ( argc, argv )
|
||||
MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
||||
{
|
||||
setOrganizationName("Forkk");
|
||||
setApplicationName("MultiMC 5");
|
||||
@ -53,15 +51,18 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
// --dir
|
||||
parser.addOption("dir", applicationDirPath());
|
||||
parser.addShortOpt("dir", 'd');
|
||||
parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of the binary location (use '.' for current)");
|
||||
parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of "
|
||||
"the binary location (use '.' for current)");
|
||||
// --update
|
||||
parser.addOption("update");
|
||||
parser.addShortOpt("update", 'u');
|
||||
parser.addDocumentation("update", "replaces the given file with the running executable", "<path>");
|
||||
parser.addDocumentation("update", "replaces the given file with the running executable",
|
||||
"<path>");
|
||||
// --quietupdate
|
||||
parser.addSwitch("quietupdate");
|
||||
parser.addShortOpt("quietupdate", 'U');
|
||||
parser.addDocumentation("quietupdate", "doesn't restart MultiMC after installing updates");
|
||||
parser.addDocumentation("quietupdate",
|
||||
"doesn't restart MultiMC after installing updates");
|
||||
// --launch
|
||||
parser.addOption("launch");
|
||||
parser.addShortOpt("launch", 'l');
|
||||
@ -72,10 +73,11 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
{
|
||||
args = parser.parse(arguments());
|
||||
}
|
||||
catch(ParsingError e)
|
||||
catch (ParsingError e)
|
||||
{
|
||||
std::cerr << "CommandLineError: " << e.what() << std::endl;
|
||||
std::cerr << "Try '%1 -h' to get help on MultiMC's command line parameters." << std::endl;
|
||||
std::cerr << "Try '%1 -h' to get help on MultiMC's command line parameters."
|
||||
<< std::endl;
|
||||
m_status = MultiMC::Failed;
|
||||
return;
|
||||
}
|
||||
@ -93,7 +95,8 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
{
|
||||
std::cout << "Version " << VERSION_STR << std::endl;
|
||||
std::cout << "Git " << GIT_COMMIT << std::endl;
|
||||
std::cout << "Tag: " << JENKINS_BUILD_TAG << " " << (ARCH==x64?"x86_64":"x86") << std::endl;
|
||||
std::cout << "Tag: " << JENKINS_BUILD_TAG << " " << (ARCH == x64 ? "x86_64" : "x86")
|
||||
<< std::endl;
|
||||
m_status = MultiMC::Succeeded;
|
||||
return;
|
||||
}
|
||||
@ -102,12 +105,13 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
// Note: cwd is always the current executable path!
|
||||
if (!args["update"].isNull())
|
||||
{
|
||||
std::cout << "Performing MultiMC update: " << qPrintable(args["update"].toString()) << std::endl;
|
||||
std::cout << "Performing MultiMC update: " << qPrintable(args["update"].toString())
|
||||
<< std::endl;
|
||||
QString cwd = QDir::currentPath();
|
||||
QDir::setCurrent(applicationDirPath());
|
||||
QFile file(applicationFilePath());
|
||||
file.copy(args["update"].toString());
|
||||
if(args["quietupdate"].toBool())
|
||||
if (args["quietupdate"].toBool())
|
||||
{
|
||||
m_status = MultiMC::Succeeded;
|
||||
return;
|
||||
@ -123,7 +127,7 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
initGlobalSettings();
|
||||
|
||||
// and instances
|
||||
m_instances.reset(new InstanceList(m_settings->get("InstanceDir").toString(),this));
|
||||
m_instances.reset(new InstanceList(m_settings->get("InstanceDir").toString(), this));
|
||||
std::cout << "Loading Instances..." << std::endl;
|
||||
m_instances->loadList();
|
||||
|
||||
@ -139,7 +143,7 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
// launch instance, if that's what should be done
|
||||
if (!args["launch"].isNull())
|
||||
{
|
||||
if(InstanceLauncher(args["launch"].toString()).launch())
|
||||
if (InstanceLauncher(args["launch"].toString()).launch())
|
||||
m_status = MultiMC::Succeeded;
|
||||
else
|
||||
m_status = MultiMC::Failed;
|
||||
@ -150,11 +154,11 @@ MultiMC::MultiMC ( int& argc, char** argv )
|
||||
|
||||
MultiMC::~MultiMC()
|
||||
{
|
||||
if(m_mmc_translator)
|
||||
if (m_mmc_translator)
|
||||
{
|
||||
removeTranslator(m_mmc_translator.data());
|
||||
}
|
||||
if(m_qt_translator)
|
||||
if (m_qt_translator)
|
||||
{
|
||||
removeTranslator(m_qt_translator.data());
|
||||
}
|
||||
@ -163,13 +167,12 @@ MultiMC::~MultiMC()
|
||||
void MultiMC::initTranslations()
|
||||
{
|
||||
m_qt_translator.reset(new QTranslator());
|
||||
if(m_qt_translator->load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
if (m_qt_translator->load("qt_" + QLocale::system().name(),
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
std::cout
|
||||
<< "Loading Qt Language File for "
|
||||
<< QLocale::system().name().toLocal8Bit().constData()
|
||||
<< "...";
|
||||
if(!installTranslator(m_qt_translator.data()))
|
||||
std::cout << "Loading Qt Language File for "
|
||||
<< QLocale::system().name().toLocal8Bit().constData() << "...";
|
||||
if (!installTranslator(m_qt_translator.data()))
|
||||
{
|
||||
std::cout << " failed.";
|
||||
m_qt_translator.reset();
|
||||
@ -182,13 +185,12 @@ void MultiMC::initTranslations()
|
||||
}
|
||||
|
||||
m_mmc_translator.reset(new QTranslator());
|
||||
if(m_mmc_translator->load("mmc_" + QLocale::system().name(), QDir("translations").absolutePath()))
|
||||
if (m_mmc_translator->load("mmc_" + QLocale::system().name(),
|
||||
QDir("translations").absolutePath()))
|
||||
{
|
||||
std::cout
|
||||
<< "Loading MMC Language File for "
|
||||
<< QLocale::system().name().toLocal8Bit().constData()
|
||||
<< "...";
|
||||
if(!installTranslator(m_mmc_translator.data()))
|
||||
std::cout << "Loading MMC Language File for "
|
||||
<< QLocale::system().name().toLocal8Bit().constData() << "...";
|
||||
if (!installTranslator(m_mmc_translator.data()))
|
||||
{
|
||||
std::cout << " failed.";
|
||||
m_mmc_translator.reset();
|
||||
@ -201,7 +203,6 @@ void MultiMC::initTranslations()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultiMC::initGlobalSettings()
|
||||
{
|
||||
m_settings.reset(new INISettingsObject("multimc.cfg", this));
|
||||
@ -223,9 +224,9 @@ void MultiMC::initGlobalSettings()
|
||||
m_settings->registerSetting(new Setting("InstanceToolbarPosition", QPoint()));
|
||||
|
||||
// Console Colors
|
||||
// m_settings->registerSetting(new Setting("SysMessageColor", QColor(Qt::blue)));
|
||||
// m_settings->registerSetting(new Setting("StdOutColor", QColor(Qt::black)));
|
||||
// m_settings->registerSetting(new Setting("StdErrColor", QColor(Qt::red)));
|
||||
// m_settings->registerSetting(new Setting("SysMessageColor", QColor(Qt::blue)));
|
||||
// m_settings->registerSetting(new Setting("StdOutColor", QColor(Qt::black)));
|
||||
// m_settings->registerSetting(new Setting("StdErrColor", QColor(Qt::red)));
|
||||
|
||||
// Window Size
|
||||
m_settings->registerSetting(new Setting("LaunchMaximized", false));
|
||||
@ -253,6 +254,15 @@ void MultiMC::initGlobalSettings()
|
||||
|
||||
// Shall the main window hide on instance launch
|
||||
m_settings->registerSetting(new Setting("NoHide", false));
|
||||
|
||||
// Persistent value for the client ID
|
||||
m_settings->registerSetting(new Setting("YggdrasilClientToken", ""));
|
||||
QString currentYggID = m_settings->get("YggdrasilClientToken").toString();
|
||||
if (currentYggID.isEmpty())
|
||||
{
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
m_settings->set("YggdrasilClientToken", uuid.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMC::initHttpMetaCache()
|
||||
@ -265,10 +275,9 @@ void MultiMC::initHttpMetaCache()
|
||||
m_metacache->Load();
|
||||
}
|
||||
|
||||
|
||||
QSharedPointer<IconList> MultiMC::icons()
|
||||
{
|
||||
if ( !m_icons )
|
||||
if (!m_icons)
|
||||
{
|
||||
m_icons.reset(new IconList);
|
||||
}
|
||||
@ -277,7 +286,7 @@ QSharedPointer<IconList> MultiMC::icons()
|
||||
|
||||
QSharedPointer<LWJGLVersionList> MultiMC::lwjgllist()
|
||||
{
|
||||
if ( !m_lwjgllist )
|
||||
if (!m_lwjgllist)
|
||||
{
|
||||
m_lwjgllist.reset(new LWJGLVersionList());
|
||||
}
|
||||
@ -286,7 +295,7 @@ QSharedPointer<LWJGLVersionList> MultiMC::lwjgllist()
|
||||
|
||||
QSharedPointer<ForgeVersionList> MultiMC::forgelist()
|
||||
{
|
||||
if ( !m_forgelist )
|
||||
if (!m_forgelist)
|
||||
{
|
||||
m_forgelist.reset(new ForgeVersionList());
|
||||
}
|
||||
@ -295,14 +304,13 @@ QSharedPointer<ForgeVersionList> MultiMC::forgelist()
|
||||
|
||||
QSharedPointer<MinecraftVersionList> MultiMC::minecraftlist()
|
||||
{
|
||||
if ( !m_minecraftlist )
|
||||
if (!m_minecraftlist)
|
||||
{
|
||||
m_minecraftlist.reset(new MinecraftVersionList());
|
||||
}
|
||||
return m_minecraftlist;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// initialize Qt
|
||||
@ -312,9 +320,7 @@ int main(int argc, char *argv[])
|
||||
MainWindow mainWin;
|
||||
mainWin.show();
|
||||
|
||||
|
||||
|
||||
switch(app.status())
|
||||
switch (app.status())
|
||||
{
|
||||
case MultiMC::Initialized:
|
||||
return app.exec();
|
||||
@ -326,5 +332,3 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#include "MultiMC.moc"
|
||||
|
||||
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
QSharedPointer<ForgeVersionList> forgelist();
|
||||
|
||||
QSharedPointer<MinecraftVersionList> minecraftlist();
|
||||
|
||||
private:
|
||||
void initGlobalSettings();
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
||||
#include "logic/lists/LwjglVersionList.h"
|
||||
#include "logic/lists/IconList.h"
|
||||
|
||||
#include "logic/tasks/LoginTask.h"
|
||||
#include "logic/net/LoginTask.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/InstanceFactory.h"
|
||||
#include "logic/MinecraftProcess.h"
|
||||
@ -491,7 +491,7 @@ void MainWindow::doLogin(const QString& errorMsg)
|
||||
QString user = loginDlg->getUsername();
|
||||
if (user.length() == 0)
|
||||
user = QString("Offline");
|
||||
m_activeLogin = {user, QString("Offline"), qint64(-1)};
|
||||
m_activeLogin = {user, QString("Offline"), QString(), QString()};
|
||||
m_activeInst = m_selectedInstance;
|
||||
launchInstance(m_activeInst, m_activeLogin);
|
||||
}
|
||||
@ -533,7 +533,7 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
|
||||
{
|
||||
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
|
||||
|
||||
proc = instance->prepareForLaunch(response.username, response.sessionID);
|
||||
proc = instance->prepareForLaunch(response);
|
||||
if(!proc)
|
||||
return;
|
||||
|
||||
@ -552,7 +552,7 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
|
||||
connect(proc, SIGNAL(log(QString, MessageLevel::Enum)),
|
||||
console, SLOT(write(QString, MessageLevel::Enum)));
|
||||
connect(proc, SIGNAL(ended()), this, SLOT(instanceEnded()));
|
||||
proc->setLogin(m_activeLogin.username, m_activeLogin.sessionID);
|
||||
proc->setLogin(response.username, response.session_id);
|
||||
proc->launch();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "logic/lists/InstanceList.h"
|
||||
#include "logic/tasks/LoginTask.h"
|
||||
#include "logic/net/LoginTask.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
|
||||
class LabeledToolButton;
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "inifile.h"
|
||||
#include "lists/BaseVersionList.h"
|
||||
#include "net/LoginTask.h"
|
||||
|
||||
class QDialog;
|
||||
class BaseUpdate;
|
||||
@ -147,7 +148,7 @@ public:
|
||||
virtual BaseUpdate* doUpdate() = 0;
|
||||
|
||||
/// returns a valid minecraft process, ready for launch
|
||||
virtual MinecraftProcess* prepareForLaunch(QString user, QString session) = 0;
|
||||
virtual MinecraftProcess* prepareForLaunch(LoginResponse response) = 0;
|
||||
|
||||
/// do any necessary cleanups after the instance finishes. also runs before 'prepareForLaunch'
|
||||
virtual void cleanupAfterRun() = 0;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "gui/logindialog.h"
|
||||
#include "gui/ProgressDialog.h"
|
||||
#include "gui/consolewindow.h"
|
||||
#include "logic/tasks/LoginTask.h"
|
||||
#include "logic/net/LoginTask.h"
|
||||
#include "logic/MinecraftProcess.h"
|
||||
#include "lists/InstanceList.h"
|
||||
|
||||
@ -25,7 +25,7 @@ void InstanceLauncher::onLoginComplete()
|
||||
LoginTask * task = ( LoginTask * ) QObject::sender();
|
||||
auto result = task->getResult();
|
||||
auto instance = MMC->instances()->getInstanceById(instId);
|
||||
proc = instance->prepareForLaunch ( result.username, result.sessionID );
|
||||
proc = instance->prepareForLaunch ( result );
|
||||
if ( !proc )
|
||||
{
|
||||
//FIXME: report error
|
||||
|
@ -29,7 +29,7 @@ BaseUpdate* LegacyInstance::doUpdate()
|
||||
return new LegacyUpdate(this, this);
|
||||
}
|
||||
|
||||
MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session)
|
||||
MinecraftProcess* LegacyInstance::prepareForLaunch(LoginResponse response)
|
||||
{
|
||||
MinecraftProcess * proc = new MinecraftProcess(this);
|
||||
|
||||
@ -73,8 +73,8 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
|
||||
args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt());
|
||||
args << QString("-XX:PermSize=%1m").arg(settings().get("PermGen").toInt());
|
||||
args << "-jar" << LAUNCHER_FILE;
|
||||
args << user;
|
||||
args << session;
|
||||
args << response.player_name;
|
||||
args << response.session_id;
|
||||
args << windowTitle;
|
||||
args << windowSize;
|
||||
args << lwjgl;
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
virtual void setShouldUpdate(bool val);
|
||||
virtual BaseUpdate* doUpdate();
|
||||
|
||||
virtual MinecraftProcess* prepareForLaunch( QString user, QString session );
|
||||
virtual MinecraftProcess* prepareForLaunch(LoginResponse response);
|
||||
virtual void cleanupAfterRun();
|
||||
virtual QDialog * createModEditDialog ( QWidget* parent );
|
||||
|
||||
|
@ -32,10 +32,10 @@
|
||||
#define IBUS "@im=ibus"
|
||||
|
||||
// constructor
|
||||
MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
|
||||
m_instance(inst)
|
||||
MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst)
|
||||
{
|
||||
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus)));
|
||||
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
SLOT(finish(int, QProcess::ExitStatus)));
|
||||
|
||||
// prepare the process environment
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
@ -59,19 +59,18 @@ MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
|
||||
connect(this, SIGNAL(readyReadStandardOutput()), SLOT(on_stdOut()));
|
||||
}
|
||||
|
||||
void MinecraftProcess::setMinecraftArguments ( QStringList args )
|
||||
void MinecraftProcess::setMinecraftArguments(QStringList args)
|
||||
{
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
void MinecraftProcess::setMinecraftWorkdir ( QString path )
|
||||
void MinecraftProcess::setMinecraftWorkdir(QString path)
|
||||
{
|
||||
QDir mcDir(path);
|
||||
this->setWorkingDirectory(mcDir.absolutePath());
|
||||
m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
|
||||
}
|
||||
|
||||
|
||||
// console window
|
||||
void MinecraftProcess::on_stdErr()
|
||||
{
|
||||
@ -81,17 +80,16 @@ void MinecraftProcess::on_stdErr()
|
||||
QStringList lines = str.split("\n");
|
||||
bool complete = str.endsWith("\n");
|
||||
|
||||
for(int i = 0; i < lines.size() - 1; i++)
|
||||
for (int i = 0; i < lines.size() - 1; i++)
|
||||
{
|
||||
QString & line = lines[i];
|
||||
emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>").toLocal8Bit(), getLevel(line, MessageLevel::Error));
|
||||
QString &line = lines[i];
|
||||
emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
|
||||
getLevel(line, MessageLevel::Error));
|
||||
}
|
||||
if(!complete)
|
||||
if (!complete)
|
||||
m_err_leftover = lines.last();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MinecraftProcess::on_stdOut()
|
||||
{
|
||||
QByteArray data = readAllStandardOutput();
|
||||
@ -100,12 +98,13 @@ void MinecraftProcess::on_stdOut()
|
||||
QStringList lines = str.split("\n");
|
||||
bool complete = str.endsWith("\n");
|
||||
|
||||
for(int i = 0; i < lines.size() - 1; i++)
|
||||
for (int i = 0; i < lines.size() - 1; i++)
|
||||
{
|
||||
QString & line = lines[i];
|
||||
emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>").toLocal8Bit(), getLevel(line, MessageLevel::Message));
|
||||
QString &line = lines[i];
|
||||
emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
|
||||
getLevel(line, MessageLevel::Message));
|
||||
}
|
||||
if(!complete)
|
||||
if (!complete)
|
||||
m_out_leftover = lines.last();
|
||||
}
|
||||
|
||||
@ -114,7 +113,7 @@ void MinecraftProcess::finish(int code, ExitStatus status)
|
||||
{
|
||||
if (status != NormalExit)
|
||||
{
|
||||
//TODO: error handling
|
||||
// TODO: error handling
|
||||
}
|
||||
|
||||
// TODO: Localization
|
||||
@ -135,7 +134,7 @@ void MinecraftProcess::finish(int code, ExitStatus status)
|
||||
m_prepostlaunchprocess.waitForFinished();
|
||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||
{
|
||||
//TODO: error handling
|
||||
// TODO: error handling
|
||||
}
|
||||
}
|
||||
m_instance->cleanupAfterRun();
|
||||
@ -156,7 +155,7 @@ void MinecraftProcess::launch()
|
||||
m_prepostlaunchprocess.waitForFinished();
|
||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||
{
|
||||
//TODO: error handling
|
||||
// TODO: error handling
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -166,30 +165,32 @@ void MinecraftProcess::launch()
|
||||
emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
|
||||
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
||||
emit log(QString("Java path: '%1'").arg(JavaPath));
|
||||
emit log(QString("Arguments: '%1'").arg(m_args.join("' '").replace(username, "<Username>").replace(sessionID, "<Session ID>")));
|
||||
emit log(QString("Arguments: '%1'").arg(
|
||||
m_args.join("' '") /*.replace(username, "<Username>").replace(sessionID, "<Session
|
||||
ID>")*/));
|
||||
start(JavaPath, m_args);
|
||||
if (!waitForStarted())
|
||||
{
|
||||
//: Error message displayed if instace can't start
|
||||
emit log(tr("Could not launch minecraft!"));
|
||||
return;
|
||||
//TODO: error handling
|
||||
// TODO: error handling
|
||||
}
|
||||
}
|
||||
|
||||
MessageLevel::Enum MinecraftProcess::getLevel(const QString &line, MessageLevel::Enum level)
|
||||
{
|
||||
|
||||
if(line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || line.contains("[FINEST]") )
|
||||
if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") ||
|
||||
line.contains("[FINER]") || line.contains("[FINEST]"))
|
||||
level = MessageLevel::Message;
|
||||
if(line.contains("[SEVERE]") || line.contains("[STDERR]"))
|
||||
if (line.contains("[SEVERE]") || line.contains("[STDERR]"))
|
||||
level = MessageLevel::Error;
|
||||
if(line.contains("[WARNING]"))
|
||||
if (line.contains("[WARNING]"))
|
||||
level = MessageLevel::Warning;
|
||||
if(line.contains("Exception in thread") || line.contains(" at "))
|
||||
if (line.contains("Exception in thread") || line.contains(" at "))
|
||||
level = MessageLevel::Fatal;
|
||||
if(line.contains("[DEBUG]"))
|
||||
if (line.contains("[DEBUG]"))
|
||||
level = MessageLevel::Debug;
|
||||
return level;
|
||||
|
||||
}
|
@ -49,21 +49,19 @@ QString replaceTokensIn(QString text, QMap<QString, QString> with)
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList OneSixInstance::processMinecraftArgs(QString user, QString session)
|
||||
QStringList OneSixInstance::processMinecraftArgs(LoginResponse response)
|
||||
{
|
||||
I_D(OneSixInstance);
|
||||
auto version = d->version;
|
||||
QString args_pattern = version->minecraftArguments;
|
||||
|
||||
QMap<QString, QString> token_mapping;
|
||||
token_mapping["auth_username"] = user;
|
||||
token_mapping["auth_session"] = session;
|
||||
// FIXME: user and player name are DIFFERENT!
|
||||
token_mapping["auth_player_name"] = user;
|
||||
// FIXME: WTF is this. I just plugged in a random UUID here.
|
||||
token_mapping["auth_uuid"] = "7d4bacf0-fd62-11e2-b778-0800200c9a66"; // obviously fake.
|
||||
token_mapping["auth_username"] = response.username;
|
||||
token_mapping["auth_session"] = response.session_id;
|
||||
token_mapping["auth_player_name"] = response.player_name;
|
||||
token_mapping["auth_uuid"] = response.player_id;
|
||||
|
||||
// this is for offline:
|
||||
// this is for offline?:
|
||||
/*
|
||||
map["auth_player_name"] = "Player";
|
||||
map["auth_player_name"] = "00000000-0000-0000-0000-000000000000";
|
||||
@ -85,7 +83,7 @@ QStringList OneSixInstance::processMinecraftArgs(QString user, QString session)
|
||||
return parts;
|
||||
}
|
||||
|
||||
MinecraftProcess *OneSixInstance::prepareForLaunch(QString user, QString session)
|
||||
MinecraftProcess *OneSixInstance::prepareForLaunch(LoginResponse response)
|
||||
{
|
||||
I_D(OneSixInstance);
|
||||
cleanupAfterRun();
|
||||
@ -142,7 +140,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(QString user, QString session
|
||||
args << classPath;
|
||||
}
|
||||
args << version->mainClass;
|
||||
args.append(processMinecraftArgs(user, session));
|
||||
args.append(processMinecraftArgs(response));
|
||||
|
||||
// create the process and set its parameters
|
||||
MinecraftProcess *proc = new MinecraftProcess(this);
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
virtual QString instanceConfigFolder() const;
|
||||
|
||||
virtual BaseUpdate* doUpdate();
|
||||
virtual MinecraftProcess* prepareForLaunch ( QString user, QString session );
|
||||
virtual MinecraftProcess* prepareForLaunch ( LoginResponse response );
|
||||
virtual void cleanupAfterRun();
|
||||
|
||||
virtual QString intendedVersionId() const;
|
||||
@ -54,5 +54,5 @@ public:
|
||||
virtual bool menuActionEnabled ( QString action_name ) const;
|
||||
virtual QString getStatusbarDescription();
|
||||
private:
|
||||
QStringList processMinecraftArgs( QString user, QString session );
|
||||
QStringList processMinecraftArgs( LoginResponse response );
|
||||
};
|
269
logic/net/LoginTask.cpp
Normal file
269
logic/net/LoginTask.cpp
Normal file
@ -0,0 +1,269 @@
|
||||
/* 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 <settingsobject.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonObject>
|
||||
|
||||
LoginTask::LoginTask(const UserInfo &uInfo, QObject *parent) : Task(parent), uInfo(uInfo)
|
||||
{
|
||||
}
|
||||
|
||||
void LoginTask::executeTask()
|
||||
{
|
||||
yggdrasilLogin();
|
||||
}
|
||||
|
||||
void LoginTask::legacyLogin()
|
||||
{
|
||||
setStatus(tr("Logging in..."));
|
||||
auto worker = MMC->qnam();
|
||||
connect(worker.data(), 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", uInfo.username);
|
||||
params.addQueryItem("password", uInfo.password);
|
||||
params.addQueryItem("version", "13");
|
||||
|
||||
netReply = worker->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
|
||||
}
|
||||
|
||||
void LoginTask::processLegacyReply(QNetworkReply *reply)
|
||||
{
|
||||
if (netReply != reply)
|
||||
return;
|
||||
// Check for errors.
|
||||
switch (reply->error())
|
||||
{
|
||||
case QNetworkReply::NoError:
|
||||
{
|
||||
// Check the response code.
|
||||
int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if (responseCode == 200)
|
||||
{
|
||||
parseLegacyReply(reply->readAll());
|
||||
}
|
||||
else if (responseCode == 503)
|
||||
{
|
||||
emitFailed(tr("The login servers are currently unavailable. Check "
|
||||
"http://help.mojang.com/ for more info."));
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(tr("Login failed: Unknown HTTP error %1 occurred.")
|
||||
.arg(QString::number(responseCode)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QNetworkReply::OperationCanceledError:
|
||||
emitFailed(tr("Login canceled."));
|
||||
break;
|
||||
|
||||
default:
|
||||
emitFailed(tr("Login failed: %1").arg(reply->errorString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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::yggdrasilLogin()
|
||||
{
|
||||
setStatus(tr("Logging in..."));
|
||||
auto worker = MMC->qnam();
|
||||
connect(worker.data(), 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
|
||||
QString requestConstent;
|
||||
requestConstent += "{";
|
||||
requestConstent += " \"agent\":{\"name\":\"Minecraft\",\"version\":1},\n";
|
||||
requestConstent += " \"username\":\"" + uInfo.username + "\",\n";
|
||||
requestConstent += " \"password\":\"" + uInfo.password + "\",\n";
|
||||
requestConstent += " \"clientToken\":\"" + clientToken + "\"\n";
|
||||
requestConstent += "}";
|
||||
netReply = worker->post(netRequest, requestConstent.toUtf8());
|
||||
}
|
||||
|
||||
void LoginTask::processYggdrasilReply(QNetworkReply *reply)
|
||||
{
|
||||
if (netReply != reply)
|
||||
return;
|
||||
// Check for errors.
|
||||
switch (reply->error())
|
||||
{
|
||||
case QNetworkReply::NoError:
|
||||
{
|
||||
// Check the response code.
|
||||
int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if (responseCode == 200)
|
||||
{
|
||||
parseYggdrasilReply(reply->readAll());
|
||||
}
|
||||
else if (responseCode == 503)
|
||||
{
|
||||
emitFailed(tr("The login servers are currently unavailable. Check "
|
||||
"http://help.mojang.com/ for more info."));
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(tr("Login failed: Unknown HTTP error %1 occurred.")
|
||||
.arg(QString::number(responseCode)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QNetworkReply::OperationCanceledError:
|
||||
emitFailed(tr("Login canceled."));
|
||||
break;
|
||||
|
||||
default:
|
||||
emitFailed(tr("Login failed: %1").arg(reply->errorString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"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;
|
||||
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 = {uInfo.username, sessionID, playerName, playerID};
|
||||
emitSucceeded();
|
||||
}
|
@ -13,10 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOGINTASK_H
|
||||
#define LOGINTASK_H
|
||||
#pragma once
|
||||
|
||||
#include "Task.h"
|
||||
#include "logic/tasks/Task.h"
|
||||
#include <QSharedPointer>
|
||||
|
||||
struct UserInfo
|
||||
@ -28,8 +27,9 @@ struct UserInfo
|
||||
struct LoginResponse
|
||||
{
|
||||
QString username;
|
||||
QString sessionID;
|
||||
qint64 latestVersion;
|
||||
QString session_id;
|
||||
QString player_name;
|
||||
QString player_id;
|
||||
};
|
||||
|
||||
class QNetworkReply;
|
||||
@ -38,21 +38,25 @@ class LoginTask : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
|
||||
explicit LoginTask(const UserInfo &uInfo, QObject *parent = 0);
|
||||
LoginResponse getResult()
|
||||
{
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void processNetReply(QNetworkReply* reply);
|
||||
void legacyLogin();
|
||||
void processLegacyReply(QNetworkReply *reply);
|
||||
void parseLegacyReply(QByteArray data);
|
||||
|
||||
void yggdrasilLogin();
|
||||
void processYggdrasilReply(QNetworkReply *reply);
|
||||
void parseYggdrasilReply(QByteArray data);
|
||||
|
||||
protected:
|
||||
void executeTask();
|
||||
|
||||
LoginResponse result;
|
||||
QNetworkReply* netReply;
|
||||
QNetworkReply *netReply;
|
||||
UserInfo uInfo;
|
||||
};
|
||||
|
||||
#endif // LOGINTASK_H
|
@ -1,111 +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 <QStringList>
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
|
||||
LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) : Task(parent), uInfo(uInfo){}
|
||||
|
||||
void LoginTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Logging in..."));
|
||||
auto worker = MMC->qnam();
|
||||
connect(worker.data(), SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*)));
|
||||
|
||||
QUrl loginURL("https://login.minecraft.net/");
|
||||
QNetworkRequest netRequest(loginURL);
|
||||
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
QUrlQuery params;
|
||||
params.addQueryItem("user", uInfo.username);
|
||||
params.addQueryItem("password", uInfo.password);
|
||||
params.addQueryItem("version", "13");
|
||||
|
||||
netReply = worker->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
|
||||
}
|
||||
|
||||
void LoginTask::processNetReply(QNetworkReply *reply)
|
||||
{
|
||||
if(netReply != reply)
|
||||
return;
|
||||
// Check for errors.
|
||||
switch (reply->error())
|
||||
{
|
||||
case QNetworkReply::NoError:
|
||||
{
|
||||
// Check the response code.
|
||||
int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
if (responseCode == 200)
|
||||
{
|
||||
QString responseStr(reply->readAll());
|
||||
|
||||
QStringList strings = responseStr.split(":");
|
||||
if (strings.count() >= 4)
|
||||
{
|
||||
bool parseSuccess;
|
||||
qint64 latestVersion = strings[0].toLongLong(&parseSuccess);
|
||||
if (parseSuccess)
|
||||
{
|
||||
// strings[1] is the download ticket. It isn't used anymore.
|
||||
QString username = strings[2];
|
||||
QString sessionID = strings[3];
|
||||
|
||||
result = {username, sessionID, latestVersion};
|
||||
emitSucceeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(tr("Failed to parse Minecraft version string."));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
else if (responseCode == 503)
|
||||
{
|
||||
emitFailed(tr("The login servers are currently unavailable. Check http://help.mojang.com/ for more info."));
|
||||
}
|
||||
else
|
||||
{
|
||||
emitFailed(tr("Login failed: Unknown HTTP error %1 occurred.").arg(QString::number(responseCode)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case QNetworkReply::OperationCanceledError:
|
||||
emitFailed(tr("Login canceled."));
|
||||
break;
|
||||
|
||||
default:
|
||||
emitFailed(tr("Login failed: %1").arg(reply->errorString()));
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user