ntminer 5 years ago
parent
commit
605f52d735

+ 4 - 0
src/NTMinerDataSchemas/User/WsUserName.cs

@@ -11,5 +11,9 @@ namespace NTMiner.User {
         public string ClientVersion { get; set; }
         public Guid ClientId { get; set; }
         public string UserId { get; set; }
+
+        public bool IsValid() {
+            return !string.IsNullOrEmpty(UserId) && ClientId != Guid.Empty && Version.TryParse(ClientVersion, out _);
+        }
     }
 }

+ 1 - 1
src/WsServer/Core/ISession.cs

@@ -15,7 +15,7 @@ namespace NTMiner.Core {
         /// 客户端进程的版本号
         /// </summary>
         /// <remarks>注意这里说的进程不是指的操作系统进程而是指运行中的开源矿工程序</remarks>
-        string ClientVersion { get; }
+        Version ClientVersion { get; }
         /// <summary>
         /// 会话的最新活动时间
         /// </summary>

+ 2 - 2
src/WsServer/Core/Impl/AbstractSession.cs

@@ -10,7 +10,7 @@ namespace NTMiner.Core.Impl {
         /// <param name="wsSessionID"></param>
         public AbstractSession(IUser user, WsUserName userName, string wsSessionID) {
             this.ClientId = userName.ClientId;
-            this.ClientVersion = userName.ClientVersion;
+            this.ClientVersion = Version.Parse(userName.ClientVersion);// 因为前面的流程已经过验证所以可以直接Parse
             this.LoginName = user.LoginName;
             this.ActiveOn = DateTime.Now;
             this.WsSessionId = wsSessionID;
@@ -18,7 +18,7 @@ namespace NTMiner.Core.Impl {
 
         public Guid ClientId { get; private set; }
 
-        public string ClientVersion { get; private set; }
+        public Version ClientVersion { get; private set; }
 
         public string LoginName { get; private set; }
 

+ 1 - 1
src/WsServer/WsRoot.cs

@@ -115,7 +115,7 @@ namespace NTMiner {
             }
             string json = Encoding.UTF8.GetString(Convert.FromBase64String(base64String));
             wsUserName = VirtualRoot.JsonSerializer.Deserialize<WsUserName>(json);
-            if (wsUserName == null) {
+            if (wsUserName == null || !wsUserName.IsValid()) {
                 return false;
             }
             userData = ReadOnlyUserSet.GetUser(UserId.Create(wsUserName.UserId));