Ejemplo n.º 1
0
        /// <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, 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);
        }
Ejemplo n.º 2
0
 public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isSynchronousVerifyMethod)
     : base(attribute, log, verify, isSynchronousVerifyMethod)
 {
     if (!attribute.IsServer)
     {
         Log.Add(AutoCSer.Log.LogType.Warn, "配置未指明的 TCP 服务端 " + ServerAttribute.ServerName);
     }
 }
Ejemplo n.º 3
0
 public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isSynchronousVerifyMethod)
     : base(attribute, log, verify, isSynchronousVerifyMethod)
 {
     if (!attribute.IsServer)
     {
         Log.Warn("配置未指明的 TCP 服务端 " + ServerAttribute.ServerName, LogLevel.Warn | LogLevel.AutoCSer);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// TCP 内部服务客户端
 /// </summary>
 /// <param name="attribute">TCP服务调用配置</param>
 /// <param name="log">日志接口</param>
 public Client(ServerAttribute attribute, ILog log)
     : base(attribute, log, int.MaxValue)
 {
     if (attribute.TcpRegisterName != null)
     {
         tcpRegisterClient = AutoCSer.Net.TcpRegister.Client.Get(attribute.TcpRegisterName, Log);
         tcpRegisterClient.Register(this);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 #region IF IsVerifyMethod
 /// <param name="verifyMethod">TCP 验证方法</param>
 #endregion IF IsVerifyMethod
 /// <param name="log">日志接口</param>
 public TcpInternalSimpleClient(AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute attribute = null /*IF:IsVerifyMethod*/, Func <TcpInternalSimpleClient, bool> verifyMethod = null /*IF:IsVerifyMethod*/, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         #region IF IsServerCode
         attribute = AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute.GetConfig("@ServerRegisterName", typeof(@Type.FullName));
         #endregion IF IsServerCode
         #region NOT IsServerCode
         attribute = AutoCSer.Config.Loader.Get <AutoCSer.Net.TcpInternalSimpleServer.ServerAttribute>("@ServerRegisterName") ?? _DefaultServerAttribute_;
         if (attribute.Name == null)
         {
             attribute.Name = "@ServerRegisterName";
         }
         #endregion NOT IsServerCode
     }
     _TcpClient_ = new AutoCSer.Net.TcpInternalSimpleServer.Client <TcpInternalSimpleClient>(this, attribute, log /*IF:IsVerifyMethod*/, verifyMethod /*IF:IsTimeVerify*/ ?? (Func <TcpInternalSimpleClient, bool>)_timerVerify_ /*IF:IsTimeVerify*//*IF:IsVerifyMethod*/);
     if (attribute.IsAuto)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// @ServerRegisterName TCP调用服务端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="verify">套接字验证委托</param>
 #region IF Type.Type.IsPublic
 /// <param name="value">TCP 服务目标对象</param>
 #endregion IF Type.Type.IsPublic
 /// <param name="log">日志接口</param>
 public TcpInternalSimpleServer(AutoCSer.Net.TcpInternalSimpleServer.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.TcpInternalSimpleServer.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();
     }
 }