Просмотр исходного кода

【优化】规划调整游戏服目录结构

johnclot69 1 год назад
Родитель
Сommit
5fb450e82c

+ 1 - 1
DotNet/Hotfix/Helper/SceneFactory.cs

@@ -31,7 +31,7 @@ namespace ET.Server
                     break;
                 case SceneType.Game:
                     scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
-                    scene.AddComponent<PlayerComponent>();
+                    scene.AddComponent<GamePlayerComponent>();
                     scene.AddComponent<GameSessionKeyComponent>();
                     break;
                 case SceneType.Map:

+ 1 - 1
DotNet/Hotfix/Module/Session/NetInnerComponentOnReadEvent.cs

@@ -118,7 +118,7 @@ namespace ET.Server
                                 await ActorMessageDispatcherComponent.Instance.Handle(entity, iActorMessage, null);
                                 break;
                             }
-                            case MailboxType.GateSession:
+                            case MailboxType.GameSession:
                             {
                                 if (entity is Session gateSession)
                                 {

+ 29 - 0
DotNet/Hotfix/Scenes/Game/GamePlayerComponentSystem.cs

@@ -0,0 +1,29 @@
+using System.Linq;
+
+namespace ET.Server
+{
+    [FriendOf(typeof(GamePlayerComponent))]
+    public static class GamePlayerComponentSystem
+    {
+        public static void Add(this GamePlayerComponent self, Player player)
+        {
+            self.idPlayers.Add(player.Id, player);
+        }
+
+        public static Player Get(this GamePlayerComponent self, long id)
+        {
+            self.idPlayers.TryGetValue(id, out Player gamer);
+            return gamer;
+        }
+
+        public static void Remove(this GamePlayerComponent self, long id)
+        {
+            self.idPlayers.Remove(id);
+        }
+
+        public static Player[] GetAll(this GamePlayerComponent self)
+        {
+            return self.idPlayers.Values.ToArray();
+        }
+    }
+}

+ 4 - 10
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -17,14 +17,6 @@ namespace ET.Server
 				return;
 			}
 			
-			// 重复请求
-			if (session.GetComponent<SessionLockComponent>() != null)
-			{
-				response.Error = ErrorCode.ERR_RequestRepeatedly;
-				reply();
-				return;
-			}
-			
 			Scene scene = session.DomainScene();
 			string account = scene.GetComponent<GameSessionKeyComponent>().Get(request.Key);
 			if (account == null)
@@ -38,11 +30,13 @@ namespace ET.Server
 			// 移除session自动超时组件
 			session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
-			PlayerComponent playerComponent = scene.GetComponent<PlayerComponent>();
+			GamePlayerComponent playerComponent = scene.GetComponent<GamePlayerComponent>();
 			Player player = playerComponent.AddChild<Player, string>(account);
 			playerComponent.Add(player);
+			
+			// 添加session组件,用于绑定角色
 			session.AddComponent<SessionPlayerComponent>().PlayerId = player.Id;
-			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
+			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GameSession);
 
 			response.PlayerId = player.Id;
 			reply();

+ 11 - 0
DotNet/Hotfix/Scenes/Game/PlayerSystem.cs → DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -8,7 +8,18 @@
         {
             protected override void Awake(Player self, string a)
             {
+                Log.Info($"创建玩家实体...");
                 self.Account = a;
+                self.IsOnline = true;
+            }
+        }
+        
+        [ObjectSystem]
+        public class PlayerDestroySystem : DestroySystem<Player>
+        {
+            protected override void Destroy(Player self)
+            {
+                Log.Info($"销毁玩家实体...");
             }
         }
     }

+ 0 - 29
DotNet/Hotfix/Scenes/Game/PlayerComponentSystem.cs

