Rules.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. DisableHouseAlignmentRequirement,
  64. /* PVP */
  65. AllowPVP,
  66. LevelRange,
  67. InvisPlayerDiscoveryRange,
  68. /* COMBAT */
  69. MaxCombatRange,
  70. DeathExperienceDebt,
  71. GroupExperienceDebt,
  72. PVPDeathExperienceDebt,
  73. ExperienceToDebt,
  74. ExperienceDebtRecoveryPercent,
  75. ExperienceDebtRecoveryPeriod,
  76. EnableSpiritShards,
  77. SpiritShardSpawnScript,
  78. ShardDebtRecoveryPercent,
  79. ShardRecoveryByRadius,
  80. /* SPAWN */
  81. SpeedMultiplier,
  82. ClassicRegen,
  83. HailMovementPause,
  84. HailDistance,
  85. UseHardCodeWaterModelType,
  86. UseHardCodeFlyingModelType,
  87. //SpeedRatio,
  88. /* UI */
  89. MaxWhoResults,
  90. MaxWhoOverrideStatus,
  91. /* WORLD */
  92. DefaultStartingZoneID,
  93. EnablePOIDiscovery,
  94. GamblingTokenItemID,
  95. GuildAutoJoin,
  96. GuildAutoJoinID,
  97. GuildAutoJoinDefaultRankID,
  98. ServerLocked,
  99. ServerLockedOverrideStatus,
  100. SyncZonesWithLogin,
  101. SyncEquipWithLogin,
  102. UseBannedIPsTable,
  103. LinkDeadTimer,
  104. RemoveDisconnectedClientsTimer,
  105. PlayerCampTimer,
  106. GMCampTimer,
  107. AutoAdminPlayers,
  108. AutoAdminGMs,
  109. AutoAdminStatusValue,
  110. DuskTime,
  111. DawnTime,
  112. ThreadedLoad,
  113. TradeskillSuccessChance,
  114. TradeskillCritSuccessChance,
  115. TradeskillFailChance,
  116. TradeskillCritFailChance,
  117. TradeskillEventChance,
  118. EditorURL,
  119. EditorIncludeID,
  120. EditorOfficialServer,
  121. IRCEnabled,
  122. IRCGlobalEnabled,
  123. IRCAddress,
  124. IRCPort,
  125. IRCChan,
  126. GroupSpellsTimer,
  127. SavePaperdollImage,
  128. SaveHeadshotImage,
  129. SendPaperdollImagesToLogin,
  130. TreasureChestDisabled,
  131. StartingZoneRuleFlag,
  132. /* ZONE */
  133. MinZoneLevelOverrideStatus,
  134. MinZoneAccessOverrideStatus,
  135. XPMultiplier,
  136. TSXPMultiplier,
  137. WeatherEnabled,
  138. WeatherType,
  139. MinWeatherSeverity,
  140. MaxWeatherSeverity,
  141. WeatherChangeFrequency,
  142. WeatherChangePerInterval,
  143. WeatherDynamicMaxOffset,
  144. WeatherChangeChance,
  145. SpawnUpdateTimer,
  146. CheckAttackPlayer,
  147. CheckAttackNPC,
  148. HOTime,
  149. /* LOOT */
  150. LootRadius,
  151. AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
  152. ChestTriggerRadiusGroup,
  153. ChestUnlockedTimeDrop,
  154. AllowChestUnlockByDropTime,
  155. ChestUnlockedTimeTrap,
  156. AllowChestUnlockByTrapTime,
  157. /* SPELLS */
  158. NoInterruptBaseChance,
  159. EnableFizzleSpells,
  160. DefaultFizzleChance,
  161. FizzleMaxSkill,
  162. FizzleDefaultSkill,
  163. EnableCrossZoneGroupBuffs,
  164. EnableCrossZoneTargetBuffs,
  165. PlayerSpellSaveStateWaitInterval,
  166. PlayerSpellSaveStateCap,
  167. RequirePreviousTierScribe,
  168. /* ZONE TIMERS */
  169. RegenTimer,
  170. ClientSaveTimer,
  171. DefaultZoneShutdownTimer,
  172. WeatherTimer,
  173. SpawnDeleteTimer,
  174. GlobalExpansionFlag,
  175. GlobalHolidayFlag,
  176. DatabaseVersion
  177. };
  178. class Rule {
  179. public:
  180. Rule();
  181. Rule(int32 category, int32 type, const char *value, const char *combined);
  182. Rule (Rule *rule_in);
  183. virtual ~Rule();
  184. void SetValue(const char *value) {strncpy(this->value, value, sizeof(this->value));}
  185. int32 GetCategory() {return category;}
  186. int32 GetType() {return type;}
  187. const char * GetValue() {return value;}
  188. const char * GetCombined() {return combined;}
  189. int8 GetInt8() {return (int8)atoul(value);}
  190. int16 GetInt16() {return (int16)atoul(value);}
  191. int32 GetInt32() {return (int32)atoul(value);}
  192. int64 GetInt64() {return (int64)atoi64(value);}
  193. sint8 GetSInt8() {return (sint8)atoi(value);}
  194. sint16 GetSInt16() {return (sint16)atoi(value);}
  195. sint32 GetSInt32() {return (sint32)atoi(value);}
  196. sint64 GetSInt64() {return (sint64)atoi64(value);}
  197. bool GetBool() {return atoul(value) > 0 ? true : false;}
  198. float GetFloat() {return atof(value);}
  199. char GetChar() {return value[0];}
  200. const char * GetString() {return value;}
  201. private:
  202. int32 category;
  203. int32 type;
  204. char value[64];
  205. char combined[256];
  206. };
  207. class RuleSet {
  208. public:
  209. RuleSet();
  210. RuleSet(RuleSet *in_rule_set);
  211. virtual ~RuleSet();
  212. void CopyRulesInto(RuleSet *in_rule_set);
  213. void SetID(int32 id) {this->id = id;}
  214. void SetName(const char *name) {strncpy(this->name, name, sizeof(this->name));}
  215. int32 GetID() {return id;}
  216. const char *GetName() {return name;}
  217. void AddRule(Rule *rule);
  218. Rule * GetRule(int32 category, int32 type);
  219. Rule * GetRule(const char *category, const char *type);
  220. void ClearRules();
  221. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  222. private:
  223. int32 id;
  224. char name[64];
  225. Mutex m_rules;
  226. map<int32, map<int32, Rule *> > rules;
  227. };
  228. class RuleManager {
  229. public:
  230. RuleManager();
  231. virtual ~RuleManager();
  232. void Init();
  233. void Flush(bool reinit=false);
  234. void LoadCodedDefaultsIntoRuleSet(RuleSet *rule_set);
  235. bool AddRuleSet(RuleSet *rule_set);
  236. int32 GetNumRuleSets();
  237. void ClearRuleSets();
  238. Rule * GetBlankRule() {return &blank_rule;}
  239. bool SetGlobalRuleSet(int32 rule_set_id);
  240. Rule * GetGlobalRule(int32 category, int32 type);
  241. Rule * GetGlobalRule(const char* category, const char* type);
  242. bool SetZoneRuleSet(int32 zone_id, int32 rule_set_id);
  243. Rule * GetZoneRule(int32 zone_id, int32 category, int32 type);
  244. void ClearZoneRuleSets();
  245. RuleSet * GetGlobalRuleSet() {return &global_rule_set;}
  246. map<int32, map<int32, Rule *> > * GetRules() {return &rules;}
  247. private:
  248. Mutex m_rule_sets;
  249. Mutex m_global_rule_set;
  250. Mutex m_zone_rule_sets;
  251. Rule blank_rule; /* READ ONLY */
  252. map<int32, map<int32, Rule *> > rules; /* all of the rules loaded with their defaults (FROM THE CODE). map<category, map<type, rule>> */
  253. map<int32, RuleSet *> rule_sets; /* all of the possible rule sets from the database. map<rule set id, rule set> */
  254. RuleSet global_rule_set; /* the global rule set, first fill it the defaults from the code, then over ride from the database */
  255. map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
  256. };
  257. #endif