Переглянути джерело

调通ActorLocation发送消息

tanghai 2 роки тому
батько
коміт
f2e0d4f70a
20 змінених файлів з 66 додано та 51 видалено
  1. 1 3
      Unity/Assets/Config/Proto/LockStepInner_S_21001.proto
  2. 6 4
      Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto
  3. 2 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LockStepSceneChangeHelper.cs
  4. 6 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs
  5. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs
  6. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Gate/Match2G_NotifyMatchSuccessHandler.cs
  7. 2 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomComponentSystem.cs
  8. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomMessageHelper.cs
  9. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Match/G2Match_MatchHandler.cs
  10. 9 9
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs
  11. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorHandleHelper.cs
  12. 9 3
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs
  13. 2 5
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs
  14. 9 3
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs
  15. 2 5
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepInner_S_21001.cs
  16. 9 3
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs
  17. 0 1
      Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/SessionInfoComponent.cs
  18. 0 1
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs
  19. 1 1
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Match/MatchComponent.cs
  20. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/ActorLocation/LocationComponent.cs

+ 1 - 3
Unity/Assets/Config/Proto/LockStepInner_S_21001.proto

@@ -8,8 +8,6 @@ message G2Match_Match // IActorRequest
 	int32 RpcId = 1;
 	
 	int64 Id = 2;
-	
-	int64 InstanceId = 3;
 }
 
 message Match2G_Match // IActorResponse
@@ -23,7 +21,7 @@ message Match2G_Match // IActorResponse
 message Match2Map_GetRoom // IActorRequest
 {
 	int32 RpcId = 1;
-	map<int64, int64> PlayerInfo = 2;
+	repeated int64 PlayerIds = 2;
 }
 
 message Map2Match_GetRoom // IActorResponse

+ 6 - 4
Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto

@@ -15,10 +15,11 @@ message G2C_Match // IResponse
 }
 
 // 匹配成功,通知客户端切换场景
-message Match2G_NotifyMatchSuccess // IActorMessage
+message Match2G_NotifyMatchSuccess // IActorLocationMessage
 {
+	int32 RpcId = 1;
 	// 房间的instanceId
-	int64 InstanceId = 1;
+	int64 InstanceId = 2;
 }
 
 // 客户端通知房间切换场景完成
@@ -35,8 +36,9 @@ message LockStepUnitInfo
 }
 
 // 房间通知客户端进入战斗
-message Room2C_EnterMap // IActorMessage
+message Room2C_EnterMap // IActorLocationMessage
 {
-	repeated LockStepUnitInfo UnitInfo = 1;
+	int32 RpcId = 1;
+	repeated LockStepUnitInfo UnitInfo = 2;
 }
 

+ 2 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LockStepSceneChangeHelper.cs

@@ -11,6 +11,7 @@ namespace ET.Client
             CurrentScenesComponent currentScenesComponent = clientScene.GetComponent<CurrentScenesComponent>();
             currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
             Scene currentScene = SceneFactory.CreateCurrentScene(sceneInstanceId, clientScene.Zone, sceneName, currentScenesComponent);
+            UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
 
             // 等待表现层订阅的事件完成
             await EventSystem.Instance.PublishAsync(clientScene, new EventType.LockStepSceneChangeStart());
@@ -19,7 +20,7 @@ namespace ET.Client
             
             // 等待Room2C_EnterMap消息
             WaitType.Wait_Room2C_EnterMap waitRoom2CEnterMap = await clientScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_Room2C_EnterMap>();
-            UnitComponent unitComponent = currentScene.GetComponent<UnitComponent>();
+
             foreach (LockStepUnitInfo lockStepUnitInfo in waitRoom2CEnterMap.Message.UnitInfo)
             {
                 FUnit unit = unitComponent.AddChild<FUnit>();

+ 6 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs

@@ -21,8 +21,12 @@ namespace ET.Server
 
 			PlayerComponent playerComponent = scene.GetComponent<PlayerComponent>();
 			Player player = playerComponent.AddChild<Player, string>(account);
-			player.AddComponent<SessionInfoComponent>().Session = session;
-			player.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
+			PlayerSessionComponent playerSessionComponent = player.AddComponent<PlayerSessionComponent>();
+			playerSessionComponent.Session = session;
+			playerSessionComponent.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
+			await playerSessionComponent.AddLocation(LocationType.GateSession);
+			
+			player.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
 			await player.AddLocation(LocationType.Player);
 			
 			session.AddComponent<SessionPlayerComponent>().Player = player;

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs

@@ -10,7 +10,7 @@
 			StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Match;
 
 			await ActorMessageSenderComponent.Instance.Call(startSceneConfig.InstanceId,
-				new G2Match_Match() { InstanceId = player.InstanceId, Id = session.InstanceId });
+				new G2Match_Match() { Id = player.Id });
 		}
 	}
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Gate/Match2G_NotifyMatchSuccessHandler.cs

