mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-24 04:22:39 +00:00
Fix account saves, start fixing local
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "AuthServer.h"
|
||||
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#include <QTcpSocket>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
AuthServer::AuthServer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -48,8 +51,37 @@ void AuthServer::newConnection()
|
||||
{
|
||||
responseStatusCode = 204;
|
||||
}
|
||||
else if (requestPath == "/auth/authenticate")
|
||||
{
|
||||
QString body = rawRequest.mid(rawRequest.indexOf("\r\n\r\n") + 4);
|
||||
auto doc = QJsonDocument::fromJson(body.toUtf8());
|
||||
auto json = doc.object();
|
||||
QString clientToken = json.value("clientToken").toString();
|
||||
QString username = json.value("username").toString();
|
||||
|
||||
QString profile = ((QString)"{\"id\":\"%1\",\"name\":\"%2\"}").arg(clientToken, username);
|
||||
|
||||
responseStatusCode = 200;
|
||||
responseBody = ((QString)"{\"accessToken\":\"%1\",\"clientToken\":\"%2\",\"availableProfiles\":[%3], \"selectedProfile\": %3}").arg(username, clientToken, profile);
|
||||
}
|
||||
else if (requestPath == "/auth/refresh")
|
||||
{
|
||||
qDebug() << "Request process222";
|
||||
QString body = rawRequest.mid(rawRequest.indexOf("\r\n\r\n") + 4);
|
||||
auto doc = QJsonDocument::fromJson(body.toUtf8());
|
||||
auto json = doc.object();
|
||||
QString clientToken = json.value("clientToken").toString();
|
||||
QString username = json.value("accessToken").toString();
|
||||
|
||||
|
||||
QString profile = ((QString) "{\"id\":\"%1\",\"name\":\"%2\"}").arg(clientToken, username);
|
||||
|
||||
responseStatusCode = 200;
|
||||
responseBody = ((QString) "{\"accessToken\":\"%1\",\"clientToken\":\"%2\",\"availableProfiles\":[%3], \"selectedProfile\": %3}").arg(username, clientToken, profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Request failed" << requestPath;
|
||||
responseBody = "Not found";
|
||||
responseStatusCode = 404;
|
||||
}
|
||||
@@ -66,7 +98,8 @@ void AuthServer::newConnection()
|
||||
{
|
||||
responseHeaders << ((QString) "Content-Length: %1").arg(responseBody.length());
|
||||
}
|
||||
|
||||
qDebug() << responseBody;
|
||||
|
||||
tcpSocket->write(((QString) "HTTP/1.1 %1 %2\r\nConnection: keep-alive\r\n").arg(responseStatusCode).arg(responseStatusText).toUtf8());
|
||||
tcpSocket->write(responseHeaders.join("\r\n").toUtf8());
|
||||
tcpSocket->write("\r\n\r\n");
|
||||
|
||||
@@ -791,9 +791,14 @@ Launcher::Launcher(int &argc, char **argv) : QApplication(argc, argv)
|
||||
qDebug() << "<> Instances loaded.";
|
||||
}
|
||||
|
||||
{
|
||||
m_authserver.reset(new AuthServer(this));
|
||||
qDebug() << "<> Auth server started.";
|
||||
}
|
||||
|
||||
// load auth providers
|
||||
{
|
||||
AuthProviders::load();
|
||||
AuthProviders::load(m_authserver);
|
||||
}
|
||||
|
||||
// and accounts
|
||||
@@ -838,11 +843,6 @@ Launcher::Launcher(int &argc, char **argv) : QApplication(argc, argv)
|
||||
m_mcedit.reset(new MCEditTool(m_settings));
|
||||
}
|
||||
|
||||
{
|
||||
m_authserver.reset(new AuthServer(this));
|
||||
qDebug() << "<> Auth server started.";
|
||||
}
|
||||
|
||||
connect(this, &Launcher::aboutToQuit, [this](){
|
||||
if(m_instances)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "AccountData.h"
|
||||
#include "AuthProviders.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
@@ -283,11 +284,9 @@ bool AccountData::resumeStateFromV3(QJsonObject data) {
|
||||
auto typeS = typeV.toString();
|
||||
if(typeS == "MSA") {
|
||||
type = AccountType::MSA;
|
||||
} else if (typeS == "Mojang") {
|
||||
type = AccountType::Mojang;
|
||||
} else {
|
||||
qWarning() << "Failed to parse account data: type is not recognized.";
|
||||
return false;
|
||||
type = AccountType::Mojang;
|
||||
provider = AuthProviders::lookup(typeS);
|
||||
}
|
||||
|
||||
if(type == AccountType::Mojang) {
|
||||
@@ -313,7 +312,7 @@ bool AccountData::resumeStateFromV3(QJsonObject data) {
|
||||
QJsonObject AccountData::saveState() const {
|
||||
QJsonObject output;
|
||||
if(type == AccountType::Mojang) {
|
||||
output["type"] = "Mojang";
|
||||
output["type"] = provider->id();
|
||||
if(legacy) {
|
||||
output["legacy"] = true;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
#include "providers/ElybyAuthProvider.h"
|
||||
#include "providers/DummyAuthProvider.h"
|
||||
#include "providers/MojangAuthProvider.h"
|
||||
#include "../../AuthServer.h"
|
||||
|
||||
#define REGISTER_AUTH_PROVIDER(Provider) \
|
||||
{ \
|
||||
AuthProviderPtr provider(new Provider()); \
|
||||
m_providers.insert(provider->id(), provider); \
|
||||
provider->setAuthServer(authserver); \
|
||||
}
|
||||
|
||||
namespace AuthProviders
|
||||
{
|
||||
QMap<QString, AuthProviderPtr> m_providers;
|
||||
|
||||
void load()
|
||||
void load(std::shared_ptr<AuthServer> authserver)
|
||||
{
|
||||
REGISTER_AUTH_PROVIDER(ElybyAuthProvider);
|
||||
REGISTER_AUTH_PROVIDER(DummyAuthProvider);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <QMap>
|
||||
|
||||
#include "providers/BaseAuthProvider.h"
|
||||
#include "../../AuthServer.h"
|
||||
|
||||
/*!
|
||||
* \brief Namespace for auth providers.
|
||||
@@ -15,7 +16,7 @@
|
||||
*/
|
||||
namespace AuthProviders
|
||||
{
|
||||
void load();
|
||||
void load(std::shared_ptr<AuthServer> authServer);
|
||||
AuthProviderPtr lookup(QString id);
|
||||
QList<AuthProviderPtr> getAll();
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ std::shared_ptr<AccountTask> MinecraftAccount::refresh(AuthSessionPtr session) {
|
||||
m_currentTask.reset(new MSASilent(&data));
|
||||
}
|
||||
else {
|
||||
qDebug() << "Account dfdf";
|
||||
m_currentTask.reset(new MojangRefresh(&data));
|
||||
}
|
||||
m_currentTask->assignSession(session);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QSet>
|
||||
#include <QProcess>
|
||||
#include <QUrl>
|
||||
#include "../../../AuthServer.h"
|
||||
|
||||
class BaseAuthProvider;
|
||||
typedef std::shared_ptr<BaseAuthProvider> AuthProviderPtr;
|
||||
@@ -37,12 +38,6 @@ public:
|
||||
return "Base";
|
||||
};
|
||||
|
||||
// Use dummy auth on login instead of calling endpoint
|
||||
virtual bool dummyAuth()
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
// Endpoint for authlib injector (use empty if authlib injector isn't required)
|
||||
virtual QString injectorEndpoint()
|
||||
{
|
||||
@@ -72,4 +67,13 @@ public:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool setAuthServer(std::shared_ptr<AuthServer> authServer)
|
||||
{
|
||||
m_authServer = authServer;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<AuthServer> m_authServer;
|
||||
};
|
||||
|
||||
@@ -31,6 +31,16 @@ public:
|
||||
|
||||
QString injectorEndpoint()
|
||||
{
|
||||
return "http://localhost:%1";
|
||||
return ((QString)"http://localhost:%1").arg(m_authServer->port());
|
||||
};
|
||||
|
||||
QString authEndpoint()
|
||||
{
|
||||
return ((QString) "http://localhost:%1/auth/").arg(m_authServer->port());
|
||||
};
|
||||
|
||||
virtual bool useYggdrasil()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user