mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-03 02:52:26 +00:00
Change rules to use cat in the actual underlying variables and by extension lua exports
This commit is contained in:
parent
a00ab6867c
commit
02518cdae1
@ -37,35 +37,35 @@
|
|||||||
values [catname] -> show the values of all rules in the specified category/
|
values [catname] -> show the values of all rules in the specified category/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *RuleManager::s_categoryNames[_CatCount+1] = {
|
const char* RuleManager::s_categoryNames[_CatCount + 1] = {
|
||||||
#define RULE_CATEGORY(catname) \
|
#define RULE_CATEGORY(catname) \
|
||||||
#catname ,
|
#catname ,
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
"InvalidCategory"
|
"InvalidCategory"
|
||||||
};
|
};
|
||||||
|
|
||||||
const RuleManager::RuleInfo RuleManager::s_RuleInfo[_IntRuleCount+_RealRuleCount+_BoolRuleCount+1] = {
|
const RuleManager::RuleInfo RuleManager::s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount + 1] = {
|
||||||
/* this is done in three steps so we can reliably get to them by index*/
|
/* this is done in three steps so we can reliably get to them by index*/
|
||||||
#define RULE_INT(cat, rule, default_value, notes) \
|
#define RULE_INT(cat, rule, default_value, notes) \
|
||||||
{ #cat ":" #rule, Category__##cat, IntRule, Int__##rule, notes },
|
{ #cat ":" #rule, Category__##cat, IntRule, Int__##cat__##rule, notes },
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
#define RULE_REAL(cat, rule, default_value, notes) \
|
#define RULE_REAL(cat, rule, default_value, notes) \
|
||||||
{ #cat ":" #rule, Category__##cat, RealRule, Real__##rule, notes },
|
{ #cat ":" #rule, Category__##cat, RealRule, Real__##cat__##rule, notes },
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
#define RULE_BOOL(cat, rule, default_value, notes) \
|
#define RULE_BOOL(cat, rule, default_value, notes) \
|
||||||
{ #cat ":" #rule, Category__##cat, BoolRule, Bool__##rule, notes },
|
{ #cat ":" #rule, Category__##cat, BoolRule, Bool__##cat__##rule, notes },
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
{ "Invalid Rule", _CatCount, IntRule }
|
{ "Invalid Rule", _CatCount, IntRule }
|
||||||
};
|
};
|
||||||
|
|
||||||
RuleManager::RuleManager()
|
RuleManager::RuleManager()
|
||||||
: m_activeRuleset(0),
|
: m_activeRuleset(0),
|
||||||
m_activeName("default")
|
m_activeName("default")
|
||||||
{
|
{
|
||||||
ResetRules(false);
|
ResetRules(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleManager::CategoryType RuleManager::FindCategory(const char *catname) {
|
RuleManager::CategoryType RuleManager::FindCategory(const char* catname) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _CatCount; i++) {
|
for (i = 0; i < _CatCount; i++) {
|
||||||
if (strcasecmp(catname, s_categoryNames[i]) == 0)
|
if (strcasecmp(catname, s_categoryNames[i]) == 0)
|
||||||
@ -74,7 +74,7 @@ RuleManager::CategoryType RuleManager::FindCategory(const char *catname) {
|
|||||||
return(InvalidCategory);
|
return(InvalidCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::ListRules(const char *catname, std::vector<const char *> &into) {
|
bool RuleManager::ListRules(const char* catname, std::vector<const char*>& into) {
|
||||||
CategoryType cat = InvalidCategory;
|
CategoryType cat = InvalidCategory;
|
||||||
if (catname != nullptr) {
|
if (catname != nullptr) {
|
||||||
cat = FindCategory(catname);
|
cat = FindCategory(catname);
|
||||||
@ -86,7 +86,7 @@ bool RuleManager::ListRules(const char *catname, std::vector<const char *> &into
|
|||||||
int i;
|
int i;
|
||||||
int rule_count = CountRules();
|
int rule_count = CountRules();
|
||||||
for (i = 0; i < rule_count; i++) {
|
for (i = 0; i < rule_count; i++) {
|
||||||
const RuleInfo &rule = s_RuleInfo[i];
|
const RuleInfo& rule = s_RuleInfo[i];
|
||||||
if (catname == nullptr || cat == rule.category) {
|
if (catname == nullptr || cat == rule.category) {
|
||||||
into.push_back(rule.name);
|
into.push_back(rule.name);
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ bool RuleManager::ListRules(const char *catname, std::vector<const char *> &into
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::ListCategories(std::vector<const char *> &into) {
|
bool RuleManager::ListCategories(std::vector<const char*>& into) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _CatCount; i++) {
|
for (i = 0; i < _CatCount; i++) {
|
||||||
into.push_back(s_categoryNames[i]);
|
into.push_back(s_categoryNames[i]);
|
||||||
@ -102,24 +102,24 @@ bool RuleManager::ListCategories(std::vector<const char *> &into) {
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::GetRule(const char *rule_name, std::string &return_value) {
|
bool RuleManager::GetRule(const char* rule_name, std::string& return_value) {
|
||||||
RuleType type;
|
RuleType type;
|
||||||
uint16 index;
|
uint16 index;
|
||||||
if (!_FindRule(rule_name, type, index))
|
if (!_FindRule(rule_name, type, index))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char tmp[255] = "";
|
char tmp[255] = "";
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case IntRule:
|
case IntRule:
|
||||||
sprintf(tmp, "%i", m_RuleIntValues[index]);
|
sprintf(tmp, "%i", m_RuleIntValues[index]);
|
||||||
break;
|
break;
|
||||||
case RealRule:
|
case RealRule:
|
||||||
sprintf(tmp, "%f", m_RuleRealValues[index]);
|
sprintf(tmp, "%f", m_RuleRealValues[index]);
|
||||||
break;
|
break;
|
||||||
case BoolRule:
|
case BoolRule:
|
||||||
std::string tmp_val = m_RuleBoolValues[index] ? "true" : "false";
|
std::string tmp_val = m_RuleBoolValues[index] ? "true" : "false";
|
||||||
sprintf(tmp, "%s", tmp_val.c_str());
|
sprintf(tmp, "%s", tmp_val.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return_value = tmp;
|
return_value = tmp;
|
||||||
@ -127,13 +127,13 @@ bool RuleManager::GetRule(const char *rule_name, std::string &return_value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Database *database, bool db_save, bool reload) {
|
bool RuleManager::SetRule(const char* rule_name, const char* rule_value, Database* database, bool db_save, bool reload) {
|
||||||
if(rule_name == nullptr || rule_value == nullptr)
|
if (rule_name == nullptr || rule_value == nullptr)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
RuleType type;
|
RuleType type;
|
||||||
uint16 index;
|
uint16 index;
|
||||||
if(!_FindRule(rule_name, type, index))
|
if (!_FindRule(rule_name, type, index))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if (reload) {
|
if (reload) {
|
||||||
@ -143,26 +143,26 @@ bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Databas
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(type) {
|
switch (type) {
|
||||||
case IntRule:
|
case IntRule:
|
||||||
m_RuleIntValues[index] = atoi(rule_value);
|
m_RuleIntValues[index] = atoi(rule_value);
|
||||||
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleIntValues[index]);
|
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleIntValues[index]);
|
||||||
break;
|
break;
|
||||||
case RealRule:
|
case RealRule:
|
||||||
m_RuleRealValues[index] = atof(rule_value);
|
m_RuleRealValues[index] = atof(rule_value);
|
||||||
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleRealValues[index]);
|
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleRealValues[index]);
|
||||||
break;
|
break;
|
||||||
case BoolRule:
|
case BoolRule:
|
||||||
uint32 val = 0;
|
uint32 val = 0;
|
||||||
if (!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1"))
|
if (!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1"))
|
||||||
val = 1;
|
val = 1;
|
||||||
|
|
||||||
m_RuleBoolValues[index] = val;
|
m_RuleBoolValues[index] = val;
|
||||||
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleBoolValues[index] == 1 ? "true" : "false");
|
LogRules("Set rule [{}] to value [{}]", rule_name, m_RuleBoolValues[index] == 1 ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(db_save)
|
if (db_save)
|
||||||
_SaveRule(database, type, index);
|
_SaveRule(database, type, index);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -179,13 +179,13 @@ void RuleManager::ResetRules(bool reload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log(Logs::Detail, Logs::Rules, "Resetting running rules to default values");
|
Log(Logs::Detail, Logs::Rules, "Resetting running rules to default values");
|
||||||
#define RULE_INT(cat, rule, default_value, notes) \
|
#define RULE_INT(cat, rule, default_value, notes) \
|
||||||
m_RuleIntValues[ Int__##rule ] = default_value;
|
m_RuleIntValues[ Int__##cat__##rule ] = default_value;
|
||||||
#define RULE_REAL(cat, rule, default_value, notes) \
|
#define RULE_REAL(cat, rule, default_value, notes) \
|
||||||
m_RuleRealValues[ Real__##rule ] = default_value;
|
m_RuleRealValues[ Real__##cat__##rule ] = default_value;
|
||||||
#define RULE_BOOL(cat, rule, default_value, notes) \
|
#define RULE_BOOL(cat, rule, default_value, notes) \
|
||||||
m_RuleBoolValues[ Bool__##rule ] = default_value;
|
m_RuleBoolValues[ Bool__##cat__##rule ] = default_value;
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
|
|
||||||
// restore these rules to their pre-reset values
|
// restore these rules to their pre-reset values
|
||||||
if (reload) {
|
if (reload) {
|
||||||
@ -194,14 +194,14 @@ void RuleManager::ResetRules(bool reload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::_FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into) {
|
bool RuleManager::_FindRule(const char* rule_name, RuleType& type_into, uint16& index_into) {
|
||||||
if (rule_name == nullptr)
|
if (rule_name == nullptr)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int rule_count = CountRules();
|
int rule_count = CountRules();
|
||||||
for (i = 0; i < rule_count; i++) {
|
for (i = 0; i < rule_count; i++) {
|
||||||
const RuleInfo &rule = s_RuleInfo[i];
|
const RuleInfo& rule = s_RuleInfo[i];
|
||||||
if (strcmp(rule_name, rule.name) == 0) {
|
if (strcmp(rule_name, rule.name) == 0) {
|
||||||
type_into = rule.type;
|
type_into = rule.type;
|
||||||
index_into = rule.rule_index;
|
index_into = rule.rule_index;
|
||||||
@ -213,38 +213,38 @@ bool RuleManager::_FindRule(const char *rule_name, RuleType &type_into, uint16 &
|
|||||||
}
|
}
|
||||||
|
|
||||||
//assumes index is valid!
|
//assumes index is valid!
|
||||||
const char *RuleManager::_GetRuleName(RuleType type, uint16 index) {
|
const char* RuleManager::_GetRuleName(RuleType type, uint16 index) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IntRule:
|
case IntRule:
|
||||||
return(s_RuleInfo[index].name);
|
return(s_RuleInfo[index].name);
|
||||||
case RealRule:
|
case RealRule:
|
||||||
return(s_RuleInfo[index+_IntRuleCount].name);
|
return(s_RuleInfo[index + _IntRuleCount].name);
|
||||||
case BoolRule:
|
case BoolRule:
|
||||||
return(s_RuleInfo[index+_IntRuleCount+_RealRuleCount].name);
|
return(s_RuleInfo[index + _IntRuleCount + _RealRuleCount].name);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//should never happen
|
//should never happen
|
||||||
return(s_RuleInfo[_IntRuleCount+_RealRuleCount+_BoolRuleCount].name); // no need to create a string when one already exists...
|
return(s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount].name); // no need to create a string when one already exists...
|
||||||
}
|
}
|
||||||
|
|
||||||
//assumes index is valid!
|
//assumes index is valid!
|
||||||
const std::string &RuleManager::_GetRuleNotes(RuleType type, uint16 index) {
|
const std::string& RuleManager::_GetRuleNotes(RuleType type, uint16 index) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IntRule:
|
case IntRule:
|
||||||
return(s_RuleInfo[index].notes);
|
return(s_RuleInfo[index].notes);
|
||||||
case RealRule:
|
case RealRule:
|
||||||
return(s_RuleInfo[index+_IntRuleCount].notes);
|
return(s_RuleInfo[index + _IntRuleCount].notes);
|
||||||
case BoolRule:
|
case BoolRule:
|
||||||
return(s_RuleInfo[index+_IntRuleCount+_RealRuleCount].notes);
|
return(s_RuleInfo[index + _IntRuleCount + _RealRuleCount].notes);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//should never happen
|
//should never happen
|
||||||
return(s_RuleInfo[_IntRuleCount+_RealRuleCount+_BoolRuleCount].notes);
|
return(s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount].notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::LoadRules(Database *database, const char *ruleset_name, bool reload) {
|
bool RuleManager::LoadRules(Database* database, const char* ruleset_name, bool reload) {
|
||||||
|
|
||||||
int ruleset_id = this->GetRulesetID(database, ruleset_name);
|
int ruleset_id = this->GetRulesetID(database, ruleset_name);
|
||||||
if (ruleset_id < 0) {
|
if (ruleset_id < 0) {
|
||||||
@ -308,8 +308,8 @@ bool RuleManager::LoadRules(Database *database, const char *ruleset_name, bool r
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleManager::SaveRules(Database *database, const char *ruleset_name) {
|
void RuleManager::SaveRules(Database* database, const char* ruleset_name) {
|
||||||
|
|
||||||
if (ruleset_name != nullptr) {
|
if (ruleset_name != nullptr) {
|
||||||
//saving to a specific name
|
//saving to a specific name
|
||||||
if (m_activeName != ruleset_name) {
|
if (m_activeName != ruleset_name) {
|
||||||
@ -340,43 +340,43 @@ void RuleManager::SaveRules(Database *database, const char *ruleset_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleManager::_SaveRule(Database *database, RuleType type, uint16 index) {
|
void RuleManager::_SaveRule(Database* database, RuleType type, uint16 index) {
|
||||||
char value_string[100];
|
char value_string[100];
|
||||||
|
|
||||||
if (type == IntRule && strcasecmp(_GetRuleName(type, index), "World:ExpansionSettings") == 0)
|
if (type == IntRule && strcasecmp(_GetRuleName(type, index), "World:ExpansionSettings") == 0)
|
||||||
return;
|
return;
|
||||||
if (type == BoolRule && strcasecmp(_GetRuleName(type, index), "World:UseClientBasedExpansionSettings") == 0)
|
if (type == BoolRule && strcasecmp(_GetRuleName(type, index), "World:UseClientBasedExpansionSettings") == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IntRule:
|
case IntRule:
|
||||||
sprintf(value_string, "%d", m_RuleIntValues[index]);
|
sprintf(value_string, "%d", m_RuleIntValues[index]);
|
||||||
break;
|
break;
|
||||||
case RealRule:
|
case RealRule:
|
||||||
sprintf(value_string, "%.13f", m_RuleRealValues[index]);
|
sprintf(value_string, "%.13f", m_RuleRealValues[index]);
|
||||||
break;
|
break;
|
||||||
case BoolRule:
|
case BoolRule:
|
||||||
sprintf(value_string, "%s", m_RuleBoolValues[index] ? "true" : "false");
|
sprintf(value_string, "%s", m_RuleBoolValues[index] ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string query = StringFormat(
|
std::string query = StringFormat(
|
||||||
"REPLACE INTO `rule_values`"
|
"REPLACE INTO `rule_values`"
|
||||||
"(`ruleset_id`, `rule_name`, `rule_value`, `notes`)"
|
"(`ruleset_id`, `rule_name`, `rule_value`, `notes`)"
|
||||||
" VALUES('%d', '%s', '%s', '%s')",
|
" VALUES('%d', '%s', '%s', '%s')",
|
||||||
m_activeRuleset,
|
m_activeRuleset,
|
||||||
_GetRuleName(type, index),
|
_GetRuleName(type, index),
|
||||||
value_string,
|
value_string,
|
||||||
EscapeString(_GetRuleNotes(type, index)).c_str()
|
EscapeString(_GetRuleNotes(type, index)).c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
database->QueryDatabase(query);
|
database->QueryDatabase(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::UpdateInjectedRules(Database *db, const char *ruleset_name, bool quiet_update)
|
bool RuleManager::UpdateInjectedRules(Database* db, const char* ruleset_name, bool quiet_update)
|
||||||
{
|
{
|
||||||
std::vector<std::string> database_data;
|
std::vector<std::string> database_data;
|
||||||
std::map<std::string, std::pair<std::string, const std::string *>> rule_data;
|
std::map<std::string, std::pair<std::string, const std::string*>> rule_data;
|
||||||
std::vector<std::tuple<int, std::string, std::string, std::string>> injected_rule_entries;
|
std::vector<std::tuple<int, std::string, std::string, std::string>> injected_rule_entries;
|
||||||
|
|
||||||
if (ruleset_name == nullptr) {
|
if (ruleset_name == nullptr) {
|
||||||
@ -402,7 +402,7 @@ bool RuleManager::UpdateInjectedRules(Database *db, const char *ruleset_name, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build rule data entries
|
// build rule data entries
|
||||||
for (const auto &ri_iter : s_RuleInfo) {
|
for (const auto& ri_iter : s_RuleInfo) {
|
||||||
if (strcasecmp(ri_iter.name, "Invalid Rule") == 0) {
|
if (strcasecmp(ri_iter.name, "Invalid Rule") == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -431,9 +431,9 @@ bool RuleManager::UpdateInjectedRules(Database *db, const char *ruleset_name, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build injected entries
|
// build injected entries
|
||||||
for (const auto &rd_iter : rule_data) {
|
for (const auto& rd_iter : rule_data) {
|
||||||
|
|
||||||
const auto &dd_iter = std::find(database_data.begin(), database_data.end(), rd_iter.first);
|
const auto& dd_iter = std::find(database_data.begin(), database_data.end(), rd_iter.first);
|
||||||
if (dd_iter == database_data.end()) {
|
if (dd_iter == database_data.end()) {
|
||||||
|
|
||||||
injected_rule_entries.push_back(
|
injected_rule_entries.push_back(
|
||||||
@ -442,7 +442,7 @@ bool RuleManager::UpdateInjectedRules(Database *db, const char *ruleset_name, bo
|
|||||||
rd_iter.first, // `rule_name`
|
rd_iter.first, // `rule_name`
|
||||||
rd_iter.second.first, // `rule_value`
|
rd_iter.second.first, // `rule_value`
|
||||||
EscapeString(*rd_iter.second.second) // `notes`
|
EscapeString(*rd_iter.second.second) // `notes`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!quiet_update) {
|
if (!quiet_update) {
|
||||||
@ -481,11 +481,11 @@ bool RuleManager::UpdateInjectedRules(Database *db, const char *ruleset_name, bo
|
|||||||
ruleset_id
|
ruleset_id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::UpdateOrphanedRules(Database *db, bool quiet_update)
|
bool RuleManager::UpdateOrphanedRules(Database* db, bool quiet_update)
|
||||||
{
|
{
|
||||||
std::vector<std::string> rule_data;
|
std::vector<std::string> rule_data;
|
||||||
std::vector<std::string> orphaned_rule_entries;
|
std::vector<std::string> orphaned_rule_entries;
|
||||||
@ -499,7 +499,7 @@ bool RuleManager::UpdateOrphanedRules(Database *db, bool quiet_update)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build rule data entries
|
// build rule data entries
|
||||||
for (const auto &ri_iter : s_RuleInfo) {
|
for (const auto& ri_iter : s_RuleInfo) {
|
||||||
if (strcasecmp(ri_iter.name, "Invalid Rule") == 0) {
|
if (strcasecmp(ri_iter.name, "Invalid Rule") == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -509,8 +509,8 @@ bool RuleManager::UpdateOrphanedRules(Database *db, bool quiet_update)
|
|||||||
|
|
||||||
// build orphaned entries
|
// build orphaned entries
|
||||||
for (auto row : results) {
|
for (auto row : results) {
|
||||||
|
|
||||||
const auto &rd_iter = std::find(rule_data.begin(), rule_data.end(), row[0]);
|
const auto& rd_iter = std::find(rule_data.begin(), rule_data.end(), row[0]);
|
||||||
if (rd_iter == rule_data.end()) {
|
if (rd_iter == rule_data.end()) {
|
||||||
|
|
||||||
orphaned_rule_entries.push_back(std::string(row[0]));
|
orphaned_rule_entries.push_back(std::string(row[0]));
|
||||||
@ -526,7 +526,7 @@ bool RuleManager::UpdateOrphanedRules(Database *db, bool quiet_update)
|
|||||||
|
|
||||||
if (orphaned_rule_entries.size()) {
|
if (orphaned_rule_entries.size()) {
|
||||||
|
|
||||||
std::string query (
|
std::string query(
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"DELETE FROM `rule_values` WHERE `rule_name` IN ({})",
|
"DELETE FROM `rule_values` WHERE `rule_name` IN ({})",
|
||||||
implode(",", std::pair<char, char>('\'', '\''), orphaned_rule_entries)
|
implode(",", std::pair<char, char>('\'', '\''), orphaned_rule_entries)
|
||||||
@ -539,11 +539,11 @@ bool RuleManager::UpdateOrphanedRules(Database *db, bool quiet_update)
|
|||||||
|
|
||||||
LogInfo("[{}] Orphaned Rule(s) Deleted from [All Rulesets] (-1)", orphaned_rule_entries.size());
|
LogInfo("[{}] Orphaned Rule(s) Deleted from [All Rulesets] (-1)", orphaned_rule_entries.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::RestoreRuleNotes(Database *db)
|
bool RuleManager::RestoreRuleNotes(Database* db)
|
||||||
{
|
{
|
||||||
std::string query("SELECT `ruleset_id`, `rule_name`, `notes` FROM `rule_values`");
|
std::string query("SELECT `ruleset_id`, `rule_name`, `notes` FROM `rule_values`");
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ bool RuleManager::RestoreRuleNotes(Database *db)
|
|||||||
int update_count = 0;
|
int update_count = 0;
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
|
||||||
auto rule = [](const char *rule_name) {
|
auto rule = [](const char* rule_name) {
|
||||||
|
|
||||||
for (auto rule_iter : s_RuleInfo) {
|
for (auto rule_iter : s_RuleInfo) {
|
||||||
if (strcasecmp(rule_iter.name, rule_name) == 0) {
|
if (strcasecmp(rule_iter.name, rule_name) == 0) {
|
||||||
@ -563,7 +563,7 @@ bool RuleManager::RestoreRuleNotes(Database *db)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_RuleInfo[_IntRuleCount+_RealRuleCount+_BoolRuleCount];
|
return s_RuleInfo[_IntRuleCount + _RealRuleCount + _BoolRuleCount];
|
||||||
}(row[1]);
|
}(row[1]);
|
||||||
|
|
||||||
if (strcasecmp(rule.name, row[1]) != 0) {
|
if (strcasecmp(rule.name, row[1]) != 0) {
|
||||||
@ -586,7 +586,7 @@ bool RuleManager::RestoreRuleNotes(Database *db)
|
|||||||
if (!db->QueryDatabase(query).Success()) {
|
if (!db->QueryDatabase(query).Success()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
++update_count;
|
++update_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,7 +597,7 @@ bool RuleManager::RestoreRuleNotes(Database *db)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RuleManager::GetRulesetID(Database *database, const char *ruleset_name) {
|
int RuleManager::GetRulesetID(Database* database, const char* ruleset_name) {
|
||||||
|
|
||||||
uint32 len = static_cast<uint32>(strlen(ruleset_name));
|
uint32 len = static_cast<uint32>(strlen(ruleset_name));
|
||||||
auto rst = new char[2 * len + 1];
|
auto rst = new char[2 * len + 1];
|
||||||
@ -617,7 +617,7 @@ int RuleManager::GetRulesetID(Database *database, const char *ruleset_name) {
|
|||||||
return atoi(row[0]);
|
return atoi(row[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RuleManager::_FindOrCreateRuleset(Database *database, const char *in_ruleset_name) {
|
int RuleManager::_FindOrCreateRuleset(Database* database, const char* in_ruleset_name) {
|
||||||
|
|
||||||
int ruleset_id = GetRulesetID(database, in_ruleset_name);
|
int ruleset_id = GetRulesetID(database, in_ruleset_name);
|
||||||
if (ruleset_id >= 0)
|
if (ruleset_id >= 0)
|
||||||
@ -636,7 +636,7 @@ int RuleManager::_FindOrCreateRuleset(Database *database, const char *in_ruleset
|
|||||||
return results.LastInsertedID();
|
return results.LastInsertedID();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RuleManager::GetRulesetName(Database *database, int ruleset_id) {
|
std::string RuleManager::GetRulesetName(Database* database, int ruleset_id) {
|
||||||
std::string query = StringFormat("SELECT name FROM rule_sets WHERE ruleset_id=%d", ruleset_id);
|
std::string query = StringFormat("SELECT name FROM rule_sets WHERE ruleset_id=%d", ruleset_id);
|
||||||
auto results = database->QueryDatabase(query);
|
auto results = database->QueryDatabase(query);
|
||||||
if (!results.Success())
|
if (!results.Success())
|
||||||
@ -650,7 +650,7 @@ std::string RuleManager::GetRulesetName(Database *database, int ruleset_id) {
|
|||||||
return row[0];
|
return row[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleManager::ListRulesets(Database *database, std::map<int, std::string> &into) {
|
bool RuleManager::ListRulesets(Database* database, std::map<int, std::string>& into) {
|
||||||
|
|
||||||
//start out with the default set which is always present.
|
//start out with the default set which is always present.
|
||||||
into[0] = "default";
|
into[0] = "default";
|
||||||
|
|||||||
@ -30,11 +30,11 @@
|
|||||||
//which makes it a global for now, but with instancing we will do exactly
|
//which makes it a global for now, but with instancing we will do exactly
|
||||||
//what we do with the zone global and just make it a member of core classes
|
//what we do with the zone global and just make it a member of core classes
|
||||||
#define RuleI(cat, rule) \
|
#define RuleI(cat, rule) \
|
||||||
RuleManager::Instance()->GetIntRule( RuleManager::Int__##rule )
|
RuleManager::Instance()->GetIntRule( RuleManager::Int__##cat__##rule )
|
||||||
#define RuleR(cat, rule) \
|
#define RuleR(cat, rule) \
|
||||||
RuleManager::Instance()->GetRealRule( RuleManager::Real__##rule )
|
RuleManager::Instance()->GetRealRule( RuleManager::Real__##cat__##rule )
|
||||||
#define RuleB(cat, rule) \
|
#define RuleB(cat, rule) \
|
||||||
RuleManager::Instance()->GetBoolRule( RuleManager::Bool__##rule )
|
RuleManager::Instance()->GetBoolRule( RuleManager::Bool__##cat__##rule )
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -49,30 +49,30 @@ class RuleManager {
|
|||||||
public:
|
public:
|
||||||
//generate our rule enums:
|
//generate our rule enums:
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#define RULE_INT(cat, rule, default_value, notes) \
|
#define RULE_INT(cat, rule, default_value, notes) \
|
||||||
Int__##rule,
|
Int__##cat__##rule,
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
_IntRuleCount
|
_IntRuleCount
|
||||||
} IntType;
|
} IntType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#define RULE_REAL(cat, rule, default_value, notes) \
|
#define RULE_REAL(cat, rule, default_value, notes) \
|
||||||
Real__##rule,
|
Real__##cat__##rule,
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
_RealRuleCount
|
_RealRuleCount
|
||||||
} RealType;
|
} RealType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#define RULE_BOOL(cat, rule, default_value, notes) \
|
#define RULE_BOOL(cat, rule, default_value, notes) \
|
||||||
Bool__##rule,
|
Bool__##cat__##rule,
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
_BoolRuleCount
|
_BoolRuleCount
|
||||||
} BoolType;
|
} BoolType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#define RULE_CATEGORY(catname) \
|
#define RULE_CATEGORY(catname) \
|
||||||
Category__##catname,
|
Category__##catname,
|
||||||
#include "ruletypes.h"
|
#include "ruletypes.h"
|
||||||
_CatCount
|
_CatCount
|
||||||
} CategoryType;
|
} CategoryType;
|
||||||
|
|
||||||
@ -86,39 +86,39 @@ public:
|
|||||||
static const BoolType InvalidBool = _BoolRuleCount;
|
static const BoolType InvalidBool = _BoolRuleCount;
|
||||||
static const CategoryType InvalidCategory = _CatCount;
|
static const CategoryType InvalidCategory = _CatCount;
|
||||||
|
|
||||||
static const uint32 _RulesCount = _IntRuleCount+_RealRuleCount+_BoolRuleCount;
|
static const uint32 _RulesCount = _IntRuleCount + _RealRuleCount + _BoolRuleCount;
|
||||||
|
|
||||||
//fetch routines, you should generally use the Rule* macros instead of this
|
//fetch routines, you should generally use the Rule* macros instead of this
|
||||||
int32 GetIntRule (IntType t) const;
|
int32 GetIntRule(IntType t) const;
|
||||||
float GetRealRule(RealType t) const;
|
float GetRealRule(RealType t) const;
|
||||||
bool GetBoolRule(BoolType t) const;
|
bool GetBoolRule(BoolType t) const;
|
||||||
|
|
||||||
//management routines
|
//management routines
|
||||||
static const char *GetRuleName(IntType t) { return(s_RuleInfo[t].name); }
|
static const char* GetRuleName(IntType t) { return(s_RuleInfo[t].name); }
|
||||||
static const char *GetRuleName(RealType t) { return(s_RuleInfo[t+_IntRuleCount].name); }
|
static const char* GetRuleName(RealType t) { return(s_RuleInfo[t + _IntRuleCount].name); }
|
||||||
static const char *GetRuleName(BoolType t) { return(s_RuleInfo[t+_IntRuleCount+_RealRuleCount].name); }
|
static const char* GetRuleName(BoolType t) { return(s_RuleInfo[t + _IntRuleCount + _RealRuleCount].name); }
|
||||||
static const std::string &GetRuleNotes(IntType t) { return(s_RuleInfo[t].notes); }
|
static const std::string& GetRuleNotes(IntType t) { return(s_RuleInfo[t].notes); }
|
||||||
static const std::string &GetRuleNotes(RealType t) { return(s_RuleInfo[t+_IntRuleCount].notes); }
|
static const std::string& GetRuleNotes(RealType t) { return(s_RuleInfo[t + _IntRuleCount].notes); }
|
||||||
static const std::string &GetRuleNotes(BoolType t) { return(s_RuleInfo[t+_IntRuleCount+_RealRuleCount].notes); }
|
static const std::string& GetRuleNotes(BoolType t) { return(s_RuleInfo[t + _IntRuleCount + _RealRuleCount].notes); }
|
||||||
static uint32 CountRules() { return(_RulesCount); }
|
static uint32 CountRules() { return(_RulesCount); }
|
||||||
static CategoryType FindCategory(const char *catname);
|
static CategoryType FindCategory(const char* catname);
|
||||||
bool ListRules(const char *catname, std::vector<const char *> &into);
|
bool ListRules(const char* catname, std::vector<const char*>& into);
|
||||||
bool ListCategories(std::vector<const char *> &into);
|
bool ListCategories(std::vector<const char*>& into);
|
||||||
bool GetRule(const char *rule_name, std::string &ret_val);
|
bool GetRule(const char* rule_name, std::string& ret_val);
|
||||||
bool SetRule(const char *rule_name, const char *rule_value, Database *db = nullptr, bool db_save = false, bool reload = false);
|
bool SetRule(const char* rule_name, const char* rule_value, Database* db = nullptr, bool db_save = false, bool reload = false);
|
||||||
|
|
||||||
int GetActiveRulesetID() const { return(m_activeRuleset); }
|
int GetActiveRulesetID() const { return(m_activeRuleset); }
|
||||||
const char *GetActiveRuleset() const { return(m_activeName.c_str()); }
|
const char* GetActiveRuleset() const { return(m_activeName.c_str()); }
|
||||||
static int GetRulesetID(Database *db, const char *rulesetname);
|
static int GetRulesetID(Database* db, const char* rulesetname);
|
||||||
static std::string GetRulesetName(Database *db, int id);
|
static std::string GetRulesetName(Database* db, int id);
|
||||||
static bool ListRulesets(Database *db, std::map<int, std::string> &into);
|
static bool ListRulesets(Database* db, std::map<int, std::string>& into);
|
||||||
|
|
||||||
void ResetRules(bool reload = false);
|
void ResetRules(bool reload = false);
|
||||||
bool LoadRules(Database *db, const char *ruleset = nullptr, bool reload = false);
|
bool LoadRules(Database* db, const char* ruleset = nullptr, bool reload = false);
|
||||||
void SaveRules(Database *db, const char *ruleset = nullptr);
|
void SaveRules(Database* db, const char* ruleset = nullptr);
|
||||||
bool UpdateInjectedRules(Database *db, const char *ruleset_name, bool quiet_update = false);
|
bool UpdateInjectedRules(Database* db, const char* ruleset_name, bool quiet_update = false);
|
||||||
bool UpdateOrphanedRules(Database *db, bool quiet_update = false);
|
bool UpdateOrphanedRules(Database* db, bool quiet_update = false);
|
||||||
bool RestoreRuleNotes(Database *db);
|
bool RestoreRuleNotes(Database* db);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RuleManager();
|
RuleManager();
|
||||||
@ -128,9 +128,9 @@ private:
|
|||||||
int m_activeRuleset;
|
int m_activeRuleset;
|
||||||
std::string m_activeName;
|
std::string m_activeName;
|
||||||
#ifdef WIN64
|
#ifdef WIN64
|
||||||
uint32 m_RuleIntValues [_IntRuleCount ];
|
uint32 m_RuleIntValues[_IntRuleCount];
|
||||||
#else
|
#else
|
||||||
int m_RuleIntValues [_IntRuleCount ];
|
int m_RuleIntValues[_IntRuleCount];
|
||||||
#endif
|
#endif
|
||||||
float m_RuleRealValues[_RealRuleCount];
|
float m_RuleRealValues[_RealRuleCount];
|
||||||
uint32 m_RuleBoolValues[_BoolRuleCount];
|
uint32 m_RuleBoolValues[_BoolRuleCount];
|
||||||
@ -141,15 +141,15 @@ private:
|
|||||||
BoolRule
|
BoolRule
|
||||||
} RuleType;
|
} RuleType;
|
||||||
|
|
||||||
static bool _FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into);
|
static bool _FindRule(const char* rule_name, RuleType& type_into, uint16& index_into);
|
||||||
static const char *_GetRuleName(RuleType type, uint16 index);
|
static const char* _GetRuleName(RuleType type, uint16 index);
|
||||||
static const std::string &_GetRuleNotes(RuleType type, uint16 index);
|
static const std::string& _GetRuleNotes(RuleType type, uint16 index);
|
||||||
static int _FindOrCreateRuleset(Database *db, const char *ruleset);
|
static int _FindOrCreateRuleset(Database* db, const char* ruleset);
|
||||||
void _SaveRule(Database *db, RuleType type, uint16 index);
|
void _SaveRule(Database* db, RuleType type, uint16 index);
|
||||||
|
|
||||||
static const char *s_categoryNames[];
|
static const char* s_categoryNames[];
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char* name;
|
||||||
CategoryType category;
|
CategoryType category;
|
||||||
RuleType type;
|
RuleType type;
|
||||||
uint16 rule_index; //index into its 'type' array
|
uint16 rule_index; //index into its 'type' array
|
||||||
|
|||||||
@ -3520,17 +3520,17 @@ luabind::scope lua_register_rules_const() {
|
|||||||
.enum_("constants")
|
.enum_("constants")
|
||||||
[
|
[
|
||||||
#define RULE_INT(cat, rule, default_value, notes) \
|
#define RULE_INT(cat, rule, default_value, notes) \
|
||||||
luabind::value(#rule, RuleManager::Int__##rule),
|
luabind::value(#cat #rule, RuleManager::Int__##cat__##rule),
|
||||||
#include "../common/ruletypes.h"
|
#include "../common/ruletypes.h"
|
||||||
luabind::value("_IntRuleCount", RuleManager::_IntRuleCount),
|
luabind::value("_IntRuleCount", RuleManager::_IntRuleCount),
|
||||||
#undef RULE_INT
|
#undef RULE_INT
|
||||||
#define RULE_REAL(cat, rule, default_value, notes) \
|
#define RULE_REAL(cat, rule, default_value, notes) \
|
||||||
luabind::value(#rule, RuleManager::Real__##rule),
|
luabind::value(#rule, RuleManager::Real__##cat__##rule),
|
||||||
#include "../common/ruletypes.h"
|
#include "../common/ruletypes.h"
|
||||||
luabind::value("_RealRuleCount", RuleManager::_RealRuleCount),
|
luabind::value("_RealRuleCount", RuleManager::_RealRuleCount),
|
||||||
#undef RULE_REAL
|
#undef RULE_REAL
|
||||||
#define RULE_BOOL(cat, rule, default_value, notes) \
|
#define RULE_BOOL(cat, rule, default_value, notes) \
|
||||||
luabind::value(#rule, RuleManager::Bool__##rule),
|
luabind::value(#rule, RuleManager::Bool__##cat__##rule),
|
||||||
#include "../common/ruletypes.h"
|
#include "../common/ruletypes.h"
|
||||||
luabind::value("_BoolRuleCount", RuleManager::_BoolRuleCount)
|
luabind::value("_BoolRuleCount", RuleManager::_BoolRuleCount)
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user