@@ -4,7 +4,7 @@
 namespace ET.Server
 {
 	[ActorMessageHandler(SceneType.Gate)]
-	public class Match2G_NotifyMatchSuccessHandler : AMActorHandler<Player, Match2G_NotifyMatchSuccess>
+	public class Match2G_NotifyMatchSuccessHandler : AMActorLocationHandler<Player, Match2G_NotifyMatchSuccess>
 	{
 		protected override async ETTask Run(Player player, Match2G_NotifyMatchSuccess message)
 		{

+ 2 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomComponentSystem.cs

@@ -10,10 +10,9 @@ namespace ET.Server
         {
             protected override void Awake(RoomComponent self, Match2Map_GetRoom match2MapGetRoom)
             {
-                foreach (var kv in match2MapGetRoom.PlayerInfo)
+                foreach (long id in match2MapGetRoom.PlayerIds)
                 {
-                    RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(kv.Key);
-                    roomPlayer.SessionInstanceId = kv.Value;
+                    RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(id);
                 }
             }
         }

+ 2 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomMessageHelper.cs

@@ -3,13 +3,13 @@ namespace ET.Server
 
     public static class RoomMessageHelper
     {
-        public static void BroadCast(Scene room, IActorMessage message)
+        public static void BroadCast(Scene room, IActorLocationMessage message)
         {
             RoomComponent roomComponent = room.GetComponent<RoomComponent>();
             foreach (var kv in roomComponent.Children)
             {
                 RoomPlayer roomPlayer = kv.Value as RoomPlayer;
-                ActorMessageSenderComponent.Instance.Send(roomPlayer.SessionInstanceId, message);
+                ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(roomPlayer.Id, message);
             }
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Match/G2Match_MatchHandler.cs

@@ -9,7 +9,7 @@ namespace ET.Server
 		protected override async ETTask Run(Scene scene, G2Match_Match request, Match2G_Match response)
 		{
 			MatchComponent matchComponent = scene.GetComponent<MatchComponent>();
-			matchComponent.Match((request.Id, request.InstanceId)).Coroutine();
+			matchComponent.Match(request.Id).Coroutine();
 			await ETTask.CompletedTask;
 		}
 	}

+ 9 - 9
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs

@@ -16,14 +16,14 @@ namespace ET.Server
             }
         }
 
-        public static async ETTask Match(this MatchComponent self, (long, long) playerInfo)
+        public static async ETTask Match(this MatchComponent self, long playerId)
         {
-            if (self.waitMatchPlayers.Contains(playerInfo))
+            if (self.waitMatchPlayers.Contains(playerId))
             {
                 return;
             }
             
-            self.waitMatchPlayers.Add(playerInfo);
+            self.waitMatchPlayers.Add(playerId);
 
             if (self.waitMatchPlayers.Count < ConstValue.MatchCount)
             {
@@ -32,19 +32,19 @@ namespace ET.Server
             
             // 申请一个房间
             StartSceneConfig startSceneConfig = RandomGenerator.RandomArray(StartSceneConfigCategory.Instance.Maps);
-            Match2Map_GetRoom match2MapGetRoom = new Match2Map_GetRoom() {PlayerInfo = new Dictionary<long, long>()};
-            foreach ((long id, long sessionInstanceId) in self.waitMatchPlayers)
+            Match2Map_GetRoom match2MapGetRoom = new Match2Map_GetRoom() {PlayerIds = new List<long>()};
+            foreach (long id in self.waitMatchPlayers)
             {
-                match2MapGetRoom.PlayerInfo.Add(id, sessionInstanceId);
+                match2MapGetRoom.PlayerIds.Add(id);
             }
             self.waitMatchPlayers.Clear();
             
             Map2Match_GetRoom map2MatchGetRoom = await ActorMessageSenderComponent.Instance.Call(
                 startSceneConfig.InstanceId, match2MapGetRoom) as Map2Match_GetRoom;
-            foreach (var kv in match2MapGetRoom.PlayerInfo) // 这里发送消息线程不会修改PlayerInfo,所以可以直接使用
+            foreach (long id in match2MapGetRoom.PlayerIds) // 这里发送消息线程不会修改PlayerInfo,所以可以直接使用
             {
-                ActorMessageSenderComponent.Instance.Send(
-                    kv.Value, new Match2G_NotifyMatchSuccess() {InstanceId = map2MatchGetRoom.InstanceId});
+                ActorLocationSenderComponent.Instance.Get(LocationType.Player).Send(
+                    id, new Match2G_NotifyMatchSuccess() {InstanceId = map2MatchGetRoom.InstanceId});
                 // 等待进入房间的确认消息,如果超时要通知所有玩家退出房间,重新匹配
             }
         }

+ 2 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorHandleHelper.cs

@@ -130,9 +130,9 @@ namespace ET.Server
                 }
                 case MailboxType.GateSession:
                 {
-                    if (entity is Player player)
+                    if (entity is PlayerSessionComponent playerSessionComponent)
                     {
-                        player.GetComponent<SessionInfoComponent>()?.Session?.Send(iActorMessage);
+                        playerSessionComponent.Session?.Send(iActorMessage);
                     }
                     break;
                 }

+ 9 - 3
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs

@@ -31,10 +31,13 @@ namespace ET
 // 匹配成功,通知客户端切换场景
 	[Message(LockStepOuter.Match2G_NotifyMatchSuccess)]
 	[ProtoContract]
-	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorMessage
+	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorLocationMessage
 	{
-// 房间的instanceId
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+// 房间的instanceId
+		[ProtoMember(2)]
 		public long InstanceId { get; set; }
 
 	}
@@ -67,9 +70,12 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
 	{
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 
 	}

+ 2 - 5
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs

@@ -15,9 +15,6 @@ namespace ET
 		[ProtoMember(2)]
 		public long Id { get; set; }
 
-		[ProtoMember(3)]
-		public long InstanceId { get; set; }
-
 	}
 
 	[Message(LockStepInner.Match2G_Match)]
@@ -43,9 +40,9 @@ namespace ET
 		[ProtoMember(1)]
 		public int RpcId { get; set; }
 
-		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(2)]
-		public Dictionary<long, long> PlayerInfo { get; set; }
+		public List<long> PlayerIds { get; set; }
+
 	}
 
 	[Message(LockStepInner.Map2Match_GetRoom)]

