EntryEvent2_InitServer.cs 3.0 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: 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. StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Options.Instance.Process);
  22. Log.Debug($"AppType: {Options.Instance.AppType}");
  23. switch (Options.Instance.AppType)
  24. {
  25. case AppType.Server:
  26. {
  27. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  28. //初始化游戏服全局参数
  29. Global.GameServerId = startMachineConfig.GameServerId;
  30. Global.GameServerUUID = Guid.NewGuid().ToString();
  31. //GameServer添加战斗服的Ice会话组件
  32. Root.Instance.Scene.AddComponent<BattleIceAgentComponent>();
  33. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
  34. var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
  35. foreach (StartSceneConfig startConfig in processScenes)
  36. {
  37. await SceneFactory.CreateServerScene(ServerSceneManagerComponent.Instance, startConfig.Id, startConfig.InstanceId, startConfig.Zone, startConfig.Name,
  38. startConfig.Type, startConfig);
  39. }
  40. break;
  41. }
  42. case AppType.Watcher:
  43. {
  44. StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
  45. WatcherComponent watcherComponent = Root.Instance.Scene.AddComponent<WatcherComponent>();
  46. watcherComponent.Start(Options.Instance.CreateScenes);
  47. Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
  48. break;
  49. }
  50. case AppType.GameTool:
  51. break;
  52. }
  53. if (Options.Instance.Console == 1)
  54. {
  55. Root.Instance.Scene.AddComponent<ConsoleComponent>();
  56. }
  57. }
  58. }
  59. }