mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Improve const correctness, use string literals in square enix login
This commit is contained in:
parent
b068d34001
commit
756f319457
2 changed files with 72 additions and 76 deletions
|
@ -27,37 +27,34 @@ QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info)
|
||||||
Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
|
Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
|
||||||
qDebug() << "Performing boot check...";
|
qDebug() << "Performing boot check...";
|
||||||
|
|
||||||
patcher = new Patcher(window, info.profile->gamePath() + "/boot", info.profile->bootData, this);
|
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/boot"), info.profile->bootData, this);
|
||||||
connect(patcher, &Patcher::done, [this, &info] {
|
connect(patcher, &Patcher::done, [this, &info] {
|
||||||
info.profile->readGameVersion();
|
info.profile->readGameVersion();
|
||||||
|
|
||||||
launcher.login(info);
|
launcher.login(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUrlQuery query;
|
const QUrlQuery query{{QStringLiteral("time"), QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd-HH-mm"))}};
|
||||||
query.addQueryItem("time", QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd-HH-mm"));
|
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("http");
|
url.setScheme(QStringLiteral("http"));
|
||||||
url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()));
|
url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()));
|
||||||
url.setPath(QString("/http/win32/ffxivneo_release_boot/%1").arg(info.profile->bootVersion));
|
url.setPath(QStringLiteral("/http/win32/ffxivneo_release_boot/%1").arg(info.profile->bootVersion));
|
||||||
url.setQuery(query);
|
url.setQuery(query);
|
||||||
|
|
||||||
auto request = QNetworkRequest(url);
|
auto request = QNetworkRequest(url);
|
||||||
if (info.profile->account()->license() == Account::GameLicense::macOS) {
|
if (info.profile->account()->license() == Account::GameLicense::macOS) {
|
||||||
request.setRawHeader("User-Agent", "FFXIV-MAC PATCH CLIENT");
|
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV-MAC PATCH CLIENT"));
|
||||||
} else {
|
} else {
|
||||||
request.setRawHeader("User-Agent", "FFXIV PATCH CLIENT");
|
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV PATCH CLIENT"));
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setRawHeader("Host", QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
|
request.setRawHeader(QByteArrayLiteral("Host"), QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
|
||||||
|
|
||||||
auto reply = window.mgr->get(request);
|
const auto reply = window.mgr->get(request);
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
const QString response = reply->readAll();
|
patcher->processPatchList(*window.mgr, reply->readAll());
|
||||||
|
|
||||||
patcher->processPatchList(*window.mgr, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> SquareBoot::checkGateStatus(LoginInformation *info)
|
QCoro::Task<> SquareBoot::checkGateStatus(LoginInformation *info)
|
||||||
|
@ -66,9 +63,9 @@ QCoro::Task<> SquareBoot::checkGateStatus(LoginInformation *info)
|
||||||
qDebug() << "Checking gate...";
|
qDebug() << "Checking gate...";
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("https");
|
url.setScheme(QStringLiteral("https"));
|
||||||
url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer()));
|
url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer()));
|
||||||
url.setPath("/worldStatus/gate_status.json");
|
url.setPath(QStringLiteral("/worldStatus/gate_status.json"));
|
||||||
url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
|
@ -76,12 +73,11 @@ QCoro::Task<> SquareBoot::checkGateStatus(LoginInformation *info)
|
||||||
// TODO: really?
|
// TODO: really?
|
||||||
window.buildRequest(*info->profile, request);
|
window.buildRequest(*info->profile, request);
|
||||||
|
|
||||||
auto reply = window.mgr->get(request);
|
const auto reply = window.mgr->get(request);
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
const bool isGateOpen = !document.isEmpty() && document.object()[QLatin1String("status")].toInt() != 0;
|
||||||
const bool isGateOpen = !document.isEmpty() && document.object()["status"].toInt() != 0;
|
|
||||||
|
|
||||||
if (isGateOpen) {
|
if (isGateOpen) {
|
||||||
bootCheck(*info);
|
bootCheck(*info);
|
||||||
|
|
|
@ -24,12 +24,12 @@ QString getFileHash(const QString &file)
|
||||||
{
|
{
|
||||||
auto f = QFile(file);
|
auto f = QFile(file);
|
||||||
if (!f.open(QIODevice::ReadOnly))
|
if (!f.open(QIODevice::ReadOnly))
|
||||||
return "";
|
return {};
|
||||||
|
|
||||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||||
hash.addData(&f);
|
hash.addData(&f);
|
||||||
|
|
||||||
return QString("%1/%2").arg(QString::number(f.size()), hash.result().toHex());
|
return QStringLiteral("%1/%2").arg(QString::number(f.size()), hash.result().toHex());
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<std::optional<SquareLauncher::StoredInfo>> SquareLauncher::getStored(const LoginInformation &info)
|
QCoro::Task<std::optional<SquareLauncher::StoredInfo>> SquareLauncher::getStored(const LoginInformation &info)
|
||||||
|
@ -38,40 +38,40 @@ QCoro::Task<std::optional<SquareLauncher::StoredInfo>> SquareLauncher::getStored
|
||||||
|
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
// en is always used to the top url
|
// en is always used to the top url
|
||||||
query.addQueryItem("lng", "en");
|
query.addQueryItem(QStringLiteral("lng"), QStringLiteral("en"));
|
||||||
// for some reason, we always use region 3. the actual region is acquired later
|
// for some reason, we always use region 3. the actual region is acquired later
|
||||||
query.addQueryItem("rgn", "3");
|
query.addQueryItem(QStringLiteral("rgn"), QStringLiteral("3"));
|
||||||
query.addQueryItem("isft", info.profile->account()->isFreeTrial() ? "1" : "0");
|
query.addQueryItem(QStringLiteral("isft"), info.profile->account()->isFreeTrial() ? QStringLiteral("1") : QStringLiteral("0"));
|
||||||
query.addQueryItem("cssmode", "1");
|
query.addQueryItem(QStringLiteral("cssmode"), QStringLiteral("1"));
|
||||||
query.addQueryItem("isnew", "1");
|
query.addQueryItem(QStringLiteral("isnew"), QStringLiteral("1"));
|
||||||
query.addQueryItem("launchver", "3");
|
query.addQueryItem(QStringLiteral("launchver"), QStringLiteral("3"));
|
||||||
|
|
||||||
if (info.profile->account()->license() == Account::GameLicense::WindowsSteam) {
|
if (info.profile->account()->license() == Account::GameLicense::WindowsSteam) {
|
||||||
query.addQueryItem("issteam", "1");
|
query.addQueryItem(QStringLiteral("issteam"), QStringLiteral("1"));
|
||||||
|
|
||||||
// TODO: get steam ticket information from steam api
|
// TODO: get steam ticket information from steam api
|
||||||
query.addQueryItem("session_ticket", "1");
|
query.addQueryItem(QStringLiteral("session_ticket"), QStringLiteral("1"));
|
||||||
query.addQueryItem("ticket_size", "1");
|
query.addQueryItem(QStringLiteral("ticket_size"), QStringLiteral("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("https");
|
url.setScheme(QStringLiteral("https"));
|
||||||
url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer()));
|
url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer()));
|
||||||
url.setPath("/oauth/ffxivarr/login/top");
|
url.setPath(QStringLiteral("/oauth/ffxivarr/login/top"));
|
||||||
url.setQuery(query);
|
url.setQuery(query);
|
||||||
|
|
||||||
auto request = QNetworkRequest(url);
|
auto request = QNetworkRequest(url);
|
||||||
window.buildRequest(*info.profile, request);
|
window.buildRequest(*info.profile, request);
|
||||||
|
|
||||||
auto reply = window.mgr->get(request);
|
const auto reply = window.mgr->get(request);
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
const auto str = QString(reply->readAll());
|
const QString str = reply->readAll();
|
||||||
|
|
||||||
// fetches Steam username
|
// fetches Steam username
|
||||||
if (info.profile->account()->license() == Account::GameLicense::WindowsSteam) {
|
if (info.profile->account()->license() == Account::GameLicense::WindowsSteam) {
|
||||||
QRegularExpression re(R"lit(<input name=""sqexid"" type=""hidden"" value=""(?<sqexid>.*)""\/>)lit");
|
const QRegularExpression re(QStringLiteral(R"lit(<input name=""sqexid"" type=""hidden"" value=""(?<sqexid>.*)""\/>)lit"));
|
||||||
QRegularExpressionMatch match = re.match(str);
|
const QRegularExpressionMatch match = re.match(str);
|
||||||
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
username = match.captured(1);
|
username = match.captured(1);
|
||||||
|
@ -82,8 +82,8 @@ QCoro::Task<std::optional<SquareLauncher::StoredInfo>> SquareLauncher::getStored
|
||||||
username = info.username;
|
username = info.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpression re(R"lit(\t<\s*input .* name="_STORED_" value="(?<stored>.*)">)lit");
|
const QRegularExpression re(QStringLiteral(R"lit(\t<\s*input .* name="_STORED_" value="(?<stored>.*)">)lit"));
|
||||||
QRegularExpressionMatch match = re.match(str);
|
const QRegularExpressionMatch match = re.match(str);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
co_return StoredInfo{match.captured(1), url};
|
co_return StoredInfo{match.captured(1), url};
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,34 +102,34 @@ QCoro::Task<> SquareLauncher::login(const LoginInformation &info)
|
||||||
const auto [stored, referer] = *storedResult;
|
const auto [stored, referer] = *storedResult;
|
||||||
|
|
||||||
QUrlQuery postData;
|
QUrlQuery postData;
|
||||||
postData.addQueryItem("_STORED_", stored);
|
postData.addQueryItem(QStringLiteral("_STORED_"), stored);
|
||||||
postData.addQueryItem("sqexid", info.username);
|
postData.addQueryItem(QStringLiteral("sqexid"), info.username);
|
||||||
postData.addQueryItem("password", info.password);
|
postData.addQueryItem(QStringLiteral("password"), info.password);
|
||||||
postData.addQueryItem("otppw", info.oneTimePassword);
|
postData.addQueryItem(QStringLiteral("otppw"), info.oneTimePassword);
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("https");
|
url.setScheme(QStringLiteral("https"));
|
||||||
url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer()));
|
url.setHost(QStringLiteral("ffxiv-login.%1").arg(window.squareEnixLoginServer()));
|
||||||
url.setPath("/oauth/ffxivarr/login/login.send");
|
url.setPath(QStringLiteral("/oauth/ffxivarr/login/login.send"));
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
window.buildRequest(*info.profile, request);
|
window.buildRequest(*info.profile, request);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded"));
|
||||||
request.setRawHeader("Referer", referer.toEncoded());
|
request.setRawHeader(QByteArrayLiteral("Referer"), referer.toEncoded());
|
||||||
request.setRawHeader("Cache-Control", "no-cache");
|
request.setRawHeader(QByteArrayLiteral("Cache-Control"), QByteArrayLiteral("no-cache"));
|
||||||
|
|
||||||
auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
|
const auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
auto str = QString(reply->readAll());
|
const QString str = reply->readAll();
|
||||||
|
|
||||||
QRegularExpression re(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit");
|
const QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit"));
|
||||||
QRegularExpressionMatch match = re.match(str);
|
const QRegularExpressionMatch match = re.match(str);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
const auto parts = match.captured(1).split(',');
|
const auto parts = match.captured(1).split(QLatin1Char(','));
|
||||||
|
|
||||||
const bool terms = parts[3] == "1";
|
const bool terms = parts[3] == QLatin1String("1");
|
||||||
const bool playable = parts[9] == "1";
|
const bool playable = parts[9] == QLatin1String("1");
|
||||||
|
|
||||||
if (!playable) {
|
if (!playable) {
|
||||||
Q_EMIT window.loginError(i18n("Your account is unplayable. Check that you have the correct license, and a valid subscription."));
|
Q_EMIT window.loginError(i18n("Your account is unplayable. Check that you have the correct license, and a valid subscription."));
|
||||||
|
@ -147,53 +147,48 @@ QCoro::Task<> SquareLauncher::login(const LoginInformation &info)
|
||||||
|
|
||||||
registerSession(info);
|
registerSession(info);
|
||||||
} else {
|
} else {
|
||||||
QRegularExpression re(R"lit(window.external.user\("login=auth,ng,err,(?<launchParams>.*)\);)lit");
|
const QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ng,err,(?<launchParams>.*)\);)lit"));
|
||||||
QRegularExpressionMatch match = re.match(str);
|
const QRegularExpressionMatch match = re.match(str);
|
||||||
|
|
||||||
const auto parts = match.captured(1).split(',');
|
|
||||||
|
|
||||||
// there's a stray quote at the end of the error string, so let's remove that
|
// there's a stray quote at the end of the error string, so let's remove that
|
||||||
QString errorStr = match.captured(1).chopped(1);
|
Q_EMIT window.loginError(match.captured(1).chopped(1));
|
||||||
|
|
||||||
Q_EMIT window.loginError(errorStr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info)
|
QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info)
|
||||||
{
|
{
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("https");
|
url.setScheme(QStringLiteral("https"));
|
||||||
url.setHost(QStringLiteral("patch-gamever.%1").arg(window.squareEnixServer()));
|
url.setHost(QStringLiteral("patch-gamever.%1").arg(window.squareEnixServer()));
|
||||||
url.setPath(QString("/http/win32/ffxivneo_release_game/%1/%2").arg(info.profile->repositories.repositories[0].version, SID));
|
url.setPath(QStringLiteral("/http/win32/ffxivneo_release_game/%1/%2").arg(info.profile->repositories.repositories[0].version, SID));
|
||||||
|
|
||||||
auto request = QNetworkRequest(url);
|
auto request = QNetworkRequest(url);
|
||||||
window.setSSL(request);
|
window.setSSL(request);
|
||||||
request.setRawHeader("X-Hash-Check", "enabled");
|
request.setRawHeader(QByteArrayLiteral("X-Hash-Check"), QByteArrayLiteral("enabled"));
|
||||||
request.setRawHeader("User-Agent", "FFXIV PATCH CLIENT");
|
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV PATCH CLIENT"));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/x-www-form-urlencoded"));
|
||||||
|
|
||||||
QString report = QString("%1=%2").arg(info.profile->bootVersion, getBootHash(info));
|
|
||||||
|
|
||||||
|
QString report = QStringLiteral("%1=%2").arg(info.profile->bootVersion, getBootHash(info));
|
||||||
for (int i = 1; i < auth.maxExpansion + 1; i++) {
|
for (int i = 1; i < auth.maxExpansion + 1; i++) {
|
||||||
if (i <= static_cast<int>(info.profile->repositories.repositories_count)) {
|
if (i <= static_cast<int>(info.profile->repositories.repositories_count)) {
|
||||||
report += QString("\nex%1\t%2").arg(QString::number(i), info.profile->repositories.repositories[i].version);
|
report += QStringLiteral("\nex%1\t%2").arg(QString::number(i), info.profile->repositories.repositories[i].version);
|
||||||
} else {
|
} else {
|
||||||
report += QString("\nex%1\t2012.01.01.0000.0000").arg(QString::number(i));
|
report += QStringLiteral("\nex%1\t2012.01.01.0000.0000").arg(QString::number(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reply = window.mgr->post(request, report.toUtf8());
|
const auto reply = window.mgr->post(request, report.toUtf8());
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
if (reply->rawHeaderList().contains("X-Patch-Unique-Id")) {
|
if (reply->rawHeaderList().contains(QByteArrayLiteral("X-Patch-Unique-Id"))) {
|
||||||
QString body = reply->readAll();
|
const QString body = reply->readAll();
|
||||||
|
|
||||||
patcher = new Patcher(window, info.profile->gamePath() + "/game", info.profile->gameData, this);
|
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/game"), info.profile->gameData, this);
|
||||||
connect(patcher, &Patcher::done, [this, &info, reply] {
|
connect(patcher, &Patcher::done, [this, &info, reply] {
|
||||||
info.profile->readGameVersion();
|
info.profile->readGameVersion();
|
||||||
|
|
||||||
auth.SID = reply->rawHeader("X-Patch-Unique-Id");
|
auth.SID = reply->rawHeader(QByteArrayLiteral("X-Patch-Unique-Id"));
|
||||||
|
|
||||||
window.launchGame(*info.profile, auth);
|
window.launchGame(*info.profile, auth);
|
||||||
});
|
});
|
||||||
|
@ -216,14 +211,19 @@ QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info)
|
||||||
|
|
||||||
QString SquareLauncher::getBootHash(const LoginInformation &info)
|
QString SquareLauncher::getBootHash(const LoginInformation &info)
|
||||||
{
|
{
|
||||||
const QList<QString> fileList = {"ffxivboot.exe", "ffxivboot64.exe", "ffxivlauncher.exe", "ffxivlauncher64.exe", "ffxivupdater.exe", "ffxivupdater64.exe"};
|
const QList<QString> fileList = {QStringLiteral("ffxivboot.exe"),
|
||||||
|
QStringLiteral("ffxivboot64.exe"),
|
||||||
|
QStringLiteral("ffxivlauncher.exe"),
|
||||||
|
QStringLiteral("ffxivlauncher64.exe"),
|
||||||
|
QStringLiteral("ffxivupdater.exe"),
|
||||||
|
QStringLiteral("ffxivupdater64.exe")};
|
||||||
|
|
||||||
QString result;
|
QString result;
|
||||||
for (int i = 0; i < fileList.count(); i++) {
|
for (int i = 0; i < fileList.count(); i++) {
|
||||||
result += fileList[i] + "/" + getFileHash(info.profile->gamePath() + "/boot/" + fileList[i]);
|
result += fileList[i] + QStringLiteral("/") + getFileHash(info.profile->gamePath() + QStringLiteral("/boot/") + fileList[i]);
|
||||||
|
|
||||||
if (i != fileList.length() - 1)
|
if (i != fileList.length() - 1)
|
||||||
result += ",";
|
result += QStringLiteral(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue