BattleIceAgentComponentSystem.cs 4.7 KB

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