Explorar el Código

登录协议增加渠道支持

johnclot69 hace 1 mes
padre
commit
caf8f1ab6a

+ 4 - 4
DotNet/Hotfix/Scenes/Game/GameSessionKeyComponentSystem.cs

@@ -3,25 +3,25 @@
     [FriendOf(typeof(GameSessionKeyComponent))]
     public static class GameSessionKeyComponentSystem
     {
-        public static void Add(this GameSessionKeyComponent self, long key, string account)
+        public static void Add(this GameSessionKeyComponent self, string key, string account)
         {
             self.sessionKey.Add(key, account);
             self.TimeoutRemoveKey(key).Coroutine();
         }
 
-        public static string Get(this GameSessionKeyComponent self, long key)
+        public static string Get(this GameSessionKeyComponent self, string key)
         {
             string account = null;
             self.sessionKey.TryGetValue(key, out account);
             return account;
         }
 
-        public static void Remove(this GameSessionKeyComponent self, long key)
+        public static void Remove(this GameSessionKeyComponent self, string key)
         {
             self.sessionKey.Remove(key);
         }
 
-        private static async ETTask TimeoutRemoveKey(this GameSessionKeyComponent self, long key)
+        private static async ETTask TimeoutRemoveKey(this GameSessionKeyComponent self, string key)
         {
             await TimerComponent.Instance.WaitAsync(20000);
             self.sessionKey.Remove(key);

+ 27 - 0
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -16,6 +16,14 @@ namespace ET.Server
 				session.Dispose();
 				return;
 			}
+
+			if (string.IsNullOrEmpty(request.Key))
+			{
+				response.Error = ErrorCore.ERR_ConnectGateKeyError;
+				response.Message = "Game key验证失败!";
+				reply();
+				return;
+			}
 			
 			Scene scene = session.DomainScene();
 			string account = scene.GetComponent<GameSessionKeyComponent>().Get(request.Key);
@@ -26,11 +34,30 @@ namespace ET.Server
 				reply();
 				return;
 			}
+
+			string[] str = request.Key.Split(",");
+			if (str.Length != 2)
+			{
+				response.Error = ErrorCore.ERR_ConnectGateKeyError;
+				response.Message = "Game key验证失败!";
+				reply();
+				return;
+			}
+			
+			int channel = int.Parse(str[1]);
+			if (channel <= 0)
+			{
+				response.Error = ErrorCore.ERR_ConnectGateKeyError;
+				response.Message = "Game key验证失败,渠道号错误";
+				reply();
+				return;
+			}
 			
 			// 移除session自动超时组件
 			session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
 			Player player = scene.GetComponent<GamePlayerComponent>().AddChild<Player, Session>(session);
+			player.Channel = channel;
 			player.Name = "玩家" + player.Id;
 			player.Diamond = 1000;
 			

+ 2 - 2
DotNet/Hotfix/Scenes/Game/Handler/R2G_GetLoginKeyHandler.cs

@@ -11,8 +11,8 @@ namespace ET.Server
 		protected override async ETTask Run(Scene scene, R2G_GetLoginKey request, G2R_GetLoginKey response, Action reply)
 		{
 			long key = RandomGenerator.RandInt64();
-			scene.GetComponent<GameSessionKeyComponent>().Add(key, request.Account);
-			response.Key = key;
+			scene.GetComponent<GameSessionKeyComponent>().Add(key.ToString(), request.Account);
+			response.Key = key + "," + request.Channel;
 			response.GameId = scene.Id;
 			reply();
 			await ETTask.CompletedTask;

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

@@ -34,7 +34,7 @@ namespace ET.Server
 			
 			// 向game请求一个key,客户端可以拿着这个key连接game
 			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await MessageHelper.CallActor(
-				config.InstanceId, new R2G_GetLoginKey() {Account = request.Account});
+				config.InstanceId, new R2G_GetLoginKey() {Account = request.Account, Channel = request.Channel});
 
 			response.Address = config.OuterIPPort.ToString();
 			response.Key = g2RGetLoginKey.Key;

+ 1 - 1
DotNet/Model/Scenes/Game/GameSessionKeyComponent.cs

@@ -5,6 +5,6 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class GameSessionKeyComponent : Entity, IAwake
     {
-        public readonly Dictionary<long, string> sessionKey = new Dictionary<long, string>();
+        public readonly Dictionary<string, string> sessionKey = new ();
     }
 }

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

@@ -9,6 +9,8 @@ namespace ET.Server
         public long GameSessionActorId { get; set; }
         /** 玩家session **/
         public Session Session { get; set; }
+        /** 渠道 10000:测试渠道全渠道 10001:黄冈 10002:鄂州 **/
+        public int Channel { get; set; }
         /** 账号 **/
         public string Account { get; set; }
         /** 服务器id **/