From 79d1abb48ecaa68940d5c72f34e67c9b97f25bfb Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 19 Apr 2021 23:08:20 +0300 Subject: [PATCH 1/4] Add a /reload command that quickly reloads the current demo --- src/demoserver.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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()); } } From 86b342badcbf15469fc827a7fbec5baf8be8fa30 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 20 Apr 2021 15:08:24 +0300 Subject: [PATCH 2/4] Reset timers, evidence list and background whenever /load or /reload is used --- src/demoserver.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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(); From 43340e88695b2adc7b8fc8141540178727fd8869 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Thu, 22 Apr 2021 23:46:55 -0500 Subject: [PATCH 3/4] move timer reset to its own method --- include/demoserver.h | 1 + src/demoserver.cpp | 38 ++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/include/demoserver.h b/include/demoserver.h index 3dc645b..0d4f0e4 100644 --- a/include/demoserver.h +++ b/include/demoserver.h @@ -24,6 +24,7 @@ public: private: void handle_packet(AOPacket packet); void load_demo(QString filename); + void reset_all_timers(); QTcpServer* tcp_server; QTcpSocket* client_sock = nullptr; 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()) From 60daac3823735dace691f7a065c3759dc535f60a Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Fri, 23 Apr 2021 14:29:16 -0500 Subject: [PATCH 4/4] Move other duplicate reset calls to their own method --- include/demoserver.h | 2 +- src/demoserver.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/demoserver.h b/include/demoserver.h index e5d5712..cadc52d 100644 --- a/include/demoserver.h +++ b/include/demoserver.h @@ -25,7 +25,7 @@ public: private: void handle_packet(AOPacket packet); void load_demo(QString filename); - void reset_all_timers(); + void reset_state(); QTcpServer* tcp_server; QTcpSocket* client_sock = nullptr; 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()