From 29f90f210a6adcaa818c718ff7fbdbd87796793c Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 14:14:19 -0600 Subject: [PATCH 1/3] add network based authentication --- include/aoapplication.h | 1 + include/courtroom.h | 1 + src/courtroom.cpp | 18 +++++++++++++++++- src/packet_distribution.cpp | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 2dc8649d6..9fa8c7502 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -87,6 +87,7 @@ class AOApplication : public QApplication { bool effects_enabled = false; bool y_offset_enabled = false; bool expanded_desk_mods_enabled = false; + bool auth_packet_enabled = false; ///////////////loading info/////////////////// diff --git a/include/courtroom.h b/include/courtroom.h index 6a64deb27..1772a978f 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -798,6 +798,7 @@ public slots: void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); void on_reload_theme_clicked(); + void on_authentication_state_received(bool p_state); private slots: void start_chat_ticking(); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index a89b81431..1259d8d31 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1634,15 +1634,31 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, color = ao_app->get_color("server_chatlog_sender_color", "courtroom_fonts.ini") .name(); - if (p_message == "Logged in as a moderator.") { + if (!auth_packet_enabled && p_message == "Logged in as a moderator.") { ui_guard->show(); append_server_chatmessage( tr("CLIENT"), tr("You were granted the Disable Modcalls button."), "1"); } + ui_server_chatlog->append_chatmessage(p_name, p_message, color); } +void Courtroom::on_authentication_state_received(int p_state) +{ + if (p_state >= 1) { + ui_guard->show(); + append_server_chatmessage(tr("CLIENT"), tr("You were granted the Disable Modcalls button."), "1"); + } + else if (p_state == 0) { + append_server_chatmessage(tr("CLIENT"), tr("Login unsuccessful."), "1"); + } + else if (p_state < 0) { + ui_guard->hide(); + append_server_chatmessate(tr("CLIENT"), tr("You were logged out."), "1"); + } +} + void Courtroom::on_chat_return_pressed() { if (is_muted) diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index ea4c77aab..f2e5a403a 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -199,6 +199,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) additive_enabled = false; effects_enabled = false; expanded_desk_mods_enabled = false; + auth_packet_enabled = false; if (f_packet.contains("yellowtext", Qt::CaseInsensitive)) yellow_text_enabled = true; if (f_packet.contains("prezoom", Qt::CaseInsensitive)) @@ -229,6 +230,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) y_offset_enabled = true; if (f_packet.contains("expanded_desk_mods", Qt::CaseInsensitive)) expanded_desk_mods_enabled = true; + if (f_packet.contains("auth_packet", Qt::CaseInsensitive)) + auth_packet_enabled = true; } else if (header == "PN") { if (f_contents.size() < 2) @@ -683,6 +686,14 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (f_contents.size() > 1 && f_contents.at(1) == "1") w_courtroom->on_reload_theme_clicked(); } + // Auth packet + else if (header == "AUTH") { + if (!courtroom_constructed || !auth_packet_enabled) + goto end; + int authenticated = f_contents.at(0).toInt(); + + w_courtroom->on_authentication_state_received(authenticated); + } end: From bdb1e8f5d4bc625186f851510a4e08d9973e4efb Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 14:39:55 -0600 Subject: [PATCH 2/3] fixes --- include/courtroom.h | 3 ++- src/courtroom.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 1772a978f..9766c7bf6 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -312,6 +312,8 @@ class Courtroom : public QMainWindow { // Truncates text so it fits within theme-specified boundaries and sets the tooltip to the full string void truncate_label_text(QWidget* p_widget, QString p_identifier); + void on_authentication_state_received(int p_state); + ~Courtroom(); private: AOApplication *ao_app; @@ -798,7 +800,6 @@ public slots: void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); void on_reload_theme_clicked(); - void on_authentication_state_received(bool p_state); private slots: void start_chat_ticking(); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 1259d8d31..c3df565f6 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1634,7 +1634,7 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, color = ao_app->get_color("server_chatlog_sender_color", "courtroom_fonts.ini") .name(); - if (!auth_packet_enabled && p_message == "Logged in as a moderator.") { + if (!ao_app->auth_packet_enabled && p_message == "Logged in as a moderator.") { ui_guard->show(); append_server_chatmessage( tr("CLIENT"), tr("You were granted the Disable Modcalls button."), "1"); @@ -1655,7 +1655,7 @@ void Courtroom::on_authentication_state_received(int p_state) } else if (p_state < 0) { ui_guard->hide(); - append_server_chatmessate(tr("CLIENT"), tr("You were logged out."), "1"); + append_server_chatmessage(tr("CLIENT"), tr("You were logged out."), "1"); } } From 916fcf406b6dc8d70dc19b1ee9ccb3b579b5efee Mon Sep 17 00:00:00 2001 From: in1tiate <32779090+in1tiate@users.noreply.github.com> Date: Wed, 10 Mar 2021 03:52:53 -0600 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: oldmud0 --- src/courtroom.cpp | 5 ++--- src/packet_distribution.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index c3df565f6..d68038c11 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1635,9 +1635,8 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, ao_app->get_color("server_chatlog_sender_color", "courtroom_fonts.ini") .name(); if (!ao_app->auth_packet_enabled && p_message == "Logged in as a moderator.") { - ui_guard->show(); - append_server_chatmessage( - tr("CLIENT"), tr("You were granted the Disable Modcalls button."), "1"); + // Emulate successful authentication + on_authentication_state_received(1); } diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index f2e5a403a..e8f98e17b 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -688,7 +688,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) } // Auth packet else if (header == "AUTH") { - if (!courtroom_constructed || !auth_packet_enabled) + if (!courtroom_constructed || !auth_packet_enabled || f_contents.size() < 1) goto end; int authenticated = f_contents.at(0).toInt();