From 56bb82b9e3906c104942a5e3bc7bdda7a42cb12c Mon Sep 17 00:00:00 2001 From: TrickyLeifa Date: Thu, 7 Nov 2024 21:36:29 +0100 Subject: [PATCH] Partial resolution of #988, #870 --- CMakeLists.txt | 2 +- src/aoapplication.h | 2 +- src/aomusicplayer.cpp | 2 +- src/charselect.cpp | 2 +- src/courtroom.cpp | 734 +++++++++++------------------------- src/courtroom.h | 23 +- src/datatypes.h | 15 +- src/evidence.cpp | 2 +- src/lobby.cpp | 2 +- src/packet_distribution.cpp | 22 +- src/serverdata.cpp | 16 - src/serverdata.h | 88 ----- src/text_file_functions.cpp | 63 +++- 13 files changed, 315 insertions(+), 658 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebaaae253..56f973dc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.7.0) -project(AttorneyOnline VERSION 2.11.0.0 LANGUAGES CXX C) +project(AttorneyOnline VERSION 2.12.0.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/src/aoapplication.h b/src/aoapplication.h index 6022ca1d7..bc39d80a7 100644 --- a/src/aoapplication.h +++ b/src/aoapplication.h @@ -103,7 +103,7 @@ class AOApplication : public QObject static QString get_version_string(); static const int RELEASE = 2; - static const int MAJOR_VERSION = 11; + static const int MAJOR_VERSION = 12; static const int MINOR_VERSION = 0; void set_server_list(QVector &servers) { server_list = servers; } diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index c4a562cb1..52975be81 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -68,7 +68,7 @@ QString AOMusicPlayer::playStream(QString song, int streamId, bool loopEnabled, { QStringList lines = ao_app->read_file(d_path).split("\n"); bool seconds_mode = false; - foreach (QString line, lines) + for (QString line : lines) { QStringList args = line.split("="); if (args.size() < 2) diff --git a/src/charselect.cpp b/src/charselect.cpp index d36220aaa..d24a2ee5e 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -281,7 +281,7 @@ void Courtroom::character_loading_finished() ao_app->generated_chars = 0; if (ui_char_button_list.size() > 0) { - foreach (AOCharButton *item, ui_char_button_list) + for (AOCharButton *item : ui_char_button_list) { delete item; } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 349e5a5bd..b089d6c92 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -306,7 +306,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) ui_flip = new QCheckBox(this); ui_flip->setText(tr("Flip")); - ui_flip->hide(); ui_flip->setObjectName("ui_flip"); ui_guard = new QCheckBox(this); @@ -316,7 +315,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) ui_additive = new QCheckBox(this); ui_additive->setText(tr("Additive")); - ui_additive->hide(); ui_additive->setObjectName("ui_additive"); ui_showname_enable = new QCheckBox(this); @@ -331,7 +329,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) ui_immediate = new QCheckBox(this); ui_immediate->setText(tr("Immediate")); - ui_immediate->hide(); ui_immediate->setObjectName("ui_immediate"); ui_custom_objection = new AOButton(ao_app, this); @@ -443,9 +440,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) connect(ui_iniswap_remove, &AOButton::clicked, this, &Courtroom::on_iniswap_remove_clicked); connect(ui_sfx_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &Courtroom::on_sfx_dropdown_changed); - connect(ui_sfx_dropdown, &QComboBox::editTextChanged, this, &Courtroom::on_sfx_dropdown_custom); connect(ui_sfx_dropdown, &QComboBox::customContextMenuRequested, this, &Courtroom::on_sfx_context_menu_requested); - connect(ui_sfx_remove, &AOButton::clicked, this, &Courtroom::on_sfx_remove_clicked); + connect(ui_sfx_remove, &AOButton::clicked, this, &Courtroom::on_sfx_reset_selection); connect(ui_effects_dropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &Courtroom::on_effects_dropdown_changed); connect(ui_effects_dropdown, &QComboBox::customContextMenuRequested, this, &Courtroom::on_effects_context_menu_requested); @@ -742,26 +738,6 @@ void Courtroom::set_widgets() set_fonts(); set_size_and_pos(ui_viewport, "viewport"); - // If there is a point to it, show all CCCC features. - // We also do this this soon so that set_size_and_pos can hide them all later, - // if needed. - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT)) - { - ui_pair_button->show(); - ui_immediate->show(); - ui_showname_enable->show(); - ui_ic_chat_name->show(); - ui_ic_chat_name->setEnabled(true); - } - else - { - ui_pair_button->hide(); - ui_immediate->hide(); - ui_showname_enable->hide(); - ui_ic_chat_name->hide(); - ui_ic_chat_name->setEnabled(false); - } - // We also show the non-server-dependent client additions. // Once again, if the theme can't display it, set_move_and_pos will catch // them. @@ -1565,59 +1541,57 @@ void Courtroom::update_character(int p_cid, QString char_name, bool reset_emote) } ui_custom_objection->hide(); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOMOBJECTIONS)) // if setting is enabled + + custom_obj_menu->clear(); + custom_objections_list.clear(); + if (file_exists(ao_app->get_image_suffix(ao_app->get_character_path(current_char, "custom")))) { - custom_obj_menu->clear(); - custom_objections_list.clear(); - if (file_exists(ao_app->get_image_suffix(ao_app->get_character_path(current_char, "custom")))) + ui_custom_objection->show(); + QString custom_name = ao_app->read_char_ini(f_char, "custom_name", "Shouts"); + QAction *action; + if (custom_name != "") { - ui_custom_objection->show(); - QString custom_name = ao_app->read_char_ini(f_char, "custom_name", "Shouts"); + action = custom_obj_menu->addAction(custom_name); + } + else + { + action = custom_obj_menu->addAction("Default"); + } + custom_obj_menu->setDefaultAction(action); + custom_objection_name = ""; + } + QString custom_objection_dir = ao_app->get_real_path(ao_app->get_character_path(current_char, "custom_objections")); + if (dir_exists(custom_objection_dir)) + { + ui_custom_objection->show(); + QDir directory(custom_objection_dir); + QStringList custom_obj = directory.entryList(QStringList() << "*.png" + << "*.gif" + << "*.apng" + << "*.webp", + QDir::Files); + for (const QString &filename : custom_obj) + { + CustomObjection custom_objection; + custom_objection.filename = filename; + QString custom_name = ao_app->read_char_ini(f_char, filename.left(filename.lastIndexOf(".")) + "_name", "Shouts"); QAction *action; if (custom_name != "") { + custom_objection.name = custom_name; action = custom_obj_menu->addAction(custom_name); } else { - action = custom_obj_menu->addAction("Default"); + custom_objection.name = filename.left(filename.lastIndexOf(".")); + action = custom_obj_menu->addAction(custom_objection.name); } - custom_obj_menu->setDefaultAction(action); - objection_custom = ""; - } - QString custom_objection_dir = ao_app->get_real_path(ao_app->get_character_path(current_char, "custom_objections")); - if (dir_exists(custom_objection_dir)) - { - ui_custom_objection->show(); - QDir directory(custom_objection_dir); - QStringList custom_obj = directory.entryList(QStringList() << "*.png" - << "*.gif" - << "*.apng" - << "*.webp", - QDir::Files); - for (const QString &filename : custom_obj) + if (custom_obj_menu->defaultAction() == nullptr) { - CustomObjection custom_objection; - custom_objection.filename = filename; - QString custom_name = ao_app->read_char_ini(f_char, filename.left(filename.lastIndexOf(".")) + "_name", "Shouts"); - QAction *action; - if (custom_name != "") - { - custom_objection.name = custom_name; - action = custom_obj_menu->addAction(custom_name); - } - else - { - custom_objection.name = filename.left(filename.lastIndexOf(".")); - action = custom_obj_menu->addAction(custom_objection.name); - } - if (custom_obj_menu->defaultAction() == nullptr) - { - custom_obj_menu->setDefaultAction(action); - objection_custom = custom_objection.filename; - } - custom_objections_list.append(custom_objection); + custom_obj_menu->setDefaultAction(action); + custom_objection_name = custom_objection.filename; } + custom_objections_list.append(custom_objection); } } @@ -1639,28 +1613,10 @@ void Courtroom::enter_courtroom() { set_evidence_page(); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING)) - { - ui_flip->show(); - } - else - { - ui_flip->hide(); - } - - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::ADDITIVE)) - { - ui_additive->show(); - } - else - { - ui_additive->hide(); - } - list_music(); list_areas(); - switch (objection_state) // no need to reset these as it was done in set_widgets() + switch (objection_id) // no need to reset these as it was done in set_widgets() { case 1: ui_hold_it->setImage("holdit_selected"); @@ -1767,29 +1723,6 @@ void Courtroom::list_areas() QString i_area; i_area.append(area_list.at(n_area)); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::ARUP)) - { - i_area.append("\n "); - - i_area.append(arup_statuses.at(n_area)); - - if (arup_cms.at(n_area) != "FREE") - { - i_area.append(" | CM: "); - i_area.append(arup_cms.at(n_area)); - } - - i_area.append("\n "); - - if (arup_players.at(n_area) != -1) - { - i_area.append(QString::number(arup_players.at(n_area))); - i_area.append(" users | "); - } - - i_area.append(arup_locks.at(n_area)); - } - QTreeWidgetItem *treeItem = ui_area_list->topLevelItem(n_area); if (treeItem == nullptr) { @@ -1797,43 +1730,7 @@ void Courtroom::list_areas() } treeItem->setText(0, area_list.at(n_area)); treeItem->setText(1, i_area); - - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::ARUP)) - { - // Coloring logic here. - treeItem->setBackground(1, free_brush); - if (arup_locks.at(n_area) == "LOCKED") - { - treeItem->setBackground(1, locked_brush); - } - else - { - if (arup_statuses.at(n_area) == "LOOKING-FOR-PLAYERS") - { - treeItem->setBackground(1, lfp_brush); - } - else if (arup_statuses.at(n_area) == "CASING") - { - treeItem->setBackground(1, casing_brush); - } - else if (arup_statuses.at(n_area) == "RECESS") - { - treeItem->setBackground(1, recess_brush); - } - else if (arup_statuses.at(n_area) == "RP") - { - treeItem->setBackground(1, rp_brush); - } - else if (arup_statuses.at(n_area) == "GAMING") - { - treeItem->setBackground(1, gaming_brush); - } - } - } - else - { - treeItem->setBackground(1, free_brush); - } + treeItem->setBackground(1, free_brush); ++n_listed_areas; } @@ -1872,11 +1769,6 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QSt { color = ao_app->get_color("server_chatlog_sender_color", "courtroom_fonts.ini").name(); } - if (!ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::AUTH_PACKET) && p_message == "Logged in as a moderator.") - { - // Emulate successful authentication - on_authentication_state_received(1); - } ui_server_chatlog->addMessage(p_name, p_message, color); @@ -1962,310 +1854,177 @@ void Courtroom::on_chat_return_pressed() // immediate_preanim#% QStringList packet_contents; - // have to fetch this early for a workaround. i hate this system, but i am stuck with it for now - int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); - - int f_desk_mod = DESK_SHOW; - - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::DESKMOD)) + packet_contents.resize(CHAT_MESSAGE_SIZE); + for (int i = 0; i < CHAT_MESSAGE_SIZE; ++i) { - f_desk_mod = ao_app->get_desk_mod(current_char, current_emote); - {} - if (!ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EXPANDED_DESK_MODS)) - { - if (f_desk_mod == DESK_PRE_ONLY_EX || f_desk_mod == DESK_PRE_ONLY) - { - f_desk_mod = DESK_HIDE; - } - else if (f_desk_mod == DESK_EMOTE_ONLY_EX || f_desk_mod == DESK_EMOTE_ONLY) - { - f_desk_mod = DESK_SHOW; - } - } - if (f_desk_mod == -1 && (f_emote_mod == 5 || f_emote_mod == 6)) // workaround for inis that broke after deprecating "chat" - { - f_desk_mod = DESK_HIDE; - } - else if (f_desk_mod == -1) - { - f_desk_mod = DESK_SHOW; - } + packet_contents[i] = QString("0"); } - packet_contents.append(QString::number(f_desk_mod)); + const bool pre_enabled = ui_pre->isChecked(); - QString f_pre = ao_app->get_pre_emote(current_char, current_emote); - QString f_sfx = "1"; - int f_sfx_delay = get_char_sfx_delay(); + int f_desk_mod = ao_app->get_desk_mod(current_char, current_emote); + packet_contents[DESK_MOD] = QString::number(f_desk_mod); - // EMOTE MOD OVERRIDES: - // Emote_mod 2 is only used by objection check later, having it in the char.ini does nothing - if (f_emote_mod == 2) - { - f_emote_mod = PREANIM; - } - // No clue what emote_mod 3 is even supposed to be. - if (f_emote_mod == 3) - { - f_emote_mod = IDLE; - } - // Emote_mod 4 seems to be a legacy bugfix that just refers it to emote_mod 5 which is zoom emote - if (f_emote_mod == 4) - { - f_emote_mod = ZOOM; - } - // If we have "pre" on, and immediate is not checked - if (ui_pre->isChecked() && !ui_immediate->isChecked()) + int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); + if (pre_enabled) { - // Turn idle into preanim - if (f_emote_mod == IDLE) + switch (f_emote_mod) { + default: f_emote_mod = PREANIM; - } - // Turn zoom into preanim zoom - else if (f_emote_mod == ZOOM && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::PREZOOM)) - { + break; + + case ZOOM: + case PREANIM_ZOOM: f_emote_mod = PREANIM_ZOOM; + break; } - // Play the sfx - f_sfx = get_char_sfx(); } - // If we have "pre" off, or immediate is checked else { - // Turn preanim into idle - if (f_emote_mod == PREANIM) + switch (f_emote_mod) { + default: f_emote_mod = IDLE; - } - // Turn preanim zoom into zoom - else if (f_emote_mod == PREANIM_ZOOM) - { - f_emote_mod = ZOOM; - } + break; - // Play the sfx if pre is checked - if (ui_pre->isChecked()) - { - f_sfx = get_char_sfx(); + case ZOOM: + case PREANIM_ZOOM: + f_emote_mod = ZOOM; + break; } } - // Custom sfx override via sound list dropdown. - if (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() != 0) + packet_contents[CHAR_ID] = QString::number(m_cid); + packet_contents[CHAR_NAME] = current_char; + packet_contents[EMOTE] = ao_app->get_emote(current_char, current_emote); + packet_contents[EMOTE_MOD] = QString::number(f_emote_mod); + if (pre_enabled) { - f_sfx = get_char_sfx(); - // We have a custom sfx but we're on idle emotes. - // Turn them into pre so the sound plays if client setting sfx_on_idle is enabled. - if (Options::getInstance().playSelectedSFXOnIdle() && (f_emote_mod == IDLE || f_emote_mod == ZOOM)) - { - // We turn idle into preanim, but make it not send a pre animation - f_pre = ""; - // Set sfx delay to 0 so the sfx plays immediately - f_sfx_delay = 0; - // Set the emote mod to preanim so the sound plays - f_emote_mod = f_emote_mod == IDLE ? PREANIM : PREANIM_ZOOM; - } + QString pre_emote = ao_app->get_pre_emote(current_char, current_emote); + packet_contents[PRE_EMOTE] = pre_emote; } - packet_contents.append(f_pre); + packet_contents[SIDE] = current_or_default_side(); - packet_contents.append(current_char); + packet_contents[MESSAGE] = ui_ic_chat_message->text(); - packet_contents.append(ao_app->get_emote(current_char, current_emote)); - - packet_contents.append(ui_ic_chat_message->text()); - - packet_contents.append(current_or_default_side()); - - packet_contents.append(f_sfx); - packet_contents.append(QString::number(f_emote_mod)); - packet_contents.append(QString::number(m_cid)); - - packet_contents.append(QString::number(f_sfx_delay)); - - QString f_obj_state; - - if ((objection_state == 4 && !ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOMOBJECTIONS)) || (objection_state < 0)) + QString sfx = QString("0"); + int sfx_delay = 0; + if (pre_enabled) { - f_obj_state = "0"; + QString target_sfx = get_current_sfx(); + if (!target_sfx.isEmpty()) + { + sfx = target_sfx; + sfx_delay = get_char_sfx_delay(); + } } - else if (objection_custom != "" && objection_state == 4) + packet_contents[SFX_NAME] = sfx; + packet_contents[SFX_DELAY] = QString::number(sfx_delay); + + if (objection_id == CUSTOM_OBJECTION && !custom_objection_name.isEmpty()) { - f_obj_state = QString::number(objection_state) + "&" + objection_custom; // we add the name of the objection so the - // packet is like: 4&(name of custom obj) + QString field = QString::number(objection_id) + "&" + custom_objection_name; + packet_contents[OBJECTION_MOD] = field; } else { - f_obj_state = QString::number(objection_state); + packet_contents[OBJECTION_MOD] = QString::number(objection_id); } - // We're doing an Objection (custom objections not yet supported) - if (objection_state == 2 && Options::getInstance().objectionStopMusic()) + if (objection_id != NO_OBJECTION && Options::getInstance().objectionStopMusic()) { music_stop(true); } - packet_contents.append(f_obj_state); - if (is_presenting_evidence) { // the evidence index is shifted by 1 because 0 is no evidence per legacy - // standards besides, older clients crash if we pass -1 - packet_contents.append(QString::number(current_evidence + 1)); - } - else - { - packet_contents.append("0"); + packet_contents[EVIDENCE_ID] = QString::number(current_evidence + 1); } - QString f_flip; + packet_contents[FLIP] = ui_flip->isChecked() ? "1" : "0"; + packet_contents[REALIZATION] = QString::number(realization_state); + packet_contents[TEXT_COLOR] = QString::number(ui_text_color->currentIndex()); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING)) + QString character_name = ui_ic_chat_name->text(); + if (character_name.isEmpty()) { - if (ui_flip->isChecked()) - { - f_flip = "1"; - } - else - { - f_flip = "0"; - } + character_name = ao_app->get_showname(current_char, current_emote); } - else - { - f_flip = QString::number(m_cid); - } - - packet_contents.append(f_flip); - - packet_contents.append(QString::number(realization_state)); - - QString f_text_color; + packet_contents[SHOWNAME] = character_name; - if (text_color < 0) + // Similarly, we send over whom we're paired with, unless we have chosen + // ourselves. Or a charid of -1 or lower, through some means. + if (other_charid > -1 && other_charid != m_cid) { - f_text_color = "0"; - } - else if (text_color >= max_colors) - { - f_text_color = "0"; + QString data = QString::number(other_charid); + // pair reordering + data += "^" + QString::number(pair_order); + packet_contents.append(data); } else { - f_text_color = QString::number(text_color); + packet_contents.append("-1"); } - packet_contents.append(f_text_color); + // Send the offset as it's gonna be used regardless + packet_contents.append(QString::number(char_offset) + "&" + QString::number(char_vert_offset)); - // If the server we're on supports CCCC stuff, we should use it! - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT)) - { - // If there is a showname entered, use that -- else, just send an empty - // packet-part. - if (!ui_ic_chat_name->text().isEmpty()) - { - packet_contents.append(ui_ic_chat_name->text()); - } - else - { - packet_contents.append(ao_app->get_showname(current_char, current_emote)); - } + packet_contents[IMMEDIATE] = QString::number(ui_immediate->isChecked()); - // Similarly, we send over whom we're paired with, unless we have chosen - // ourselves. Or a charid of -1 or lower, through some means. - if (other_charid > -1 && other_charid != m_cid) - { - QString packet = QString::number(other_charid); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) // Only servers with effects - // enabled will support pair - // reordering - { - packet += "^" + QString::number(pair_order); - } - packet_contents.append(packet); - } - else - { - packet_contents.append("-1"); - } - // Send the offset as it's gonna be used regardless - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::Y_OFFSET)) - { - packet_contents.append(QString::number(char_offset) + "&" + QString::number(char_vert_offset)); - } - else - { - packet_contents.append(QString::number(char_offset)); - } - - // Finally, we send over if we want our pres to not interrupt. - if (ui_immediate->isChecked() && ui_pre->isChecked()) - { - packet_contents.append("1"); - } - else - { - packet_contents.append("0"); - } - } - - // If the server we're on supports Looping SFX and Screenshake, use it if the - // emote uses it. - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::LOOPING_SFX)) - { - packet_contents.append(ao_app->get_sfx_looping(current_char, current_emote)); - packet_contents.append(QString::number(screenshake_state)); + { // feature LOOPING_SFX + packet_contents[LOOPING_SFX] = ao_app->get_sfx_looping(current_char, current_emote); + packet_contents[SCREENSHAKE] = QString::number(screenshake_state); QString pre_emote = ao_app->get_pre_emote(current_char, current_emote); QString emote = ao_app->get_emote(current_char, current_emote); QStringList emotes_to_check = {pre_emote, "(b)" + emote, "(a)" + emote}; QStringList effects_to_check = {"_FrameScreenshake", "_FrameRealization", "_FrameSFX"}; - foreach (QString f_effect, effects_to_check) + static const QList PAYLOAD_FIELD_MAP{FRAME_SCREENSHAKE, FRAME_REALIZATION, FRAME_SFX}; + for (int i = 0; i < effects_to_check.length(); ++i) { - QString packet; - foreach (QString f_emote, emotes_to_check) + const QString &f_effect = effects_to_check.at(i); + + QString payload; + for (QString f_emote : emotes_to_check) { - packet += f_emote; + payload += f_emote; if (Options::getInstance().networkedFrameSfxEnabled()) { QString sfx_frames = ao_app->read_ini_tags(ao_app->get_character_path(current_char, "char.ini"), f_emote.append(f_effect)).join("|"); if (sfx_frames != "") { - packet += "|" + sfx_frames; + payload += "|" + sfx_frames; } } - packet += "^"; + payload += "^"; } - packet_contents.append(packet); + + packet_contents[PAYLOAD_FIELD_MAP.value(i)] = payload; } } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::ADDITIVE)) - { - packet_contents.append(ui_additive->isChecked() ? "1" : "0"); - } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) - { + packet_contents[ADDITIVE] = QString::number(ui_additive->isChecked()); + + { // feature EFFECTS QString p_effect_folder = ao_app->read_char_ini(current_char, "effects", "Options"); QString fx_sound = ao_app->get_effect_property(effect, current_char, p_effect_folder, "sound"); - // Don't overlap the two sfx - if (!ui_pre->isChecked() && (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() == 1)) + // don't overlap sfxs + if (!packet_contents[SFX_NAME].isEmpty()) { fx_sound = "0"; } - packet_contents.append(effect + "|" + p_effect_folder + "|" + fx_sound); + packet_contents[EFFECTS] = effect + "|" + p_effect_folder + "|" + fx_sound; } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOM_BLIPS)) - { - packet_contents.append(ao_app->get_blipname(current_char, current_emote)); - - packet_contents.append(ui_slide_enable->isChecked() ? "1" : "0"); // just let the server figure out what to do with this - } + // feature CUSTOM_BLIPS + packet_contents[BLIPNAME] = ao_app->get_blipname(current_char, current_emote); + packet_contents[SLIDE] = QString::number(ui_slide_enable->isChecked()); ao_app->send_server_packet(AOPacket("MS", packet_contents)); } @@ -2277,8 +2036,8 @@ void Courtroom::reset_ui() { ui_ic_chat_message->insert(" "); } - objection_state = 0; - realization_state = 0; + objection_id = NO_OBJECTION; + realization_state = false; screenshake_state = 0; is_presenting_evidence = false; ui_hold_it->setImage("holdit"); @@ -2295,7 +2054,6 @@ void Courtroom::reset_ui() // Reset the SFX Dropdown to "Default" ui_sfx_dropdown->setCurrentIndex(0); ui_sfx_remove->hide(); - custom_sfx = ""; } // Why was this in the IC enter key handler before...? Whatever. Hopefully putting it here instead doesn't break anything. if (!Options::getInstance().clearEffectsDropdownOnPlayEnabled() && !ao_app->get_effect_property(effect, current_char, ao_app->read_char_ini(current_char, "effects", "Options"), "sticky").startsWith("true")) @@ -2431,25 +2189,6 @@ void Courtroom::skip_chatmessage_queue() void Courtroom::unpack_chatmessage(QStringList p_contents) { - for (int n_string = 0; n_string < MS_MAXIMUM; ++n_string) - { - m_previous_chatmessage[n_string] = m_chatmessage[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 < MS_MINIMUM || ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT))) - { - m_chatmessage[n_string] = p_contents.at(n_string); - } - else - { - m_chatmessage[n_string] = ""; - } - } - // if the char ID matches our client's char ID (most likely, this is our message coming back to us) bool sender = Options::getInstance().desynchronisedLogsEnabled() || m_chatmessage[CHAR_ID].toInt() == m_cid; @@ -2801,16 +2540,7 @@ void Courtroom::display_pair_character(QString other_charid, QString other_offse ui_vp_sideplayer_char->loadCharacterEmote(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE], kal::CharacterAnimationLayer::IdleEmote); ui_vp_sideplayer_char->show(); ui_vp_sideplayer_char->setPlayOnce(false); - - // Flip the pair character - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING) && m_chatmessage[OTHER_FLIP].toInt() == 1) - { - ui_vp_sideplayer_char->setFlipped(true); - } - else - { - ui_vp_sideplayer_char->setFlipped(false); - } + ui_vp_sideplayer_char->setFlipped(m_chatmessage[OTHER_FLIP].toInt() == 1); ui_vp_sideplayer_char->startPlayback(); } @@ -4169,7 +3899,7 @@ void Courtroom::start_chat_ticking() QString f_blips = ao_app->get_blipname(m_chatmessage[CHAR_NAME]); f_blips = ao_app->get_blips(f_blips); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOM_BLIPS) && !m_chatmessage[BLIPNAME].isEmpty()) + if (!m_chatmessage[BLIPNAME].isEmpty()) { f_blips = ao_app->get_blips(m_chatmessage[BLIPNAME]); } @@ -4923,10 +4653,7 @@ void Courtroom::mod_called(QString p_ip) void Courtroom::on_ooc_return_pressed() { QString ooc_message = ui_ooc_chat_message->text(); - - // We ignore it when the server is compatible with 2.8 - // Using an arbitrary 2.8 feature flag certainly won't cause issues someday. - if (ooc_message.startsWith("/pos") && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) + if (ooc_message.startsWith("/pos")) { if (ooc_message == "/pos jud") { @@ -5014,7 +4741,7 @@ void Courtroom::on_ooc_return_pressed() std::sort(case_evidence.begin(), case_evidence.end(), [](const QString &a, const QString &b) { return a.toInt() < b.toInt(); }); // load evidence - foreach (QString evi, case_evidence) + for (QString evi : case_evidence) { if (evi == "General") { @@ -5164,7 +4891,7 @@ void Courtroom::on_music_search_edited(QString p_text) { // Search in metadata QList clist = ui_music_list->findItems(ui_music_search->text(), Qt::MatchContains | Qt::MatchRecursive, 1); - foreach (QTreeWidgetItem *item, clist) + for (QTreeWidgetItem *item : clist) { if (item->parent() != nullptr) // So the category shows up too { @@ -5178,7 +4905,7 @@ void Courtroom::on_music_search_edited(QString p_text) { // Search in metadata QList alist = ui_area_list->findItems(ui_music_search->text(), Qt::MatchContains | Qt::MatchRecursive, 1); - foreach (QTreeWidgetItem *item, alist) + for (QTreeWidgetItem *item : alist) { if (item->parent() != nullptr) // So the category shows up too { @@ -5392,6 +5119,9 @@ void Courtroom::set_sfx_dropdown() sound_list += ao_app->get_list_file(VPath("soundlist.ini")); QStringList display_sounds; + display_sounds.append("Default"); + display_sounds.append("None"); + display_sounds.append(QString()); for (const QString &sound : qAsConst(sound_list)) { QStringList unpacked = sound.split("="); @@ -5403,30 +5133,26 @@ void Courtroom::set_sfx_dropdown() display_sounds.append(display); } - display_sounds.prepend("Nothing"); - display_sounds.prepend("Default"); ui_sfx_dropdown->show(); ui_sfx_dropdown->addItems(display_sounds); - ui_sfx_dropdown->setCurrentIndex(0); - ui_sfx_remove->hide(); + ui_sfx_dropdown->setCurrentIndex(SFX_DEFAULT); ui_sfx_dropdown->blockSignals(false); } void Courtroom::on_sfx_dropdown_changed(int p_index) { - custom_sfx = ""; - focus_ic_input(); - if (p_index == 0) + ui_sfx_remove->setHidden(p_index == SFX_DEFAULT); + ui_sfx_dropdown->setEditable(p_index == SFX_EDITABLE); + if (ui_sfx_dropdown->isEditable()) { - ui_sfx_remove->hide(); + ui_sfx_dropdown->setPlaceholderText("Editable custom sfx"); } -} - -void Courtroom::on_sfx_dropdown_custom(QString p_sfx) -{ - ui_sfx_remove->show(); - custom_sfx = p_sfx; + else + { + ui_sfx_dropdown->setPlaceholderText(QString()); + } + focus_ic_input(); } void Courtroom::on_sfx_context_menu_requested(const QPoint &pos) @@ -5435,12 +5161,13 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos) menu->setAttribute(Qt::WA_DeleteOnClose); menu->addSeparator(); - // SFX is not "Nothing" or "Default"? - if (get_char_sfx() != "0" && get_char_sfx() != "1" && get_char_sfx() != "-") + + const QString sfx = get_current_sfx(); + if (!sfx.isEmpty()) { - // Add an option to play the SFX - menu->addAction(QString("Play " + get_char_sfx()), this, &Courtroom::on_sfx_play_clicked); + menu->addAction(QString("Play " + sfx), this, &Courtroom::on_sfx_play_clicked); } + if (file_exists(ao_app->get_real_path(ao_app->get_character_path(current_char, "soundlist.ini")))) { menu->addAction(QString("Edit " + current_char + "/soundlist.ini"), this, &Courtroom::on_sfx_edit_requested); @@ -5449,10 +5176,12 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos) { menu->addAction(QString("Edit base soundlist.ini"), this, &Courtroom::on_sfx_edit_requested); } - if (!custom_sfx.isEmpty()) + + if (ui_sfx_dropdown->isEditable()) { - menu->addAction(QString("Clear Edit Text"), this, &Courtroom::on_sfx_remove_clicked); + menu->addAction(QString("Clear Edit Text"), this, &Courtroom::on_sfx_reset_selection); } + menu->addSeparator(); menu->addAction(QString("Open base sounds folder"), this, [=] { QString p_path = get_base_path() + "sounds/general/"; @@ -5467,7 +5196,7 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos) void Courtroom::on_sfx_play_clicked() { - sfx_player->findAndPlayCharacterSfx(get_char_sfx(), get_current_char()); + sfx_player->findAndPlayCharacterSfx(get_current_sfx(), get_current_char()); } void Courtroom::on_sfx_edit_requested() @@ -5490,11 +5219,13 @@ void Courtroom::on_sfx_edit_requested() QDesktopServices::openUrl(QUrl::fromLocalFile(p_path)); } -void Courtroom::on_sfx_remove_clicked() +void Courtroom::on_sfx_reset_selection() { - ui_sfx_remove->hide(); - ui_sfx_dropdown->setCurrentIndex(0); - custom_sfx = ""; + if (ui_sfx_dropdown->isEditable()) + { + ui_sfx_dropdown->setCurrentText(QString()); + } + ui_sfx_dropdown->setCurrentIndex(SFX_DEFAULT); } void Courtroom::set_effects_dropdown() @@ -5543,6 +5274,7 @@ void Courtroom::on_effects_context_menu_requested(const QPoint &pos) menu->addAction(QString("Open theme's effects folder"), this, &Courtroom::on_effects_edit_requested); menu->popup(ui_effects_dropdown->mapToGlobal(pos)); } + void Courtroom::on_effects_edit_requested() { QString p_path = ao_app->get_real_path(ao_app->get_theme_path("effects/")); @@ -5588,27 +5320,25 @@ bool Courtroom::effects_dropdown_find_and_set(QString effect) return false; } -QString Courtroom::get_char_sfx() +QString Courtroom::get_current_sfx() { - if (!custom_sfx.isEmpty()) + const int index = ui_sfx_dropdown->currentIndex(); + switch (index) { - return custom_sfx; - } - int index = ui_sfx_dropdown->currentIndex(); - if (index == 0) - { // Default + case SFX_DEFAULT: // Default return ao_app->get_sfx_name(current_char, current_emote); + + case SFX_NONE: // Nothing + return QString(); + + case SFX_CUSTOM: + return ui_sfx_dropdown->currentText(); + + default: + return sound_list.value(index - (SFX_EDITABLE + 1)).split("=")[0].trimmed(); } - if (index == 1) - { // Nothing - return "1"; - } - QString sfx = sound_list[index - 2].split("=")[0].trimmed(); - if (sfx == "") - { - return "1"; - } - return sfx; + + return QString(); } int Courtroom::get_char_sfx_delay() @@ -5726,14 +5456,8 @@ void Courtroom::on_music_list_double_clicked(QTreeWidgetItem *p_item, int column QStringList packet_contents; packet_contents.append(p_song); packet_contents.append(QString::number(m_cid)); - if ((!ui_ic_chat_name->text().isEmpty() && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT)) || ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) - { - packet_contents.append(ui_ic_chat_name->text()); - } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) - { - packet_contents.append(QString::number(music_flags)); - } + packet_contents.append(ui_ic_chat_name->text()); + packet_contents.append(QString::number(music_flags)); ao_app->send_server_packet(AOPacket("MC", packet_contents)); } @@ -5877,25 +5601,18 @@ void Courtroom::music_stop(bool no_effects) QStringList packet_contents; // its music list packet_contents.append(fake_song); // this is our fake song, playing it triggers special code packet_contents.append(QString::number(m_cid)); + packet_contents.append(ui_ic_chat_name->text()); - if ((!ui_ic_chat_name->text().isEmpty() && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT)) || ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) + if (no_effects) { - packet_contents.append(ui_ic_chat_name->text()); + packet_contents.append("0"); } - - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) + else { - if (no_effects) - { - packet_contents.append("0"); - } - else - { - packet_contents.append(QString::number(music_flags)); - } - - ao_app->send_server_packet(AOPacket("MC", packet_contents)); + packet_contents.append(QString::number(music_flags)); } + + ao_app->send_server_packet(AOPacket("MC", packet_contents)); } void Courtroom::on_area_list_double_clicked(QTreeWidgetItem *p_item, int column) @@ -5912,10 +5629,10 @@ void Courtroom::on_area_list_double_clicked(QTreeWidgetItem *p_item, int column) void Courtroom::on_hold_it_clicked() { - if (objection_state == 1) + if (objection_id == HOLD_IT) { ui_hold_it->setImage("holdit"); - objection_state = 0; + objection_id = NO_OBJECTION; } else { @@ -5924,7 +5641,7 @@ void Courtroom::on_hold_it_clicked() ui_custom_objection->setImage("custom"); ui_hold_it->setImage("holdit_selected"); - objection_state = 1; + objection_id = HOLD_IT; } focus_ic_input(); @@ -5932,10 +5649,10 @@ void Courtroom::on_hold_it_clicked() void Courtroom::on_objection_clicked() { - if (objection_state == 2) + if (objection_id == OBJECTION) { ui_objection->setImage("objection"); - objection_state = 0; + objection_id = NO_OBJECTION; } else { @@ -5944,7 +5661,7 @@ void Courtroom::on_objection_clicked() ui_custom_objection->setImage("custom"); ui_objection->setImage("objection_selected"); - objection_state = 2; + objection_id = OBJECTION; } focus_ic_input(); @@ -5952,10 +5669,10 @@ void Courtroom::on_objection_clicked() void Courtroom::on_take_that_clicked() { - if (objection_state == 3) + if (objection_id == TAKE_THAT) { ui_take_that->setImage("takethat"); - objection_state = 0; + objection_id = NO_OBJECTION; } else { @@ -5964,7 +5681,7 @@ void Courtroom::on_take_that_clicked() ui_custom_objection->setImage("custom"); ui_take_that->setImage("takethat_selected"); - objection_state = 3; + objection_id = TAKE_THAT; } focus_ic_input(); @@ -5972,10 +5689,10 @@ void Courtroom::on_take_that_clicked() void Courtroom::on_custom_objection_clicked() { - if (objection_state == 4) + if (objection_id == CUSTOM_OBJECTION) { ui_custom_objection->setImage("custom"); - objection_state = 0; + objection_id = NO_OBJECTION; } else { @@ -5984,7 +5701,7 @@ void Courtroom::on_custom_objection_clicked() ui_hold_it->setImage("holdit"); ui_custom_objection->setImage("custom_selected"); - objection_state = 4; + objection_id = CUSTOM_OBJECTION; } focus_ic_input(); @@ -6002,29 +5719,29 @@ void Courtroom::show_custom_objection_menu(const QPoint &pos) ui_custom_objection->setImage("custom_selected"); if (selecteditem->text() == ao_app->read_char_ini(current_char, "custom_name", "Shouts") || selecteditem->text() == "Default") { - objection_custom = ""; + custom_objection_name = ""; } else { - foreach (CustomObjection custom_objection, custom_objections_list) + for (CustomObjection custom_objection : custom_objections_list) { if (custom_objection.name == selecteditem->text()) { - objection_custom = custom_objection.filename; + custom_objection_name = custom_objection.filename; break; } } } - objection_state = 4; + objection_id = CUSTOM_OBJECTION; custom_obj_menu->setDefaultAction(selecteditem); } } void Courtroom::on_realization_clicked() { - if (realization_state == 0) + realization_state = !realization_state; + if (realization_state == false) { - realization_state = 1; if (effects_dropdown_find_and_set("realization")) { on_effects_dropdown_changed(ui_effects_dropdown->currentIndex()); @@ -6034,7 +5751,6 @@ void Courtroom::on_realization_clicked() } else { - realization_state = 0; ui_effects_dropdown->setCurrentIndex(0); on_effects_dropdown_changed(ui_effects_dropdown->currentIndex()); ui_realization->setImage("realization"); @@ -6045,14 +5761,13 @@ void Courtroom::on_realization_clicked() void Courtroom::on_screenshake_clicked() { - if (screenshake_state == 0) + screenshake_state = !screenshake_state; + if (screenshake_state) { - screenshake_state = 1; ui_screenshake->setImage("screenshake_pressed"); } else { - screenshake_state = 0; ui_screenshake->setImage("screenshake"); } @@ -6084,10 +5799,7 @@ void Courtroom::on_pair_clicked() { ui_pair_list->show(); ui_pair_offset_spinbox->show(); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::Y_OFFSET)) - { - ui_pair_vert_offset_spinbox->show(); - } + ui_pair_vert_offset_spinbox->show(); ui_pair_order_dropdown->show(); ui_mute_list->hide(); ui_mute->setImage("mute"); @@ -6404,17 +6116,11 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::MODCALL_REASON)) - { - auto maybe_reason = call_moderator_support(); - if (maybe_reason) - { - ao_app->send_server_packet(AOPacket("ZZ", {maybe_reason.value(), "-1"})); - } - } - else + // feature MODCALL_REASON + auto maybe_reason = call_moderator_support(); + if (maybe_reason) { - ao_app->send_server_packet(AOPacket("ZZ")); + ao_app->send_server_packet(AOPacket("ZZ", {maybe_reason.value(), "-1"})); } focus_ic_input(); @@ -6452,7 +6158,7 @@ void Courtroom::regenerate_ic_chatlog() { ui_ic_chatlog->clear(); last_ic_message = ""; - foreach (ChatLogPiece item, ic_chatlog_history) + for (ChatLogPiece item : ic_chatlog_history) { QString message = item.message; QString name = ui_showname_enable->isChecked() ? item.character_name : item.character; diff --git a/src/courtroom.h b/src/courtroom.h index 6cae0ff48..01fa227bd 100644 --- a/src/courtroom.h +++ b/src/courtroom.h @@ -483,16 +483,16 @@ class Courtroom : public QMainWindow // cid and this may differ in cases of ini-editing QString current_char; - int objection_state = 0; - QString objection_custom; + int objection_id = NO_OBJECTION; + QString custom_objection_name; struct CustomObjection { QString name; QString filename; }; QList custom_objections_list; - int realization_state = 0; - int screenshake_state = 0; + bool realization_state = false; + bool screenshake_state = 0; int text_color = 0; // How many unique user colors are possible @@ -532,9 +532,6 @@ class Courtroom : public QMainWindow // Current list file sorted line by line QStringList sound_list; - // Current SFX the user put in for the sfx dropdown list - QString custom_sfx; - // is the message we're about to send supposed to present evidence? bool is_presenting_evidence = false; bool c_played = false; // whether we've played a (c)-style postanimation yet @@ -677,6 +674,13 @@ class Courtroom : public QMainWindow QComboBox *ui_iniswap_dropdown; AOButton *ui_iniswap_remove; + enum SfxSlot + { + SFX_DEFAULT, + SFX_NONE, + SFX_EDITABLE, + SFX_CUSTOM, + }; QComboBox *ui_sfx_dropdown; AOButton *ui_sfx_remove; @@ -862,12 +866,11 @@ private Q_SLOTS: void on_iniswap_remove_clicked(); void on_sfx_dropdown_changed(int p_index); - void on_sfx_dropdown_custom(QString p_sfx); void set_sfx_dropdown(); void on_sfx_context_menu_requested(const QPoint &pos); void on_sfx_play_clicked(); void on_sfx_edit_requested(); - void on_sfx_remove_clicked(); + void on_sfx_reset_selection(); void set_effects_dropdown(); void on_effects_context_menu_requested(const QPoint &pos); @@ -876,7 +879,7 @@ private Q_SLOTS: void on_effects_dropdown_changed(int p_index); bool effects_dropdown_find_and_set(QString effect); - QString get_char_sfx(); + QString get_current_sfx(); int get_char_sfx_delay(); void on_evidence_name_edited(); diff --git a/src/datatypes.h b/src/datatypes.h index 0bc6b20f7..46d824966 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -70,26 +70,35 @@ enum CHAT_MESSAGE EFFECTS, BLIPNAME, SLIDE, + CHAT_MESSAGE_SIZE, }; enum EMOTE_MOD_TYPE { IDLE = 0, PREANIM = 1, + LEGACY_ZOOM = 4, ZOOM = 5, PREANIM_ZOOM = 6, }; enum DESK_MOD_TYPE { - DESK_HIDE = 0, + DESK_HIDE, DESK_SHOW, DESK_EMOTE_ONLY, DESK_PRE_ONLY, DESK_EMOTE_ONLY_EX, DESK_PRE_ONLY_EX, - //"EX" for "expanded" - // dumb, i know, but throw the first stone if you have a better idea +}; + +enum OBJECTION_TYPE +{ + NO_OBJECTION, + HOLD_IT, + OBJECTION, + TAKE_THAT, + CUSTOM_OBJECTION, }; enum MUSIC_EFFECT diff --git a/src/evidence.cpp b/src/evidence.cpp index 322970faa..974e5a26a 100644 --- a/src/evidence.cpp +++ b/src/evidence.cpp @@ -864,7 +864,7 @@ void Courtroom::evidence_load(QString filename) inventory.setIniCodec("UTF-8"); #endif private_evidence_list.clear(); - foreach (QString evi, inventory.childGroups()) + for (QString evi : inventory.childGroups()) { if (evi == "General") { diff --git a/src/lobby.cpp b/src/lobby.cpp index f19845fad..2b9109b1b 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -413,7 +413,7 @@ void Lobby::on_server_search_edited(QString p_text) { // Search in metadata QList clist = ui_serverlist_tree->findItems(ui_serverlist_search->text(), Qt::MatchContains | Qt::MatchRecursive, 1); - foreach (QTreeWidgetItem *item, clist) + for (QTreeWidgetItem *item : clist) { if (item->parent() != nullptr) // So the category shows up too { diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 6cf5c74fc..f4507d699 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -31,12 +31,13 @@ void AOApplication::server_packet_received(AOPacket packet) bool log_to_demo = true; -#ifdef DEBUG_NETWORK - if (header != "checkconnection") + if (DEBUG_NETWORK) { - qDebug() << "R:" << f_packet; + if (header != "checkconnection") + { + qDebug() << "R:" << packet.toString(); + } } -#endif if (header == "decryptor") { @@ -45,9 +46,6 @@ void AOApplication::server_packet_received(AOPacket packet) return; } - // default(legacy) values - m_serverdata.set_features(QStringList()); - QString f_hdid; f_hdid = get_hdid(); @@ -89,7 +87,6 @@ void AOApplication::server_packet_received(AOPacket packet) } else if (header == "FL") { - m_serverdata.set_features(content); w_courtroom->set_widgets(); log_to_demo = false; } @@ -633,7 +630,7 @@ void AOApplication::server_packet_received(AOPacket packet) // Auth packet else if (header == "AUTH") { - if (!is_courtroom_constructed() || !m_serverdata.get_feature(server::BASE_FEATURE_SET::AUTH_PACKET) || content.isEmpty()) + if (!is_courtroom_constructed() || content.isEmpty()) { return; } @@ -715,8 +712,9 @@ void AOApplication::server_packet_received(AOPacket packet) void AOApplication::send_server_packet(AOPacket p_packet) { QString f_packet = p_packet.toString(); -#ifdef DEBUG_NETWORK - qDebug() << "S:" << p_packet.to_string(); -#endif + if (DEBUG_NETWORK) + { + qDebug() << "S:" << p_packet.toString(); + } net_manager->ship_server_packet(p_packet); } diff --git a/src/serverdata.cpp b/src/serverdata.cpp index 5b3d139db..0a5b388ad 100644 --- a/src/serverdata.cpp +++ b/src/serverdata.cpp @@ -1,25 +1,9 @@ #include #include -#include namespace server { -bool ServerData::get_feature(const BASE_FEATURE_SET &f_feature) const -{ - return get_feature(QVariant::fromValue(f_feature).toString()); -} - -bool ServerData::get_feature(const QString &f_feature) const -{ - return m_features.contains(f_feature, Qt::CaseInsensitive); -} - -void ServerData::set_features(const QStringList &f_feature_list) -{ - m_features = f_feature_list; -} - void ServerData::set_server_software(const QString &newServer_software) { m_server_software = newServer_software; diff --git a/src/serverdata.h b/src/serverdata.h index 993518529..fe63408e9 100644 --- a/src/serverdata.h +++ b/src/serverdata.h @@ -9,97 +9,12 @@ namespace server { Q_NAMESPACE -/// The base feature set that almost all servers are supposed to support. -enum class BASE_FEATURE_SET -{ - YELLOWTEXT, ///< Yellow text in in-character messages. - ///< @since 2.1.0 - FLIPPING, ///< The ability to mirror a character in-game. - ///< @since 2.1.0 - CUSTOMOBJECTIONS, ///< Enables the use of a single custom objection named - ///< `custom`. - ///< @since 2.1.0 - FASTLOADING, ///< Enables the use of "fast loading" instead of the legacy - ///< loading protocol. - ///< @since 2.1.0 - NOENCRYPTION, ///< Disables "FantaCrypt" for the remainder of the session. - ///< @since 2.1.0 - DESKMOD, ///< Allows forcing the appearance or disappearance of the desk. - ///< @since 2.3 to 2.5 - EVIDENCE, ///< Allows creating and presenting evidence. - ///< @since 2.3 to 2.5 - CCCC_IC_SUPPORT, ///< The ability to pair up with another user's character, - ///< the ability to change one's displayed name - ///< in-character ("showname"), and the ability to perform - ///< "immediate" preanimations (ones that happen alongside - ///< text display). - ///< @since 2.6.0 - ARUP, ///< Areas have more data about them than just their name (including - ///< their status, their "lockedness", and who is the Case Master in - ///< the area), and sets the client up to receive and send ARUP - ///< packets. - ///< @since 2.6.0 - CASING_ALERTS, ///< The client gains a new window to announce cases with, - ///< and the settings to set itself up to receive case alerts - ///< based on casing preferences. No longer used. - ///< @since 2.6.0 - MODCALL_REASON, ///< Enables entering a custom reason for calling - ///< moderators. - ///< @since 2.6.0 - LOOPING_SFX, ///< Enables looping SFX extensions for the in-character - ///< command. - ///< @since 2.8.0 - ADDITIVE, ///< Enables "additive" text that allows in-character messages to - ///< concatenate to the previous one sent by the same character. - ///< @since 2.8.0 - EFFECTS, ///< Enables effect overlays. - ///< @since 2.8.0 - Y_OFFSET, ///< Enables support for vertical offsets. - ///< @since 2.9.0 - EXPANDED_DESK_MODS, ///< Enables desk modifiers 2 through 5. - ///< @since 2.9.0 - AUTH_PACKET, ///< Enables the use of the AUTH packet. - ///< @since 2.9.1 - PREZOOM, ///< Preanim zoom. - CUSTOM_BLIPS ///< Allows the in-character messages to contain data about - ///< what blips to use for the character's current message. -}; -Q_ENUM_NS(BASE_FEATURE_SET) - /** * @brief Arranges data about the server the client is connected to. */ class ServerData { public: - /** - * @brief Returns true if one of the standard features exists on the server. - * - * @details Internally, this calls get_feature(const QString &f_feature) - * with the enum's value converted to string. - * - * @param f_feature The feature to check for. - * - * @return True if the feature exists on the server. - */ - bool get_feature(const BASE_FEATURE_SET &f_feature) const; - - /** - * @brief Returns true if the feature exists on the server. - * - * @param f_feature The feature to check for. Case insensitive. - * - * @return True if the feature exists on the server. - */ - bool get_feature(const QString &f_feature) const; - - /** - * @brief Sets the feature list, overwriting the existing one. - * - * @param f_feature_list The new feature list of the server. - */ - void set_features(const QStringList &f_feature_list); - /** * @brief Self-explanatory: gets the software the server is running on. * @@ -135,9 +50,6 @@ class ServerData void set_asset_url(const QString &f_asset_url); private: - /// The features available on the server. Determines what - QStringList m_features; - /// The software the server is running. QString m_server_software; diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 0b077b6c6..4cf770b0e 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -431,7 +431,7 @@ QStringList AOApplication::read_ini_tags(VPath p_path, QString target_tag) settings.beginGroup(target_tag); } QStringList keys = settings.allKeys(); - foreach (QString key, keys) + for (QString key : keys) { QString value = settings.value(key).value(); r_values << key + "=" + value; @@ -660,9 +660,35 @@ int AOApplication::get_emote_mod(QString p_char, int p_emote) if (result_contents.size() < 4) { qWarning() << "misformatted char.ini: " << p_char << ", " << QString::number(p_emote); - return 0; + return IDLE; + } + + bool result = false; + int type = result_contents.at(3).toInt(&result); + if (!result) + { + switch (type) + { + default: + qWarning() << "Invalid emote type" << type << "for character" << p_char << ", emote" << p_emote; + type = IDLE; + break; + + case IDLE: + break; + + case LEGACY_ZOOM: + type = ZOOM; + break; + } + } + else + { + qWarning() << "Invalid emote type" << type << "for character" << p_char << ", emote" << p_emote; + type = IDLE; } - return result_contents.at(3).toInt(); + + return type; } int AOApplication::get_desk_mod(QString p_char, int p_emote) @@ -670,19 +696,38 @@ int AOApplication::get_desk_mod(QString p_char, int p_emote) QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); - if (result_contents.size() < 5) { - return -1; + return DESK_SHOW; } - QString string_result = result_contents.at(4); - if (string_result == "") + bool result; + int type = result_contents.at(4).toInt(&result); + if (!result) { - return -1; + switch (type) + { + default: + qWarning() << "Invalid desk type" << type << "for character" << p_char << ", emote" << p_emote; + type = DESK_SHOW; + break; + + case DESK_HIDE: + case DESK_SHOW: + case DESK_EMOTE_ONLY: + case DESK_PRE_ONLY: + case DESK_EMOTE_ONLY_EX: + case DESK_PRE_ONLY_EX: + break; + } + } + else + { + qWarning() << "Invalid desk type" << type << "for character" << p_char << ", emote" << p_emote; + type = DESK_SHOW; } - return string_result.toInt(); + return type; } QString AOApplication::get_sfx_name(QString p_char, int p_emote)