Skip to content
18 changes: 12 additions & 6 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ AOApplication::AOApplication(QObject *parent)
: QObject(parent)
{
net_manager = new NetworkManager(this);
debug_func = new debug_functions(this);
Comment thread
stonedDiscord marked this conversation as resolved.
Outdated

discord = new AttorneyOnline::Discord();

asset_lookup_cache.reserve(2048);
Expand Down Expand Up @@ -142,10 +144,11 @@ void AOApplication::server_disconnected()
{
if (w_courtroom->isVisible())
{
call_notice(tr("Disconnected from server."));
construct_lobby();
destruct_courtroom();
// call_notice(tr("Disconnected from server."));
Comment thread
stonedDiscord marked this conversation as resolved.
Outdated
debug_func->call_notice_reconnect(tr("Disconnected from server, reconnect?"));
}
construct_lobby();
destruct_courtroom();
}
Options::getInstance().setServerSubTheme(QString());
}
Expand All @@ -158,14 +161,17 @@ void AOApplication::loading_cancelled()
void AOApplication::call_settings_menu()
{
AOOptionsDialog *l_dialog = new AOOptionsDialog(this);
// force disconnect as a test
server_disconnected();

if (is_courtroom_constructed())
{
connect(l_dialog, &AOOptionsDialog::reloadThemeRequest, w_courtroom, &Courtroom::on_reload_theme_clicked);
}

if (is_lobby_constructed())
{}
l_dialog->exec();
// if (is_lobby_constructed())
// {}
// l_dialog->exec();
Comment thread
WisoAltred marked this conversation as resolved.
Outdated

if (is_courtroom_constructed())
{
Expand Down
2 changes: 2 additions & 0 deletions src/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NetworkManager;
class Lobby;
class Courtroom;
class Options;
class debug_functions;
Comment thread
WisoAltred marked this conversation as resolved.
Outdated

class VPath : QString
{
Expand Down Expand Up @@ -57,6 +58,7 @@ class AOApplication : public QObject
~AOApplication();

NetworkManager *net_manager;
debug_functions *debug_func;
Lobby *w_lobby = nullptr;
Courtroom *w_courtroom = nullptr;
AttorneyOnline::Discord *discord;
Expand Down
53 changes: 53 additions & 0 deletions src/debug_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "debug_functions.h"
#include "aoapplication.h"
#include "networkmanager.h"

#include <QCoreApplication>
#include <QDialogButtonBox>
Expand All @@ -9,6 +11,12 @@

#include <functional>

debug_functions::debug_functions(AOApplication *parent)
: QObject(parent)
{
ao_app = parent;
}

void call_error(QString p_message)
{
QMessageBox *msgBox = new QMessageBox;
Expand Down Expand Up @@ -58,3 +66,48 @@ void call_notice(QString p_message)

msgBox->exec();
}

void debug_functions::call_notice_reconnect(QString p_message)
{
auto *msgBox = new QMessageBox;
Comment thread
stonedDiscord marked this conversation as resolved.
Outdated

msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setText(p_message);
msgBox->setWindowTitle(QCoreApplication::translate("debug_functions", "Notice"));

msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->defaultButton()->setEnabled(false);

QPushButton *reconnectButton = msgBox->addButton(QObject::tr("Reconnect"), QMessageBox::ActionRole);

QTimer intervalTimer;
intervalTimer.setInterval(1000);

int counter = 3;
Comment thread
stonedDiscord marked this conversation as resolved.
Outdated
const auto updateCounter = [msgBox, &counter] {
if (counter <= 0)
{
return;
}
msgBox->defaultButton()->setText(QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter));
counter--;
};

QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter);
intervalTimer.start();
updateCounter();

QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] {
msgBox->defaultButton()->setEnabled(true);
msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK"));
intervalTimer.stop();
});

msgBox->exec();

if (msgBox->clickedButton() == reconnectButton)
{
ao_app->net_manager->reconnect_to_last_server();
}
}
13 changes: 13 additions & 0 deletions src/debug_functions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#pragma once

#include "aoapplication.h"

#include <QString>

void call_error(QString message);
void call_notice(QString message);

class debug_functions : public QObject
{
Q_OBJECT

public:
explicit debug_functions(AOApplication *parent);
AOApplication *ao_app;

void call_notice_reconnect(QString message);
};
Comment thread
WisoAltred marked this conversation as resolved.
Outdated
6 changes: 6 additions & 0 deletions src/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void NetworkManager::request_document(MSDocumentType document_type, const std::f

void NetworkManager::connect_to_server(ServerInfo server)
{
m_last_server = server;
disconnect_from_server();

qInfo().noquote() << QObject::tr("Connecting to %1").arg(server.toString());
Expand All @@ -167,6 +168,11 @@ void NetworkManager::disconnect_from_server()
}
}

void NetworkManager::reconnect_to_last_server()
{
connect_to_server(m_last_server);
}

void NetworkManager::ship_server_packet(AOPacket packet)
{
if (!m_connection)
Expand Down
3 changes: 3 additions & 0 deletions src/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class NetworkManager : public QObject

void connect_to_server(ServerInfo p_server);
void disconnect_from_server();
void reconnect_to_last_server();

QString get_user_agent() const;

Expand Down Expand Up @@ -60,4 +61,6 @@ private Q_SLOTS:
const int heartbeat_interval = 60 * 5 * 1000;

unsigned int s_decryptor = 5;

ServerInfo m_last_server;
};
Loading