From 11250e13864dc5e3cdd799b02498905c58db55ea Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 06:50:19 -0500 Subject: [PATCH 1/7] Ensure consistent behavior in IC log, clarify showname logic, and define constants for minimum and maximum packet sizes --- include/courtroom.h | 6 ++++-- src/courtroom.cpp | 34 +++++++++++++++------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 182c2a6..6132ed9 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -349,8 +349,10 @@ private: // amount by which we multiply the delay when we parse punctuation chars const int punctuation_modifier = 3; - static const int chatmessage_size = 30; - QString m_chatmessage[chatmessage_size]; + // Minumum and maximum number of parameters in the MS packet + static const int MS_MINIMUM = 15; + static const int MS_MAXIMUM = 30; + QString m_chatmessage[MS_MAXIMUM]; bool chatmessage_is_empty = false; QString previous_ic_message = ""; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 98b6a9c..5f7a613 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1765,19 +1765,16 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) // Instead of checking for whether a message has at least chatmessage_size // amount of packages, we'll check if it has at least 15. // That was the original chatmessage_size. - if (p_contents->size() < 15) + if (p_contents->size() < MS_MINIMUM) return; - for (int n_string = 0; n_string < chatmessage_size; ++n_string) { - // m_chatmessage[n_string] = p_contents->at(n_string); - + for (int n_string = 0; n_string < MS_MAXIMUM; ++n_string) { // Note that we have added stuff that vanilla clients and servers simply // won't send. So now, we have to check if the thing we want even exists // amongst the packet's content. We also have to check if the server even // supports CCCC's IC features, or if it's just japing us. Also, don't // forget! A size 15 message will have indices from 0 to 14. - if (n_string < p_contents->size() && - (n_string < 15 || ao_app->cccc_ic_support_enabled)) { + if (n_string < p_contents->size() && (n_string < MS_MINIMUM || ao_app->cccc_ic_support_enabled)) { m_chatmessage[n_string] = p_contents->at(n_string); } else { @@ -1786,27 +1783,26 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) } int f_char_id = m_chatmessage[CHAR_ID].toInt(); + const bool is_spectator = (f_char_id == -1); - if (f_char_id >= 0 && f_char_id >= char_list.size()) + if (f_char_id >= char_list.size()) return; - if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) return; - QString f_showname; - if (f_char_id > -1 && - (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) { - f_showname = ao_app->get_showname(char_list.at(f_char_id).name); + QString f_displayname; + if (!is_spectator && (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) { + f_displayname = ao_app->get_showname(char_list.at(f_char_id).name); } else { - f_showname = m_chatmessage[SHOWNAME]; + f_displayname = m_chatmessage[SHOWNAME]; } - if (f_showname.trimmed() - .isEmpty()) // Pure whitespace showname, get outta here. - f_showname = m_chatmessage[CHAR_NAME]; + // If chatblank is enabled, use the character's name for logs + if (f_displayname.trimmed().isEmpty()) + f_displayname = ao_app->get_showname(char_list.at(f_char_id).name); - QString f_message = f_showname + ": " + m_chatmessage[MESSAGE] + '\n'; + QString f_message = f_displayname + ": " + m_chatmessage[MESSAGE] + '\n'; // Remove undesired newline chars m_chatmessage[MESSAGE].remove("\n"); chatmessage_is_empty = @@ -1868,7 +1864,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) f_charname = ao_app->get_showname(char_list.at(f_char_id).name); chatlogpiece *temp = - new chatlogpiece(f_charname, f_showname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt()); + new chatlogpiece(f_charname, f_displayname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt()); ic_chatlog_history.append(*temp); if (ao_app->get_auto_logging_enabled()) ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); @@ -1878,7 +1874,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) ic_chatlog_history.removeFirst(); } - append_ic_text(m_chatmessage[MESSAGE], f_showname, "", m_chatmessage[TEXT_COLOR].toInt()); + append_ic_text(m_chatmessage[MESSAGE], f_displayname, "", m_chatmessage[TEXT_COLOR].toInt()); QString f_char = m_chatmessage[CHAR_NAME]; QString f_custom_theme = ao_app->get_char_shouts(f_char); From 079ce93b85ecc25e338d61614318fb6ed6cce696 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 07:06:53 -0500 Subject: [PATCH 2/7] Remove clientside doublepost checking --- src/courtroom.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 5f7a613..f26645f 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1792,9 +1792,11 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) QString f_displayname; if (!is_spectator && (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) { + // If the users is not a spectator and showname is disabled, use the character's name f_displayname = ao_app->get_showname(char_list.at(f_char_id).name); } else { + // Otherwise, use the showname f_displayname = m_chatmessage[SHOWNAME]; } @@ -1803,20 +1805,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) f_displayname = ao_app->get_showname(char_list.at(f_char_id).name); QString f_message = f_displayname + ": " + m_chatmessage[MESSAGE] + '\n'; - // Remove undesired newline chars - m_chatmessage[MESSAGE].remove("\n"); - chatmessage_is_empty = - m_chatmessage[MESSAGE] == " " || m_chatmessage[MESSAGE] == ""; - if (f_char_id >= 0 && !chatmessage_is_empty && - f_message == previous_ic_message) // Not a system message - return; - - if (f_char_id <= -1) - previous_ic_message = - ""; // System messages don't care about repeating themselves - else - previous_ic_message = f_message; bool ok; int objection_mod = m_chatmessage[OBJECTION_MOD].toInt( &ok, 10); // checks if its a custom obj. From 507180d164e2b96653522f81d737f9ef3d7b9483 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 08:37:12 -0500 Subject: [PATCH 3/7] Clean up logic in handle_chatmessage() --- src/courtroom.cpp | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index f26645f..3f72397 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1804,29 +1804,27 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) if (f_displayname.trimmed().isEmpty()) f_displayname = ao_app->get_showname(char_list.at(f_char_id).name); - QString f_message = f_displayname + ": " + m_chatmessage[MESSAGE] + '\n'; - - bool ok; - int objection_mod = m_chatmessage[OBJECTION_MOD].toInt( - &ok, 10); // checks if its a custom obj. + // Check if a custom objection is in use + int objection_mod = 0; QString custom_objection = ""; - if (!ok && m_chatmessage[OBJECTION_MOD].contains("4&")) { + if (m_chatmessage[OBJECTION_MOD].contains("4&")) { objection_mod = 4; - custom_objection = m_chatmessage[OBJECTION_MOD].split( - "4&")[1]; // takes the name of custom objection. + custom_objection = m_chatmessage[OBJECTION_MOD].split("4&")[1]; // takes the name of custom objection. + } + else{ + objection_mod = m_chatmessage[OBJECTION_MOD].toInt(); } - // Stop the chat arrow from animating - ui_vp_chat_arrow->stop(); + // Reset IC display + ui_vp_chat_arrow->stop(); text_state = 0; anim_state = 0; ui_vp_objection->stop(); chat_tick_timer->stop(); ui_vp_evidence_display->reset(); - // Hey, our message showed up! Cool! - if (m_chatmessage[MESSAGE] == ui_ic_chat_message->text().remove("\n") && - m_chatmessage[CHAR_ID].toInt() == m_cid) { + // Reset UI elements after client message gets sent + if (m_chatmessage[CHAR_ID].toInt() == m_cid) { ui_ic_chat_message->clear(); if (ui_additive->isChecked()) ui_ic_chat_message->insert(" "); @@ -1848,12 +1846,8 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) // Let the server handle actually checking if they're allowed to do this. is_additive = m_chatmessage[ADDITIVE].toInt() == 1; - QString f_charname = ""; - if (f_char_id >= 0) - f_charname = ao_app->get_showname(char_list.at(f_char_id).name); - chatlogpiece *temp = - new chatlogpiece(f_charname, f_displayname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt()); + new chatlogpiece(f_displayname, f_displayname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt()); ic_chatlog_history.append(*temp); if (ao_app->get_auto_logging_enabled()) ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); @@ -1888,26 +1882,17 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) // case 4 is AO2 only case 4: if (custom_objection != "") { - ui_vp_objection->play("custom_objections/" + custom_objection, f_char, - f_custom_theme, shout_stay_time); - objection_player->play("custom_objections/" + - custom_objection.split('.')[0], - f_char, f_custom_theme); + ui_vp_objection->play("custom_objections/" + custom_objection, f_char, f_custom_theme, shout_stay_time); + objection_player->play("custom_objections/" + custom_objection.split('.')[0], f_char, f_custom_theme); } else { - ui_vp_objection->play("custom", f_char, f_custom_theme, - shout_stay_time); + ui_vp_objection->play("custom", f_char, f_custom_theme, shout_stay_time); objection_player->play("custom", f_char, f_custom_theme); } break; - default: - qDebug() << "W: Logic error in objection switch statement!"; + m_chatmessage[EMOTE_MOD] = 1; } sfx_player->clear(); // Objection played! Cut all sfx. - int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); - - if (emote_mod == 0) - m_chatmessage[EMOTE_MOD] = 1; } else handle_chatmessage_2(); From 1c5b097f654d16e0dde47f7ae62d236427077cb7 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 12:43:26 -0500 Subject: [PATCH 4/7] further cleanup of chat handler --- include/courtroom.h | 2 ++ src/courtroom.cpp | 58 ++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index a4bacc2..ca271a4 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -648,6 +648,8 @@ private: void refresh_evidence(); void set_evidence_page(); + void reset_ic(); + void reset_ui(); public slots: void objection_done(); void preanim_done(); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 3b3f699..bc8405c 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1762,6 +1762,36 @@ void Courtroom::on_chat_return_pressed() ao_app->send_server_packet(new AOPacket("MS", packet_contents)); } +void Courtroom::reset_ic(){ + ui_vp_chat_arrow->stop(); + text_state = 0; + anim_state = 0; + ui_vp_objection->stop(); + chat_tick_timer->stop(); + ui_vp_evidence_display->reset(); +} + +void Courtroom::reset_ui(){ + if (m_chatmessage[CHAR_ID].toInt() == m_cid) { + ui_ic_chat_message->clear(); + if (ui_additive->isChecked()) + ui_ic_chat_message->insert(" "); + objection_state = 0; + realization_state = 0; + screenshake_state = 0; + is_presenting_evidence = false; + if (!ao_app->is_stickypres_enabled()) + ui_pre->setChecked(false); + ui_hold_it->set_image("holdit"); + ui_objection->set_image("objection"); + ui_take_that->set_image("takethat"); + ui_custom_objection->set_image("custom"); + ui_realization->set_image("realization"); + ui_screenshake->set_image("screenshake"); + ui_evidence_present->set_image("present"); + } +} + void Courtroom::handle_chatmessage(QStringList *p_contents) { // Instead of checking for whether a message has at least chatmessage_size @@ -1818,32 +1848,10 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) } // Reset IC display - ui_vp_chat_arrow->stop(); - text_state = 0; - anim_state = 0; - ui_vp_objection->stop(); - chat_tick_timer->stop(); - ui_vp_evidence_display->reset(); + reset_ic(); // Reset UI elements after client message gets sent - if (m_chatmessage[CHAR_ID].toInt() == m_cid) { - ui_ic_chat_message->clear(); - if (ui_additive->isChecked()) - ui_ic_chat_message->insert(" "); - objection_state = 0; - realization_state = 0; - screenshake_state = 0; - is_presenting_evidence = false; - if (!ao_app->is_stickypres_enabled()) - ui_pre->setChecked(false); - ui_hold_it->set_image("holdit"); - ui_objection->set_image("objection"); - ui_take_that->set_image("takethat"); - ui_custom_objection->set_image("custom"); - ui_realization->set_image("realization"); - ui_screenshake->set_image("screenshake"); - ui_evidence_present->set_image("present"); - } + reset_ui(); // Let the server handle actually checking if they're allowed to do this. is_additive = m_chatmessage[ADDITIVE].toInt() == 1; @@ -1870,7 +1878,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) color_rgb_list.append(color); } - append_ic_text(m_chatmessage[MESSAGE], f_showname, "", m_chatmessage[TEXT_COLOR].toInt()); + append_ic_text(m_chatmessage[MESSAGE], f_displayname, "", m_chatmessage[TEXT_COLOR].toInt()); // if an objection is used if (objection_mod <= 4 && objection_mod >= 1) { From 95725eb129f72231b0615a35cee2299c74c9a6a8 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 13:53:16 -0500 Subject: [PATCH 5/7] fix incorrect emote modifier --- src/courtroom.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index bc8405c..04a7960 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1613,7 +1613,7 @@ void Courtroom::on_chat_return_pressed() if (f_emote_mod == 0) f_emote_mod = 1; else if (f_emote_mod == 5 && ao_app->prezoom_enabled) - f_emote_mod = 4; + f_emote_mod = 6; } else { if (f_emote_mod == 1) @@ -1772,7 +1772,6 @@ void Courtroom::reset_ic(){ } void Courtroom::reset_ui(){ - if (m_chatmessage[CHAR_ID].toInt() == m_cid) { ui_ic_chat_message->clear(); if (ui_additive->isChecked()) ui_ic_chat_message->insert(" "); @@ -1789,7 +1788,6 @@ void Courtroom::reset_ui(){ ui_realization->set_image("realization"); ui_screenshake->set_image("screenshake"); ui_evidence_present->set_image("present"); - } } void Courtroom::handle_chatmessage(QStringList *p_contents) @@ -1851,7 +1849,9 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) reset_ic(); // Reset UI elements after client message gets sent - reset_ui(); + if (m_chatmessage[CHAR_ID].toInt() == m_cid) { + reset_ui(); + } // Let the server handle actually checking if they're allowed to do this. is_additive = m_chatmessage[ADDITIVE].toInt() == 1; From 3c031db2ea3bfe56072b32ce240875b597014c16 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 14:14:26 -0500 Subject: [PATCH 6/7] fix check for negative char_id --- src/courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 04a7960..943c2d4 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1815,7 +1815,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) int f_char_id = m_chatmessage[CHAR_ID].toInt(); const bool is_spectator = (f_char_id == -1); - if (f_char_id >= char_list.size()) + if (f_char_id < 0 || f_char_id >= char_list.size()) return; if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) return; From 4b7efc8536f4ea518eb43483e3805255f36ada75 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 16 Aug 2020 14:17:58 -0500 Subject: [PATCH 7/7] allow -1 charid for system messages --- src/courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 943c2d4..fa55ba8 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1815,7 +1815,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) int f_char_id = m_chatmessage[CHAR_ID].toInt(); const bool is_spectator = (f_char_id == -1); - if (f_char_id < 0 || f_char_id >= char_list.size()) + if (f_char_id < -1 || f_char_id >= char_list.size()) return; if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) return;