From febfbeafc11ecad57d6e9a06575c28f1b13da8da Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:18:49 +0300 Subject: Actually make use of the completely useless CHECK and CH keepalive timer and use them to determine the client's ping. Display ping in the application window title. keepalive timer now fires every second instead of every minute Remove meme clock starting on set_widgets() implement get_ping() on w_courtroom --- src/packet_distribution.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index e4e5d5c2..9422cfdb 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -116,7 +116,13 @@ void AOApplication::server_packet_received(AOPacket *p_packet) qDebug() << "R:" << f_packet; #endif - if (header == "decryptor") { + if (header == "CHECK") { + if (courtroom_constructed) { + last_ping = w_courtroom->get_ping(); + w_courtroom->set_window_title(window_title + " [ping:" + QString::number(last_ping) + "]"); + } + } + else if (header == "decryptor") { if (f_contents.size() == 0) goto end; @@ -250,7 +256,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) courtroom_loaded = false; - QString window_title = tr("Attorney Online 2"); + window_title = tr("Attorney Online 2"); int selected_server = w_lobby->get_selected_server(); QString server_address = "", server_name = ""; -- cgit From 7e9c5726e02a65023d9563f49e833525bf8f4bae Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:21:10 +0300 Subject: Introduce the timer packet - "TI". This timer will start the clock accounting for latency! Cool, right? Remove useless qDebug() for music looping --- src/packet_distribution.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 9422cfdb..1f49719f 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -728,6 +728,17 @@ void AOApplication::server_packet_received(AOPacket *p_packet) f_contents.at(4) == "1", f_contents.at(5) == "1"); } + else if (header == "TI") { // Timer packet + if (courtroom_constructed && f_contents.size() >= 1) { + qint64 resolution = f_contents.at(0).toInt(); + qDebug() << "timer" << resolution << last_ping << resolution - last_ping; + resolution = resolution - last_ping; + if (resolution > 0) + w_courtroom->start_clock(resolution); + else + w_courtroom->stop_clock(); + } + } end: -- cgit From ee3bad44c72329d61a2cb0c4064c22512451372d Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:48:09 +0300 Subject: Implement clock pausing Implement clock setting w/o starting or stopping Both of these should make it possible for the server to start/stop/pause/resume the clock with perfect synchronization to the true time. --- src/packet_distribution.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 1f49719f..578f6df0 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -729,12 +729,25 @@ void AOApplication::server_packet_received(AOPacket *p_packet) f_contents.at(5) == "1"); } else if (header == "TI") { // Timer packet - if (courtroom_constructed && f_contents.size() >= 1) { + if (courtroom_constructed && f_contents.size() > 0) { qint64 resolution = f_contents.at(0).toInt(); + //Type 0 = start/stop timer + //Type 1 = pause timer + int type = 0; + if (f_contents.size() > 1) + type = f_contents.at(1).toInt(); qDebug() << "timer" << resolution << last_ping << resolution - last_ping; resolution = resolution - last_ping; if (resolution > 0) - w_courtroom->start_clock(resolution); + { + if (type == 1) + { + w_courtroom->pause_clock(); + w_courtroom->set_clock(resolution); + } + else + w_courtroom->start_clock(resolution); + } else w_courtroom->stop_clock(); } -- cgit From 610510eb7b13475f0625d69e9a8e2b1d14669198 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 13:00:00 +0300 Subject: move "check" to the very end instead of very start in packet_distribution --- src/packet_distribution.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 578f6df0..e0a6ccbc 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -116,13 +116,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) qDebug() << "R:" << f_packet; #endif - if (header == "CHECK") { - if (courtroom_constructed) { - last_ping = w_courtroom->get_ping(); - w_courtroom->set_window_title(window_title + " [ping:" + QString::number(last_ping) + "]"); - } - } - else if (header == "decryptor") { + if (header == "decryptor") { if (f_contents.size() == 0) goto end; @@ -752,6 +746,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->stop_clock(); } } + else if (header == "CHECK") { + if (courtroom_constructed) { + last_ping = w_courtroom->get_ping(); + w_courtroom->set_window_title(window_title + " [ping:" + QString::number(last_ping) + "]"); + } + } end: -- cgit From de3533fbf2615a40efc60c9ed2e96f1a3b5da3c1 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sat, 9 Jan 2021 01:18:19 -0600 Subject: Rework timer and ping logic The timer's time as received by the server is clarified to be the actual numerical time, in milliseconds, to be shown on the clock. --- src/packet_distribution.cpp | 59 +++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index e0a6ccbc..17e57bf7 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -723,34 +723,57 @@ void AOApplication::server_packet_received(AOPacket *p_packet) f_contents.at(5) == "1"); } else if (header == "TI") { // Timer packet - if (courtroom_constructed && f_contents.size() > 0) { - qint64 resolution = f_contents.at(0).toInt(); - //Type 0 = start/stop timer - //Type 1 = pause timer - int type = 0; - if (f_contents.size() > 1) - type = f_contents.at(1).toInt(); - qDebug() << "timer" << resolution << last_ping << resolution - last_ping; - resolution = resolution - last_ping; - if (resolution > 0) + if (!courtroom_constructed || f_contents.size() < 2) + goto end; + + // Note: timer ID is reserved as argument 0 + + // Type 0 = start/resume/sync timer at time + // Type 1 = pause timer at time + // Type 2 = show timer + // Type 3 = hide timer + int type = f_contents.at(1).toInt(); + + if (type == 0 || type == 1) + { + if (f_contents.size() < 2) + goto end; + + // The time as displayed on the clock, in milliseconds. + // If the number received is negative, stop the timer. + qint64 timer_value = f_contents.at(2).toLongLong(); + qDebug() << "timer:" << timer_value; + if (timer_value > 0) { - if (type == 1) + if (type == 0) { - w_courtroom->pause_clock(); - w_courtroom->set_clock(resolution); + timer_value -= latency / 2; + w_courtroom->start_clock(timer_value); } else - w_courtroom->start_clock(resolution); + { + w_courtroom->pause_clock(); + w_courtroom->set_clock(timer_value); + } } else + { w_courtroom->stop_clock(); + } } + else if (type == 2) + w_courtroom->set_clock_visibility(true); + else if (type == 3) + w_courtroom->set_clock_visibility(false); } else if (header == "CHECK") { - if (courtroom_constructed) { - last_ping = w_courtroom->get_ping(); - w_courtroom->set_window_title(window_title + " [ping:" + QString::number(last_ping) + "]"); - } + if (!courtroom_constructed) + goto end; + + qint64 ping_time = w_courtroom->pong(); + qDebug() << "ping:" << ping_time; + if (ping_time != -1) + latency = ping_time; } end: -- cgit From 45c78ea5caf58b6b8494decc6021540c755fabd7 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 11 Jan 2021 17:38:08 +0300 Subject: Add "id" variable to the clock functions and properly parse the ID Implement scalable maximum clock count, right now it's at 5 clocks a theme can have max Theme "clock_" starts from 1 instead of 0 since users don't know when stuff starts at index 0 TODO: testing lol --- src/packet_distribution.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 0bc38141..2699f08f 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -578,7 +578,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed || f_contents.size() < 2) goto end; - // Note: timer ID is reserved as argument 0 + // Timer ID is reserved as argument 0 + int id = f_contents.at(0).toInt(); + + // ID is invalid + if (id < 0 || id >= w_courtroom->max_clocks) + goto end; // Type 0 = start/resume/sync timer at time // Type 1 = pause timer at time @@ -600,23 +605,23 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (type == 0) { timer_value -= latency / 2; - w_courtroom->start_clock(timer_value); + w_courtroom->start_clock(id, timer_value); } else { - w_courtroom->pause_clock(); - w_courtroom->set_clock(timer_value); + w_courtroom->pause_clock(id); + w_courtroom->set_clock(id, timer_value); } } else { - w_courtroom->stop_clock(); + w_courtroom->stop_clock(id); } } else if (type == 2) - w_courtroom->set_clock_visibility(true); + w_courtroom->set_clock_visibility(id, true); else if (type == 3) - w_courtroom->set_clock_visibility(false); + w_courtroom->set_clock_visibility(id, false); } else if (header == "CHECK") { if (!courtroom_constructed) -- cgit From 07993a621b046985ee39ddef1427d8b4cc6042b1 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 12 Jan 2021 12:02:07 +0300 Subject: Better place to check invalid ID's --- src/packet_distribution.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/packet_distribution.cpp') diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 4aae789e..6865987c 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -583,10 +583,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet) // Timer ID is reserved as argument 0 int id = f_contents.at(0).toInt(); - // ID is invalid - if (id < 0 || id >= w_courtroom->max_clocks) - goto end; - // Type 0 = start/resume/sync timer at time // Type 1 = pause timer at time // Type 2 = show timer -- cgit