Rules.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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_Combat,
  30. R_Spawn,
  31. R_UI,
  32. R_World,
  33. R_Zone,
  34. R_Loot,
  35. R_Spells
  36. };
  37. enum RuleType {
  38. /* CLIENT */
  39. ShowWelcomeScreen,
  40. /* FACTION */
  41. AllowFactionBasedCombat,
  42. /* GUILD */
  43. /* PLAYER */
  44. MaxLevel,
  45. MaxLevelOverrideStatus,
  46. MaxPlayers,
  47. MaxPlayersOverrideStatus,
  48. VitalityAmount,
  49. VitalityFrequency,
  50. MaxAA,
  51. MaxClassAA,
  52. MaxSubclassAA,
  53. MaxShadowsAA,
  54. MaxHeroicAA,
  55. MaxTradeskillAA,
  56. MaxPrestigeAA,
  57. MaxTradeskillPrestigeAA,
  58. MaxDragonAA,
  59. MinLastNameLevel,
  60. MaxLastNameLength,
  61. MinLastNameLength,
  62. /* PVP */
  63. AllowPVP,
  64. LevelRange,
  65. InvisPlayerDiscoveryRange,
  66. /* COMBAT */
  67. MaxCombatRange,
  68. /* SPAWN */
  69. SpeedMultiplier,
  70. SpeedRatio,
  71. /* UI */
  72. MaxWhoResults,
  73. MaxWhoOverrideStatus,
  74. /* WORLD */
  75. DefaultStartingZoneID,
  76. EnablePOIDiscovery,
  77. GamblingTokenItemID,
  78. GuildAutoJoin,
  79. GuildAutoJoinID,
  80. GuildAutoJoinDefaultRankID,
  81. ServerLocked,
  82. ServerLockedOverrideStatus,
  83. SyncZonesWithLogin,
  84. SyncEquipWithLogin,
  85. UseBannedIPsTable,
  86. LinkDeadTimer,
  87. RemoveDisconnectedClientsTimer,
  88. PlayerCampTimer,
  89. GMCampTimer,
  90. AutoAdminPlayers,
  91. AutoAdminGMs,
  92. AutoAdminStatusValue,
  93. DuskTime,
  94. DawnTime,
  95. ThreadedLoad,
  96. TradeskillSuccessChance,
  97. TradeskillCritSuccessChance,
  98. TradeskillFailChance,
  99. TradeskillCritFailChance,
  100. TradeskillEventChance,
  101. EditorURL,
  102. EditorIncludeID,
  103. EditorOfficialServer,
  104. IRCEnabled,
  105. IRCGlobalEnabled,
  106. IRCAddress,
  107. IRCPort,
  108. IRCChan,
  109. GroupSpellsTimer,
  110. SavePaperdollImage,
  111. SaveHeadshotImage,
  112. SendPaperdollImagesToLogin,
  113. TreasureChestDisabled,
  114. /* ZONE */
  115. MinZoneLevelOverrideStatus,
  116. MinZoneAccessOverrideStatus,
  117. XPMultiplier,
  118. TSXPMultiplier,
  119. WeatherEnabled,
  120. WeatherType,
  121. MinWeatherSeverity,
  122. MaxWeatherSeverity,
  123. WeatherChangeFrequency,
  124. WeatherChangePerInterval,
  125. WeatherDynamicMaxOffset,
  126. WeatherChangeChance,
  127. SpawnUpdateTimer,
  128. CheckAttackPlayer,
  129. CheckAttackNPC,
  130. HOTime,
  131. /* LOOT */
  132. LootRadius,
  133. AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
  134. /* SPELLS */
  135. NoInterruptBaseChance,
  136. /* ZONE TIMERS */
  137. RegenTimer,
  138. ClientSaveTimer,
  139. DefaultZoneShutdownTimer,
  140. WeatherTimer,
  141. SpawnDeleteTimer
  142. };
  143. class Rule {
  144. public:
  145. Rule();
  146. Rule(int32 category, int32 type, const char *value, const char *combined);
  147. Rule (Rule *rule_in);
  148. virtual ~Rule();
  149. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  150. int32 GetCategory() {return category;}
  151. int32 GetType() {return type;}
  152. const char * GetValue() {return value;}
  153. const char * GetCombined() {return combined;}
  154. int8 GetInt8() {return (int8)atoul(value);}
  155. int16 GetInt16() {return (int16)atoul(value);}
  156. int32 GetInt32() {return (int32)atoul(value);}
  157. int64 GetInt64() {return (int64)atoi64(value);}
  158. sint8 GetSInt8() {return (sint8)atoi(value);}
  159. sint16 GetSInt16() {return (sint16)atoi(value);}
  160. sint32 GetSInt32() {return (sint32)atoi(value);}
  161. sint64 GetSInt64() {return (sint64)atoi64(value);}
  162. bool GetBool() {return atoul(value) > 0 ? true : false;}
  163. float GetFloat() {return atof(value);}
  164. char GetChar() {return value[0];}
  165. const char * GetString() {return value;}
  166. private:
  167. int32 category;
  168. int32 type;
  169. char value[64];
  170. char combined[256];
  171. };
  172. class RuleSet {
  173. public:
  174. RuleSet();
  175. RuleSet(RuleSet *in_rule_set);
  176. virtual ~RuleSet();
  177. void CopyRulesInto(RuleSet *in_rule_set);
  178. void SetID(int32 id) {this->id = id;}
  179. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  180. int32 GetID() {return id;}
  181. const char *GetName() {return name;}
  182. void AddRule(Rule *rule);
  183. Rule * GetRule(int32 category, int32 type);
  184. Rule * GetRule(const char *category, const char *type);
  185. void ClearRules();
  186. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  187. private:
  188. int32 id;
  189. char name[64];
  190. Mutex m_rules;
  191. map<int32, map<int32, Rule *> > rules;
  192. };
  193. class RuleManager {
  194. public:
  195. RuleManager();
  196. virtual ~RuleManager();
  197. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  198. bool AddRuleSet(RuleSet *rule_set);
  199. int32 GetNumRuleSets();
  200. void ClearRuleSets();
  201. Rule * GetBlankRule() {return &blank_rule;}
  202. bool SetGlobalRuleSet(int32 rule_set_id);
  203. Rule * GetGlobalRule(int32 category, int32 type);
  204. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  205. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  206. void ClearZoneRuleSets();
  207. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  208. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  209. private:
  210. Mutex m_rule_sets;
  211. Mutex m_global_rule_set;
  212. Mutex m_zone_rule_sets;
  213. Rule blank_rule; /* READ ONLY */
  214. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  215. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  216. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  217. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  218. };
  219. #endif