diff options
| author | oldmud0 <oldmud0@users.noreply.github.com> | 2021-01-19 10:02:31 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-19 10:02:31 -0600 |
| commit | e097df09adc365db948858d2ab3bfff0f07e1143 (patch) | |
| tree | 39ea2ed35b536bdd5a06141398eb3bc379fccd09 /src/packet_distribution.cpp | |
| parent | 0926f3c15842a71002c0ec374fd54832469036d8 (diff) | |
| parent | 1b016ddf91cb8b065215d046e7e0b4064b5d8633 (diff) | |
Merge pull request #384 from AttorneyOnline/feature/timerclock
Countdown timer
Diffstat (limited to 'src/packet_distribution.cpp')
| -rw-r--r-- | src/packet_distribution.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 822b2dc9..2da6981c 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -260,7 +260,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 = ""; @@ -604,6 +604,60 @@ 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() < 2) + goto end; + + // Timer ID is reserved as argument 0 + int id = f_contents.at(0).toInt(); + + // 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 == 0) + { + timer_value -= latency / 2; + w_courtroom->start_clock(id, timer_value); + } + else + { + w_courtroom->pause_clock(id); + w_courtroom->set_clock(id, timer_value); + } + } + else + { + w_courtroom->stop_clock(id); + } + } + else if (type == 2) + w_courtroom->set_clock_visibility(id, true); + else if (type == 3) + w_courtroom->set_clock_visibility(id, false); + } + else if (header == "CHECK") { + if (!courtroom_constructed) + goto end; + + qint64 ping_time = w_courtroom->pong(); + qDebug() << "ping:" << ping_time; + if (ping_time != -1) + latency = ping_time; + } end: |
