BattleIceAgentComponentSystem.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using Ice;
  2. using System;
  3. using System.Threading;
  4. using BattleIce;
  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. IceApp IceApp = new IceApp();
  18. IceApp.main(Array.Empty<string>(), "../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. Application.communicator().Dispose();
  29. }
  30. }
  31. [ObjectSystem]
  32. [FriendOf(typeof (BattleIceAgentComponent))]
  33. private class IceApp: Application
  34. {
  35. public override int run(string[] args)
  36. {
  37. try
  38. {
  39. ZoneManagerPrx ZoneIce = 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(15000);
  48. ObjectAdapter adapter = communicator().createObjectAdapter("");
  49. ObjectPrx prx = adapter.add(new ZoneManagerCallback(), communicator().stringToIdentity("bs-" + ConstGame.GameServerId));
  50. ZoneIce.ice_getCachedConnection().setAdapter(adapter);
  51. //-3: 未知异常
  52. //-2: 异常参数;
  53. //-1: 已有在线的,拒绝;
  54. //0 : 加入成功
  55. //1 : 加入成功,重连
  56. int code = ZoneIce.setCallback(prx.ice_getIdentity(), ConstGame.GameServerUUID);
  57. if (code < 0)
  58. {
  59. Log.Error($"战斗服连接异常: {code}");
  60. return 2;
  61. }
  62. //向战斗服注册本GameServer
  63. string res = ZoneIce.registerGameServer(ConstGame.GameServerId, ConstGame.GameServerId);
  64. BattleIceAgentComponent.Instance.StrBattleServerVersion = res;
  65. Log.Info($"Battle Server version: {res}");
  66. }
  67. catch (Ice.Exception e)
  68. {
  69. Log.Error($"BattleIceAgentComponent ZoneManagerPrx Exception.{e.Message}");
  70. return 3;
  71. }
  72. try
  73. {
  74. XmdsManagerPrx XmdsIce = XmdsManagerPrxHelper.checkedCast(communicator().propertyToProxy("XmdsManager.Proxy"));
  75. if (XmdsIce == null)
  76. {
  77. Log.Error("not found ice proxy: XmdsManager");
  78. return 4;
  79. }
  80. Log.Debug("got XmdsManager.Proxy");
  81. BattleIceAgentComponent.Instance.IceXmdsManager = XmdsIce;
  82. XmdsIce.ice_invocationTimeout(15000);
  83. }
  84. catch (Ice.Exception e)
  85. {
  86. Log.Error($"BattleIceAgentComponent XmdsManagerPrx Exception.{e.Message}");
  87. return 5;
  88. }
  89. //连接战斗服FastStream组件
  90. BattleIceAgentComponent.Instance.DomainScene().AddComponent<FastStreamComponent>();
  91. IceApp.communicator().waitForShutdown();
  92. Log.Info("ice thread end");
  93. return 0;
  94. }
  95. }
  96. [ObjectSystem]
  97. private class ZoneManagerCallback: ZoneManagerCallbackDisp_
  98. {
  99. public override void eventNotify(string eventType, string msg, Current current__)
  100. {
  101. Log.Debug("======================================");
  102. Log.Debug($"battleServer zone notify: type({eventType}), msg({msg})");
  103. Log.Debug("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  104. switch (eventType)
  105. {
  106. case "areaEvent":
  107. case "zoneEvent":
  108. {
  109. return;
  110. }
  111. case "playerEvent":
  112. {
  113. return;
  114. }
  115. case "taskEvent":
  116. {
  117. return;
  118. }
  119. case "mapNotify":
  120. {
  121. return;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }