EntryEvent2_InitServer.cs 2.9 KB

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