| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using GFGGame;
- using System.Net;
- namespace ET
- {
- public class AppStart_Init : AEvent<EventType.AppStart>
- {
- protected override async ETTask Run(EventType.AppStart args)
- {
- Game.Scene.AddComponent<ConfigComponent>();
- await ConfigComponent.Instance.LoadAsync();
- //HttpClient
- Game.Scene.AddComponent<HttpClientComponent>();
- if (Options.Instance.ErrorReport || !string.IsNullOrEmpty(Options.Instance.QDName))
- {
- var errorReportComponent = Game.Scene.AddComponent<ErrorReportComponent>();
- var errorInfo = errorReportComponent.ErrorInfo;
- errorInfo.Process = Options.Instance.Process;
- errorInfo.ProcessId = Environment.ProcessId;
- var localIps = NetworkHelper.GetNonLoopbackIP();
- if (!string.IsNullOrEmpty(localIps)) errorInfo.LocalIP = localIps;
- var outIpv4 = await NetworkHelper.GetOutIpv4();
- if (!string.IsNullOrEmpty(outIpv4)) errorInfo.IP = outIpv4;
- errorReportComponent.Url = StartGlobalConfigCategory.Instance.GlobalConfig.ErrorReportUrl;
- errorReportComponent.DetectionReportUrl =
- StartGlobalConfigCategory.Instance.GlobalConfig.DetectionReportUrl;
- Log.ErrorAction += msg => ErrorReportComponent.Instance?.Report(msg);
- Log.DetectionErrorAction += msg => ErrorReportComponent.Instance?.DetectionReportReport(msg);
- }
- //设置时区
- TimeInfo.Instance.TimeZone = 8;
- Game.Scene.AddComponent<TimerComponent>();
- Game.Scene.AddComponent<OpcodeTypeComponent>();
- Game.Scene.AddComponent<MessageDispatcherComponent>();
- Game.Scene.AddComponent<SessionStreamDispatcher>();
- Game.Scene.AddComponent<CoroutineLockComponent>();
- // 发送普通actor消息
- Game.Scene.AddComponent<ActorMessageSenderComponent>();
- // 发送location actor消息
- Game.Scene.AddComponent<ActorLocationSenderComponent>();
- // 访问location server的组件
- Game.Scene.AddComponent<LocationProxyComponent>();
- Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
- // 数值订阅组件
- Game.Scene.AddComponent<NumericWatcherComponent>();
- Game.Scene.AddComponent<NetThreadComponent>();
- switch (Game.Options.AppType)
- {
- case AppType.Server:
- {
- StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);
- Game.Scene.AddComponent<DBManagerComponent>();
- //OBS
- Game.Scene.AddComponent<ObsClientComponent>();
- var qdName = Options.Instance.QDName;
- //发行平台
- if (!string.IsNullOrEmpty(qdName) && qdName.Contains(QDName.TapTap))
- {
- Game.Scene.AddComponent<PlatformTaptapComponent>();
- }
-
- //实例化配置表
- CommonDataManager.Init();
- //添加日志组件
- Game.Scene.AddComponent<LogAddComponent>();
- Game.Scene.AddComponent<LogSplicingComponent>();
- Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort,
- SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
- var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
- foreach (StartSceneConfig startConfig in processScenes)
- {
- await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone,
- startConfig.Name,
- startConfig.Type, startConfig);
- }
- //日清定时器,确保所有scene都已经创建完毕
- Game.Scene.AddComponent<GlobalDayClearComponent>();
- break;
- }
- case AppType.Watcher:
- {
- StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Game.Options.Process);
- //var startMachineConfig = WatcherHelper.GetThisMachineConfig();
- Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort,
- SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
- var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
- foreach (StartSceneConfig startConfig in processScenes)
- {
- await SceneFactory.Create(Game.Scene, startConfig.Id, startConfig.InstanceId, startConfig.Zone,
- startConfig.Name,
- startConfig.Type, startConfig);
- }
- Game.Scene.AddComponent<WatcherComponent>().Start(Game.Options.CreateScenes);
- break;
- }
- case AppType.GameTool:
- break;
- }
- if (Game.Options.Console == 1)
- {
- Game.Scene.AddComponent<ConsoleComponent>();
- }
- var openReportUrl = StartGlobalConfigCategory.Instance.GlobalConfig.OpenReportUrl;
- if (!string.IsNullOrEmpty(openReportUrl))
- {
- ErrorReportComponent.Instance?.Report("开服成功", openReportUrl);
- }
- }
- }
- }
|