EntryEvent2_InitServer.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Root.Instance.Scene.AddComponent<NavmeshComponent>();
  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. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  30. //初始化游戏服全局参数
  31. Global.GameServerId = startMachineConfig.GameServerId;
  32. Global.GameServerUUID = Guid.NewGuid().ToString();
  33. //GameServer添加战斗服的Ice会话组件
  34. Root.Instance.Scene.AddComponent<BattleIceAgentComponent>();
  35. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
  36. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
  37. foreach (StartSceneConfig startConfig in processScenes)
  38. {
  39. await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
  40. startConfig.Type, startConfig);
  41. }
  42. break;
  43. }
  44. case AppType.Watcher:
  45. {
  46. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  47. WatcherComponent watcherComponent = Root.Instance.Scene.AddComponent<WatcherComponent>();
  48. watcherComponent.Start(Options.Instance.CreateScenes);
  49. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
  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. }