Rules.h 5.9 KB

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