Rules.h 6.1 KB

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