Rules.h 5.7 KB

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