Rules.h 5.7 KB

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