9
3

RulesDB.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <assert.h>
  17. #include "../../common/Log.h"
  18. #include "../WorldDatabase.h"
  19. extern RuleManager rule_manager;
  20. void WorldDatabase::LoadGlobalRuleSet() {
  21. Query query;
  22. MYSQL_ROW row;
  23. MYSQL_RES *res;
  24. int32 rule_set_id = 0;
  25. res = query.RunQuery2(Q_SELECT, "SELECT `variable_value`\n"
  26. "FROM `variables`\n"
  27. "WHERE `variable_name`='default_ruleset_id'");
  28. if (res && (row = mysql_fetch_row(res)))
  29. {
  30. rule_set_id = atoul(row[0]);
  31. LogWrite(RULESYS__DEBUG, 5, "Rules", "\t\tLoading Global Ruleset id %i", rule_set_id);
  32. }
  33. if (rule_set_id > 0 && !rule_manager.SetGlobalRuleSet(rule_set_id))
  34. LogWrite(RULESYS__ERROR, 0, "Rules", "Error loading global rule set. A rule set with ID %u does not exist.", rule_set_id);
  35. }
  36. void WorldDatabase::LoadRuleSets() {
  37. RuleSet *rule_set;
  38. Query query;
  39. MYSQL_ROW row;
  40. MYSQL_RES *res;
  41. /* first load the coded defaults in */
  42. rule_manager.LoadCodedDefaultsIntoRuleSet(rule_manager.GetGlobalRuleSet());
  43. res = query.RunQuery2(Q_SELECT, "SELECT `ruleset_id`,`ruleset_name`\n"
  44. "FROM `rulesets`\n"
  45. "WHERE `ruleset_active`>0");
  46. if (res) {
  47. while ((row = mysql_fetch_row(res))) {
  48. rule_set = new RuleSet();
  49. rule_set->SetID(atoul(row[0]));
  50. rule_set->SetName(row[1]);
  51. if (rule_manager.AddRuleSet(rule_set))
  52. {
  53. LogWrite(RULESYS__DEBUG, 5, "Rules", "\t\tLoading rule set '%s' (%u)", rule_set->GetName(), rule_set->GetID());
  54. LoadRuleSetDetails(rule_set);
  55. }
  56. else {
  57. LogWrite(RULESYS__ERROR, 0, "Rules", "Unable to add rule set '%s'. A ruleset with ID %u already exists.", rule_set->GetName(), rule_set->GetID());
  58. safe_delete(rule_set);
  59. }
  60. }
  61. }
  62. LogWrite(RULESYS__DEBUG, 3, "Rules", "--Loaded %u Rule Sets", rule_manager.GetNumRuleSets());
  63. LoadGlobalRuleSet();
  64. }
  65. void WorldDatabase::LoadRuleSetDetails(RuleSet *rule_set) {
  66. Rule *rule;
  67. Query query;
  68. MYSQL_ROW row;
  69. MYSQL_RES *res;
  70. assert(rule_set);
  71. rule_set->CopyRulesInto(rule_manager.GetGlobalRuleSet());
  72. res = query.RunQuery2(Q_SELECT, "SELECT `rule_category`,`rule_type`,`rule_value`\n"
  73. "FROM `ruleset_details`\n"
  74. "WHERE `ruleset_id`=%u",
  75. rule_set->GetID());
  76. if (res) {
  77. while ((row = mysql_fetch_row(res))) {
  78. if (!(rule = rule_set->GetRule(row[0], row[1]))) {
  79. LogWrite(RULESYS__ERROR, 0, "Rules", "Unknown rule with category '%s' and type '%s'", row[0], row[1]);
  80. continue;
  81. }
  82. LogWrite(RULESYS__DEBUG, 5, "Rules", "---Setting rule category '%s', type '%s' to value: %s", row[0], row[1], row[2]);
  83. rule->SetValue(row[2]);
  84. }
  85. }
  86. }