@@ -1,29 +0,0 @@
-using System.Linq;
-
-namespace ET.Server
-{
-    [FriendOf(typeof(PlayerComponent))]
-    public static class PlayerComponentSystem
-    {
-        public static void Add(this PlayerComponent self, Player player)
-        {
-            self.idPlayers.Add(player.Id, player);
-        }
-
-        public static Player Get(this PlayerComponent self, long id)
-        {
-            self.idPlayers.TryGetValue(id, out Player gamer);
-            return gamer;
-        }
-
-        public static void Remove(this PlayerComponent self, long id)
-        {
-            self.idPlayers.Remove(id);
-        }
-
-        public static Player[] GetAll(this PlayerComponent self)
-        {
-            return self.idPlayers.Values.ToArray();
-        }
-    }
-}

+ 8 - 2
DotNet/Hotfix/Scenes/Game/SessionPlayerComponentSystem.cs → DotNet/Hotfix/Scenes/Game/Session/SessionPlayerComponentSystem.cs

@@ -2,6 +2,7 @@
 
 namespace ET.Server
 {
+	[FriendOf(typeof (SessionPlayerComponent))]
 	public static class SessionPlayerComponentSystem
 	{
 		public class SessionPlayerComponentDestroySystem: DestroySystem<SessionPlayerComponent>
@@ -10,13 +11,18 @@ namespace ET.Server
 			{
 				// 发送断线消息
 				ActorLocationSenderComponent.Instance?.Send(self.PlayerId, new G2M_SessionDisconnect());
-				self.DomainScene().GetComponent<PlayerComponent>()?.Remove(self.PlayerId);
+				self.DomainScene().GetComponent<GamePlayerComponent>()?.Remove(self.PlayerId);
 			}
 		}
 
+		/// <summary>
+		/// 获取玩家实体
+		/// </summary>
+		/// <param name="self"></param>
+		/// <returns></returns>
 		public static Player GetMyPlayer(this SessionPlayerComponent self)
 		{
-			return self.DomainScene().GetComponent<PlayerComponent>().Get(self.PlayerId);
+			return self.DomainScene().GetComponent<GamePlayerComponent>().Get(self.PlayerId);
 		}
 	}
 }

+ 1 - 1
DotNet/Model/Module/Actor/MailboxType.cs

@@ -4,6 +4,6 @@
     {
         MessageDispatcher,
         UnOrderMessageDispatcher,
-        GateSession,
+        GameSession,
     }
 }

+ 5 - 1
DotNet/Model/Scenes/Game/PlayerComponent.cs → DotNet/Model/Scenes/Game/GamePlayerComponent.cs

@@ -3,9 +3,13 @@ using System.Linq;
 
 namespace ET.Server
 {
+	/// <summary>
+	/// 在线玩家管理组件
+	/// </summary>
 	[ComponentOf(typeof(Scene))]
-	public class PlayerComponent : Entity, IAwake, IDestroy
+	public class GamePlayerComponent : Entity, IAwake, IDestroy
 	{
+		/** 在线玩家集合 **/
 		public readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
 	}
 }

+ 2 - 2
DotNet/Model/Scenes/Game/Player.cs → DotNet/Model/Scenes/Game/Player/Player.cs

@@ -1,7 +1,7 @@
 namespace ET.Server
 {
-    [ChildOf(typeof(PlayerComponent))]
-    public sealed class Player : Entity, IAwake<string>
+    [ChildOf(typeof(GamePlayerComponent))]
+    public sealed class Player : Entity, IAwake<string>, IDestroy
     {
         /** 账号 **/
         public string Account { get; set; }

+ 0 - 0
DotNet/Model/Scenes/Game/SessionInfoComponent.cs → DotNet/Model/Scenes/Game/Session/SessionInfoComponent.cs


+ 0 - 0
DotNet/Model/Scenes/Game/SessionLockComponent.cs → DotNet/Model/Scenes/Game/Session/SessionLockComponent.cs


+ 1 - 0
DotNet/Model/Scenes/Game/SessionPlayerComponent.cs → DotNet/Model/Scenes/Game/Session/SessionPlayerComponent.cs

@@ -3,6 +3,7 @@
 	[ComponentOf(typeof(Session))]
 	public class SessionPlayerComponent : Entity, IAwake, IDestroy
 	{
+		/** 角色id **/
 		public long PlayerId { get; set; }
 	}
 }