GlobalConfig.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. 
  2. using DeepCore;
  3. using DeepCore.Log;
  4. using DeepCore.Reflection;
  5. using DeepCrystal.RPC;
  6. using System;
  7. using System.Reflection;
  8. namespace DeepMMO.Server
  9. {
  10. public static class GlobalConfig
  11. {
  12. // public const string RPGServerBattleManagerKey = "RPGServerBattleManager";
  13. // public const string RPGServerManagerKey = "RPGServerManagerKey";
  14. // public const string RPGServerTemplateManagerKey = "RPGServerTemplateManager";
  15. // public const string ZoneDataFactoryKey = "ZoneDataFactory";
  16. // public const string InstanceZoneFactoryKey = "InstanceZoneFactory";
  17. // public const string ZoneNodeFactoryKey = "ZoneNodeFactory";
  18. // public const string DataRootKey = "DataRoot";
  19. public static bool EnableServerTest
  20. {
  21. get { return IService.GlobalConfig.GetAs<bool>(nameof(EnableServerTest)); }
  22. }
  23. public static string RealmID
  24. {
  25. get { return IService.GlobalConfig.Get(nameof(RealmID)); }
  26. }
  27. public static string RPGServerBattleManager
  28. {
  29. get { return IService.GlobalConfig.Get(nameof(RPGServerBattleManager)); }
  30. }
  31. public static string RPGServerPersistenceManager
  32. {
  33. get { return IService.GlobalConfig.Get(nameof(RPGServerPersistenceManager)); }
  34. }
  35. public static string RPGServerManager
  36. {
  37. get { return IService.GlobalConfig.Get(nameof(RPGServerManager)); }
  38. }
  39. public static string RPGServerTemplateManager
  40. {
  41. get { return IService.GlobalConfig.Get(nameof(RPGServerTemplateManager)); }
  42. }
  43. public static string ZoneDataFactory
  44. {
  45. get { return IService.GlobalConfig.Get(nameof(ZoneDataFactory)); }
  46. }
  47. public static string InstanceZoneFactory
  48. {
  49. get { return IService.GlobalConfig.Get(nameof(InstanceZoneFactory)); }
  50. }
  51. public static string ZoneServerFactory
  52. {
  53. get { return IService.GlobalConfig.Get(nameof(ZoneServerFactory)); }
  54. }
  55. public static Properties ZoneNodeConfig
  56. {
  57. get { return IService.GlobalConfig.SubProperties(nameof(ZoneNodeConfig) + "."); }
  58. }
  59. public static string GMTUrl
  60. {
  61. get { return IService.GlobalConfig.Get(nameof(GMTUrl)); }
  62. }
  63. public static string ServerListUrl
  64. {
  65. get { return IService.GlobalConfig.Get(nameof(ServerListUrl)); }
  66. }
  67. public static string BattleDataRoot
  68. {
  69. get { return IService.GlobalConfig.Get(nameof(BattleDataRoot)); }
  70. }
  71. public static string GameEditorRoot
  72. {
  73. get { return IService.GlobalConfig.Get(nameof(GameEditorRoot)); }
  74. }
  75. public static string ServerDataRoot
  76. {
  77. get { return IService.GlobalConfig.Get(nameof(ServerDataRoot)); }
  78. }
  79. public static string ReplaceNetHost
  80. {
  81. get { return IService.GlobalConfig.Get(nameof(ReplaceNetHost)); }
  82. }
  83. public static string TemplateDataRoot
  84. {
  85. get { return ServerDataRoot + "/templates_lua/"; }
  86. }
  87. public static string EventScriptRoot
  88. {
  89. get { return ServerDataRoot + "/event_script/"; }
  90. }
  91. internal static void LoadAll()
  92. {
  93. foreach (var cfgType in ReflectionUtil.GetAllTypes())
  94. {
  95. if (cfgType.TryGetAttribute<LoadFromGlobalConfigAttribute>(out var attr))
  96. {
  97. LoadStaticFieldsFromGlobal(cfgType);
  98. }
  99. }
  100. }
  101. public static void LoadStaticFieldsFromGlobal(Type type)
  102. {
  103. var log = new LazyLogger(type.FullName);
  104. var subcfg = IService.GlobalConfig.SubProperties(type.FullName + ".");
  105. if (subcfg != null)
  106. {
  107. subcfg.LoadStaticFields(type, (f) =>
  108. {
  109. log.Error($"'{f.Name}' Not Exist In GlobalConfig");
  110. });
  111. }
  112. }
  113. }
  114. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
  115. public class LoadFromGlobalConfigAttribute : Attribute
  116. {
  117. }
  118. }