mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-05 15:36:38 +00:00
[Commands] Cleanup #rules Command. (#2593)
* [Commands] Cleanup #rules Command. - Cleanup messages and logic. - Rewrite all rules logic to use `std::string` and repositories. * References * Update rules.cpp * Strings::Equal and Strings::EqualFold. * Cleanup. * Update rulesys.cpp * Update rulesys.cpp Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
+73
-65
@@ -29,12 +29,12 @@
|
||||
//note, these macros assume there is always a RuleManager *rules in scope,
|
||||
//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
|
||||
#define RuleI(cat, rule) \
|
||||
RuleManager::Instance()->GetIntRule( RuleManager::Int__##rule )
|
||||
#define RuleR(cat, rule) \
|
||||
RuleManager::Instance()->GetRealRule( RuleManager::Real__##rule )
|
||||
#define RuleB(cat, rule) \
|
||||
RuleManager::Instance()->GetBoolRule( RuleManager::Bool__##rule )
|
||||
#define RuleI(category_name, rule_name) \
|
||||
RuleManager::Instance()->GetIntRule( RuleManager::Int__##rule_name )
|
||||
#define RuleR(category_name, rule_name) \
|
||||
RuleManager::Instance()->GetRealRule( RuleManager::Real__##rule_name )
|
||||
#define RuleB(category_name, rule_name) \
|
||||
RuleManager::Instance()->GetBoolRule( RuleManager::Bool__##rule_name )
|
||||
|
||||
|
||||
#include <vector>
|
||||
@@ -49,91 +49,101 @@ class RuleManager {
|
||||
public:
|
||||
//generate our rule enums:
|
||||
typedef enum {
|
||||
#define RULE_INT(cat, rule, default_value, notes) \
|
||||
Int__##rule,
|
||||
#include "ruletypes.h"
|
||||
#define RULE_INT(category_name, rule_name, default_value, notes) \
|
||||
Int__##rule_name,
|
||||
|
||||
#include "ruletypes.h"
|
||||
|
||||
_IntRuleCount
|
||||
} IntType;
|
||||
|
||||
typedef enum {
|
||||
#define RULE_REAL(cat, rule, default_value, notes) \
|
||||
Real__##rule,
|
||||
#include "ruletypes.h"
|
||||
#define RULE_REAL(category_name, rule_name, default_value, notes) \
|
||||
Real__##rule_name,
|
||||
|
||||
#include "ruletypes.h"
|
||||
|
||||
_RealRuleCount
|
||||
} RealType;
|
||||
|
||||
typedef enum {
|
||||
#define RULE_BOOL(cat, rule, default_value, notes) \
|
||||
Bool__##rule,
|
||||
#include "ruletypes.h"
|
||||
#define RULE_BOOL(category_name, rule_name, default_value, notes) \
|
||||
Bool__##rule_name,
|
||||
|
||||
#include "ruletypes.h"
|
||||
|
||||
_BoolRuleCount
|
||||
} BoolType;
|
||||
|
||||
typedef enum {
|
||||
#define RULE_CATEGORY(catname) \
|
||||
Category__##catname,
|
||||
#include "ruletypes.h"
|
||||
#define RULE_CATEGORY(category_name) \
|
||||
Category__##category_name,
|
||||
|
||||
#include "ruletypes.h"
|
||||
|
||||
_CatCount
|
||||
} CategoryType;
|
||||
|
||||
static RuleManager* Instance() {
|
||||
static RuleManager *Instance()
|
||||
{
|
||||
static RuleManager rules;
|
||||
return &rules;
|
||||
}
|
||||
|
||||
static const IntType InvalidInt = _IntRuleCount;
|
||||
static const RealType InvalidReal = _RealRuleCount;
|
||||
static const BoolType InvalidBool = _BoolRuleCount;
|
||||
static const IntType InvalidInt = _IntRuleCount;
|
||||
static const RealType InvalidReal = _RealRuleCount;
|
||||
static const BoolType InvalidBool = _BoolRuleCount;
|
||||
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
|
||||
int32 GetIntRule (IntType t) const;
|
||||
int GetIntRule(IntType t) const;
|
||||
float GetRealRule(RealType t) const;
|
||||
bool GetBoolRule(BoolType t) const;
|
||||
|
||||
//management routines
|
||||
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(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(RealType t) { return(s_RuleInfo[t+_IntRuleCount].notes); }
|
||||
static const std::string &GetRuleNotes(BoolType t) { return(s_RuleInfo[t+_IntRuleCount+_RealRuleCount].notes); }
|
||||
static uint32 CountRules() { return(_RulesCount); }
|
||||
static CategoryType FindCategory(const char *catname);
|
||||
bool ListRules(const char *catname, std::vector<const char *> &into);
|
||||
bool ListCategories(std::vector<const char *> &into);
|
||||
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);
|
||||
static std::string GetRuleName(IntType t) { return s_RuleInfo[t].name; }
|
||||
static std::string GetRuleName(RealType t) { return s_RuleInfo[t + _IntRuleCount].name; }
|
||||
static std::string 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(RealType t) { return s_RuleInfo[t + _IntRuleCount].notes; }
|
||||
static const std::string &GetRuleNotes(BoolType t) { return s_RuleInfo[t + _IntRuleCount + _RealRuleCount].notes; }
|
||||
static uint32 CountRules() { return _RulesCount; }
|
||||
static CategoryType FindCategory(const std::string &category_name);
|
||||
bool ListRules(const std::string &category_name, std::vector <std::string> &l);
|
||||
bool ListCategories(std::vector <std::string> &l);
|
||||
bool GetRule(const std::string &rule_name, std::string &rule_value);
|
||||
bool SetRule(
|
||||
const std::string &rule_name,
|
||||
const std::string &rule_value,
|
||||
Database *db = nullptr,
|
||||
bool db_save = false,
|
||||
bool reload = false
|
||||
);
|
||||
|
||||
int GetActiveRulesetID() const { return(m_activeRuleset); }
|
||||
const char *GetActiveRuleset() const { return(m_activeName.c_str()); }
|
||||
static int GetRulesetID(Database *db, const char *rulesetname);
|
||||
static std::string GetRulesetName(Database *db, int id);
|
||||
static bool ListRulesets(Database *db, std::map<int, std::string> &into);
|
||||
int GetActiveRulesetID() const { return m_activeRuleset; }
|
||||
std::string GetActiveRuleset() const { return m_activeName; }
|
||||
static bool ListRulesets(Database *db, std::map<int, std::string> &l);
|
||||
|
||||
void ResetRules(bool reload = false);
|
||||
bool LoadRules(Database *db, const char *ruleset = nullptr, bool reload = false);
|
||||
void SaveRules(Database *db, const char *ruleset = nullptr);
|
||||
bool UpdateInjectedRules(Database *db, const char *ruleset_name, bool quiet_update = false);
|
||||
bool LoadRules(Database *db, const std::string &rule_set_name, bool reload = false);
|
||||
void SaveRules(Database *db, const std::string &rule_set_name);
|
||||
bool UpdateInjectedRules(Database *db, const std::string &rule_set_name, bool quiet_update = false);
|
||||
bool UpdateOrphanedRules(Database *db, bool quiet_update = false);
|
||||
bool RestoreRuleNotes(Database *db);
|
||||
|
||||
private:
|
||||
RuleManager();
|
||||
RuleManager(const RuleManager&);
|
||||
const RuleManager& operator=(const RuleManager&);
|
||||
RuleManager(const RuleManager &);
|
||||
const RuleManager &operator=(const RuleManager &);
|
||||
|
||||
int m_activeRuleset;
|
||||
int m_activeRuleset;
|
||||
std::string m_activeName;
|
||||
#ifdef WIN64
|
||||
uint32 m_RuleIntValues [_IntRuleCount ];
|
||||
#else
|
||||
int m_RuleIntValues [_IntRuleCount ];
|
||||
#endif
|
||||
float m_RuleRealValues[_RealRuleCount];
|
||||
uint32 m_RuleBoolValues[_BoolRuleCount];
|
||||
|
||||
int m_RuleIntValues[_IntRuleCount];
|
||||
float m_RuleRealValues[_RealRuleCount];
|
||||
uint32 m_RuleBoolValues[_BoolRuleCount];
|
||||
|
||||
typedef enum {
|
||||
IntRule,
|
||||
@@ -141,23 +151,21 @@ private:
|
||||
BoolRule
|
||||
} RuleType;
|
||||
|
||||
static bool _FindRule(const char *rule_name, RuleType &type_into, uint16 &index_into);
|
||||
static const char *_GetRuleName(RuleType type, uint16 index);
|
||||
static bool _FindRule(const std::string &rule_name, RuleType &type_into, uint16 &index_into);
|
||||
static std::string _GetRuleName(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 std::string &rule_set_name);
|
||||
void _SaveRule(Database *db, RuleType type, uint16 index);
|
||||
|
||||
static const char *s_categoryNames[];
|
||||
|
||||
static const char* s_categoryNames[];
|
||||
typedef struct {
|
||||
const char *name;
|
||||
CategoryType category;
|
||||
RuleType type;
|
||||
uint16 rule_index; //index into its 'type' array
|
||||
std::string name;
|
||||
CategoryType category;
|
||||
RuleType type;
|
||||
uint16 rule_index;
|
||||
const std::string notes;
|
||||
} RuleInfo;
|
||||
static const RuleInfo s_RuleInfo[];
|
||||
|
||||
};
|
||||
|
||||
#endif /*RULESYS_H_*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user