EntryEvent2_InitServer.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Net;
  3. using ET;
  4. namespace ET.Server
  5. {
  6. [Event(SceneType.Process)]
  7. public class EntryEvent2_InitServer: AEvent<ET.EventType.EntryEvent2>
  8. {
  9. protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent2 args)
  10. {
  11. // 发送普通actor消息
  12. Root.Instance.Scene.AddComponent<ActorMessageSenderComponent>();
  13. // 发送location actor消息
  14. Root.Instance.Scene.AddComponent<ActorLocationSenderComponent>();
  15. // 访问location server的组件
  16. Root.Instance.Scene.AddComponent<LocationProxyComponent>();
  17. Root.Instance.Scene.AddComponent<ActorMessageDispatcherComponent>();
  18. Root.Instance.Scene.AddComponent<ServerSceneManagerComponent>();
  19. Root.Instance.Scene.AddComponent<RobotCaseComponent>();
  20. // 访问mongodb数据库组件
  21. Root.Instance.Scene.AddComponent<DBManagerComponent>();
  22. StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Options.Instance.Process);
  23. Log.Debug($"AppType: {Options.Instance.AppType}");
  24. switch (Options.Instance.AppType)
  25. {
  26. case AppType.Server:
  27. {
  28. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
  29. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
  30. foreach (StartSceneConfig startConfig in processScenes)
  31. {
  32. await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
  33. startConfig.Type, startConfig);
  34. }
  35. break;
  36. }
  37. case AppType.Watcher:
  38. {
  39. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  40. WatcherComponent watcherComponent = Root.Instance.Scene.AddComponent<WatcherComponent>();
  41. watcherComponent.Start(Options.Instance.CreateScenes);
  42. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
  43. break;
  44. }
  45. case AppType.GameTool:
  46. break;
  47. }
  48. if (Options.Instance.Console == 1)
  49. {
  50. Root.Instance.Scene.AddComponent<ConsoleComponent>();
  51. }
  52. }
  53. }
  54. }