+ 9 - 3
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs

@@ -31,10 +31,13 @@ namespace ET
 // 匹配成功,通知客户端切换场景
 	[Message(LockStepOuter.Match2G_NotifyMatchSuccess)]
 	[ProtoContract]
-	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorMessage
+	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorLocationMessage
 	{
-// 房间的instanceId
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+// 房间的instanceId
+		[ProtoMember(2)]
 		public long InstanceId { get; set; }
 
 	}
@@ -67,9 +70,12 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
 	{
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 
 	}

+ 2 - 5
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepInner_S_21001.cs

@@ -15,9 +15,6 @@ namespace ET
 		[ProtoMember(2)]
 		public long Id { get; set; }
 
-		[ProtoMember(3)]
-		public long InstanceId { get; set; }
-
 	}
 
 	[Message(LockStepInner.Match2G_Match)]
@@ -43,9 +40,9 @@ namespace ET
 		[ProtoMember(1)]
 		public int RpcId { get; set; }
 
-		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(2)]
-		public Dictionary<long, long> PlayerInfo { get; set; }
+		public List<long> PlayerIds { get; set; }
+
 	}
 
 	[Message(LockStepInner.Map2Match_GetRoom)]

+ 9 - 3
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs

@@ -31,10 +31,13 @@ namespace ET
 // 匹配成功,通知客户端切换场景
 	[Message(LockStepOuter.Match2G_NotifyMatchSuccess)]
 	[ProtoContract]
-	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorMessage
+	public partial class Match2G_NotifyMatchSuccess: ProtoObject, IActorLocationMessage
 	{
-// 房间的instanceId
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+// 房间的instanceId
+		[ProtoMember(2)]
 		public long InstanceId { get; set; }
 
 	}
@@ -67,9 +70,12 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
 	{
 		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 
 	}

+ 0 - 1
Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/SessionInfoComponent.cs

@@ -1 +0,0 @@
-

+ 0 - 1
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs

@@ -4,7 +4,6 @@ namespace ET.Server
     [ChildOf(typeof (RoomComponent))]
     public class RoomPlayer: Entity, IAwake
     {
-        public long SessionInstanceId { get; set; }
         public bool IsJoinRoom { get; set; }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Match/MatchComponent.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class MatchComponent: Entity, IAwake
     {
-        public List<(long, long)> waitMatchPlayers = new List<(long, long)>();
+        public List<long> waitMatchPlayers = new List<long>();
     }
 
 }

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/ActorLocation/LocationComponent.cs

@@ -9,6 +9,7 @@ namespace ET.Server
         public const int Player = 1;
         public const int Friend = 2;
         public const int Chat = 3;
+        public const int GateSession = 4;
         public const int Max = 100;
     }