Rules.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. /* SPAWN */
  62. SpeedMultiplier,
  63. SpeedRatio,
  64. /* UI */
  65. MaxWhoResults,
  66. MaxWhoOverrideStatus,
  67. /* WORLD */
  68. DefaultStartingZoneID,
  69. EnablePOIDiscovery,
  70. GamblingTokenItemID,
  71. GuildAutoJoin,
  72. GuildAutoJoinID,
  73. GuildAutoJoinDefaultRankID,
  74. ServerLocked,
  75. ServerLockedOverrideStatus,
  76. SyncZonesWithLogin,
  77. SyncEquipWithLogin,
  78. UseBannedIPsTable,
  79. LinkDeadTimer,
  80. RemoveDisconnectedClientsTimer,
  81. PlayerCampTimer,
  82. GMCampTimer,
  83. AutoAdminPlayers,
  84. AutoAdminGMs,
  85. AutoAdminStatusValue,
  86. DuskTime,
  87. DawnTime,
  88. ThreadedLoad,
  89. TradeskillSuccessChance,
  90. TradeskillCritSuccessChance,
  91. TradeskillFailChance,
  92. TradeskillCritFailChance,
  93. TradeskillEventChance,
  94. EditorURL,
  95. EditorIncludeID,
  96. EditorOfficialServer,
  97. IRCEnabled,
  98. IRCGlobalEnabled,
  99. IRCAddress,
  100. IRCPort,
  101. IRCChan,
  102. GroupSpellsTimer,
  103. SavePaperdollImage,
  104. SaveHeadshotImage,
  105. SendPaperdollImagesToLogin,
  106. TreasureChestDisabled,
  107. /* ZONE */
  108. MinZoneLevelOverrideStatus,
  109. MinZoneAccessOverrideStatus,
  110. XPMultiplier,
  111. TSXPMultiplier,
  112. WeatherEnabled,
  113. WeatherType,
  114. MinWeatherSeverity,
  115. MaxWeatherSeverity,
  116. WeatherChangeFrequency,
  117. WeatherChangePerInterval,
  118. WeatherDynamicMaxOffset,
  119. WeatherChangeChance,
  120. SpawnUpdateTimer,
  121. CheckAttackPlayer,
  122. CheckAttackNPC,
  123. HOTime,
  124. /* ZONE TIMERS */
  125. RegenTimer,
  126. ClientSaveTimer,
  127. DefaultZoneShutdownTimer,
  128. WeatherTimer,
  129. SpawnDeleteTimer
  130. };
  131. class Rule {
  132. public:
  133. Rule();
  134. Rule(int32 category, int32 type, const char *value, const char *combined);
  135. Rule (Rule *rule_in);
  136. virtual ~Rule();
  137. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  138. int32 GetCategory() {return category;}
  139. int32 GetType() {return type;}
  140. const char * GetValue() {return value;}
  141. const char * GetCombined() {return combined;}
  142. int8 GetInt8() {return (int8)atoul(value);}
  143. int16 GetInt16() {return (int16)atoul(value);}
  144. int32 GetInt32() {return (int32)atoul(value);}
  145. int64 GetInt64() {return (int64)atoi64(value);}
  146. sint8 GetSInt8() {return (sint8)atoi(value);}
  147. sint16 GetSInt16() {return (sint16)atoi(value);}
  148. sint32 GetSInt32() {return (sint32)atoi(value);}
  149. sint64 GetSInt64() {return (sint64)atoi64(value);}
  150. bool GetBool() {return atoul(value) > 0 ? true : false;}
  151. float GetFloat() {return atof(value);}
  152. char GetChar() {return value[0];}
  153. const char * GetString() {return value;}
  154. private:
  155. int32 category;
  156. int32 type;
  157. char value[64];
  158. char combined[256];
  159. };
  160. class RuleSet {
  161. public:
  162. RuleSet();
  163. RuleSet(RuleSet *in_rule_set);
  164. virtual ~RuleSet();
  165. void CopyRulesInto(RuleSet *in_rule_set);
  166. void SetID(int32 id) {this->id = id;}
  167. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  168. int32 GetID() {return id;}
  169. const char *GetName() {return name;}
  170. void AddRule(Rule *rule);
  171. Rule * GetRule(int32 category, int32 type);
  172. Rule * GetRule(const char *category, const char *type);
  173. void ClearRules();
  174. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  175. private:
  176. int32 id;
  177. char name[64];
  178. Mutex m_rules;
  179. map<int32, map<int32, Rule *> > rules;
  180. };
  181. class RuleManager {
  182. public:
  183. RuleManager();
  184. virtual ~RuleManager();
  185. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  186. bool AddRuleSet(RuleSet *rule_set);
  187. int32 GetNumRuleSets();
  188. void ClearRuleSets();
  189. Rule * GetBlankRule() {return &blank_rule;}
  190. bool SetGlobalRuleSet(int32 rule_set_id);
  191. Rule * GetGlobalRule(int32 category, int32 type);
  192. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  193. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  194. void ClearZoneRuleSets();
  195. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  196. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  197. private:
  198. Mutex m_rule_sets;
  199. Mutex m_global_rule_set;
  200. Mutex m_zone_rule_sets;
  201. Rule blank_rule; /* READ ONLY */
  202. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  203. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  204. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  205. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  206. };
  207. #endif