From 28b0fe85373323bc8cb8b4162868bad5c263e8cd Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 17 Sep 2023 08:55:25 -0400 Subject: [PATCH] Modernize SapphireLauncher --- launcher/src/sapphirelauncher.cpp | 37 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/launcher/src/sapphirelauncher.cpp b/launcher/src/sapphirelauncher.cpp index 4f09ca6..8592f74 100644 --- a/launcher/src/sapphirelauncher.cpp +++ b/launcher/src/sapphirelauncher.cpp @@ -3,6 +3,7 @@ #include "sapphirelauncher.h" +#include #include #include #include @@ -15,51 +16,51 @@ SapphireLauncher::SapphireLauncher(LauncherCore &window, QObject *parent) 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); - 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] { 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; } - QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); + const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); if (!document.isEmpty()) { LoginAuth auth; - auth.SID = document["sId"].toString(); - auth.lobbyhost = document["lobbyHost"].toString(); - auth.frontierHost = document["frontierHost"].toString(); + auth.SID = document[QLatin1String("sId")].toString(); + auth.lobbyhost = document[QLatin1String("lobbyHost")].toString(); + auth.frontierHost = document[QLatin1String("frontierHost")].toString(); auth.region = 3; window.launchGame(*info.profile, auth); } 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) { - QJsonObject data{{"username", info.username}, {"pass", info.password}}; - QUrl url(lobbyUrl + "/sapphire-api/lobby/createAccount"); + const QJsonObject data{{QStringLiteral("username"), info.username}, {QStringLiteral("pass"), info.password}}; + const QUrl url(lobbyUrl + QStringLiteral("/sapphire-api/lobby/createAccount")); 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, [&] { - QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); + const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); LoginAuth auth; - auth.SID = document["sId"].toString(); - auth.lobbyhost = document["lobbyHost"].toString(); - auth.frontierHost = document["frontierHost"].toString(); + auth.SID = document[QLatin1String("sId")].toString(); + auth.lobbyhost = document[QLatin1String("lobbyHost")].toString(); + auth.frontierHost = document[QLatin1String("frontierHost")].toString(); auth.region = 3; window.launchGame(*info.profile, auth);