Browse Source

【优化】调整协议,增加玩家登录数据

johnclot69 1 năm trước cách đây
mục cha
commit
240d5fd8eb

+ 16 - 0
Config/Proto/CommonProto_CS_10001.proto

@@ -0,0 +1,16 @@
+syntax = "proto3";
+package ET;
+
+message Player
+{
+  int64 id = 1;
+  string name = 2;
+  int32 sex = 3;
+  int32 pro = 4;
+  int64 exp = 5;
+  int32 level = 6;
+  int32 vip = 7;
+  int32 hp = 8;
+  int32 mp = 9;
+  int64 fightPower = 10;
+}

+ 2 - 1
Config/Proto/OuterMessage_C_10001.proto → Config/Proto/OuterMessage_C_30001.proto

@@ -1,5 +1,6 @@
 syntax = "proto3";
 package ET;
+import 'Common.proto';
 
 message HttpGetRouterResponse
 {
@@ -187,7 +188,7 @@ message G2C_LoginGame // IResponse
 	int32 RpcId = 1;
 	int32 Error = 2;
 	string Message = 3;
-	int64 PlayerId = 4;
+	Player Player = 4;
 }
 
 message G2C_TestHotfixMessage // IMessage

+ 8 - 0
DotNet/App/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "DotNet.App": {
+      "commandName": "Project",
+      "commandLineArgs": "--AppType=Server"
+    }
+  }
+}

+ 31 - 0
DotNet/Hotfix/Helper/PlayerHelper.cs

@@ -0,0 +1,31 @@
+namespace ET.Server
+{
+    /// <summary>
+    /// 玩家工具类
+    /// </summary>
+    public static class PlayerHelper
+    {
+        /// <summary>
+        /// 玩家信息转proto
+        /// </summary>
+        /// <param name="player"></param>
+        /// <returns></returns>
+        public static ET.Player PlayerInfoToProto(Player player)
+        {
+            return new ET.Player()
+            {
+                id = player.Id,
+                name = player.Name,
+                sex = player.Sex,
+                pro = player.Pro,
+                exp = player.Exp,
+                level = player.Level,
+                vip = 0,
+                hp = 1000,
+                mp = 0,
+                fightPower = 5
+            };
+        }
+
+    }
+}

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

@@ -30,15 +30,14 @@ namespace ET.Server
 			// 移除session自动超时组件
 			session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
-			GamePlayerComponent playerComponent = scene.GetComponent<GamePlayerComponent>();
-			Player player = playerComponent.AddChild<Player, string>(account);
-			playerComponent.Add(player);
+			GamePlayerComponent gamePlayerComponent = scene.GetComponent<GamePlayerComponent>();
+			Player player = gamePlayerComponent.AddChild<Player, string>(account);
 			
 			// 添加session组件,用于绑定角色
 			session.AddComponent<SessionPlayerComponent>().PlayerId = player.Id;
 			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GameSession);
 
-			response.PlayerId = player.Id;
+			response.Player = PlayerHelper.PlayerInfoToProto(player);
 			reply();
 			await ETTask.CompletedTask;
 		}

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

@@ -11,6 +11,9 @@
                 Log.Info($"创建玩家实体...");
                 self.Account = a;
                 self.IsOnline = true;
+                self.LoginTime = TimeHelper.ServerNow();
+                // 添加本地玩家数据
+                self.DomainScene().GetComponent<GamePlayerComponent>().Add(self);
             }
         }
         
@@ -20,6 +23,8 @@
             protected override void Destroy(Player self)
             {
                 Log.Info($"销毁玩家实体...");
+                // 移除本地玩家数据
+                self.DomainScene().GetComponent<GamePlayerComponent>()?.Remove(self.Id);
             }
         }
     }

+ 10 - 1
DotNet/Hotfix/Scenes/Game/Session/SessionPlayerComponentSystem.cs

@@ -9,9 +9,18 @@ namespace ET.Server
 		{
 			protected override void Destroy(SessionPlayerComponent self)
 			{
+				Player player = self.GetMyPlayer();
+				if (player == null)
+				{
+					return;
+				}
+
+				Log.Info($"玩家断线了, playerId={self.PlayerId}, name={player.Name}");
+				
 				// 发送断线消息
 				ActorLocationSenderComponent.Instance?.Send(self.PlayerId, new G2M_SessionDisconnect());
-				self.DomainScene().GetComponent<GamePlayerComponent>()?.Remove(self.PlayerId);
+				// 销毁玩家实体
+				player.Dispose();
 			}
 		}
 

+ 46 - 0
DotNet/Model/Generate/Message/CommonProto_CS_10001.cs

