/// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="client"></param>
        /// <param name="userID">用户ID</param>
        /// <param name="verifyString">验证字符串</param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, AutoCSer.Net.TcpOpenSimpleServer.Client client, string userID, string verifyString)
        {
            long            ticks;
            ulong           markData  = 0;
            ServerAttribute attribute = client.Attribute;

            if (attribute.IsMarkData)
            {
                markData = attribute.VerifyHashCode;
            }
            ticks = Date.NowTime.SetUtc().Ticks;
            do
            {
                ulong randomPrefix = Random.Default.SecureNextULongNotZero();
                while (randomPrefix == markData)
                {
                    randomPrefix = Random.Default.SecureNextULongNotZero();
                }
                client.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL;
                client.SendMarkData    = 0;
                long lastTicks = ticks;
                TcpServer.ReturnValue <bool> isVerify = verify(userID, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks);
                if (isVerify.Value)
                {
                    client.SendMarkData = client.ReceiveMarkData;
                    return(true);
                }
                if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks)
                {
                    client.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString());
                    return(false);
                }
                client.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString());
            }while (true);
        }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 #region IF IsVerifyMethod
 /// <param name="verifyMethod">TCP验证方法</param>
 #endregion IF IsVerifyMethod
 /// <param name="log">日志接口</param>
 public TcpOpenSimpleClient(AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute attribute = null /*IF:IsVerifyMethod*/, Func <TcpOpenSimpleClient, bool> verifyMethod = null /*IF:IsVerifyMethod*/, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         #region IF IsServerCode
         attribute = AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute.GetConfig("@ServerRegisterName", typeof(@Type.FullName));
         #endregion IF IsServerCode
         #region NOT IsServerCode
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute>("@ServerRegisterName") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "@ServerRegisterName";
         }
         #endregion NOT IsServerCode
     }
     _TcpClient_ = new AutoCSer.Net.TcpOpenSimpleServer.Client <TcpOpenSimpleClient>(this, attribute, log /*IF:IsVerifyMethod*/, verifyMethod /*IF:IsTimeVerify*/ ?? (Func <TcpOpenSimpleClient, bool>)_timerVerify_ /*IF:IsTimeVerify*//*IF:IsVerifyMethod*/);
     if (attribute.IsAutoClient)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
 /// <summary>
 /// @ServerRegisterName TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 #region IF Type.Type.IsPublic
 /// <param name="value">TCP服务目标对象</param>
 #endregion IF Type.Type.IsPublic
 /// <param name="log">日志接口</param>
 public TcpOpenSimpleServer(AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null /*IF:Type.Type.IsPublic*/, @Type.FullName value = null /*IF:Type.Type.IsPublic*/, AutoCSer.Log.ILog log = null)
     : base(attribute ?? (attribute = AutoCSer.Net.TcpOpenSimpleServer.ServerAttribute.GetConfig("@ServerRegisterName", typeof(@Type.FullName))), verify, log, @IsCallQueue)
 {
     Value = /*IF:Type.Type.IsPublic*/ value ?? /*IF:Type.Type.IsPublic*/ new @Type.FullName();
     setCommandData(@MethodIndexs.Length);
     #region LOOP MethodIndexs
     #region NOT IsNullMethod
     #region IF IsVerifyMethod
     setVerifyCommand(@MethodIndex);
     #endregion IF IsVerifyMethod
     #region NOT IsVerifyMethod
     setCommand(@MethodIndex);
     #endregion NOT IsVerifyMethod
     #endregion NOT IsNullMethod
     #endregion LOOP MethodIndexs
     #region IF IsSetTcpServer
     Value.SetTcpServer(this);
     #endregion IF IsSetTcpServer
     if (attribute.IsAutoServer)
     {
         Start();
     }
 }
Exemple #4
0
 /// <summary>
 /// TCP 开放服务客户端
 /// </summary>
 /// <param name="attribute">TCP服务调用配置</param>
 /// <param name="log">日志接口</param>
 public Client(ServerAttribute attribute, ILog log)
     : base(attribute, log, attribute.GetMaxInputSize)
 {
 }
Exemple #5
0
 public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isSynchronousVerifyMethod)
     : base(attribute, log, verify, isSynchronousVerifyMethod)
 {
 }