Sfoglia il codice sorgente

【优化】服务器间连接增加重连和连接两种状态

meijun 3 anni fa
parent
commit
cc0fff8445

+ 4 - 4
Common/Pomelo/PomeloShare/FuckFastStream.cs

@@ -149,8 +149,8 @@ namespace Pomelo
 						log.Warn("A Session Binded : " + session + " : connetorId=" + connetorId + ", info:" + session.RemoteEndPoint.ToString());
 						session.ConnectorId = connetorId;
 						sessions.AddOrUpdate(connetorId, session, (key, oldValue) => session);
-
-						/*
+                        zone.onNetReconnect(connetorId, session);
+                        /*
                       //客户端版本号信息
                       using (var stream = new MemoryStream(5))
                       {
@@ -159,7 +159,7 @@ namespace Pomelo
                           session.Send(stream.GetBuffer(), 0, (int)stream.Position);
                       }
                       */
-					}
+                    }
                     else                
                     {
                         //发送数据到场景
@@ -206,7 +206,7 @@ namespace Pomelo
                 }
             }
         }
-        class FuckSession : AppSession<FuckSession, BinaryRequestInfo>, IFastSession
+        public class FuckSession : AppSession<FuckSession, BinaryRequestInfo>, IFastSession
         {
             public string ConnectorId { get; internal set; }
 

+ 33 - 13
Common/Pomelo/PomeloShare/IceManager.cs

@@ -4,6 +4,7 @@ using Ice;
 using System.Web.Helpers;
 using CommonLang;
 using System.Collections.Concurrent;
+using Pomelo.JSGModule;
 
 namespace Pomelo
 {
@@ -91,17 +92,18 @@ namespace Pomelo
     public class ICEZoneSession
     {
 		private CommonLang.Log.Logger log = CommonLang.Log.LoggerFactory.GetLogger("ICEZoneSession");
-
+        public string srvUUID;
         public ZoneManagerCallbackPrx client;
 		public ZoneManagerCallbackPrx callback;
 		public IFastSession fastSession;
 		public int failTimes = 0;
         public ConcurrentQueue<ICENotifyData> notifyFailData = new ConcurrentQueue<ICENotifyData>();
 
-		public ICEZoneSession(ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
+		public ICEZoneSession(string srvUUID, ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
         {
 			try
 			{
+                this.srvUUID = srvUUID;
                 this.client = client;
 				this.callback = callback;
 				this.failTimes = 0;
@@ -176,7 +178,11 @@ namespace Pomelo
                 return callbacks.Get(gameServerId);
             }
         }
-        public int setCallback(string gameServerId, ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
+
+
+
+
+        public int setCallback(string gameServerId, string srvUUID, ZoneManagerCallbackPrx client, ZoneManagerCallbackPrx callback)
         {
             lock (callbacks)
             {
@@ -187,25 +193,39 @@ namespace Pomelo
 					{
 						cacheSession.callback.ice_ping();
 						log.Error("已有服务器在线ice, 拒绝连接!");
-						return 1;
+						return GSBindResult.ALREADY_EXISTS;
 					}
 					catch(System.Exception)
-					{
-						log.Error("ice连入,远端已经失效,重新设置!");
-						cacheSession.callback = callback;
-
-                        //处理失败的逻辑
-                        cacheSession.RetryFailNotifys();
-                        return 0;
+					{						
+                        try
+                        {
+                            log.Error("ice连入,远端已经失效,重新设置!");
+                            cacheSession.callback = callback;
+                            bool reconnect = cacheSession.srvUUID.Equals(srvUUID);
+
+                            //重连处理失败的逻辑
+                            if (reconnect)
+                            {                                
+                                cacheSession.RetryFailNotifys();
+                            }
+
+                            cacheSession.srvUUID = srvUUID;
+                            return reconnect ? GSBindResult.JOIN_RECONNECT : GSBindResult.JOIN_OK;
+                        }
+                        catch (System.Exception e)
+                        {
+                            log.Error("setCallback未处理异常:", e);
+                            return GSBindResult.UNKOWN;
+                        }
 					}
 				}
                 else
                 {					
-					callbacks.Put(gameServerId, new ICEZoneSession(client, callback));
+					callbacks.Put(gameServerId, new ICEZoneSession(srvUUID, client, callback));
                 }
             }
 
-			return 0;
+			return GSBindResult.JOIN_OK;
         }
 
 		public bool setFastSession(string gameServerId, IFastSession session)

+ 3 - 0
Common/Pomelo/PomeloShare/Interface/IZone.cs

@@ -23,6 +23,9 @@ namespace Pomelo
         //开启场景控制器
         void Start(ZoneConfig zoneConfig);
 
+        /** 网络重置 */
+        void onNetReconnect(string connetorId, IFastSession session);
+
         //关闭场景控制器
         void Stop();
 

+ 24 - 0
Common/Pomelo/PomeloShare/JSGModule/PomeloData.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Pomelo.JSGModule
+{
+
+    //技能释放状态
+    public static class GSBindResult
+    {
+        /** 未知异常 */
+        public static readonly int UNKOWN = -3;
+        /** 异常参数  */
+        public static readonly int PARAM_ERROR = -2;
+        /** 已有在线的,拒绝  */
+        public static readonly int ALREADY_EXISTS = -1;
+        /** 加入成功 */
+        public static readonly int JOIN_OK = 0;
+        /** 加入成功,重连 */
+        public static readonly int JOIN_RECONNECT = 1;
+    }
+}

+ 1 - 0
Common/Pomelo/PomeloShare/PomeloShare.csproj

@@ -104,6 +104,7 @@
     <Compile Include="generated\ZoneManager.cs" />
     <Compile Include="IceManager.cs" />
     <Compile Include="Interface\IZone.cs" />
+    <Compile Include="JSGModule\PomeloData.cs" />
     <Compile Include="PomeloLog.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="ZoneManagerI.cs" />

+ 5 - 5
Common/Pomelo/PomeloShare/ZoneManagerI.cs

@@ -4,7 +4,7 @@ using System.Collections.Generic;
 using System.Web.Helpers;
 using CommonLang.Log;
 using System.Collections;
-
+using Pomelo.JSGModule;
 
 namespace Pomelo
 {
@@ -20,18 +20,18 @@ namespace Pomelo
         private CommonLang.Log.Logger log = LoggerFactory.GetLogger("ZoneManagerI");
 
 
-        public override int setCallback(Identity ident, Current current__)
+        public override int setCallback(Identity ident, string srvUUID, Current current__)
         {
 			string gameSrvId = ident.name;
-			if (string.IsNullOrEmpty(gameSrvId))
+			if (string.IsNullOrEmpty(gameSrvId) || string.IsNullOrEmpty(srvUUID))
 			{
-				return 2;
+				return GSBindResult.PARAM_ERROR;
 			}
 
             //current__.con.setCallback();
             Ice.ObjectPrx @base = current__.con.createProxy(ident);
             ZoneManagerCallbackPrx client = ZoneManagerCallbackPrxHelper.uncheckedCast(@base);
-            int resCode = IceManager.instance().setCallback(ident.name, client, (ZoneManagerCallbackPrx)client.ice_oneway());
+            int resCode = IceManager.instance().setCallback(ident.name, srvUUID, client, (ZoneManagerCallbackPrx)client.ice_oneway());
 			zone.SetCallBack(ident.name);
 			return resCode;
         }

+ 30 - 27
Common/Pomelo/PomeloShare/generated/ZoneManager.cs

@@ -127,27 +127,27 @@ namespace Pomelo
         /// 场景管理器相关协议
         /// </summary>
         
-        int setCallback(Ice.Identity ident);
+        int setCallback(Ice.Identity ident, string srvUUID);
 
         /// <summary>
         /// 场景管理器相关协议
         /// </summary>
         /// <param name="ctx__">The Context map to send with the invocation.</param>
         
-        int setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__);
+        int setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__);
 
         /// <summary>
         /// 场景管理器相关协议
         /// </summary>
         /// <returns>An asynchronous result object.</returns>
-        Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident);
+        Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, string srvUUID);
 
         /// <summary>
         /// 场景管理器相关协议
         /// </summary>
         /// <param name="ctx__">The Context map to send with the invocation.</param>
         /// <returns>An asynchronous result object.</returns>
-        Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__);
+        Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__);
 
         /// <summary>
         /// 场景管理器相关协议
@@ -155,7 +155,7 @@ namespace Pomelo
         /// <param name="cb__">Asynchronous callback invoked when the operation completes.</param>
         /// <param name="cookie__">Application data to store in the asynchronous result object.</param>
         /// <returns>An asynchronous result object.</returns>
-        Ice.AsyncResult begin_setCallback(Ice.Identity ident, Ice.AsyncCallback cb__, object cookie__);
+        Ice.AsyncResult begin_setCallback(Ice.Identity ident, string srvUUID, Ice.AsyncCallback cb__, object cookie__);
 
         /// <summary>
         /// 场景管理器相关协议
@@ -164,7 +164,7 @@ namespace Pomelo
         /// <param name="cb__">Asynchronous callback invoked when the operation completes.</param>
         /// <param name="cookie__">Application data to store in the asynchronous result object.</param>
         /// <returns>An asynchronous result object.</returns>
-        Ice.AsyncResult begin_setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__, Ice.AsyncCallback cb__, object cookie__);
+        Ice.AsyncResult begin_setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__, Ice.AsyncCallback cb__, object cookie__);
 
         /// <summary>
         /// 场景管理器相关协议
