mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Modernize SapphireLauncher
This commit is contained in:
parent
f990b9dd75
commit
28b0fe8537
1 changed files with 19 additions and 18 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "sapphirelauncher.h"
|
#include "sapphirelauncher.h"
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
@ -15,51 +16,51 @@ SapphireLauncher::SapphireLauncher(LauncherCore &window, QObject *parent)
|
||||||
|
|
||||||
void SapphireLauncher::login(const QString &lobbyUrl, const LoginInformation &info)
|
void SapphireLauncher::login(const QString &lobbyUrl, const LoginInformation &info)
|
||||||
{
|
{
|
||||||
QJsonObject data{{"username", info.username}, {"pass", info.password}};
|
const QJsonObject data{{QStringLiteral("username"), info.username}, {QStringLiteral("pass"), info.password}};
|
||||||
|
|
||||||
QUrl url(lobbyUrl + "/sapphire-api/lobby/login");
|
const QUrl url(lobbyUrl + QStringLiteral("/sapphire-api/lobby/login"));
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded"));
|
||||||
|
|
||||||
auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
const auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
connect(reply, &QNetworkReply::finished, [this, reply, &info] {
|
connect(reply, &QNetworkReply::finished, [this, reply, &info] {
|
||||||
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
if (reply->error() != QNetworkReply::NetworkError::NoError) {
|
||||||
Q_EMIT window.loginError(QStringLiteral("Could not contact lobby server.\n\n%1").arg(reply->errorString()));
|
Q_EMIT window.loginError(i18n("Could not contact lobby server.\n\n%1", reply->errorString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
||||||
if (!document.isEmpty()) {
|
if (!document.isEmpty()) {
|
||||||
LoginAuth auth;
|
LoginAuth auth;
|
||||||
auth.SID = document["sId"].toString();
|
auth.SID = document[QLatin1String("sId")].toString();
|
||||||
auth.lobbyhost = document["lobbyHost"].toString();
|
auth.lobbyhost = document[QLatin1String("lobbyHost")].toString();
|
||||||
auth.frontierHost = document["frontierHost"].toString();
|
auth.frontierHost = document[QLatin1String("frontierHost")].toString();
|
||||||
auth.region = 3;
|
auth.region = 3;
|
||||||
|
|
||||||
window.launchGame(*info.profile, auth);
|
window.launchGame(*info.profile, auth);
|
||||||
} else {
|
} else {
|
||||||
Q_EMIT window.loginError("Invalid username or password.");
|
Q_EMIT window.loginError(i18n("Invalid username or password."));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SapphireLauncher::registerAccount(const QString &lobbyUrl, const LoginInformation &info)
|
void SapphireLauncher::registerAccount(const QString &lobbyUrl, const LoginInformation &info)
|
||||||
{
|
{
|
||||||
QJsonObject data{{"username", info.username}, {"pass", info.password}};
|
const QJsonObject data{{QStringLiteral("username"), info.username}, {QStringLiteral("pass"), info.password}};
|
||||||
QUrl url(lobbyUrl + "/sapphire-api/lobby/createAccount");
|
const QUrl url(lobbyUrl + QStringLiteral("/sapphire-api/lobby/createAccount"));
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded"));
|
||||||
|
|
||||||
auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
const auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
connect(reply, &QNetworkReply::finished, [&] {
|
connect(reply, &QNetworkReply::finished, [&] {
|
||||||
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
|
||||||
LoginAuth auth;
|
LoginAuth auth;
|
||||||
auth.SID = document["sId"].toString();
|
auth.SID = document[QLatin1String("sId")].toString();
|
||||||
auth.lobbyhost = document["lobbyHost"].toString();
|
auth.lobbyhost = document[QLatin1String("lobbyHost")].toString();
|
||||||
auth.frontierHost = document["frontierHost"].toString();
|
auth.frontierHost = document[QLatin1String("frontierHost")].toString();
|
||||||
auth.region = 3;
|
auth.region = 3;
|
||||||
|
|
||||||
window.launchGame(*info.profile, auth);
|
window.launchGame(*info.profile, auth);
|
||||||
|
|
Loading…
Add table
Reference in a new issue