Rules.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. ChestTriggerRadiusGroup,
  135. /* SPELLS */
  136. NoInterruptBaseChance,
  137. /* ZONE TIMERS */
  138. RegenTimer,
  139. ClientSaveTimer,
  140. DefaultZoneShutdownTimer,
  141. WeatherTimer,
  142. SpawnDeleteTimer
  143. };
  144. class Rule {
  145. public:
  146. Rule();
  147. Rule(int32 category, int32 type, const char *value, const char *combined);
  148. Rule (Rule *rule_in);
  149. virtual ~Rule();
  150. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  151. int32 GetCategory() {return category;}
  152. int32 GetType() {return type;}
  153. const char * GetValue() {return value;}
  154. const char * GetCombined() {return combined;}
  155. int8 GetInt8() {return (int8)atoul(value);}
  156. int16 GetInt16() {return (int16)atoul(value);}
  157. int32 GetInt32() {return (int32)atoul(value);}
  158. int64 GetInt64() {return (int64)atoi64(value);}
  159. sint8 GetSInt8() {return (sint8)atoi(value);}
  160. sint16 GetSInt16() {return (sint16)atoi(value);}
  161. sint32 GetSInt32() {return (sint32)atoi(value);}
  162. sint64 GetSInt64() {return (sint64)atoi64(value);}
  163. bool GetBool() {return atoul(value) > 0 ? true : false;}
  164. float GetFloat() {return atof(value);}
  165. char GetChar() {return value[0];}
  166. const char * GetString() {return value;}
  167. private:
  168. int32 category;
  169. int32 type;
  170. char value[64];
  171. char combined[256];
  172. };
  173. class RuleSet {
  174. public:
  175. RuleSet();
  176. RuleSet(RuleSet *in_rule_set);
  177. virtual ~RuleSet();
  178. void CopyRulesInto(RuleSet *in_rule_set);
  179. void SetID(int32 id) {this->id = id;}
  180. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  181. int32 GetID() {return id;}
  182. const char *GetName() {return name;}
  183. void AddRule(Rule *rule);
  184. Rule * GetRule(int32 category, int32 type);
  185. Rule * GetRule(const char *category, const char *type);
  186. void ClearRules();
  187. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  188. private:
  189. int32 id;
  190. char name[64];
  191. Mutex m_rules;
  192. map<int32, map<int32, Rule *> > rules;
  193. };
  194. class RuleManager {
  195. public:
  196. RuleManager();
  197. virtual ~RuleManager();
  198. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  199. bool AddRuleSet(RuleSet *rule_set);
  200. int32 GetNumRuleSets();
  201. void ClearRuleSets();
  202. Rule * GetBlankRule() {return &blank_rule;}
  203. bool SetGlobalRuleSet(int32 rule_set_id);
  204. Rule * GetGlobalRule(int32 category, int32 type);
  205. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  206. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  207. void ClearZoneRuleSets();
  208. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  209. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  210. private:
  211. Mutex m_rule_sets;
  212. Mutex m_global_rule_set;
  213. Mutex m_zone_rule_sets;
  214. Rule blank_rule; /* READ ONLY */
  215. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  216. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  217. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  218. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  219. };
  220. #endif