AppStart_Init.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using GFGGame;
  3. using System.Net;
  4. namespace ET
  5. {
  6. public class AppStart_Init : AEvent<EventType.AppStart>
  7. {
  8. protected override async ETTask Run(EventType.AppStart args)
  9. {
  10. Game.Scene.AddComponent<ConfigComponent>();
  11. await ConfigComponent.Instance.LoadAsync();
  12. //HttpClient
  13. Game.Scene.AddComponent<HttpClientComponent>();
  14. if (Options.Instance.ErrorReport || !string.IsNullOrEmpty(Options.Instance.QDName))
  15. {
  16. var errorReportComponent = Game.Scene.AddComponent<ErrorReportComponent>();
  17. var errorInfo = errorReportComponent.ErrorInfo;
  18. errorInfo.Process = Options.Instance.Process;
  19. errorInfo.ProcessId = Environment.ProcessId;
  20. var localIps = NetworkHelper.GetNonLoopbackIP();
  21. if (!string.IsNullOrEmpty(localIps)) errorInfo.LocalIP = localIps;
  22. var outIpv4 = await NetworkHelper.GetOutIpv4();
  23. if (!string.IsNullOrEmpty(outIpv4)) errorInfo.IP = outIpv4;
  24. errorReportComponent.Url = StartGlobalConfigCategory.Instance.GlobalConfig.ErrorReportUrl;
  25. errorReportComponent.DetectionReportUrl =
  26. StartGlobalConfigCategory.Instance.GlobalConfig.DetectionReportUrl;
  27. Log.ErrorAction += msg => ErrorReportComponent.Instance?.Report(msg);
  28. Log.DetectionErrorAction += msg => ErrorReportComponent.Instance?.DetectionReportReport(msg);
  29. }
  30. //设置时区
  31. TimeInfo.Instance.TimeZone = 8;
  32. Game.Scene.AddComponent<TimerComponent>();
  33. Game.Scene.AddComponent<OpcodeTypeComponent>();
  34. Game.Scene.AddComponent<MessageDispatcherComponent>();
  35. Game.Scene.AddComponent<SessionStreamDispatcher>();
  36. Game.Scene.AddComponent<CoroutineLockComponent>();
  37. // 发送普通actor消息
  38. Game.Scene.AddComponent<ActorMessageSenderComponent>();
  39. // 发送location actor消息
  40. Game.Scene.AddComponent<ActorLocationSenderComponent>();
  41. // 访问location server的组件
  42. Game.Scene.AddComponent<LocationProxyComponent>();
  43. Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
  44. // 数值订阅组件
  45. Game.Scene.AddComponent<NumericWatcherComponent>();
  46. Game.Scene.AddComponent<NetThreadComponent>();
  47. switch (Game.Options.AppType)
  48. {
  49. case AppType.Server:
  50. {
  51. StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);
  52. Game.Scene.AddComponent<DBManagerComponent>();
  53. //OBS
  54. Game.Scene.AddComponent<ObsClientComponent>();
  55. var qdName = Options.Instance.QDName;
  56. //发行平台
  57. if (!string.IsNullOrEmpty(qdName) && qdName.Contains(QDName.TapTap))
  58. {
  59. Game.Scene.AddComponent<PlatformTaptapComponent>();
  60. }
  61. //实例化配置表
  62. CommonDataManager.Init();
  63. //添加日志组件
  64. Game.Scene.AddComponent<LogAddComponent>();
  65. Game.Scene.AddComponent<LogSplicingComponent>();
  66. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort,
  67. SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
  68. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
  69. foreach (StartSceneConfig startConfig in processScenes)
  70. {
  71. await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone,
  72. startConfig.Name,
  73. startConfig.Type, startConfig);
  74. }
  75. //日清定时器,确保所有scene都已经创建完毕
  76. Game.Scene.AddComponent<GlobalDayClearComponent>();
  77. break;
  78. }
  79. case AppType.Watcher:
  80. {
  81. StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);
  82. //var startMachineConfig = WatcherHelper.GetThisMachineConfig();
  83. Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort,
  84. SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
  85. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
  86. foreach (StartSceneConfig startConfig in processScenes)
  87. {
  88. await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone,
  89. startConfig.Name,
  90. startConfig.Type, startConfig);
  91. }
  92. Game.Scene.AddComponent<WatcherComponent>().Start(Game.Options.CreateScenes);
  93. break;
  94. }
  95. case AppType.GameTool:
  96. break;
  97. }
  98. if (Game.Options.Console == 1)
  99. {
  100. Game.Scene.AddComponent<ConsoleComponent>();
  101. }
  102. var openReportUrl = StartGlobalConfigCategory.Instance.GlobalConfig.OpenReportUrl;
  103. if (!string.IsNullOrEmpty(openReportUrl))
  104. {
  105. ErrorReportComponent.Instance?.Report("开服成功", openReportUrl);
  106. }
  107. }
  108. }
  109. }