@@ -406,7 +406,7 @@ namespace Pomelo
         /// </summary>
         /// <param name="current__">The Current object for the invocation.</param>
         
-        int setCallback(Ice.Identity ident, Ice.Current current__);
+        int setCallback(Ice.Identity ident, string srvUUID, Ice.Current current__);
 
         /// <summary>
         /// 场景副本相关协议
@@ -446,7 +446,7 @@ namespace Pomelo
         /// 场景管理器相关协议
         /// </summary>
         
-        int setCallback(Ice.Identity ident);
+        int setCallback(Ice.Identity ident, string srvUUID);
 
         /// <summary>
         /// 场景副本相关协议
@@ -867,20 +867,20 @@ namespace Pomelo
             return end_registerGameServer(begin_registerGameServer(serverid, crossid, context__, explicitCtx__, true, null, null));
         }
 
-        public int setCallback(Ice.Identity ident)
+        public int setCallback(Ice.Identity ident, string srvUUID)
         {
-            return this.setCallback(ident, null, false);
+            return this.setCallback(ident, srvUUID, null, false);
         }
 
-        public int setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__)
+        public int setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__)
         {
-            return this.setCallback(ident, ctx__, true);
+            return this.setCallback(ident, srvUUID, ctx__, true);
         }
 
-        private int setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> context__, bool explicitCtx__)
+        private int setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> context__, bool explicitCtx__)
         {
             checkTwowayOnly__(__setCallback_name);
-            return end_setCallback(begin_setCallback(ident, context__, explicitCtx__, true, null, null));
+            return end_setCallback(begin_setCallback(ident, srvUUID, context__, explicitCtx__, true, null, null));
         }
 
         #endregion
