From 9815f50efab22edc290fa4b966602787b617b0d6 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Sun, 2 Jan 2022 20:52:29 -0600 Subject: [PATCH] [Expansion] Content Filtering Adjustments (#1910) * Change default expansion values for ALL to -1 from 0 * Adjust content_filter_criteria * Refactor content filtering logic * Allow flag strings to also just be empty instead of null * Formatting * Editor oops --- common/content/world_content_service.cpp | 110 +++++++++++++--- common/content/world_content_service.h | 25 ++-- .../criteria/content_filter_criteria.h | 23 ++-- common/servertalk.h | 1 + common/version.h | 2 +- utils/sql/db_update_manifest.txt | 1 + ...2022_01_02_expansion_default_value_all.sql | 117 ++++++++++++++++++ world/main.cpp | 5 + world/world_server_command_handler.cpp | 23 ++-- world/zoneserver.cpp | 6 + zone/CMakeLists.txt | 1 + zone/command.cpp | 1 + zone/command.h | 1 + zone/embparser_api.cpp | 19 +-- zone/gm_commands/reloadcontentflags.cpp | 15 +++ zone/lua_general.cpp | 4 +- zone/main.cpp | 6 +- zone/spawngroup.cpp | 7 +- zone/worldserver.cpp | 62 +++++++--- zone/zone.cpp | 7 +- zone/zone_event_scheduler.cpp | 9 +- zone/zone_store.cpp | 38 ------ zone/zone_store.h | 3 - 23 files changed, 365 insertions(+), 121 deletions(-) create mode 100644 utils/sql/git/required/2022_01_02_expansion_default_value_all.sql create mode 100755 zone/gm_commands/reloadcontentflags.cpp diff --git a/common/content/world_content_service.cpp b/common/content/world_content_service.cpp index feb0f5b76..42397cdbb 100644 --- a/common/content/world_content_service.cpp +++ b/common/content/world_content_service.cpp @@ -35,8 +35,12 @@ int WorldContentService::GetCurrentExpansion() const return current_expansion; } -void WorldContentService::SetExpansionContext() +WorldContentService *WorldContentService::SetExpansionContext() { + // do a rule manager reload until where we store expansion is changed to somewhere else + RuleManager::Instance()->LoadRules(GetDatabase(), "default", true); + + // pull expansion from rules int expansion = RuleI(Expansion, CurrentExpansion); if (expansion >= Expansion::Classic && expansion <= Expansion::MaxId) { content_service.SetCurrentExpansion(expansion); @@ -47,6 +51,8 @@ void WorldContentService::SetExpansionContext() GetCurrentExpansion(), GetCurrentExpansionName() ); + + return this; } std::string WorldContentService::GetCurrentExpansionName() @@ -73,15 +79,47 @@ void WorldContentService::SetCurrentExpansion(int current_expansion) /** * @return */ -const std::vector &WorldContentService::GetContentFlags() const +const std::vector &WorldContentService::GetContentFlags() const { return content_flags; } +/** + * @return + */ +std::vector WorldContentService::GetContentFlagsEnabled() +{ + std::vector enabled_flags; + + for (auto &f: GetContentFlags()) { + if (f.enabled) { + enabled_flags.emplace_back(f.flag_name); + } + } + + return enabled_flags; +} + +/** + * @return + */ +std::vector WorldContentService::GetContentFlagsDisabled() +{ + std::vector disabled_flags; + + for (auto &f: GetContentFlags()) { + if (!f.enabled) { + disabled_flags.emplace_back(f.flag_name); + } + } + + return disabled_flags; +} + /** * @param content_flags */ -void WorldContentService::SetContentFlags(std::vector content_flags) +void WorldContentService::SetContentFlags(std::vector content_flags) { WorldContentService::content_flags = content_flags; } @@ -90,10 +128,10 @@ void WorldContentService::SetContentFlags(std::vector content_flags * @param content_flag * @return */ -bool WorldContentService::IsContentFlagEnabled(const std::string& content_flag) +bool WorldContentService::IsContentFlagEnabled(const std::string &content_flag) { - for (auto &flag : GetContentFlags()) { - if (flag == content_flag) { + for (auto &f: GetContentFlags()) { + if (f.flag_name == content_flag) { return true; } } @@ -101,20 +139,58 @@ bool WorldContentService::IsContentFlagEnabled(const std::string& content_flag) return false; } -void WorldContentService::ReloadContentFlags(Database &db) +void WorldContentService::ReloadContentFlags() { - std::vector set_content_flags; - auto content_flags = ContentFlagsRepository::GetWhere(db, "enabled = 1"); + std::vector set_content_flags; + auto flags = ContentFlagsRepository::All(*GetDatabase()); - set_content_flags.reserve(content_flags.size()); - for (auto &flags: content_flags) { - set_content_flags.push_back(flags.flag_name); + set_content_flags.reserve(flags.size()); + for (auto &f: flags) { + set_content_flags.push_back(f); + + LogInfo( + "Loaded content flag [{}] [{}]", + f.flag_name, + (f.enabled ? "Enabled" : "Disabled") + ); } - LogInfo( - "Enabled content flags [{}]", - implode(", ", set_content_flags) - ); - SetContentFlags(set_content_flags); } + +Database *WorldContentService::GetDatabase() const +{ + return m_database; +} + +WorldContentService *WorldContentService::SetDatabase(Database *database) +{ + WorldContentService::m_database = database; + + return this; +} + +void WorldContentService::SetContentFlag(const std::string &content_flag_name, bool enabled) +{ + auto flags = ContentFlagsRepository::GetWhere( + *GetDatabase(), + fmt::format("flag_name = '{}'", content_flag_name) + ); + + auto f = ContentFlagsRepository::NewEntity(); + if (!flags.empty()) { + f = flags.front(); + } + + f.enabled = enabled ? 1 : 0; + f.flag_name = content_flag_name; + + if (!flags.empty()) { + ContentFlagsRepository::UpdateOne(*GetDatabase(), f); + } + else { + ContentFlagsRepository::InsertOne(*GetDatabase(), f); + } + + ReloadContentFlags(); +} diff --git a/common/content/world_content_service.h b/common/content/world_content_service.h index 47220b349..512f2c92c 100644 --- a/common/content/world_content_service.h +++ b/common/content/world_content_service.h @@ -23,6 +23,7 @@ #include #include +#include "../repositories/content_flags_repository.h" class Database; @@ -160,15 +161,25 @@ public: bool IsCurrentExpansionTheBurningLands() { return current_expansion == Expansion::ExpansionNumber::TheBurningLands; } bool IsCurrentExpansionTormentOfVelious() { return current_expansion == Expansion::ExpansionNumber::TormentOfVelious; } + const std::vector &GetContentFlags() const; + std::vector GetContentFlagsEnabled(); + std::vector GetContentFlagsDisabled(); + bool IsContentFlagEnabled(const std::string& content_flag); + void SetContentFlags(std::vector content_flags); + void ReloadContentFlags(); + WorldContentService * SetExpansionContext(); + + WorldContentService * SetDatabase(Database *database); + Database *GetDatabase() const; + + void SetContentFlag(const std::string &content_flag_name, bool enabled); + private: int current_expansion{}; - std::vector content_flags; -public: - const std::vector &GetContentFlags() const; - bool IsContentFlagEnabled(const std::string& content_flag); - void SetContentFlags(std::vector content_flags); - void ReloadContentFlags(Database &db); - void SetExpansionContext(); + std::vector content_flags; + + // reference to database + Database *m_database; }; extern WorldContentService content_service; diff --git a/common/repositories/criteria/content_filter_criteria.h b/common/repositories/criteria/content_filter_criteria.h index 6fa1adc71..8d73eefe4 100644 --- a/common/repositories/criteria/content_filter_criteria.h +++ b/common/repositories/criteria/content_filter_criteria.h @@ -40,43 +40,48 @@ namespace ContentFilterCriteria { } criteria += fmt::format( - " AND ({}min_expansion <= {} OR {}min_expansion = 0)", + " AND ({}min_expansion <= {} OR {}min_expansion = -1)", table_prefix, current_expansion_filter_criteria, table_prefix ); criteria += fmt::format( - " AND ({}max_expansion >= {} OR {}max_expansion = 0)", + " AND ({}max_expansion >= {} OR {}max_expansion = -1)", table_prefix, current_expansion_filter_criteria, table_prefix ); - std::vector flags = content_service.GetContentFlags(); + std::vector flags_disabled = content_service.GetContentFlagsDisabled(); + std::vector flags_enabled = content_service.GetContentFlagsEnabled(); std::string flags_in_filter_enabled; std::string flags_in_filter_disabled; - if (!flags.empty()) { + if (!flags_enabled.empty()) { flags_in_filter_enabled = fmt::format( " OR CONCAT(',', {}content_flags, ',') REGEXP ',({}),' ", table_prefix, - implode("|", flags) + implode("|", flags_enabled) ); + } + if (!flags_disabled.empty()) { flags_in_filter_disabled = fmt::format( - " OR CONCAT(',', {}content_flags_disabled, ',') NOT REGEXP ',({}),' ", + " OR CONCAT(',', {}content_flags_disabled, ',') REGEXP ',({}),' ", table_prefix, - implode("|", flags) + implode("|", flags_disabled) ); } criteria += fmt::format( - " AND ({}content_flags IS NULL{}) ", + " AND (({}content_flags IS NULL OR {}content_flags = ''){}) ", + table_prefix, table_prefix, flags_in_filter_enabled ); criteria += fmt::format( - " AND ({}content_flags_disabled IS NULL{}) ", + " AND (({}content_flags_disabled IS NULL OR {}content_flags_disabled = ''){}) ", + table_prefix, table_prefix, flags_in_filter_disabled ); diff --git a/common/servertalk.h b/common/servertalk.h index 86d4b08a6..37c96d844 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -226,6 +226,7 @@ #define ServerOP_UCSServerStatusReply 0x4010 #define ServerOP_HotReloadQuests 0x4011 #define ServerOP_UpdateSchedulerEvents 0x4012 +#define ServerOP_ReloadContentFlags 0x4013 #define ServerOP_CZDialogueWindow 0x4500 #define ServerOP_CZLDoNUpdate 0x4501 diff --git a/common/version.h b/common/version.h index f8eb10b8c..568513041 100644 --- a/common/version.h +++ b/common/version.h @@ -34,7 +34,7 @@ * Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt */ -#define CURRENT_BINARY_DATABASE_VERSION 9174 +#define CURRENT_BINARY_DATABASE_VERSION 9175 #ifdef BOTS #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9028 diff --git a/utils/sql/db_update_manifest.txt b/utils/sql/db_update_manifest.txt index 153155c5d..3c210a287 100644 --- a/utils/sql/db_update_manifest.txt +++ b/utils/sql/db_update_manifest.txt @@ -428,6 +428,7 @@ 9172|2021_05_21_shared_tasks.sql|SHOW TABLES LIKE 'shared_tasks'|empty| 9173|2021_09_14_zone_lava_damage.sql|SHOW COLUMNS FROM `zone` LIKE 'lava_damage'|empty| 9174|2021_10_09_not_null_door_columns.sql|SELECT * FROM db_version WHERE version >= 9174|empty| +9175|2022_01_02_expansion_default_value_all.sql|SHOW COLUMNS FROM `forage` LIKE 'min_expansion'|contains|unsigned # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/required/2022_01_02_expansion_default_value_all.sql b/utils/sql/git/required/2022_01_02_expansion_default_value_all.sql new file mode 100644 index 000000000..3b2261014 --- /dev/null +++ b/utils/sql/git/required/2022_01_02_expansion_default_value_all.sql @@ -0,0 +1,117 @@ +-- forage + +ALTER TABLE `forage` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `forage` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE forage set min_expansion = -1 where min_expansion = 0; +UPDATE forage set max_expansion = -1 where max_expansion = 0; + +-- tradeskill_recipe + +ALTER TABLE `tradeskill_recipe` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `tradeskill_recipe` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE tradeskill_recipe set min_expansion = -1 where min_expansion = 0; +UPDATE tradeskill_recipe set max_expansion = -1 where max_expansion = 0; + +-- fishing + +ALTER TABLE `fishing` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `fishing` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE fishing set min_expansion = -1 where min_expansion = 0; +UPDATE fishing set max_expansion = -1 where max_expansion = 0; + +-- zone + +ALTER TABLE `zone` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `zone` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE zone set min_expansion = -1 where min_expansion = 0; +UPDATE zone set max_expansion = -1 where max_expansion = 0; + +-- traps + +ALTER TABLE `traps` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `traps` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE traps set min_expansion = -1 where min_expansion = 0; +UPDATE traps set max_expansion = -1 where max_expansion = 0; + +-- loottable + +ALTER TABLE `loottable` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `loottable` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE loottable set min_expansion = -1 where min_expansion = 0; +UPDATE loottable set max_expansion = -1 where max_expansion = 0; + +-- ground_spawns + +ALTER TABLE `ground_spawns` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `ground_spawns` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE ground_spawns set min_expansion = -1 where min_expansion = 0; +UPDATE ground_spawns set max_expansion = -1 where max_expansion = 0; + +-- starting_items + +ALTER TABLE `starting_items` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `starting_items` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE starting_items set min_expansion = -1 where min_expansion = 0; +UPDATE starting_items set max_expansion = -1 where max_expansion = 0; + +-- spawn2 + +ALTER TABLE `spawn2` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `spawn2` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE spawn2 set min_expansion = -1 where min_expansion = 0; +UPDATE spawn2 set max_expansion = -1 where max_expansion = 0; + +-- zone_points + +ALTER TABLE `zone_points` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `zone_points` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE zone_points set min_expansion = -1 where min_expansion = 0; +UPDATE zone_points set max_expansion = -1 where max_expansion = 0; + +-- lootdrop + +ALTER TABLE `lootdrop` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `lootdrop` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE lootdrop set min_expansion = -1 where min_expansion = 0; +UPDATE lootdrop set max_expansion = -1 where max_expansion = 0; + +-- global_loot + +ALTER TABLE `global_loot` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `global_loot` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE global_loot set min_expansion = -1 where min_expansion = 0; +UPDATE global_loot set max_expansion = -1 where max_expansion = 0; + +-- doors + +ALTER TABLE `doors` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `doors` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE doors set min_expansion = -1 where min_expansion = 0; +UPDATE doors set max_expansion = -1 where max_expansion = 0; + +-- object + +ALTER TABLE `object` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `object` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE object set min_expansion = -1 where min_expansion = 0; +UPDATE object set max_expansion = -1 where max_expansion = 0; + +-- start_zones + +ALTER TABLE `start_zones` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `start_zones` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE start_zones set min_expansion = -1 where min_expansion = 0; +UPDATE start_zones set max_expansion = -1 where max_expansion = 0; + +-- merchantlist + +ALTER TABLE `merchantlist` CHANGE `max_expansion` `max_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +ALTER TABLE `merchantlist` CHANGE `min_expansion` `min_expansion` tinyint(4) NOT NULL DEFAULT -1 COMMENT ''; +UPDATE merchantlist set min_expansion = -1 where min_expansion = 0; +UPDATE merchantlist set max_expansion = -1 where max_expansion = 0; + +-- spawnentry +ALTER TABLE `spawnentry` ADD `min_expansion` tinyint(4) NOT NULL DEFAULT -1; +ALTER TABLE `spawnentry` ADD `max_expansion` tinyint(4) NOT NULL DEFAULT -1; +ALTER TABLE `spawnentry` ADD `content_flags` varchar(100) NULL; +ALTER TABLE `spawnentry` ADD `content_flags_disabled` varchar(100) NULL; diff --git a/world/main.cpp b/world/main.cpp index ff4cdece9..ee9f12705 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -503,6 +503,11 @@ int main(int argc, char **argv) LogInfo("Initializing [EventScheduler]"); event_scheduler.SetDatabase(&database)->LoadScheduledEvents(); + LogInfo("Initializing [WorldContentService]"); + content_service.SetDatabase(&database) + ->SetExpansionContext() + ->ReloadContentFlags(); + LogInfo("Initializing [SharedTaskManager]"); shared_task_manager.SetDatabase(&database) ->SetContentDatabase(&content_db) diff --git a/world/world_server_command_handler.cpp b/world/world_server_command_handler.cpp index 4c5a36cc7..0eade4f43 100644 --- a/world/world_server_command_handler.cpp +++ b/world/world_server_command_handler.cpp @@ -165,37 +165,37 @@ namespace WorldserverCommandHandler { Json::Value player_tables_json; std::vector player_tables = DatabaseSchema::GetPlayerTables(); - for (const auto &table : player_tables) { + for (const auto &table: player_tables) { player_tables_json.append(table); } Json::Value content_tables_json; std::vector content_tables = DatabaseSchema::GetContentTables(); - for (const auto &table : content_tables) { + for (const auto &table: content_tables) { content_tables_json.append(table); } Json::Value server_tables_json; std::vector server_tables = DatabaseSchema::GetServerTables(); - for (const auto &table : server_tables) { + for (const auto &table: server_tables) { server_tables_json.append(table); } Json::Value login_tables_json; std::vector login_tables = DatabaseSchema::GetLoginTables(); - for (const auto &table : login_tables) { + for (const auto &table: login_tables) { login_tables_json.append(table); } Json::Value state_tables_json; std::vector state_tables = DatabaseSchema::GetStateTables(); - for (const auto &table : state_tables) { + for (const auto &table: state_tables) { state_tables_json.append(table); } Json::Value version_tables_json; std::vector version_tables = DatabaseSchema::GetVersionTables(); - for (const auto &table : version_tables) { + for (const auto &table: version_tables) { version_tables_json.append(table); } @@ -313,11 +313,20 @@ namespace WorldserverCommandHandler { content_service.SetCurrentExpansion(RuleI(Expansion, CurrentExpansion)); - std::vector flags = { + std::vector flags = {}; + auto f = ContentFlagsRepository::NewEntity(); + f.enabled = 1; + + std::vector flag_names = { "hateplane_enabled", "patch_nerf_7077", }; + for (auto &name: flag_names) { + f.flag_name = name; + flags.push_back(f); + } + content_service.SetContentFlags(flags); LogInfo( diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index ae0b2682b..8326c0657 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -41,6 +41,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "shared_task_world_messaging.h" #include "../common/shared_tasks.h" #include "shared_task_manager.h" +#include "../common/content/world_content_service.h" extern ClientList client_list; extern GroupLFPList LFPGroupList; @@ -868,6 +869,11 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { RuleManager::Instance()->LoadRules(&database, "default", true); break; } + case ServerOP_ReloadContentFlags: { + zoneserver_list.SendPacket(pack); + content_service.SetExpansionContext()->ReloadContentFlags(); + break; + } case ServerOP_ReloadRulesWorld: { RuleManager::Instance()->LoadRules(&database, "default", true); diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 1e1f548ba..3c24da07a 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -459,6 +459,7 @@ SET(gm_commands gm_commands/refreshgroup.cpp gm_commands/reloadaa.cpp gm_commands/reloadallrules.cpp + gm_commands/reloadcontentflags.cpp gm_commands/reloademote.cpp gm_commands/reloadlevelmods.cpp gm_commands/reloadmerchants.cpp diff --git a/zone/command.cpp b/zone/command.cpp index be3547754..2eee4e1f1 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -295,6 +295,7 @@ int command_init(void) command_add("refreshgroup", "- Refreshes Group.", AccountStatus::Player, command_refreshgroup) || command_add("reloadaa", "Reloads AA data", AccountStatus::GMMgmt, command_reloadaa) || command_add("reloadallrules", "Executes a reload of all rules.", AccountStatus::QuestTroupe, command_reloadallrules) || + command_add("reloadcontentflags", "Executes a reload of all expansion and content flags", AccountStatus::QuestTroupe, command_reloadcontentflags) || command_add("reloademote", "Reloads NPC Emotes", AccountStatus::QuestTroupe, command_reloademote) || command_add("reloadlevelmods", nullptr, AccountStatus::Max, command_reloadlevelmods) || command_add("reloadmerchants", nullptr, AccountStatus::Max, command_reloadmerchants) || diff --git a/zone/command.h b/zone/command.h index 177b53cb4..dc64da7b2 100644 --- a/zone/command.h +++ b/zone/command.h @@ -216,6 +216,7 @@ void command_randomfeatures(Client *c, const Seperator *sep); void command_refreshgroup(Client *c, const Seperator *sep); void command_reloadaa(Client *c, const Seperator *sep); void command_reloadallrules(Client *c, const Seperator *sep); +void command_reloadcontentflags(Client *c, const Seperator *sep); void command_reloademote(Client *c, const Seperator *sep); void command_reloadlevelmods(Client *c, const Seperator *sep); void command_reloadmerchants(Client *c, const Seperator *sep); diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index e78112de2..94e403508 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -4802,7 +4802,8 @@ XS(XS__SetContentFlag) std::string flag_name = (std::string) SvPV_nolen(ST(0)); bool enabled = (int) SvIV(ST(1)) != 0; - ZoneStore::SetContentFlag(flag_name, enabled); + + content_service.SetContentFlag(flag_name, enabled); XSRETURN_EMPTY; } @@ -5141,7 +5142,7 @@ XS(XS__gethexcolorcode) { sv_setpv(TARG, hex_color_code.c_str()); XSprePUSH; PUSHTARG; - XSRETURN(1); + XSRETURN(1); } XS(XS__getaaexpmodifierbycharid); @@ -5149,7 +5150,7 @@ XS(XS__getaaexpmodifierbycharid) { dXSARGS; if (items != 2) Perl_croak(aTHX_ "Usage: quest::getaaexpmodifierbycharid(uint32 character_id, uint32 zone_id)"); - + dXSTARG; double aa_modifier; uint32 character_id = (uint32) SvUV(ST(0)); @@ -5165,7 +5166,7 @@ XS(XS__getexpmodifierbycharid) { dXSARGS; if (items != 2) Perl_croak(aTHX_ "Usage: quest::getexpmodifierbycharid(uint32 character_id, uint32 zone_id)"); - + dXSTARG; double exp_modifier; uint32 character_id = (uint32) SvUV(ST(0)); @@ -5313,7 +5314,7 @@ XS(XS__getspellstat) { uint8 slot = 0; if (items == 3) slot = (uint8) SvUV(ST(2)); - + stat_value = quest_manager.getspellstat(spell_id, stat_identifier, slot); XSprePUSH; @@ -7551,7 +7552,7 @@ XS(XS__worldwideassigntask) { if (items == 3) max_status = (uint8) SvUV(ST(2)); - + quest_manager.WorldWideTaskUpdate(update_type, task_identifier, task_subidentifier, update_count, enforce_level_requirement, min_status, max_status); } XSRETURN_EMPTY; @@ -7616,7 +7617,7 @@ XS(XS__worldwidedisabletask) { if (items == 3) max_status = (uint8) SvUV(ST(2)); - + quest_manager.WorldWideTaskUpdate(update_type, task_identifier, task_subidentifier, update_count, enforce_level_requirement, min_status, max_status); } XSRETURN_EMPTY; @@ -7640,7 +7641,7 @@ XS(XS__worldwideenabletask) { if (items == 3) max_status = (uint8) SvUV(ST(2)); - + quest_manager.WorldWideTaskUpdate(update_type, task_identifier, task_subidentifier, update_count, enforce_level_requirement, min_status, max_status); } XSRETURN_EMPTY; @@ -7664,7 +7665,7 @@ XS(XS__worldwidefailtask) { if (items == 3) max_status = (uint8) SvUV(ST(2)); - + quest_manager.WorldWideTaskUpdate(update_type, task_identifier, task_subidentifier, update_count, enforce_level_requirement, min_status, max_status); } XSRETURN_EMPTY; diff --git a/zone/gm_commands/reloadcontentflags.cpp b/zone/gm_commands/reloadcontentflags.cpp new file mode 100755 index 000000000..2098fa329 --- /dev/null +++ b/zone/gm_commands/reloadcontentflags.cpp @@ -0,0 +1,15 @@ +#include "../client.h" +#include "../worldserver.h" + +extern WorldServer worldserver; + +void command_reloadcontentflags(Client *c, const Seperator *sep) +{ + if (c) { + auto pack = new ServerPacket(ServerOP_ReloadContentFlags, 0); + worldserver.SendPacket(pack); + c->Message(Chat::Red, "Successfully sent the packet to world to reload content flags globally."); + safe_delete(pack); + } +} + diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index a806be066..444f1ad03 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -1410,7 +1410,7 @@ void lua_add_spawn_point(luabind::adl::object table) { lua_remove_spawn_point(spawn2_id); auto t = new Spawn2(spawn2_id, spawngroup_id, x, y, z, heading, respawn, - variance, timeleft, grid, path_when_zone_idle, condition_id, + variance, timeleft, grid, path_when_zone_idle, condition_id, condition_min_value, enabled, static_cast(animation)); zone->spawn2_list.Insert(t); @@ -1743,7 +1743,7 @@ bool lua_is_content_flag_enabled(std::string content_flag){ } void lua_set_content_flag(std::string flag_name, bool enabled){ - ZoneStore::SetContentFlag(flag_name, enabled); + content_service.SetContentFlag(flag_name, enabled); } Lua_Expedition lua_get_expedition() { diff --git a/zone/main.cpp b/zone/main.cpp index eab175639..f92ea9ea8 100644 --- a/zone/main.cpp +++ b/zone/main.cpp @@ -386,9 +386,9 @@ int main(int argc, char** argv) { LogInfo("Initialized dynamic dictionary entries"); } - content_service.SetExpansionContext(); - - ZoneStore::LoadContentFlags(); + content_service.SetDatabase(&database) + ->SetExpansionContext() + ->ReloadContentFlags(); event_scheduler.SetDatabase(&database)->LoadScheduledEvents(); diff --git a/zone/spawngroup.cpp b/zone/spawngroup.cpp index c337bfac0..84ae2a8f9 100644 --- a/zone/spawngroup.cpp +++ b/zone/spawngroup.cpp @@ -244,8 +244,11 @@ bool ZoneDatabase::LoadSpawnGroups(const char *zone_name, uint16 version, SpawnG AND spawnentry.spawngroupID = spawn2.spawngroupID AND - zone = '{}'), - zone_name + zone = '{}' + {} + ), + zone_name, + ContentFilterCriteria::apply("spawnentry") ); results = QueryDatabase(query); diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 09f1e8134..e478f62f4 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -1977,6 +1977,34 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) RuleManager::Instance()->LoadRules(&database, RuleManager::Instance()->GetActiveRuleset(), true); break; } + case ServerOP_ReloadContentFlags: { + if (zone) { + worldserver.SendEmoteMessage( + 0, + 0, + AccountStatus::GMAdmin, + Chat::Yellow, + fmt::format( + "Content flags (and expansion) reloaded for {}.", + fmt::format( + "{} ({})", + zone->GetLongName(), + zone->GetZoneID() + ), + ( + zone->GetInstanceID() ? + fmt::format( + "Instance ID: {}", + zone->GetInstanceID() + ) : + "" + ) + ).c_str() + ); + } + content_service.SetExpansionContext()->ReloadContentFlags(); + break; + } case ServerOP_ReloadLogs: { LogSys.LoadLogDatabaseSettings(); break; @@ -2069,7 +2097,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { DialogueWindow::Render(client.second, message); } @@ -2243,7 +2271,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } break; - } + } break; } case ServerOP_CZMarquee: @@ -2290,7 +2318,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { client.second->SendMarqueeMessage(type, priority, fade_in, fade_out, duration, message); } @@ -2343,7 +2371,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { client.second->Message(type, message); } @@ -2425,7 +2453,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { switch (update_subtype) { case CZMoveUpdateSubtype_MoveZone: @@ -2492,7 +2520,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { client.second->SetEntityVariable(variable_name, variable_value); } @@ -2549,7 +2577,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { client.second->Signal(signal); } @@ -2609,7 +2637,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) if (client_raid) { for (int member_index = 0; member_index < MAX_RAID_MEMBERS; member_index++) { if (client_raid->members[member_index].member && client_raid->members[member_index].member->IsClient()) { - auto raid_member = client_raid->members[member_index].member->CastToClient(); + auto raid_member = client_raid->members[member_index].member->CastToClient(); switch (update_subtype) { case CZSpellUpdateSubtype_Cast: raid_member->SpellFinished(spell_id, raid_member); @@ -2635,7 +2663,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) } } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { switch (update_subtype) { case CZSpellUpdateSubtype_Cast: @@ -2792,9 +2820,9 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) break; } } - } + } } else if (update_type == CZUpdateType_Expedition) { - for (auto &client: entity_list.GetClientList()) { + for (auto &client: entity_list.GetClientList()) { if (client.second->GetExpedition() && client.second->GetExpedition()->GetID() == update_identifier) { switch (update_subtype) { case CZTaskUpdateSubtype_ActivityReset: @@ -2968,7 +2996,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) uint8 min_status = WWSEV->min_status; uint8 max_status = WWSEV->max_status; if (update_type == WWSetEntityVariableUpdateType_Character) { - for (auto &client : entity_list.GetClientList()) { + for (auto &client : entity_list.GetClientList()) { if (client.second->Admin() >= min_status && (client.second->Admin() <= max_status || max_status == AccountStatus::Player)) { client.second->SetEntityVariable(variable_name, variable_value); } @@ -2988,7 +3016,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) uint8 min_status = WWS->min_status; uint8 max_status = WWS->max_status; if (update_type == WWSignalUpdateType_Character) { - for (auto &client : entity_list.GetClientList()) { + for (auto &client : entity_list.GetClientList()) { if (client.second->Admin() >= min_status && (client.second->Admin() <= max_status || max_status == AccountStatus::Player)) { client.second->Signal(signal); } @@ -3008,13 +3036,13 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) uint8 min_status = WWS->min_status; uint8 max_status = WWS->max_status; if (update_type == WWSpellUpdateType_Cast) { - for (auto &client : entity_list.GetClientList()) { + for (auto &client : entity_list.GetClientList()) { if (client.second->Admin() >= min_status && (client.second->Admin() <= max_status || max_status == AccountStatus::Player)) { client.second->SpellFinished(spell_id, client.second); } } } else if (update_type == WWSpellUpdateType_Remove) { - for (auto &client : entity_list.GetClientList()) { + for (auto &client : entity_list.GetClientList()) { if (client.second->Admin() >= min_status && (client.second->Admin() <= max_status || max_status == AccountStatus::Player)) { client.second->BuffFadeBySpellID(spell_id); } @@ -3031,8 +3059,8 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) int update_count = WWTU->update_count; bool enforce_level_requirement = WWTU->enforce_level_requirement; uint8 min_status = WWTU->min_status; - uint8 max_status = WWTU->max_status; - for (auto &client : entity_list.GetClientList()) { + uint8 max_status = WWTU->max_status; + for (auto &client : entity_list.GetClientList()) { if (client.second->Admin() >= min_status && (client.second->Admin() <= max_status || max_status == AccountStatus::Player)) { switch (update_type) { case WWTaskUpdateType_ActivityReset: diff --git a/zone/zone.cpp b/zone/zone.cpp index 2bfbd882b..2dffad339 100755 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1255,9 +1255,8 @@ void Zone::ReloadStaticData() { ); } // if that fails, try the file name, then load defaults - content_service.SetExpansionContext(); + content_service.SetExpansionContext()->ReloadContentFlags(); - ZoneStore::LoadContentFlags(); LogInfo("Zone Static Data Reloaded"); } @@ -2749,7 +2748,7 @@ uint32 Zone::GetCurrencyID(uint32 item_id) if (!item_id) { return 0; } - + for (const auto& alternate_currency : AlternateCurrencies) { if (item_id == alternate_currency.item_id) { return alternate_currency.id; @@ -2772,4 +2771,4 @@ uint32 Zone::GetCurrencyItemID(uint32 currency_id) } return 0; -} \ No newline at end of file +} diff --git a/zone/zone_event_scheduler.cpp b/zone/zone_event_scheduler.cpp index 4bdb2cd6f..2294ad50e 100644 --- a/zone/zone_event_scheduler.cpp +++ b/zone/zone_event_scheduler.cpp @@ -54,7 +54,7 @@ void ZoneEventScheduler::Process(Zone *zone, WorldContentService *content_servic auto flag_name = e.event_data; if (!flag_name.empty()) { LogScheduler("Deactivating event [{}] resetting content flags", e.description); - content_service->ReloadContentFlags(*m_database); + content_service->ReloadContentFlags(); } // force active events clear and reapply all active events because we reset the entire state @@ -117,8 +117,13 @@ void ZoneEventScheduler::Process(Zone *zone, WorldContentService *content_servic flag_name ); + // add new flag entity to stack auto flags = content_service->GetContentFlags(); - flags.push_back(flag_name); + auto f = ContentFlagsRepository::NewEntity(); + f.flag_name = flag_name; + f.enabled = 1; + flags.push_back(f); + content_service->SetContentFlags(flags); m_active_events.push_back(e); } diff --git a/zone/zone_store.cpp b/zone/zone_store.cpp index 67eaeb21e..52eeace3c 100644 --- a/zone/zone_store.cpp +++ b/zone/zone_store.cpp @@ -160,41 +160,3 @@ ZoneRepository::Zone ZoneStore::GetZone(const char *in_zone_name) return ZoneRepository::Zone(); } - -/** - * @return - */ -void ZoneStore::LoadContentFlags() -{ - content_service.ReloadContentFlags(database); -} - -/** - * Sets the value in the database and proceeds to load content flags into the server context again - * - * @param content_flag_name - * @param enabled - */ -void ZoneStore::SetContentFlag(const std::string &content_flag_name, bool enabled) -{ - auto content_flags = ContentFlagsRepository::GetWhere(database, - fmt::format("flag_name = '{}'", content_flag_name) - ); - - auto content_flag = ContentFlagsRepository::NewEntity(); - if (!content_flags.empty()) { - content_flag = content_flags.front(); - } - - content_flag.enabled = enabled ? 1 : 0; - content_flag.flag_name = content_flag_name; - - if (!content_flags.empty()) { - ContentFlagsRepository::UpdateOne(database, content_flag); - } - else { - ContentFlagsRepository::InsertOne(database, content_flag); - } - - LoadContentFlags(); -} diff --git a/zone/zone_store.h b/zone/zone_store.h index 521ec63bb..7238b0ade 100644 --- a/zone/zone_store.h +++ b/zone/zone_store.h @@ -42,9 +42,6 @@ public: std::string GetZoneLongName(uint32 zone_id); const char *GetZoneName(uint32 zone_id, bool error_unknown = false); const char *GetZoneLongName(uint32 zone_id, bool error_unknown = false); - - static void LoadContentFlags(); - static void SetContentFlag(const std::string& content_flag_name, bool enabled); }; extern ZoneStore zone_store;