aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscatterflower <2956568+scatterflower@users.noreply.github.com>2020-08-16 12:36:37 -0500
committerGitHub <noreply@github.com>2020-08-16 12:36:37 -0500
commite546ead1fa6d0f3c58fd7a429d36e2b2cb65ada5 (patch)
treef3c3d5b64608780b1a8abcdcdb416de453790261
parenta31693323cbebc74fe2657df6dce07943e1bfdb2 (diff)
parent5c6dad88ce4d189152b5a52936f08b37b12ce0f1 (diff)
Merge pull request #1 from scatterflower/ic_fixes
Ic fixes
-rw-r--r--include/courtroom.h6
-rw-r--r--src/courtroom.cpp92
2 files changed, 35 insertions, 63 deletions
diff --git a/include/courtroom.h b/include/courtroom.h
index f1cb0265..a4bacc22 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -348,8 +348,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 fc6747bd..3b3f6991 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -1767,19 +1767,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 {
@@ -1788,62 +1785,48 @@ 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())) {
+ // 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 {
- f_showname = m_chatmessage[SHOWNAME];
+ // Otherwise, use the showname
+ f_displayname = m_chatmessage[SHOWNAME];
}
- if (f_showname.trimmed()
- .isEmpty()) // Pure whitespace showname, get outta here.
- f_showname = m_chatmessage[CHAR_NAME];
-
- QString f_message = f_showname + ": " + m_chatmessage[MESSAGE] + '\n';
- // Remove undesired newline chars
- m_chatmessage[MESSAGE].remove("\n");
- chatmessage_is_empty =
- m_chatmessage[MESSAGE] == " " || m_chatmessage[MESSAGE] == "";
+ // 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);
- 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.
+ // 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(" ");
@@ -1865,12 +1848,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_showname, 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);
@@ -1879,7 +1858,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
log_maximum_blocks > 0) {
ic_chatlog_history.removeFirst();
}
-
+
QString f_char = m_chatmessage[CHAR_NAME];
QString f_custom_theme = ao_app->get_char_shouts(f_char);
@@ -1913,26 +1892,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();