Forráskód Böngészése

优化服务端AMRpcHandler

johnclot69 1 éve
szülő
commit
216b765215

+ 1 - 1
DotNet/Hotfix/Scenes/Benchmark/C2G_BenchmarkHandler.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     [MessageHandler(SceneType.BenchmarkServer)]
     public class C2G_BenchmarkHandler: AMRpcHandler<C2G_Benchmark, G2C_Benchmark>
     {
-        protected override async ETTask Run(Session session, C2G_Benchmark request, G2C_Benchmark response, Action reply)
+        protected override async ETTask Run(Session session, C2G_Benchmark request, G2C_Benchmark response)
         {            
             BenchmarkServerComponent benchmarkServerComponent = session.DomainScene().GetComponent<BenchmarkServerComponent>();
             if (benchmarkServerComponent.Count++ % 1000000 == 0)

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/C2G_EnterMapHandler.cs

@@ -5,7 +5,7 @@ namespace ET.Server
 	[MessageHandler(SceneType.Game)]
 	public class C2G_EnterMapHandler : AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
 	{
-		protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply)
+		protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response)
 		{
 			Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
 

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -5,7 +5,7 @@ namespace ET.Server
 	[MessageHandler(SceneType.Game)]
 	public class C2G_LoginGameHandler : AMRpcHandler<C2G_LoginGate, G2C_LoginGate>
 	{
-		protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
+		protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response)
 		{
 			Scene scene = session.DomainScene();
 			string account = scene.GetComponent<GameSessionKeyComponent>().Get(request.Key);

+ 1 - 2
DotNet/Hotfix/Scenes/Game/Handler/C2G_PingHandler.cs

@@ -8,10 +8,9 @@ namespace ET.Server
 	[MessageHandler(SceneType.Game)]
 	public class C2G_PingHandler : AMRpcHandler<C2G_Ping, G2C_Ping>
 	{
-		protected override async ETTask Run(Session session, C2G_Ping request, G2C_Ping response, Action reply)
+		protected override async ETTask Run(Session session, C2G_Ping request, G2C_Ping response)
 		{
 			response.Time = TimeHelper.ClientNow();
-			reply();
 			await ETTask.CompletedTask;
 		}
 	}

+ 1 - 2
DotNet/Hotfix/Scenes/Realm/Handler/C2R_LoginHandler.cs

@@ -9,7 +9,7 @@ namespace ET.Server
 	[MessageHandler(SceneType.Realm)]
 	public class C2R_LoginHandler : AMRpcHandler<C2R_Login, R2C_Login>
 	{
-		protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
+		protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response)
 		{
 			if (session.DomainScene().SceneType != SceneType.Realm)
 			{
@@ -22,7 +22,6 @@ namespace ET.Server
 			if (session.GetComponent<SessionLockComponent>() != null)
 			{
 				response.Error = ErrorCode.ERR_RequestRepeatedly;
-				reply();
 				return;
 			}
 			

+ 11 - 16
DotNet/Model/Module/Message/AMRpcHandler.cs

@@ -4,7 +4,7 @@ namespace ET.Server
 {
     public abstract class AMRpcHandler<Request, Response>: IMHandler where Request : class, IRequest where Response : class, IResponse
     {
-        protected abstract ETTask Run(Session session, Request request, Response response, Action reply);
+        protected abstract ETTask Run(Session session, Request request, Response response);
 
         public void Handle(Session session, object message)
         {
@@ -22,34 +22,29 @@ namespace ET.Server
                 }
 
                 int rpcId = request.RpcId;
-
                 long instanceId = session.InstanceId;
 
                 Response response = Activator.CreateInstance<Response>();
 
-                void Reply()
-                {
-                    // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
-                    if (session.InstanceId != instanceId)
-                    {
-                        return;
-                    }
-
-                    response.RpcId = rpcId;
-                    session.Send(response);
-                }
-
                 try
                 {
-                    await this.Run(session, request, response, Reply);
+                    await this.Run(session, request, response);
                 }
                 catch (Exception exception)
                 {
                     Log.Error(exception);
                     response.Error = ErrorCore.ERR_RpcFail;
                     response.Message = exception.ToString();
-                    Reply();
                 }
+                
+                // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
+                if (session.InstanceId != instanceId)
+                {
+                    return;
+                }
+                
+                response.RpcId = rpcId; // 在这里设置rpcId是为了防止在Run中不小心修改rpcId字段
+                session.Send(response);
             }
             catch (Exception e)
             {