Skip to content

Commit

Permalink
Added automatic gf version and blackbox to login request
Browse files Browse the repository at this point in the history
  • Loading branch information
hatz2 committed Dec 10, 2022
1 parent 80b8f6f commit 480e0e1
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 132 deletions.
5 changes: 0 additions & 5 deletions account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,3 @@ NostaleAuth *Account::getAuthenticator() const
{
return authenticator;
}

void Account::setGfVersion(QString ver)
{
authenticator->setGfVersion(ver);
}
2 changes: 0 additions & 2 deletions account.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class Account : public QObject

NostaleAuth *getAuthenticator() const;

void setGfVersion(QString ver);

private:
QString gameforgeAccountUsername;
NostaleAuth* authenticator;
Expand Down
25 changes: 1 addition & 24 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(settingsDialog, &SettingsDialog::autoLoginStateChanged, ui->characterLabel, &QLabel::setEnabled);
connect(settingsDialog, &SettingsDialog::profilesPathSelected, this, &MainWindow::loadAccountProfiles);
connect(settingsDialog, &SettingsDialog::identityPathSelected, this, &MainWindow::loadIdentity);
connect(settingsDialog, &SettingsDialog::gfVersionChanged, this, &MainWindow::updateGfVersion);

loadSettings();
}
Expand All @@ -37,7 +36,6 @@ void MainWindow::on_openAccountsButton_clicked()
if (ui->accountsListWidget->currentRow() < 0) return;
if (!checkGameClientPath()) return;
if (!checkIdentityPath()) return;
if (!checkGfVersion()) return;

int openInterval = settingsDialog->getOpenInterval();
QString gameforgeAccountUsername = ui->gameforgeAccountComboBox->currentText();
Expand Down Expand Up @@ -115,7 +113,6 @@ void MainWindow::loadSettings()
settingsDialog->setServer(settings.value("server", 0).toInt());
ui->channelComboBox->setCurrentIndex(settings.value("channel", 0).toInt());
ui->characterComboBox->setCurrentIndex(settings.value("character", 0).toInt());
settingsDialog->setGfClientVersion(settings.value("gfver").toString());

settings.endGroup();

Expand Down Expand Up @@ -149,7 +146,6 @@ void MainWindow::saveSettings()
settings.setValue("server", settingsDialog->getServer());
settings.setValue("channel", ui->channelComboBox->currentIndex());
settings.setValue("character", ui->characterComboBox->currentIndex());
settings.setValue("gfver", settingsDialog->getGfClientVersion());
settings.endGroup();

settings.beginGroup("Gameforge Accounts");
Expand Down Expand Up @@ -302,7 +298,7 @@ void MainWindow::displayProfiles(const QString &gameforgeAccount)

void MainWindow::addGameforgeAccount(const QString &email, const QString &password)
{
NostaleAuth* nostaleAuth = new NostaleAuth(identity, settingsDialog->getGfClientVersion(), this);
NostaleAuth* nostaleAuth = new NostaleAuth(identity, this);
bool captcha = false;
bool wrongCredentials = false;
QString gfChallengeId;
Expand Down Expand Up @@ -350,25 +346,6 @@ void MainWindow::loadIdentity(const QString &path)
identity->load(path);
}

void MainWindow::updateGfVersion(QString gfver)
{
for (auto accs : accounts)
{
accs->setGfVersion(gfver);
}
}

bool MainWindow::checkGfVersion()
{
if (settingsDialog->getGfClientVersion().isEmpty())
{
QMessageBox::critical(this, "Error", "Gameforge Client version is empty. Please set it up on Options > Settings");
return false;
}

return true;
}

