9
3

Rules.h 6.0 KB

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