Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "aoapplication.h"

#include "courtroom.h"
#include "debug_functions.h"
#include "lobby.h"
#include "networkmanager.h"
#include "options.h"
Expand All @@ -20,6 +19,7 @@ AOApplication::AOApplication(QObject *parent)
: QObject(parent)
{
net_manager = new NetworkManager(this);

discord = new AttorneyOnline::Discord();

asset_lookup_cache.reserve(2048);
Expand Down Expand Up @@ -138,16 +138,23 @@ QString AOApplication::find_image(QStringList p_list)

void AOApplication::server_disconnected()
{
bool try_reconnect = false;
if (is_courtroom_constructed())
{
if (w_courtroom->isVisible())
{
call_notice(tr("Disconnected from server."));
}
try_reconnect = w_courtroom->isVisible();
construct_lobby();
destruct_courtroom();
}
Options::getInstance().setServerSubTheme(QString());

if (try_reconnect && QMessageBox::question(nullptr,
tr("Server Disconnected"),
tr("Connection to the server has been lost. "
"Do you want to reconnect?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
net_manager->reconnect_to_last_server();
}
}

void AOApplication::loading_cancelled()
Expand All @@ -158,14 +165,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 on lines +176 to +178
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remove these, this snippet is for the execution of the lobby settings when the settings button is pressed.
Currently, pressing it causes a disconnection for the purposes of testing the reconnection button.


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs removed


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
10 changes: 10 additions & 0 deletions src/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void NetworkManager::connect_to_server(ServerInfo server)
{
disconnect_from_server();

m_last_server = server;

qInfo().noquote() << QObject::tr("Connecting to %1").arg(server.toString());
m_connection = new WebSocketConnection(ao_app, this);

Expand All @@ -167,6 +169,13 @@ void NetworkManager::disconnect_from_server()
}
}

void NetworkManager::reconnect_to_last_server()
{
connect(this, &NetworkManager::server_connected, this, &NetworkManager::join_to_server);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs disconnected after rejoining the server.


connect_to_server(m_last_server);
}

void NetworkManager::ship_server_packet(AOPacket packet)
{
if (!m_connection)
Expand All @@ -188,6 +197,7 @@ void NetworkManager::ship_server_packet(AOPacket packet)

void NetworkManager::join_to_server()
{
disconnect(this, &NetworkManager::server_connected, this, &NetworkManager::join_to_server);
ship_server_packet(AOPacket("askchaa"));
}

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