void MainWindow::createTrayIcon()
{
QAction* showAction = new QAction("Show", this);
Expand Down
2 changes: 0 additions & 2 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ private slots:
void displayProfiles(const QString& gameforgeAccount);
void addGameforgeAccount(const QString& email, const QString& password);
void loadIdentity(const QString& path);
void updateGfVersion(QString gfver);
bool checkGfVersion();

Ui::MainWindow *ui;
SettingsDialog* settingsDialog;
Expand Down
36 changes: 28 additions & 8 deletions nostaleauth.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "nostaleauth.h"

NostaleAuth::NostaleAuth(const std::shared_ptr<Identity> &id, const QString &gfver, QObject *parent) : QObject(parent), identity(id)
NostaleAuth::NostaleAuth(const std::shared_ptr<Identity> &id, QObject *parent) : QObject(parent), identity(id)
{
this->locale = QLocale().name();
this->browserUserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
setGfVersion(gfver);

initGfVersion();
initCert();
initInstallationId();
initAllCerts();
Expand Down Expand Up @@ -60,6 +60,10 @@ bool NostaleAuth::authenthicate(const QString &email, const QString &password, b
request.setRawHeader("Origin", "spark://www.gameforge.com");
request.setRawHeader("Connection", "Keep-Alive");

identity->update();
BlackBox blackbox(identity, QJsonValue::Null);

content["blackbox"] = blackbox.encoded();
content["email"] = email;
content["locale"] = locale;
content["password"] = password;
Expand Down Expand Up @@ -140,12 +144,6 @@ QString NostaleAuth::getToken(const QString &accountId)
return jsonResponse["code"].toString();
}

void NostaleAuth::setGfVersion(QString ver)
{
this->chromeVersion = "C" + ver;
this->gameforgeVersion = ver.left(ver.lastIndexOf("."));
}

QChar NostaleAuth::getFirstNumber(QString uuid)
{
for (const auto& c : uuid)
Expand Down Expand Up @@ -332,3 +330,25 @@ void NostaleAuth::initPrivateKey()

this->privateKey = QSslKey(key, QSsl::Rsa);
}

void NostaleAuth::initGfVersion()
{
QJsonObject jsonResponse;
QNetworkRequest request(QUrl("http://dl.tnt.gameforge.com/tnt/final-ms3/clientversioninfo.json"));
SyncNetworAccesskManager networkManager(this);
QNetworkReply* reply = nullptr;


reply = networkManager.get(request);
reply->deleteLater();

QByteArray response = reply->readAll();

if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200)
return;

jsonResponse = QJsonDocument::fromJson(response).object();

this->chromeVersion = "C" + jsonResponse["version"].toString();
this->gameforgeVersion = jsonResponse["minimumVersionForDelayedUpdate"].toString();
}
6 changes: 3 additions & 3 deletions nostaleauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ class NostaleAuth : public QObject
{
Q_OBJECT
public:
explicit NostaleAuth(const std::shared_ptr<Identity>& id, const QString& gfver, QObject *parent = nullptr);
explicit NostaleAuth(const std::shared_ptr<Identity>& id, QObject *parent = nullptr);

QMap<QString /* displayName */, QString /* id */> getAccounts();

bool authenthicate(const QString& email, const QString& password, bool &captcha, QString &gfChallengeId, bool& wrongCredentials);

QString getToken(const QString& accountId);

void setGfVersion(QString ver);

signals:
void captchaStart();
void captchaEnd();
Expand All @@ -53,6 +51,8 @@ class NostaleAuth : public QObject

void initPrivateKey();

void initGfVersion();

QString locale;
QString installationId;
QString chromeVersion;
Expand Down
15 changes: 0 additions & 15 deletions settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ bool SettingsDialog::autoLogIn() const
return ui->autoLogInCheckBox->isChecked();
}

QString SettingsDialog::getGfClientVersion() const
{
return ui->gfClientVersionEdit->text();
}

void SettingsDialog::setGameClientPath(const QString &path)
{
ui->gameClientPathLineEdit->setText(path);
Expand Down Expand Up @@ -106,11 +101,6 @@ void SettingsDialog::setAutoLogin(bool login)
ui->autoLogInCheckBox->setChecked(login);
}

void SettingsDialog::setGfClientVersion(const QString &version)
{
ui->gfClientVersionEdit->setText(version);
}

void SettingsDialog::on_selectGamePathButton_clicked()
{
QString path = QFileDialog::getOpenFileName(this, "Select NostaleClientX.exe", QDir::rootPath(), "NostaleClientX.exe (NostaleClientX.exe)");
Expand Down Expand Up @@ -169,8 +159,3 @@ void SettingsDialog::on_selectIdentityButton_clicked()
}


void SettingsDialog::on_gfClientVersionEdit_textChanged(const QString &arg1)
{
emit gfVersionChanged(arg1);
}

8 changes: 0 additions & 8 deletions settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class SettingsDialog : public QDialog

bool autoLogIn() const;

QString getGfClientVersion() const;

void setGameClientPath(const QString& path);

void setProfilesPath(const QString& path);
Expand All @@ -52,17 +50,13 @@ class SettingsDialog : public QDialog

void setAutoLogin(bool login);

void setGfClientVersion(const QString& version);

signals:
void autoLoginStateChanged(bool);

void profilesPathSelected(QString);

void identityPathSelected(QString);

void gfVersionChanged(QString);

private slots:
void on_selectGamePathButton_clicked();

Expand All @@ -72,8 +66,6 @@ private slots:

void on_selectIdentityButton_clicked();

void on_gfClientVersionEdit_textChanged(const QString &arg1);

private:
void initLanguageComboBox();

Expand Down
Loading

0 comments on commit 480e0e1

Please sign in to comment.