@@ -1650,24 +1650,24 @@ namespace Pomelo
             }
         }
 
-        public Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident)
+        public Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, string srvUUID)
         {
-            return begin_setCallback(ident, null, false, false, null, null);
+            return begin_setCallback(ident, srvUUID, null, false, false, null, null);
         }
 
-        public Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__)
+        public Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__)
         {
-            return begin_setCallback(ident, ctx__, true, false, null, null);
+            return begin_setCallback(ident, srvUUID, ctx__, true, false, null, null);
         }
 
-        public Ice.AsyncResult begin_setCallback(Ice.Identity ident, Ice.AsyncCallback cb__, object cookie__)
+        public Ice.AsyncResult begin_setCallback(Ice.Identity ident, string srvUUID, Ice.AsyncCallback cb__, object cookie__)
         {
-            return begin_setCallback(ident, null, false, false, cb__, cookie__);
+            return begin_setCallback(ident, srvUUID, null, false, false, cb__, cookie__);
         }
 
-        public Ice.AsyncResult begin_setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__, Ice.AsyncCallback cb__, object cookie__)
+        public Ice.AsyncResult begin_setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__, Ice.AsyncCallback cb__, object cookie__)
         {
-            return begin_setCallback(ident, ctx__, true, false, cb__, cookie__);
+            return begin_setCallback(ident, srvUUID, ctx__, true, false, cb__, cookie__);
         }
 
         private const string __setCallback_name = "setCallback";
@@ -1700,7 +1700,7 @@ namespace Pomelo
             }
         }
 
-        private Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, _System.Collections.Generic.Dictionary<string, string> ctx__, bool explicitContext__, bool synchronous__, Ice.AsyncCallback cb__, object cookie__)
+        private Ice.AsyncResult<Pomelo.Callback_ZoneManager_setCallback> begin_setCallback(Ice.Identity ident, string srvUUID, _System.Collections.Generic.Dictionary<string, string> ctx__, bool explicitContext__, bool synchronous__, Ice.AsyncCallback cb__, object cookie__)
         {
             checkAsyncTwowayOnly__(__setCallback_name);
             IceInternal.TwowayOutgoingAsync<Pomelo.Callback_ZoneManager_setCallback> result__ =  getTwowayOutgoingAsync<Pomelo.Callback_ZoneManager_setCallback>(__setCallback_name, setCallback_completed__, cookie__);
@@ -1713,6 +1713,7 @@ namespace Pomelo
                 result__.prepare(__setCallback_name, Ice.OperationMode.Normal, ctx__, explicitContext__, synchronous__);
                 IceInternal.BasicStream os__ = result__.startWriteParams(Ice.FormatType.DefaultFormat);
                 Ice.Identity.write__(os__, ident);
+                os__.writeString(srvUUID);
                 result__.endWriteParams();
                 result__.invoke();
             }
