소스 검색

gate session转发给client,假如发送失败,需要会给actorproxy一个response

tanghai 8 년 전
부모
커밋
fd5cb2a209

+ 17 - 7
Server/Hotfix/Other/EntityActorHandler.cs

@@ -1,4 +1,5 @@
-using System.Threading.Tasks;
+using System;
+using System.Threading.Tasks;
 using Model;
 
 namespace Hotfix
@@ -10,12 +11,21 @@ namespace Hotfix
     {
         public async Task Handle(Session session, Entity entity, ActorRequest message)
         {
-            ((Session)entity).Send(message.AMessage);
-            ActorResponse response = new ActorResponse
-            {
-                RpcId = message.RpcId
-            };
-            session.Reply(response);
+	        ActorResponse response = new ActorResponse { RpcId = message.RpcId };
+
+			try
+	        {
+		        ((Session)entity).Send(message.AMessage);
+		        session.Reply(response);
+		        await Task.CompletedTask;
+	        }
+	        catch (Exception e)
+	        {
+		        response.Error = ErrorCode.ERR_SessionActorError;
+		        response.Message = $"session actor error {e}";
+				session.Reply(response);
+				throw;
+	        }
         }
     }
 

+ 5 - 1
Server/Hotfix/System/ActorComponentSystem.cs

@@ -90,10 +90,14 @@ namespace Hotfix
 		{
 			while (true)
 			{
+				if (self.Id == 0)
+				{
+					return;
+				}
 				try
 				{
 					ActorMessageInfo info = await self.GetAsync();
-					await self.entityActorHandler.Handle(info.Session, self.Entity, info.Message);
+					await self.entityActorHandler.Handle(info.Session, self.Entity, info.Message); 
 				}
 				catch (Exception e)
 				{

+ 2 - 0
Server/Model/Base/Message/ErrorCode.cs

@@ -12,5 +12,7 @@ namespace Model
 		public const int ERR_ReloadFail = 104;
 		public const int ERR_NotFoundUnit = 105;
 		public const int ERR_ActorLocationNotFound = 106;
+		public const int ERR_SessionActorError = 107;
+		public const int ERR_ActorError = 108;
 	}
 }

+ 2 - 0
Server/Model/Component/ActorComponent.cs

@@ -34,6 +34,8 @@ namespace Model
 
 				base.Dispose();
 
+				this.tcs?.SetException(new Exception($"actor disposed! {this.actorId}"));
+
 				Game.Scene.GetComponent<ActorManagerComponent>().Remove(actorId);
 			}
 			catch (Exception)

+ 1 - 1
Unity/Assets/Scripts/Base/Log.cs

@@ -21,7 +21,7 @@
 		{
 			UnityEngine.Debug.Log(msg);
 		}
-
+		
 		public static void Flush()
 		{
 		}