2021-11-01 09:54:58 -04:00
|
|
|
#include "sapphirelauncher.h"
|
|
|
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
SapphireLauncher::SapphireLauncher(LauncherCore& window) : window(window) {
|
2021-11-01 09:54:58 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SapphireLauncher::login(QString lobbyUrl, const LoginInformation& info) {
|
|
|
|
QJsonObject data {
|
|
|
|
{"username", info.username},
|
|
|
|
{"pass", info.password}
|
|
|
|
};
|
|
|
|
|
|
|
|
QUrl url;
|
|
|
|
url.setScheme("http");
|
|
|
|
url.setHost(lobbyUrl);
|
|
|
|
url.setPath("/sapphire-api/lobby/login");
|
|
|
|
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
|
|
|
|
|
|
|
|
auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
|
|
|
connect(reply, &QNetworkReply::finished, [=] {
|
|
|
|
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.region = 3;
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
window.launchGame(*info.settings, auth);
|
2021-11-01 09:54:58 -04:00
|
|
|
} else {
|
|
|
|
auto messageBox = new QMessageBox(QMessageBox::Icon::Critical, "Failed to Login", "Invalid username/password.");
|
|
|
|
messageBox->show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void SapphireLauncher::registerAccount(QString lobbyUrl, const LoginInformation& info) {
|
|
|
|
QJsonObject data {
|
|
|
|
{"username", info.username},
|
|
|
|
{"pass", info.password}
|
|
|
|
};
|
|
|
|
QUrl url;
|
|
|
|
url.setScheme("http");
|
|
|
|
url.setHost(lobbyUrl);
|
|
|
|
url.setPath("/sapphire-api/lobby/createAccount");
|
|
|
|
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
|
|
|
|
|
|
|
|
auto reply = window.mgr->post(request, QJsonDocument(data).toJson(QJsonDocument::JsonFormat::Compact));
|
|
|
|
connect(reply, &QNetworkReply::finished, [=] {
|
|
|
|
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
|
|
|
|
|
|
|
LoginAuth auth;
|
|
|
|
auth.SID = document["sId"].toString();
|
|
|
|
auth.lobbyhost = document["lobbyHost"].toString();
|
|
|
|
auth.frontierHost = document["frontierHost"].toString();
|
|
|
|
auth.region = 3;
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
window.launchGame(*info.settings, auth);
|
2021-11-01 09:54:58 -04:00
|
|
|
});
|
|
|
|
}
|