Rules.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef RULES_H_
  17. #define RULES_H_
  18. #include <string.h>
  19. #include <map>
  20. #include "../../common/Mutex.h"
  21. #include "../../common/types.h"
  22. using namespace std;
  23. enum RuleCategory {
  24. R_Client,
  25. R_Faction,
  26. R_Guild,
  27. R_Player,
  28. R_PVP,
  29. R_Spawn,
  30. R_UI,
  31. R_World,
  32. R_Zone
  33. };
  34. enum RuleType {
  35. /* CLIENT */
  36. ShowWelcomeScreen,
  37. /* FACTION */
  38. AllowFactionBasedCombat,
  39. /* GUILD */
  40. /* PLAYER */
  41. MaxLevel,
  42. MaxLevelOverrideStatus,
  43. MaxPlayers,
  44. MaxPlayersOverrideStatus,
  45. VitalityAmount,
  46. VitalityFrequency,
  47. MaxAA,
  48. MaxClassAA,
  49. MaxSubclassAA,
  50. MaxShadowsAA,
  51. MaxHeroicAA,
  52. MaxTradeskillAA,
  53. MaxPrestigeAA,
  54. MaxTradeskillPrestigeAA,
  55. MaxDragonAA,
  56. MinLastNameLevel,
  57. MaxLastNameLength,
  58. MinLastNameLength,
  59. /* PVP */
  60. AllowPVP,
  61. LevelRange,
  62. /* SPAWN */
  63. SpeedMultiplier,
  64. SpeedRatio,
  65. /* UI */
  66. MaxWhoResults,
  67. MaxWhoOverrideStatus,
  68. /* WORLD */
  69. DefaultStartingZoneID,
  70. EnablePOIDiscovery,
  71. GamblingTokenItemID,
  72. GuildAutoJoin,
  73. GuildAutoJoinID,
  74. GuildAutoJoinDefaultRankID,
  75. ServerLocked,
  76. ServerLockedOverrideStatus,
  77. SyncZonesWithLogin,
  78. SyncEquipWithLogin,
  79. UseBannedIPsTable,
  80. LinkDeadTimer,
  81. RemoveDisconnectedClientsTimer,
  82. PlayerCampTimer,
  83. GMCampTimer,
  84. AutoAdminPlayers,
  85. AutoAdminGMs,
  86. AutoAdminStatusValue,
  87. DuskTime,
  88. DawnTime,
  89. ThreadedLoad,
  90. TradeskillSuccessChance,
  91. TradeskillCritSuccessChance,
  92. TradeskillFailChance,
  93. TradeskillCritFailChance,
  94. TradeskillEventChance,
  95. EditorURL,
  96. EditorIncludeID,
  97. EditorOfficialServer,
  98. IRCEnabled,
  99. IRCGlobalEnabled,
  100. IRCAddress,
  101. IRCPort,
  102. IRCChan,
  103. GroupSpellsTimer,
  104. SavePaperdollImage,
  105. SaveHeadshotImage,
  106. SendPaperdollImagesToLogin,
  107. TreasureChestDisabled,
  108. /* ZONE */
  109. MinZoneLevelOverrideStatus,
  110. MinZoneAccessOverrideStatus,
  111. XPMultiplier,
  112. TSXPMultiplier,
  113. WeatherEnabled,
  114. WeatherType,
  115. MinWeatherSeverity,
  116. MaxWeatherSeverity,
  117. WeatherChangeFrequency,
  118. WeatherChangePerInterval,
  119. WeatherDynamicMaxOffset,
  120. WeatherChangeChance,
  121. SpawnUpdateTimer,
  122. CheckAttackPlayer,
  123. CheckAttackNPC,
  124. HOTime,
  125. /* ZONE TIMERS */
  126. RegenTimer,
  127. ClientSaveTimer,
  128. DefaultZoneShutdownTimer,
  129. WeatherTimer,
  130. SpawnDeleteTimer
  131. };
  132. class Rule {
  133. public:
  134. Rule();
  135. Rule(int32 category, int32 type, const char *value, const char *combined);
  136. Rule (Rule *rule_in);
  137. virtual ~Rule();
  138. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  139. int32 GetCategory() {return category;}
  140. int32 GetType() {return type;}
  141. const char * GetValue() {return value;}
  142. const char * GetCombined() {return combined;}
  143. int8 GetInt8() {return (int8)atoul(value);}
  144. int16 GetInt16() {return (int16)atoul(value);}
  145. int32 GetInt32() {return (int32)atoul(value);}
  146. int64 GetInt64() {return (int64)atoi64(value);}
  147. sint8 GetSInt8() {return (sint8)atoi(value);}
  148. sint16 GetSInt16() {return (sint16)atoi(value);}
  149. sint32 GetSInt32() {return (sint32)atoi(value);}
  150. sint64 GetSInt64() {return (sint64)atoi64(value);}
  151. bool GetBool() {return atoul(value) > 0 ? true : false;}
  152. float GetFloat() {return atof(value);}
  153. char GetChar() {return value[0];}
  154. const char * GetString() {return value;}
  155. private:
  156. int32 category;
  157. int32 type;
  158. char value[64];
  159. char combined[256];
  160. };
  161. class RuleSet {
  162. public:
  163. RuleSet();
  164. RuleSet(RuleSet *in_rule_set);
  165. virtual ~RuleSet();
  166. void CopyRulesInto(RuleSet *in_rule_set);
  167. void SetID(int32 id) {this->id = id;}
  168. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  169. int32 GetID() {return id;}
  170. const char *GetName() {return name;}
  171. void AddRule(Rule *rule);
  172. Rule * GetRule(int32 category, int32 type);
  173. Rule * GetRule(const char *category, const char *type);
  174. void ClearRules();
  175. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  176. private:
  177. int32 id;
  178. char name[64];
  179. Mutex m_rules;
  180. map<int32, map<int32, Rule *> > rules;
  181. };
  182. class RuleManager {
  183. public:
  184. RuleManager();
  185. virtual ~RuleManager();
  186. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  187. bool AddRuleSet(RuleSet *rule_set);
  188. int32 GetNumRuleSets();
  189. void ClearRuleSets();
  190. Rule * GetBlankRule() {return &blank_rule;}
  191. bool SetGlobalRuleSet(int32 rule_set_id);
  192. Rule * GetGlobalRule(int32 category, int32 type);
  193. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  194. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  195. void ClearZoneRuleSets();
  196. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  197. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  198. private:
  199. Mutex m_rule_sets;
  200. Mutex m_global_rule_set;
  201. Mutex m_zone_rule_sets;
  202. Rule blank_rule; /* READ ONLY */
  203. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  204. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  205. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  206. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  207. };
  208. #endif