@@ -0,0 +1,46 @@
+using ET;
+using ProtoBuf;
+using System.Collections.Generic;
+namespace ET
+{
+	[Message(CommonProto.Player)]
+	[ProtoContract]
+	public partial class Player: ProtoObject
+	{
+		[ProtoMember(1)]
+		public long id { get; set; }
+
+		[ProtoMember(2)]
+		public string name { get; set; }
+
+		[ProtoMember(3)]
+		public int sex { get; set; }
+
+		[ProtoMember(4)]
+		public int pro { get; set; }
+
+		[ProtoMember(5)]
+		public long exp { get; set; }
+
+		[ProtoMember(6)]
+		public int level { get; set; }
+
+		[ProtoMember(7)]
+		public int vip { get; set; }
+
+		[ProtoMember(8)]
+		public int hp { get; set; }
+
+		[ProtoMember(9)]
+		public int mp { get; set; }
+
+		[ProtoMember(10)]
+		public long fightPower { get; set; }
+
+	}
+
+	public static class CommonProto
+	{
+		 public const ushort Player = 10002;
+	}
+}

+ 35 - 35
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs → DotNet/Model/Generate/Message/OuterMessage_C_30001.cs

@@ -385,7 +385,7 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public long PlayerId { get; set; }
+		public Player Player { get; set; }
 
 	}
 
@@ -481,39 +481,39 @@ namespace ET
 
 	public static class OuterMessage
 	{
-		 public const ushort HttpGetRouterResponse = 10002;
-		 public const ushort RouterSync = 10003;
-		 public const ushort C2M_TestRequest = 10004;
-		 public const ushort M2C_TestResponse = 10005;
-		 public const ushort Actor_TransferRequest = 10006;
-		 public const ushort Actor_TransferResponse = 10007;
-		 public const ushort C2G_EnterMap = 10008;
-		 public const ushort G2C_EnterMap = 10009;
-		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGame = 10027;
-		 public const ushort G2C_LoginGame = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort HttpGetRouterResponse = 30002;
+		 public const ushort RouterSync = 30003;
+		 public const ushort C2M_TestRequest = 30004;
+		 public const ushort M2C_TestResponse = 30005;
+		 public const ushort Actor_TransferRequest = 30006;
+		 public const ushort Actor_TransferResponse = 30007;
+		 public const ushort C2G_EnterMap = 30008;
+		 public const ushort G2C_EnterMap = 30009;
+		 public const ushort MoveInfo = 30010;
+		 public const ushort UnitInfo = 30011;
+		 public const ushort M2C_CreateUnits = 30012;
+		 public const ushort M2C_CreateMyUnit = 30013;
+		 public const ushort M2C_StartSceneChange = 30014;
+		 public const ushort M2C_RemoveUnits = 30015;
+		 public const ushort C2M_PathfindingResult = 30016;
+		 public const ushort C2M_Stop = 30017;
+		 public const ushort M2C_PathfindingResult = 30018;
+		 public const ushort M2C_Stop = 30019;
+		 public const ushort C2G_Ping = 30020;
+		 public const ushort G2C_Ping = 30021;
+		 public const ushort G2C_Test = 30022;
+		 public const ushort C2M_Reload = 30023;
+		 public const ushort M2C_Reload = 30024;
+		 public const ushort C2R_Login = 30025;
+		 public const ushort R2C_Login = 30026;
+		 public const ushort C2G_LoginGame = 30027;
+		 public const ushort G2C_LoginGame = 30028;
+		 public const ushort G2C_TestHotfixMessage = 30029;
+		 public const ushort C2M_TestRobotCase = 30030;
+		 public const ushort M2C_TestRobotCase = 30031;
+		 public const ushort C2M_TransferMap = 30032;
+		 public const ushort M2C_TransferMap = 30033;
+		 public const ushort C2G_Benchmark = 30034;
+		 public const ushort G2C_Benchmark = 30035;
 	}
 }

+ 24 - 5
DotNet/Model/Scenes/Game/Player/Player.cs

@@ -6,13 +6,32 @@
         /** 账号 **/
         public string Account { get; set; }
 		
-        /** 单位id **/
-        public long UnitId { get; set; }
-        
+        /** 服务器id **/
+        public int LogicServerId { get; set; }
+        /** 创建时间 **/
+        public long CreateTime { get; set; }
+        /** 登陆时间 **/
+        public long LoginTime { get; set; }
+        /** 下线时间 **/
+        public long LogoutTime { get; set; }
         /** 在线状态 **/
         public bool IsOnline { get; set; }
         
-        /** 创建时间 **/
-        public long CreateTime { get; set; }
+        /** 单位id **/
+        public long UnitId { get; set; }
+        
+        /** 头像 **/
+        public string AvatarUrl { get; set; }
+        /** 名称 **/
+        public string Name { get; set; }
+        /** 性别 **/
+        public int Sex { get; set; }
+        /** 职业 **/
+        public int Pro { get; set; }
+
+        /** 经验 **/
+        public long Exp { get; set; }
+        /** 等级 **/
+        public int Level { get; set; }
     }
 }

