123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- 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<BattleIceAgentComponent>
- {
- protected override void Awake(BattleIceAgentComponent self)
- {
- BattleIceAgentComponent.Instance = self;
- Thread thread = new Thread(() =>
- {
- IceApp IceApp = new IceApp();
- IceApp.main(Array.Empty<string>(), "../Config/ice.config");
- });
- thread.Start();
- }
- }
- public class BattleIceAgentComponentDestroySystem: DestroySystem<BattleIceAgentComponent>
- {
- 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<FastStreamComponent>();
- 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;
- }
- }
- }
- }
- }
- }
|