diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-24 23:10:21 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-03-30 13:07:11 +0000 |
| commit | 14a48530d911e9d9d0539eb4c273ce1379534607 (patch) | |
| tree | 0f81a04410502eafddbd56d8c6e14ee0ae489c24 | |
| parent | 4858f1d4049d514cc99792c7ff13518dfe95398c (diff) | |
Constrain the lifetime of the demo server
Demo server was being deleted and recreated every time the lobby was
constructed, so it was always active. This rendered the "are we playing
a demo" checks useless as they always assumed we did. Logs didn't work
because of it, for example.
Construct the demo server only when the user selects demo playback, and
destroy it during the destruction of courtroom.
Make log_filename based on the application path, so `logs` subdirectory
is created relative to the executable rather than the working directory.
| -rw-r--r-- | src/aoapplication.cpp | 7 | ||||
| -rw-r--r-- | src/lobby.cpp | 5 | ||||
| -rw-r--r-- | src/packet_distribution.cpp | 5 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index ecfd97a..f253a5a 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -65,11 +65,6 @@ void AOApplication::construct_lobby() discord->state_lobby(); } - if (demo_server) - { - demo_server->deleteLater(); - } - demo_server = new DemoServer(this); w_lobby->show(); } @@ -120,6 +115,8 @@ void AOApplication::destruct_courtroom() return; } + delete demo_server; + demo_server = nullptr; delete w_courtroom; w_courtroom = nullptr; } diff --git a/src/lobby.cpp b/src/lobby.cpp index a283d4e..6c0e551 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -443,6 +443,11 @@ void Lobby::on_demo_clicked(QTreeWidgetItem *item, int column) } QString l_filepath = (get_app_path() + "/logs/%1/%2").arg(item->data(0, Qt::DisplayRole).toString(), item->data(1, Qt::DisplayRole).toString()); + + if (ao_app->demo_server == nullptr) + { + ao_app->demo_server = new DemoServer(ao_app); + } ao_app->demo_server->start_server(); ServerInfo demo_server; demo_server.address = "127.0.0.1"; diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 69448d4..6e7dd72 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -6,6 +6,7 @@ #include "lobby.h" #include "networkmanager.h" #include "options.h" +#include "file_functions.h" void AOApplication::append_to_demofile(QString packet_string) { @@ -176,7 +177,9 @@ void AOApplication::server_packet_received(AOPacket packet) static QRegularExpression illegal_filename_chars("[\\\\/:*?\"<>|\']"); if (Options::getInstance().logToDemoFileEnabled() && !demo_server) { - this->log_filename = QDateTime::currentDateTime().toUTC().toString("'logs/" + server_name_stripped.remove(illegal_filename_chars) + "/'yyyy-MM-dd hh-mm-ss t'.log'"); + server_name_stripped.remove(illegal_filename_chars); + QString timestamp = QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh-mm-ss t"); + this->log_filename = QDir(get_app_path()).filePath("logs/" + server_name_stripped + "/" + timestamp + ".log"); this->write_to_file("Joined server " + server_name_stripped + " hosted on address " + server_address + " on " + QDateTime::currentDateTime().toUTC().toString(), log_filename, true); } else |
