Ensure consistent behavior in IC log, clarify showname logic, and define constants for minimum and maximum packet sizes

This commit is contained in:
scatterflower 2020-08-16 06:50:19 -05:00
parent ec1c95bdb3
commit 11250e1386
2 changed files with 19 additions and 21 deletions

View File

@ -349,8 +349,10 @@ private:
// amount by which we multiply the delay when we parse punctuation chars // amount by which we multiply the delay when we parse punctuation chars
const int punctuation_modifier = 3; const int punctuation_modifier = 3;
static const int chatmessage_size = 30; // Minumum and maximum number of parameters in the MS packet
QString m_chatmessage[chatmessage_size]; static const int MS_MINIMUM = 15;
static const int MS_MAXIMUM = 30;
QString m_chatmessage[MS_MAXIMUM];
bool chatmessage_is_empty = false; bool chatmessage_is_empty = false;
QString previous_ic_message = ""; QString previous_ic_message = "";

View File

@ -1765,19 +1765,16 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
// Instead of checking for whether a message has at least chatmessage_size // Instead of checking for whether a message has at least chatmessage_size
// amount of packages, we'll check if it has at least 15. // amount of packages, we'll check if it has at least 15.
// That was the original chatmessage_size. // That was the original chatmessage_size.
if (p_contents->size() < 15) if (p_contents->size() < MS_MINIMUM)
return; return;
for (int n_string = 0; n_string < chatmessage_size; ++n_string) { for (int n_string = 0; n_string < MS_MAXIMUM; ++n_string) {
// m_chatmessage[n_string] = p_contents->at(n_string);
// Note that we have added stuff that vanilla clients and servers simply // 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 // 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 // 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 // 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. // forget! A size 15 message will have indices from 0 to 14.
if (n_string < p_contents->size() && if (n_string < p_contents->size() && (n_string < MS_MINIMUM || ao_app->cccc_ic_support_enabled)) {
(n_string < 15 || ao_app->cccc_ic_support_enabled)) {
m_chatmessage[n_string] = p_contents->at(n_string); m_chatmessage[n_string] = p_contents->at(n_string);
} }
else { else {
@ -1786,27 +1783,26 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
} }
int f_char_id = m_chatmessage[CHAR_ID].toInt(); 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; return;
if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) if (mute_map.value(m_chatmessage[CHAR_ID].toInt()))
return; return;
QString f_showname; QString f_displayname;
if (f_char_id > -1 && if (!is_spectator && (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) {
(m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) { f_displayname = ao_app->get_showname(char_list.at(f_char_id).name);
f_showname = ao_app->get_showname(char_list.at(f_char_id).name);
} }
else { else {
f_showname = m_chatmessage[SHOWNAME]; f_displayname = m_chatmessage[SHOWNAME];
} }
if (f_showname.trimmed() // If chatblank is enabled, use the character's name for logs
.isEmpty()) // Pure whitespace showname, get outta here. if (f_displayname.trimmed().isEmpty())
f_showname = m_chatmessage[CHAR_NAME]; 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 // Remove undesired newline chars
m_chatmessage[MESSAGE].remove("\n"); m_chatmessage[MESSAGE].remove("\n");
chatmessage_is_empty = 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); f_charname = ao_app->get_showname(char_list.at(f_char_id).name);
chatlogpiece *temp = 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); ic_chatlog_history.append(*temp);
if (ao_app->get_auto_logging_enabled()) if (ao_app->get_auto_logging_enabled())
ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); 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(); 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_char = m_chatmessage[CHAR_NAME];
QString f_custom_theme = ao_app->get_char_shouts(f_char); QString f_custom_theme = ao_app->get_char_shouts(f_char);