+ 46 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/CommonProto_CS_10001.cs

@@ -0,0 +1,46 @@
+using ET;
+using ProtoBuf;
+using System.Collections.Generic;
+namespace ET
+{
+	[Message(CommonProto.Player)]
+	[ProtoContract]
+	public partial class Player: ProtoObject
+	{
+		[ProtoMember(1)]
+		public long id { get; set; }
+
+		[ProtoMember(2)]
+		public string name { get; set; }
+
+		[ProtoMember(3)]
+		public int sex { get; set; }
+
+		[ProtoMember(4)]
+		public int pro { get; set; }
+
+		[ProtoMember(5)]
+		public long exp { get; set; }
+
+		[ProtoMember(6)]
+		public int level { get; set; }
+
+		[ProtoMember(7)]
+		public int vip { get; set; }
+
+		[ProtoMember(8)]
+		public int hp { get; set; }
+
+		[ProtoMember(9)]
+		public int mp { get; set; }
+
+		[ProtoMember(10)]
+		public long fightPower { get; set; }
+
+	}
+
+	public static class CommonProto
+	{
+		 public const ushort Player = 10002;
+	}
+}

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 1fd4e02222d252743bc06510ed72cff3
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 35 - 35
DotNet/Model/Generate/Message/OuterMessage_C_10001.cs → Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_30001.cs

@@ -385,7 +385,7 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public long PlayerId { get; set; }
+		public Player Player { get; set; }
 
 	}
 
@@ -481,39 +481,39 @@ namespace ET
 
 	public static class OuterMessage
 	{
-		 public const ushort HttpGetRouterResponse = 10002;
-		 public const ushort RouterSync = 10003;
-		 public const ushort C2M_TestRequest = 10004;
-		 public const ushort M2C_TestResponse = 10005;
-		 public const ushort Actor_TransferRequest = 10006;
-		 public const ushort Actor_TransferResponse = 10007;
-		 public const ushort C2G_EnterMap = 10008;
-		 public const ushort G2C_EnterMap = 10009;
-		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGame = 10027;
-		 public const ushort G2C_LoginGame = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort HttpGetRouterResponse = 30002;
+		 public const ushort RouterSync = 30003;
+		 public const ushort C2M_TestRequest = 30004;
+		 public const ushort M2C_TestResponse = 30005;
+		 public const ushort Actor_TransferRequest = 30006;
+		 public const ushort Actor_TransferResponse = 30007;
+		 public const ushort C2G_EnterMap = 30008;
+		 public const ushort G2C_EnterMap = 30009;
+		 public const ushort MoveInfo = 30010;
+		 public const ushort UnitInfo = 30011;
+		 public const ushort M2C_CreateUnits = 30012;
+		 public const ushort M2C_CreateMyUnit = 30013;
+		 public const ushort M2C_StartSceneChange = 30014;
+		 public const ushort M2C_RemoveUnits = 30015;
+		 public const ushort C2M_PathfindingResult = 30016;
+		 public const ushort C2M_Stop = 30017;
+		 public const ushort M2C_PathfindingResult = 30018;
+		 public const ushort M2C_Stop = 30019;
+		 public const ushort C2G_Ping = 30020;
+		 public const ushort G2C_Ping = 30021;
+		 public const ushort G2C_Test = 30022;
+		 public const ushort C2M_Reload = 30023;
+		 public const ushort M2C_Reload = 30024;
+		 public const ushort C2R_Login = 30025;
+		 public const ushort R2C_Login = 30026;
+		 public const ushort C2G_LoginGame = 30027;
+		 public const ushort G2C_LoginGame = 30028;
+		 public const ushort G2C_TestHotfixMessage = 30029;
+		 public const ushort C2M_TestRobotCase = 30030;
+		 public const ushort M2C_TestRobotCase = 30031;
+		 public const ushort C2M_TransferMap = 30032;
+		 public const ushort M2C_TransferMap = 30033;
+		 public const ushort C2G_Benchmark = 30034;
+		 public const ushort G2C_Benchmark = 30035;
 	}
 }

+ 46 - 0
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/CommonProto_CS_10001.cs

