Procházet zdrojové kódy

修复传送逻辑,之前M2C_StartSceneChange跟M2C_CreateMyUnit在两个进程发送,可能会有顺序问题

tanghai před 3 roky
rodič
revize
19cc8816f1

+ 10 - 11
Unity/Assets/Config/Proto/InnerMessage_S_20001.proto

@@ -142,14 +142,6 @@ message G2R_GetLoginKey // IActorResponse
 	int64 GateId = 2;
 }
 
-message M2M_UnitTransferResponse // IActorResponse
-{
-	int32 RpcId = 1;
-	int32 Error = 2;
-	string Message = 3;
-	int64 NewInstanceId = 4;
-}
-
 message G2M_SessionDisconnect // IActorLocationMessage
 {
 	int32 RpcId = 90;
@@ -164,11 +156,18 @@ message ObjectQueryResponse // IActorResponse
 	bytes entity = 1;
 }
 
-
 //ResponseType M2M_UnitTransferResponse
 message M2M_UnitTransferRequest // IActorRequest
 {
 	int32 RpcId = 1;
-	bytes Unit = 2;
-	repeated bytes Entitys = 3;
+	int64 OldInstanceId = 2;
+	bytes Unit = 3;
+	repeated bytes Entitys = 4;
+}
+
+message M2M_UnitTransferResponse // IActorResponse
+{
+	int32 RpcId = 1;
+	int32 Error = 2;
+	string Message = 3;
 }

+ 9 - 5
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs

@@ -8,7 +8,8 @@ namespace ET.Server
 	{
 		protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
 		{
-			await ETTask.CompletedTask;
+			reply();
+			
 			UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
 			Unit unit = MongoHelper.FromBson<Unit>(request.Unit);
 			
@@ -26,18 +27,21 @@ namespace ET.Server
 			unit.Position = new float3(-10, 0, -10);
 			
 			unit.AddComponent<MailBoxComponent>();
+
+			// 通知客户端开始切场景
+			M2C_StartSceneChange m2CStartSceneChange = new M2C_StartSceneChange() {SceneInstanceId = scene.InstanceId, SceneName = scene.Name};
+			MessageHelper.SendToClient(unit, m2CStartSceneChange);
 			
 			// 通知客户端创建My Unit
 			M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();
-			m2CCreateUnits.Unit = Server.UnitHelper.CreateUnitInfo(unit);
+			m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
 			MessageHelper.SendToClient(unit, m2CCreateUnits);
 			
 			// 加入aoi
 			unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
-
-			response.NewInstanceId = unit.InstanceId;
 			
-			reply();
+			// 解锁location,可以接收发给Unit的消息
+			await LocationProxyComponent.Instance.UnLock(unit.Id, request.OldInstanceId, unit.InstanceId);
 		}
 	}
 }

+ 7 - 11
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/Transfer/TransferHelper.cs

@@ -6,11 +6,12 @@ namespace ET.Server
     {
         public static async ETTask Transfer(Unit unit, long sceneInstanceId, string sceneName)
         {
-            // 通知客户端开始切场景
-            M2C_StartSceneChange m2CStartSceneChange = new M2C_StartSceneChange() {SceneInstanceId = sceneInstanceId, SceneName = sceneName};
-            MessageHelper.SendToClient(unit, m2CStartSceneChange);
+            // location加锁
+            long unitId = unit.Id;
+            long unitInstanceId = unit.InstanceId;
             
             M2M_UnitTransferRequest request = new M2M_UnitTransferRequest();
+            request.OldInstanceId = unitInstanceId;
             request.Unit = unit.ToBson();
             foreach (Entity entity in unit.Components.Values)
             {
@@ -19,15 +20,10 @@ namespace ET.Server
                     request.Entitys.Add(entity.ToBson());
                 }
             }
-            // 删除Mailbox,让发给Unit的ActorLocation消息重发
-            unit.RemoveComponent<MailBoxComponent>();
-            
-            // location加锁
-            long oldInstanceId = unit.InstanceId;
-            await LocationProxyComponent.Instance.Lock(unit.Id, unit.InstanceId);
-            M2M_UnitTransferResponse response = await ActorMessageSenderComponent.Instance.Call(sceneInstanceId, request) as M2M_UnitTransferResponse;
-            await LocationProxyComponent.Instance.UnLock(unit.Id, oldInstanceId, response.NewInstanceId);
             unit.Dispose();
+            
+            await LocationProxyComponent.Instance.Lock(unitId, unitInstanceId);
+            await ActorMessageSenderComponent.Instance.Call(sceneInstanceId, request);
         }
     }
 }

+ 23 - 23
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs

@@ -298,24 +298,6 @@ namespace ET
 
 	}
 
