using Ice; using System; using System.Threading; using BattleIce; using Newtonsoft.Json.Linq; namespace ET.Server { [FriendOf(typeof (BattleIceAgentComponent))] public static class BattleIceAgentComponentSystem { public class BattleIceAgentComponentAwakeSystem: AwakeSystem { protected override void Awake(BattleIceAgentComponent self) { BattleIceAgentComponent.Instance = self; Thread thread = new Thread(() => { IceApp IceApp = new IceApp(); IceApp.main(Array.Empty(), "../Config/ice.config"); }); thread.Start(); } } public class BattleIceAgentComponentDestroySystem: DestroySystem { protected override void Destroy(BattleIceAgentComponent self) { Log.Info($"Ice component destroyed"); Application.communicator().Dispose(); } } [ObjectSystem] [FriendOf(typeof (BattleIceAgentComponent))] private class IceApp: Application { public override int run(string[] args) { try { ZoneManagerPrx ZoneIce = 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(15000); ObjectAdapter adapter = communicator().createObjectAdapter(""); ObjectPrx prx = adapter.add(new ZoneManagerCallback(), communicator().stringToIdentity("bs-" + ConstGame.GameServerId)); ZoneIce.ice_getCachedConnection().setAdapter(adapter); //-3: 未知异常 //-2: 异常参数; //-1: 已有在线的,拒绝; //0 : 加入成功 //1 : 加入成功,重连 int code = ZoneIce.setCallback(prx.ice_getIdentity(), ConstGame.GameServerUUID); if (code < 0) { Log.Error($"战斗服连接异常: {code}"); return 2; } //向战斗服注册本GameServer string res = ZoneIce.registerGameServer(ConstGame.GameServerId, ConstGame.GameServerId); BattleIceAgentComponent.Instance.StrBattleServerVersion = res; Log.Info($"Battle Server version: {res}"); } catch (Ice.Exception e) { Log.Error($"BattleIceAgentComponent ZoneManagerPrx Exception.{e.Message}"); return 3; } try { XmdsManagerPrx XmdsIce = XmdsManagerPrxHelper.checkedCast(communicator().propertyToProxy("XmdsManager.Proxy")); if (XmdsIce == null) { Log.Error("not found ice proxy: XmdsManager"); return 4; } Log.Debug("got XmdsManager.Proxy"); BattleIceAgentComponent.Instance.IceXmdsManager = XmdsIce; XmdsIce.ice_invocationTimeout(15000); } catch (Ice.Exception e) { Log.Error($"BattleIceAgentComponent XmdsManagerPrx Exception.{e.Message}"); return 5; } //连接战斗服FastStream组件 BattleIceAgentComponent.Instance.DomainScene().AddComponent(); IceApp.communicator().waitForShutdown(); Log.Info("ice thread end"); return 0; } } [ObjectSystem] private class ZoneManagerCallback: ZoneManagerCallbackDisp_ { public override void eventNotify(string eventType, string msg, Current current__) { switch (eventType) { case "areaEvent": case "zoneEvent": { BattleServerEventHelper.AreaBattleServerEvent(JObject.Parse(msg)); return; } case "playerEvent": { BattleServerEventHelper.PlayerBattleServerEvent(JObject.Parse(msg)); return; } case "taskEvent": { BattleServerEventHelper.TaskBattleServerEvent(JObject.Parse(msg)); return; } case "mapNotify": { BattleServerEventHelper.MapNotifyEvent(JObject.Parse(msg)); return; } } } } } }