[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
This commit is contained in:
Chris Miles
2022-01-02 20:52:29 -06:00
committed by GitHub
parent c0f57bed1f
commit 9815f50efa
23 changed files with 365 additions and 121 deletions
+93 -17
View File
@@ -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<std::string> &WorldContentService::GetContentFlags() const
const std::vector<ContentFlagsRepository::ContentFlags> &WorldContentService::GetContentFlags() const
{
return content_flags;
}
/**
* @return
*/
std::vector<std::string> WorldContentService::GetContentFlagsEnabled()
{
std::vector<std::string> enabled_flags;
for (auto &f: GetContentFlags()) {
if (f.enabled) {
enabled_flags.emplace_back(f.flag_name);
}
}
return enabled_flags;
}
/**
* @return
*/
std::vector<std::string> WorldContentService::GetContentFlagsDisabled()
{
std::vector<std::string> 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<std::string> content_flags)
void WorldContentService::SetContentFlags(std::vector<ContentFlagsRepository::ContentFlags> content_flags)
{
WorldContentService::content_flags = content_flags;
}
@@ -90,10 +128,10 @@ void WorldContentService::SetContentFlags(std::vector<std::string> 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<std::string> set_content_flags;
auto content_flags = ContentFlagsRepository::GetWhere(db, "enabled = 1");
std::vector<ContentFlagsRepository::ContentFlags> 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();
}
+18 -7
View File
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
#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<ContentFlagsRepository::ContentFlags> &GetContentFlags() const;
std::vector<std::string> GetContentFlagsEnabled();
std::vector<std::string> GetContentFlagsDisabled();
bool IsContentFlagEnabled(const std::string& content_flag);
void SetContentFlags(std::vector<ContentFlagsRepository::ContentFlags> 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<std::string> content_flags;
public:
const std::vector<std::string> &GetContentFlags() const;
bool IsContentFlagEnabled(const std::string& content_flag);
void SetContentFlags(std::vector<std::string> content_flags);
void ReloadContentFlags(Database &db);
void SetExpansionContext();
std::vector<ContentFlagsRepository::ContentFlags> content_flags;
// reference to database
Database *m_database;
};
extern WorldContentService content_service;
@@ -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<std::string> flags = content_service.GetContentFlags();
std::vector<std::string> flags_disabled = content_service.GetContentFlagsDisabled();
std::vector<std::string> 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
);
+1
View File
@@ -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
+1 -1
View File
@@ -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