-	[Message(InnerMessage.M2M_UnitTransferResponse)]
-	[ProtoContract]
-	public partial class M2M_UnitTransferResponse: Object, IActorResponse
-	{
-		[ProtoMember(1)]
-		public int RpcId { get; set; }
-
-		[ProtoMember(2)]
-		public int Error { get; set; }
-
-		[ProtoMember(3)]
-		public string Message { get; set; }
-
-		[ProtoMember(4)]
-		public long NewInstanceId { get; set; }
-
-	}
-
 	[Message(InnerMessage.G2M_SessionDisconnect)]
 	[ProtoContract]
 	public partial class G2M_SessionDisconnect: Object, IActorLocationMessage
@@ -352,13 +334,31 @@ namespace ET
 		public int RpcId { get; set; }
 
 		[ProtoMember(2)]
-		public byte[] Unit { get; set; }
+		public long OldInstanceId { get; set; }
 
 		[ProtoMember(3)]
+		public byte[] Unit { get; set; }
+
+		[ProtoMember(4)]
 		public List<byte[]> Entitys = new List<byte[]>();
 
 	}
 
+	[Message(InnerMessage.M2M_UnitTransferResponse)]
+	[ProtoContract]
+	public partial class M2M_UnitTransferResponse: Object, IActorResponse
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int Error { get; set; }
+
+		[ProtoMember(3)]
+		public string Message { get; set; }
+
+	}
+
 	public static class InnerMessage
 	{
 		 public const ushort ObjectQueryRequest = 20002;
@@ -380,9 +380,9 @@ namespace ET
 		 public const ushort ObjectGetResponse = 20018;
 		 public const ushort R2G_GetLoginKey = 20019;
 		 public const ushort G2R_GetLoginKey = 20020;
-		 public const ushort M2M_UnitTransferResponse = 20021;
-		 public const ushort G2M_SessionDisconnect = 20022;
-		 public const ushort ObjectQueryResponse = 20023;
-		 public const ushort M2M_UnitTransferRequest = 20024;
+		 public const ushort G2M_SessionDisconnect = 20021;
+		 public const ushort ObjectQueryResponse = 20022;
+		 public const ushort M2M_UnitTransferRequest = 20023;
+		 public const ushort M2M_UnitTransferResponse = 20024;
 	}
 }

+ 23 - 23
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/InnerMessage_S_20001.cs

@@ -298,24 +298,6 @@ namespace ET
 
 	}
 
-	[Message(InnerMessage.M2M_UnitTransferResponse)]
-	[ProtoContract]
-	public partial class M2M_UnitTransferResponse: Object, IActorResponse
-	{
-		[ProtoMember(1)]
-		public int RpcId { get; set; }
-
-		[ProtoMember(2)]
-		public int Error { get; set; }
-
-		[ProtoMember(3)]
-		public string Message { get; set; }
-
-		[ProtoMember(4)]
-		public long NewInstanceId { get; set; }
-
-	}
-
 	[Message(InnerMessage.G2M_SessionDisconnect)]
 	[ProtoContract]
 	public partial class G2M_SessionDisconnect: Object, IActorLocationMessage
@@ -352,13 +334,31 @@ namespace ET
 		public int RpcId { get; set; }
 
 		[ProtoMember(2)]
-		public byte[] Unit { get; set; }
+		public long OldInstanceId { get; set; }
 
 		[ProtoMember(3)]
+		public byte[] Unit { get; set; }
+
+		[ProtoMember(4)]
 		public List<byte[]> Entitys = new List<byte[]>();
 
 	}
 
+	[Message(InnerMessage.M2M_UnitTransferResponse)]
+	[ProtoContract]
+	public partial class M2M_UnitTransferResponse: Object, IActorResponse
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int Error { get; set; }
+
+		[ProtoMember(3)]
+		public string Message { get; set; }
+
+	}
+
 	public static class InnerMessage
 	{
 		 public const ushort ObjectQueryRequest = 20002;
@@ -380,9 +380,9 @@ namespace ET
 		 public const ushort ObjectGetResponse = 20018;
 		 public const ushort R2G_GetLoginKey = 20019;
 		 public const ushort G2R_GetLoginKey = 20020;
-		 public const ushort M2M_UnitTransferResponse = 20021;
-		 public const ushort G2M_SessionDisconnect = 20022;
-		 public const ushort ObjectQueryResponse = 20023;
-		 public const ushort M2M_UnitTransferRequest = 20024;
+		 public const ushort G2M_SessionDisconnect = 20021;
+		 public const ushort ObjectQueryResponse = 20022;
+		 public const ushort M2M_UnitTransferRequest = 20023;
+		 public const ushort M2M_UnitTransferResponse = 20024;
 	}
 }