From 4140a3339aad886be0287c17bd4eabe7597af8e9 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sun, 28 Mar 2021 23:11:22 -0500 Subject: fix packets containing unencoded newlines being incorrectly split into multiple entries --- src/demoserver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 88dfdb4..509a356 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -233,8 +233,9 @@ void DemoServer::load_demo(QString filename) demo_stream.setCodec("UTF-8"); QString line = demo_stream.readLine(); while (!line.isNull()) { - if (!line.endsWith("%")) { + while (!line.endsWith("%")) { line += "\n"; + line += demo_stream.readLine(); } demo_data.enqueue(line); line = demo_stream.readLine(); -- cgit From b15e669beed1fae103fba9f16b746e5fb76e2267 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 30 Mar 2021 11:00:25 -0500 Subject: add translation support to demo server messages --- src/demoserver.cpp | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 509a356..fe296e6 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -150,7 +150,8 @@ void DemoServer::handle_packet(AOPacket packet) } else if (header == "CC") { client_sock->write("PV#0#CID#-1#%"); - client_sock->write("CT#DEMO#Demo file loaded. Send /play or > in OOC to begin playback.#1#%"); + QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%"; + client_sock->write(packet.toUtf8()); } else if (header == "CT") { if (contents[1].startsWith("/load")) @@ -159,14 +160,16 @@ void DemoServer::handle_packet(AOPacket packet) if (path.isEmpty()) return; load_demo(path); - client_sock->write("CT#DEMO#Demo file loaded. Send /play or > in OOC to begin playback.#1#%"); + QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%"; + client_sock->write(packet.toUtf8()); } else if (contents[1].startsWith("/play") || contents[1] == ">") { if (timer->interval() != 0 && !timer->isActive()) { timer->start(); - client_sock->write("CT#DEMO#Resuming playback.#1#%"); + QString packet = "CT#DEMO#" + tr("Resuming playback.") + "#1#%"; + client_sock->write(packet.toUtf8()); } else { @@ -180,7 +183,8 @@ void DemoServer::handle_packet(AOPacket packet) int timeleft = timer->remainingTime(); timer->stop(); timer->setInterval(timeleft); - client_sock->write("CT#DEMO#Pausing playback.#1#%"); + QString packet = "CT#DEMO#" + tr("Pausing playback.") + "#1#%"; + client_sock->write(packet.toUtf8()); } else if (contents[1].startsWith("/max_wait")) { @@ -194,29 +198,38 @@ void DemoServer::handle_packet(AOPacket packet) if (p_max_wait < 0) p_max_wait = -1; max_wait = p_max_wait; - client_sock->write("CT#DEMO#Setting max_wait to "); + QString packet = "CT#DEMO#" + tr("Setting max_wait to") + " "; + client_sock->write(packet.toUtf8()); client_sock->write(QString::number(max_wait).toUtf8()); - client_sock->write(" milliseconds.#1#%"); + packet = " " + tr("milliseconds.") + "#1#%"; + client_sock->write(packet.toUtf8()); } else { - client_sock->write("CT#DEMO#Not a valid integer!#1#%"); + QString packet = "CT#DEMO#" + tr("Not a valid integer!") + "#1#%"; + client_sock->write(packet.toUtf8()); } } else { - client_sock->write("CT#DEMO#Current max_wait is "); - client_sock->write(QString::number(max_wait).toUtf8()); - client_sock->write(" milliseconds.#1#%"); + + QString packet = "CT#DEMO#" + tr("Current max_wait is") + " "; + client_sock->write(packet.toUtf8()); + client_sock->write(QString::number(max_wait).toUtf8()); + packet = " " + tr("milliseconds.") + "#1#%"; + client_sock->write(packet.toUtf8()); + } } } else if (contents[1].startsWith("/min_wait")) { - client_sock->write("CT#DEMO#min_wait is deprecated. Use the client Settings for minimum wait instead!"); + QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%"; + client_sock->write(packet.toUtf8()); } else if (contents[1].startsWith("/help")) { - client_sock->write("CT#DEMO#Available commands:\nload, play, pause, max_wait, help#1#%"); + QString packet = "CT#DEMO#" + tr("Available commands:\nload, play, pause, max_wait, help") + "#1#%"; + client_sock->write(packet.toUtf8()); } } } @@ -265,12 +278,16 @@ void DemoServer::playback() // Skip the difference on the timers emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); } + else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) { + duration = qMax(0, timer->interval() - elapsed_time); + emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); + } elapsed_time += duration; timer->start(duration); } - else - { - client_sock->write("CT#DEMO#Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.#1#%"); + else { + QString end_packet = "CT#DEMO#" + tr("Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.") + "#1#%"; + client_sock->write(end_packet.toUtf8()); timer->setInterval(0); } } -- cgit From 9707753777c9a7d5ea429391f307201fde11db27 Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Tue, 30 Mar 2021 22:10:29 -0500 Subject: Update src/demoserver.cpp Co-authored-by: oldmud0 --- src/demoserver.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index fe296e6..764cf22 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -218,7 +218,6 @@ void DemoServer::handle_packet(AOPacket packet) client_sock->write(QString::number(max_wait).toUtf8()); packet = " " + tr("milliseconds.") + "#1#%"; client_sock->write(packet.toUtf8()); - } } } else if (contents[1].startsWith("/min_wait")) -- cgit From 79d1abb48ecaa68940d5c72f34e67c9b97f25bfb Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 19 Apr 2021 23:08:20 +0300 Subject: Add a /reload command that quickly reloads the current demo --- src/demoserver.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 764cf22..866f32d 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -220,6 +220,12 @@ void DemoServer::handle_packet(AOPacket packet) client_sock->write(packet.toUtf8()); } } + else if (contents[1].startsWith("/reload")) + { + load_demo(p_path); + QString packet = "CT#DEMO#" + tr("Current demo file reloaded. Send /play or > in OOC to begin playback.") + "#1#%"; + client_sock->write(packet.toUtf8()); + } else if (contents[1].startsWith("/min_wait")) { QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%"; @@ -227,7 +233,7 @@ void DemoServer::handle_packet(AOPacket packet) } else if (contents[1].startsWith("/help")) { - QString packet = "CT#DEMO#" + tr("Available commands:\nload, play, pause, max_wait, help") + "#1#%"; + QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%"; client_sock->write(packet.toUtf8()); } } -- cgit From 86b342badcbf15469fc827a7fbec5baf8be8fa30 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 20 Apr 2021 15:08:24 +0300 Subject: Reset timers, evidence list and background whenever /load or /reload is used --- src/demoserver.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 866f32d..8b82d75 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -162,6 +162,23 @@ void DemoServer::handle_packet(AOPacket packet) load_demo(path); QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%"; client_sock->write(packet.toUtf8()); + // Reset evidence list + client_sock->write("LE##%"); + // Reset timers + client_sock->write("TI#0#3#0#%"); + client_sock->write("TI#0#1#0#%"); + client_sock->write("TI#1#1#0#%"); + client_sock->write("TI#1#3#0#%"); + client_sock->write("TI#2#1#0#%"); + client_sock->write("TI#2#3#0#%"); + client_sock->write("TI#3#1#0#%"); + client_sock->write("TI#3#3#0#%"); + client_sock->write("TI#4#1#0#%"); + client_sock->write("TI#4#3#0#%"); + // Set the BG to default (also breaks up the message queue) + client_sock->write("BN#default#wit#%"); + // Stop the wait packet timer + timer->stop(); } else if (contents[1].startsWith("/play") || contents[1] == ">") { @@ -225,6 +242,23 @@ void DemoServer::handle_packet(AOPacket packet) load_demo(p_path); QString packet = "CT#DEMO#" + tr("Current demo file reloaded. Send /play or > in OOC to begin playback.") + "#1#%"; client_sock->write(packet.toUtf8()); + // Reset evidence list + client_sock->write("LE##%"); + // Reset timers + client_sock->write("TI#0#3#0#%"); + client_sock->write("TI#0#1#0#%"); + client_sock->write("TI#1#1#0#%"); + client_sock->write("TI#1#3#0#%"); + client_sock->write("TI#2#1#0#%"); + client_sock->write("TI#2#3#0#%"); + client_sock->write("TI#3#1#0#%"); + client_sock->write("TI#3#3#0#%"); + client_sock->write("TI#4#1#0#%"); + client_sock->write("TI#4#3#0#%"); + // Set the BG to default (also breaks up the message queue) + client_sock->write("BN#default#wit#%"); + // Stop the wait packet timer + timer->stop(); } else if (contents[1].startsWith("/min_wait")) { @@ -245,8 +279,11 @@ void DemoServer::load_demo(QString filename) demo_file.open(QIODevice::ReadOnly); if (!demo_file.isOpen()) return; + // Clear demo data demo_data.clear(); + // Set the demo filepath p_path = filename; + // Process the demo file QTextStream demo_stream(&demo_file); demo_stream.setCodec("UTF-8"); QString line = demo_stream.readLine(); -- cgit From 7b058d1401ddc1721304516f5cc7cdbdb15fee5d Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Wed, 21 Apr 2021 02:14:49 +0300 Subject: Fix last line in the .demo file not being processed Fix timings for OOC being really busted if max_wait is -1 (dunno at which point this bug was introduced) --- src/demoserver.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 764cf22..09741fd 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -264,22 +264,26 @@ void DemoServer::playback() if (current_packet.startsWith("MS#")) elapsed_time = 0; - while (!current_packet.startsWith("wait") && !demo_data.isEmpty()) { + while (!current_packet.startsWith("wait#")) { client_sock->write(current_packet.toUtf8()); + if (demo_data.isEmpty()) + break; current_packet = demo_data.dequeue(); } if (!demo_data.isEmpty()) { AOPacket wait_packet = AOPacket(current_packet); int duration = wait_packet.get_contents().at(0).toInt(); - if (max_wait != -1 && duration + elapsed_time > max_wait) { - duration = qMax(0, max_wait - elapsed_time); - // Skip the difference on the timers - emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); - } - else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) { - duration = qMax(0, timer->interval() - elapsed_time); + if (max_wait != -1) { + if (duration + elapsed_time > max_wait) { + duration = qMax(0, max_wait - elapsed_time); + // Skip the difference on the timers emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); + } + else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) { + duration = qMax(0, timer->interval() - elapsed_time); + emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); + } } elapsed_time += duration; timer->start(duration); -- cgit From 43340e88695b2adc7b8fc8141540178727fd8869 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Thu, 22 Apr 2021 23:46:55 -0500 Subject: move timer reset to its own method --- src/demoserver.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 8b82d75..b9721bf 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -164,17 +164,7 @@ void DemoServer::handle_packet(AOPacket packet) client_sock->write(packet.toUtf8()); // Reset evidence list client_sock->write("LE##%"); - // Reset timers - client_sock->write("TI#0#3#0#%"); - client_sock->write("TI#0#1#0#%"); - client_sock->write("TI#1#1#0#%"); - client_sock->write("TI#1#3#0#%"); - client_sock->write("TI#2#1#0#%"); - client_sock->write("TI#2#3#0#%"); - client_sock->write("TI#3#1#0#%"); - client_sock->write("TI#3#3#0#%"); - client_sock->write("TI#4#1#0#%"); - client_sock->write("TI#4#3#0#%"); + reset_all_timers(); // Set the BG to default (also breaks up the message queue) client_sock->write("BN#default#wit#%"); // Stop the wait packet timer @@ -244,17 +234,7 @@ void DemoServer::handle_packet(AOPacket packet) client_sock->write(packet.toUtf8()); // Reset evidence list client_sock->write("LE##%"); - // Reset timers - client_sock->write("TI#0#3#0#%"); - client_sock->write("TI#0#1#0#%"); - client_sock->write("TI#1#1#0#%"); - client_sock->write("TI#1#3#0#%"); - client_sock->write("TI#2#1#0#%"); - client_sock->write("TI#2#3#0#%"); - client_sock->write("TI#3#1#0#%"); - client_sock->write("TI#3#3#0#%"); - client_sock->write("TI#4#1#0#%"); - client_sock->write("TI#4#3#0#%"); + reset_all_timers(); // Set the BG to default (also breaks up the message queue) client_sock->write("BN#default#wit#%"); // Stop the wait packet timer @@ -297,6 +277,20 @@ void DemoServer::load_demo(QString filename) } } +void DemoServer::reset_all_timers() +{ + client_sock->write("TI#0#3#0#%"); + client_sock->write("TI#0#1#0#%"); + client_sock->write("TI#1#1#0#%"); + client_sock->write("TI#1#3#0#%"); + client_sock->write("TI#2#1#0#%"); + client_sock->write("TI#2#3#0#%"); + client_sock->write("TI#3#1#0#%"); + client_sock->write("TI#3#3#0#%"); + client_sock->write("TI#4#1#0#%"); + client_sock->write("TI#4#3#0#%"); +} + void DemoServer::playback() { if (demo_data.isEmpty()) -- cgit From 9fbe899c0e6ff464d91c2b2171eebb8fb879facb Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 23 Apr 2021 09:55:04 +0300 Subject: Automatically fix desynced demo files with issues pre-#496 PR (#532) * Implement a demo auto-fixing solution. If the client detects a pre-2.9.1 demo file, it will prompt the user if they wish to correct it, since otherwise the demo will be desynched from reality. The aforementioned issue was fixed in https://github.com/AttorneyOnline/AO2-Client/pull/496 however 2.9.0 still has incorrect demo recording. Fix potential memory leak by not flushing and closing the demo file after opening it for reading. * backup broken demo file before fixing it * comments ahoy Co-authored-by: in1tiate --- src/demoserver.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 09741fd..d6927a5 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -252,6 +252,56 @@ void DemoServer::load_demo(QString filename) demo_data.enqueue(line); line = demo_stream.readLine(); } + demo_file.flush(); + demo_file.close(); + + // No-shenanigans 2.9.0 demo file with the dreaded demo desync bug detected https://github.com/AttorneyOnline/AO2-Client/pull/496 + // If we don't start with the SC packet this means user-edited weirdo shenanigans. Don't screw around with those. + if (demo_data.head().startsWith("SC#") && demo_data.last().startsWith("wait#")) { + qDebug() << "Loaded a broken pre-2.9.1 demo file, with the wait desync issue!"; + QMessageBox *msgBox = new QMessageBox; + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setTextFormat(Qt::RichText); + msgBox->setText("This appears to be a broken pre-2.9.1 demo file with the wait desync issue!
Do you want to correct this file? If you refuse, this demo will be desynchronized!"); + msgBox->setWindowTitle("Pre-2.9.1 demo detected!"); + msgBox->setStandardButtons(QMessageBox::NoButton); + QTimer::singleShot(2000, msgBox, std::bind(&QMessageBox::setStandardButtons,msgBox,QMessageBox::Yes|QMessageBox::No)); + int ret = msgBox->exec(); + QQueue p_demo_data; + switch (ret) { + case QMessageBox::Yes: + qDebug() << "Making a backup of the broken demo..."; + QFile::copy(filename, filename + ".backup"); + while (!demo_data.isEmpty()) { + QString current_packet = demo_data.dequeue(); + // TODO: faster way of doing this, maybe with QtConcurrent's MapReduce methods? + if (!current_packet.startsWith("SC#") && current_packet.startsWith("wait#")) { + p_demo_data.insert(qMax(1, p_demo_data.size()-1), current_packet); + continue; + } + p_demo_data.enqueue(current_packet); + } + if (demo_file.open(QIODevice::WriteOnly | QIODevice::Text | + QIODevice::Truncate)) { + QTextStream out(&demo_file); + out.setCodec("UTF-8"); + out << p_demo_data.dequeue(); + for (QString line : p_demo_data) { + out << "\n" << line; + } + demo_file.flush(); + demo_file.close(); + } + load_demo(filename); + break; + case QMessageBox::No: + // No was clicked + break; + default: + // should never be reached + break; + } + } } void DemoServer::playback() -- cgit From 60daac3823735dace691f7a065c3759dc535f60a Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Fri, 23 Apr 2021 14:29:16 -0500 Subject: Move other duplicate reset calls to their own method --- src/demoserver.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/demoserver.cpp') diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 5a0d579..ee0fcf2 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -162,13 +162,7 @@ void DemoServer::handle_packet(AOPacket packet) load_demo(path); QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%"; client_sock->write(packet.toUtf8()); - // Reset evidence list - client_sock->write("LE##%"); - reset_all_timers(); - // Set the BG to default (also breaks up the message queue) - client_sock->write("BN#default#wit#%"); - // Stop the wait packet timer - timer->stop(); + reset_state(); } else if (contents[1].startsWith("/play") || contents[1] == ">") { @@ -232,13 +226,7 @@ void DemoServer::handle_packet(AOPacket packet) load_demo(p_path); QString packet = "CT#DEMO#" + tr("Current demo file reloaded. Send /play or > in OOC to begin playback.") + "#1#%"; client_sock->write(packet.toUtf8()); - // Reset evidence list - client_sock->write("LE##%"); - reset_all_timers(); - // Set the BG to default (also breaks up the message queue) - client_sock->write("BN#default#wit#%"); - // Stop the wait packet timer - timer->stop(); + reset_state(); } else if (contents[1].startsWith("/min_wait")) { @@ -327,8 +315,12 @@ void DemoServer::load_demo(QString filename) } } -void DemoServer::reset_all_timers() +void DemoServer::reset_state() { + // Reset evidence list + client_sock->write("LE##%"); + + // Reset timers client_sock->write("TI#0#3#0#%"); client_sock->write("TI#0#1#0#%"); client_sock->write("TI#1#1#0#%"); @@ -339,6 +331,12 @@ void DemoServer::reset_all_timers() client_sock->write("TI#3#3#0#%"); client_sock->write("TI#4#1#0#%"); client_sock->write("TI#4#3#0#%"); + + // Set the BG to default (also breaks up the message queue) + client_sock->write("BN#default#wit#%"); + + // Stop the wait packet timer + timer->stop(); } void DemoServer::playback() -- cgit