BattleIceAgentComponentSystem.cs 3.4 KB

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