BattleIceAgentComponentSystem.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Ice;
  2. using System;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. namespace ET.Server
  6. {
  7. [FriendOf(typeof(BattleIceAgentComponent))]
  8. public static class BattleIceAgentComponentSystem
  9. {
  10. public class BattleIceAgentComponentAwakeSystem : AwakeSystem<BattleIceAgentComponent>
  11. {
  12. protected override void Awake(BattleIceAgentComponent self)
  13. {
  14. BattleIceAgentComponent.Instance = self;
  15. Thread thread = new Thread(() =>
  16. {
  17. var IceApp = new IceApp();
  18. IceApp.main(new string[0], "../Config/ice.config");
  19. });
  20. thread.Start();
  21. }
  22. }
  23. public class BattleIceAgentComponentDestroySystem : DestroySystem<BattleIceAgentComponent>
  24. {
  25. protected override void Destroy(BattleIceAgentComponent self)
  26. {
  27. Log.Info($"Ice component destroyed");
  28. Ice.Application.communicator().Dispose();
  29. }
  30. }
  31. [ObjectSystem]
  32. [FriendOf(typeof(BattleIceAgentComponent))]
  33. public class IceApp : Ice.Application
  34. {
  35. public override int run(string[] args)
  36. {
  37. try
  38. {
  39. var ZoneIce = BattleIce.ZoneManagerPrxHelper.checkedCast(communicator().propertyToProxy("zoneManager.Proxy"));
  40. if (ZoneIce == null)
  41. {
  42. Log.Error("not found ice proxy: zoneManager");
  43. return 1;
  44. }
  45. BattleIceAgentComponent.Instance.IceZoneManager = ZoneIce;
  46. Log.Debug("got zoneManager.Proxy");
  47. ZoneIce.ice_invocationTimeout(15);
  48. Ice.ObjectAdapter adapter = communicator().createObjectAdapter("");
  49. var prx = adapter.add(new ZoneManagerCallback(), communicator().stringToIdentity("bs-" + Global.GameServerId));
  50. ZoneIce.ice_getCachedConnection().setAdapter(adapter);
  51. ZoneIce.setCallback(prx.ice_getIdentity(), Global.GameServerUUID);
  52. //向战斗服注册本GameServer
  53. var res = ZoneIce.registerGameServer(Global.GameServerId, Global.GameServerId);
  54. BattleIceAgentComponent.Instance.StrBattleServerVersion = res;
  55. Log.Info($"Battle Server version: {res}");
  56. }
  57. catch(Ice.Exception e)
  58. {
  59. Log.Error(e.Message);
  60. return 1;
  61. }
  62. try
  63. {
  64. var XmdsIce = BattleIce.XmdsManagerPrxHelper.checkedCast(communicator().propertyToProxy("XmdsManager.Proxy"));
  65. if (XmdsIce == null)
  66. {
  67. Log.Error("not found ice proxy: XmdsManager");
  68. return 1;
  69. }
  70. Log.Debug("got XmdsManager.Proxy");
  71. BattleIceAgentComponent.Instance.IceXmdsManager = XmdsIce;
  72. XmdsIce.ice_invocationTimeout(15);
  73. }
  74. catch(Ice.Exception e)
  75. {
  76. Log.Error(e.Message);
  77. return 2;
  78. }
  79. //连接战斗服FastStream组件
  80. Root.Instance.Scene.AddComponent<FastStreamComponent>();
  81. IceApp.communicator().waitForShutdown();
  82. Log.Info("ice thread end");
  83. return 0;
  84. }
  85. }
  86. [ObjectSystem]
  87. public class ZoneManagerCallback : BattleIce.ZoneManagerCallbackDisp_
  88. {
  89. public override void eventNotify(string eventType, string msg, Current current__)
  90. {
  91. Log.Debug("======================================");
  92. Log.Debug($"battleServer zone notify: type({eventType}), msg({msg})");
  93. }
  94. }
  95. }
  96. }