123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using Ice;
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ET.Server
- {
- [FriendOf(typeof(BattleIceAgentComponent))]
- public static class BattleIceAgentComponentSystem
- {
- public class BattleIceAgentComponentAwakeSystem : AwakeSystem<BattleIceAgentComponent>
- {
- protected override void Awake(BattleIceAgentComponent self)
- {
- BattleIceAgentComponent.Instance = self;
- Thread thread = new Thread(() =>
- {
- var IceApp = new IceApp();
- IceApp.main(new string[0], "../Config/ice.config");
- });
- thread.Start();
- }
- }
- public class BattleIceAgentComponentDestroySystem : DestroySystem<BattleIceAgentComponent>
- {
- protected override void Destroy(BattleIceAgentComponent self)
- {
- Log.Info($"Ice component destroyed");
- Ice.Application.communicator().Dispose();
- }
- }
- [ObjectSystem]
- [FriendOf(typeof(BattleIceAgentComponent))]
- public class IceApp : Ice.Application
- {
- public override int run(string[] args)
- {
- try
- {
- var ZoneIce = BattleIce.ZoneManagerPrxHelper.checkedCast(communicator().propertyToProxy("zoneManager.Proxy"));
- if (ZoneIce == null)
- {
- Log.Error("not found ice proxy: zoneManager");
- return 1;
- }
- BattleIceAgentComponent.Instance.IceZoneManager = ZoneIce;
- Log.Debug("got zoneManager.Proxy");
- ZoneIce.ice_invocationTimeout(15);
- Ice.ObjectAdapter adapter = communicator().createObjectAdapter("");
- var prx = adapter.add(new ZoneManagerCallback(), communicator().stringToIdentity("bs-" + Global.GameServerId));
- ZoneIce.ice_getCachedConnection().setAdapter(adapter);
- ZoneIce.setCallback(prx.ice_getIdentity(), Global.GameServerUUID);
- //向战斗服注册本GameServer
- var res = ZoneIce.registerGameServer(Global.GameServerId, Global.GameServerId);
- BattleIceAgentComponent.Instance.StrBattleServerVersion = res;
- Log.Info($"Battle Server version: {res}");
- }
- catch(Ice.Exception e)
- {
- Log.Error(e.Message);
- return 1;
- }
- try
- {
- var XmdsIce = BattleIce.XmdsManagerPrxHelper.checkedCast(communicator().propertyToProxy("XmdsManager.Proxy"));
- if (XmdsIce == null)
- {
- Log.Error("not found ice proxy: XmdsManager");
- return 1;
- }
- Log.Debug("got XmdsManager.Proxy");
- BattleIceAgentComponent.Instance.IceXmdsManager = XmdsIce;
- XmdsIce.ice_invocationTimeout(15);
- }
- catch(Ice.Exception e)
- {
- Log.Error(e.Message);
- return 2;
- }
- //连接战斗服FastStream组件
- Root.Instance.Scene.AddComponent<FastStreamComponent>();
- IceApp.communicator().waitForShutdown();
- Log.Info("ice thread end");
- return 0;
- }
- }
- [ObjectSystem]
- public class ZoneManagerCallback : BattleIce.ZoneManagerCallbackDisp_
- {
- public override void eventNotify(string eventType, string msg, Current current__)
- {
- Log.Debug("======================================");
- Log.Debug($"battleServer zone notify: type({eventType}), msg({msg})");
- }
- }
- }
- }
|