@@ -0,0 +1,46 @@
+using ET;
+using ProtoBuf;
+using System.Collections.Generic;
+namespace ET
+{
+	[Message(CommonProto.Player)]
+	[ProtoContract]
+	public partial class Player: ProtoObject
+	{
+		[ProtoMember(1)]
+		public long id { get; set; }
+
+		[ProtoMember(2)]
+		public string name { get; set; }
+
+		[ProtoMember(3)]
+		public int sex { get; set; }
+
+		[ProtoMember(4)]
+		public int pro { get; set; }
+
+		[ProtoMember(5)]
+		public long exp { get; set; }
+
+		[ProtoMember(6)]
+		public int level { get; set; }
+
+		[ProtoMember(7)]
+		public int vip { get; set; }
+
+		[ProtoMember(8)]
+		public int hp { get; set; }
+
+		[ProtoMember(9)]
+		public int mp { get; set; }
+
+		[ProtoMember(10)]
+		public long fightPower { get; set; }
+
+	}
+
+	public static class CommonProto
+	{
+		 public const ushort Player = 10002;
+	}
+}

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 96ed2a04e6c607a41ac19dfd87a4eac2
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 0ebfc7019c9a70440a0b1da13853de46
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 35 - 35
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs → Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_30001.cs

@@ -385,7 +385,7 @@ namespace ET
 		public string Message { get; set; }
 
 		[ProtoMember(4)]
-		public long PlayerId { get; set; }
+		public Player Player { get; set; }
 
 	}
 
@@ -481,39 +481,39 @@ namespace ET
 
 	public static class OuterMessage
 	{
-		 public const ushort HttpGetRouterResponse = 10002;
-		 public const ushort RouterSync = 10003;
-		 public const ushort C2M_TestRequest = 10004;
-		 public const ushort M2C_TestResponse = 10005;
-		 public const ushort Actor_TransferRequest = 10006;
-		 public const ushort Actor_TransferResponse = 10007;
-		 public const ushort C2G_EnterMap = 10008;
-		 public const ushort G2C_EnterMap = 10009;
-		 public const ushort MoveInfo = 10010;
-		 public const ushort UnitInfo = 10011;
-		 public const ushort M2C_CreateUnits = 10012;
-		 public const ushort M2C_CreateMyUnit = 10013;
-		 public const ushort M2C_StartSceneChange = 10014;
-		 public const ushort M2C_RemoveUnits = 10015;
-		 public const ushort C2M_PathfindingResult = 10016;
-		 public const ushort C2M_Stop = 10017;
-		 public const ushort M2C_PathfindingResult = 10018;
-		 public const ushort M2C_Stop = 10019;
-		 public const ushort C2G_Ping = 10020;
-		 public const ushort G2C_Ping = 10021;
-		 public const ushort G2C_Test = 10022;
-		 public const ushort C2M_Reload = 10023;
-		 public const ushort M2C_Reload = 10024;
-		 public const ushort C2R_Login = 10025;
-		 public const ushort R2C_Login = 10026;
-		 public const ushort C2G_LoginGame = 10027;
-		 public const ushort G2C_LoginGame = 10028;
-		 public const ushort G2C_TestHotfixMessage = 10029;
-		 public const ushort C2M_TestRobotCase = 10030;
-		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort HttpGetRouterResponse = 30002;
+		 public const ushort RouterSync = 30003;
+		 public const ushort C2M_TestRequest = 30004;
+		 public const ushort M2C_TestResponse = 30005;
+		 public const ushort Actor_TransferRequest = 30006;
+		 public const ushort Actor_TransferResponse = 30007;
+		 public const ushort C2G_EnterMap = 30008;
+		 public const ushort G2C_EnterMap = 30009;
+		 public const ushort MoveInfo = 30010;
+		 public const ushort UnitInfo = 30011;
+		 public const ushort M2C_CreateUnits = 30012;
+		 public const ushort M2C_CreateMyUnit = 30013;
+		 public const ushort M2C_StartSceneChange = 30014;
+		 public const ushort M2C_RemoveUnits = 30015;
+		 public const ushort C2M_PathfindingResult = 30016;
+		 public const ushort C2M_Stop = 30017;
+		 public const ushort M2C_PathfindingResult = 30018;
+		 public const ushort M2C_Stop = 30019;
+		 public const ushort C2G_Ping = 30020;
+		 public const ushort G2C_Ping = 30021;
+		 public const ushort G2C_Test = 30022;
+		 public const ushort C2M_Reload = 30023;
+		 public const ushort M2C_Reload = 30024;
+		 public const ushort C2R_Login = 30025;
+		 public const ushort R2C_Login = 30026;
+		 public const ushort C2G_LoginGame = 30027;
+		 public const ushort G2C_LoginGame = 30028;
+		 public const ushort G2C_TestHotfixMessage = 30029;
+		 public const ushort C2M_TestRobotCase = 30030;
+		 public const ushort M2C_TestRobotCase = 30031;
+		 public const ushort C2M_TransferMap = 30032;
+		 public const ushort M2C_TransferMap = 30033;
+		 public const ushort C2G_Benchmark = 30034;
+		 public const ushort G2C_Benchmark = 30035;
 	}
 }