Rules.h 6.7 KB

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