@@ -2037,12 +2038,12 @@ namespace Pomelo
     {
         #region Slice operations
 
-        public int setCallback(Ice.Identity ident)
+        public int setCallback(Ice.Identity ident, string srvUUID)
         {
-            return setCallback(ident, Ice.ObjectImpl.defaultCurrent);
+            return setCallback(ident, srvUUID, Ice.ObjectImpl.defaultCurrent);
         }
 
-        public abstract int setCallback(Ice.Identity ident, Ice.Current current__);
+        public abstract int setCallback(Ice.Identity ident, string srvUUID, Ice.Current current__);
 
         public void createZoneRequest_async(Pomelo.AMD_ZoneManager_createZoneRequest cb__, string playerId, string gameServerId, int mapTemplateId, string instanceId, bool force, string data)
         {
@@ -2170,9 +2171,11 @@ namespace Pomelo
             IceInternal.BasicStream is__ = inS__.startReadParams();
             Ice.Identity ident;
             ident = null;
+            string srvUUID;
             ident = Ice.Identity.read__(is__, ident);
+            srvUUID = is__.readString();
             inS__.endReadParams();
-            int ret__ = obj__.setCallback(ident, current__);
+            int ret__ = obj__.setCallback(ident, srvUUID, current__);
             IceInternal.BasicStream os__ = inS__.startWriteParams__(Ice.FormatType.DefaultFormat);
             os__.writeInt(ret__);
             inS__.endWriteParams__(true);

+ 11 - 1
XmdsServerCS/XmdsServerEdgeJS/Zone/XmdsPlayer.cs

@@ -14,6 +14,7 @@ using CommonLang.IO.Attribute;
 using CommonLang.Log;
 using CommonLang.Concurrent;
 using CommonLang;
+using static Pomelo.FuckFastStream;
 
 namespace XmdsServerEdgeJS.Zone
 {
@@ -25,7 +26,7 @@ namespace XmdsServerEdgeJS.Zone
         private readonly XmdsZoneNode node;
         private readonly ZoneService service;
         private readonly string instanceId;
-        private readonly IFastSession connectServerId;
+        private IFastSession connectServerId;
         private readonly string uid;
 
         private HashMap<string, object> attributes = new HashMap<string, object>(1);
@@ -46,6 +47,15 @@ namespace XmdsServerEdgeJS.Zone
         public IFastSession ConnectServerId { get { return connectServerId; } }
         public string Uid { get { return uid; } }
 
+        public void OnNetReconnect(string connetorId, IFastSession session)
+        {
+            if(this.connectServerId != null && this.connectServerId.ConnectorId != null && connetorId != null && this.connectServerId.ConnectorId.Equals(connetorId))
+            {
+                this.connectServerId = session;
+            }            
+         }
+
+
         /// <summary>
         /// 用于显示的名字
         /// </summary>

+ 21 - 1
XmdsServerCS/XmdsServerEdgeJS/Zone/ZoneService.cs

@@ -23,7 +23,7 @@ namespace XmdsServerEdgeJS.Zone
 	public abstract class ZoneService : IZone
 	{
 		//战斗服版本号
-		private static readonly string S_BSVersion = "1.0.0";
+		private static readonly string S_BSVersion = "1.0.1";
 
 		public static ZoneService Instance { get; private set; }
 		protected ZoneService()
@@ -198,6 +198,26 @@ namespace XmdsServerEdgeJS.Zone
 			}
 		}
 
+		/** 网络重置 */
+		public void onNetReconnect(string connetorId, IFastSession session)
+        {
+            try
+            {
+				lock (players)
+				{
+					foreach (var player in players.Values)
+					{
+						player.OnNetReconnect(connetorId, session);
+					}
+				}
+			}
+			catch(Exception e)
+            {
+				log.Error("onNetReconnect catch: " + connetorId + ", " + e);
+            }
+		}
+
+
 		public void Stop()
 		{