9
3

Rules.h 6.9 KB

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