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
This commit is contained in:
Crystalwarrior 2020-08-25 12:18:49 +03:00
parent f27f210efe
commit febfbeafc1
4 changed files with 21 additions and 6 deletions

View File

@ -61,6 +61,9 @@ public:
void call_settings_menu(); void call_settings_menu();
void call_announce_menu(Courtroom *court); void call_announce_menu(Courtroom *court);
qint64 last_ping;
QString window_title;
/////////////////server metadata////////////////// /////////////////server metadata//////////////////
unsigned int s_decryptor = 5; unsigned int s_decryptor = 5;

View File

@ -57,7 +57,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QTextBoundaryFinder> #include <QTextBoundaryFinder>
#include <QTextCharFormat> #include <QTextCharFormat>
//#include <QRandomGenerator> #include <QElapsedTimer>
#include <stack> #include <stack>
@ -251,6 +251,8 @@ public:
void check_connection_received(); void check_connection_received();
qint64 get_ping() { return ping_timer.elapsed(); }
~Courtroom(); ~Courtroom();
private: private:
@ -299,11 +301,15 @@ private:
QVector<chatlogpiece> ic_chatlog_history; QVector<chatlogpiece> ic_chatlog_history;
// triggers ping_server() every 60 seconds // triggers ping_server() every 1 second
QTimer *keepalive_timer; QTimer *keepalive_timer;
// determines how fast messages tick onto screen // determines how fast messages tick onto screen
QTimer *chat_tick_timer; QTimer *chat_tick_timer;
// count up timer to check how long it took for us to get a response from ping_server()
QElapsedTimer ping_timer;
// int chat_tick_interval = 60; // int chat_tick_interval = 60;
// which tick position(character in chat message) we are at // which tick position(character in chat message) we are at
int tick_pos = 0; int tick_pos = 0;

View File

@ -8,7 +8,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000)); qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000));
keepalive_timer = new QTimer(this); keepalive_timer = new QTimer(this);
keepalive_timer->start(60000); keepalive_timer->start(1000);
chat_tick_timer = new QTimer(this); chat_tick_timer = new QTimer(this);
@ -623,7 +623,6 @@ void Courtroom::set_widgets()
ui_music_display->set_play_once(false); ui_music_display->set_play_once(false);
set_size_and_pos(ui_clock, "clock"); set_size_and_pos(ui_clock, "clock");
ui_clock->start(30000);
if (is_ao2_bg) { if (is_ao2_bg) {
set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message");
@ -4672,6 +4671,7 @@ void Courtroom::on_switch_area_music_clicked()
void Courtroom::ping_server() void Courtroom::ping_server()
{ {
ping_timer.start();
ao_app->send_server_packet( ao_app->send_server_packet(
new AOPacket("CH#" + QString::number(m_cid) + "#%")); new AOPacket("CH#" + QString::number(m_cid) + "#%"));
} }

View File

@ -116,7 +116,13 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
qDebug() << "R:" << f_packet; qDebug() << "R:" << f_packet;
#endif #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) if (f_contents.size() == 0)
goto end; goto end;
@ -250,7 +256,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
courtroom_loaded = false; courtroom_loaded = false;
QString window_title = tr("Attorney Online 2"); window_title = tr("Attorney Online 2");
int selected_server = w_lobby->get_selected_server(); int selected_server = w_lobby->get_selected_server();
QString server_address = "", server_name = ""; QString server_address = "", server_name = "";