Exemplo n.º 1
0
        public bool SendCustomData(SubArray <byte> data)
        {
            if (data.Length > maxCustomDataSize)
            {
                throw new ArgumentOutOfRangeException("data.Length" + data.Length.toString() + " > maxCustomDataSize[" + maxCustomDataSize.toString() + "]");
            }
            ClientSocketSender sender = Sender;

            return(sender.CustomData(ref data));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="sender"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpOpenServer.Client client)
        {
            string verifyString = client.Attribute.VerifyString;

            if (verifyString == null)
            {
                long ticks = 0;
                return(verify(sender, null, 0, null, ref ticks).Value);
            }
            return(Verify(verify, sender, client, null, verifyString));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="sender"></param>
        /// <param name="client"></param>
        /// <param name="userID">用户ID</param>
        /// <param name="verifyString">验证字符串</param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpOpenServer.Client client, string userID, string verifyString)
        {
            TcpServer.ServerBaseAttribute attribute = client.Attribute;
            ulong markData = 0;

            if (attribute.IsMarkData)
            {
                markData = attribute.VerifyHashCode;
            }
            long ticks = AutoCSer.Net.TcpInternalServer.TimeVerifyClient.GetTicks();

            TcpServer.ClientSocketBase socket = sender.ClientSocket;
            bool isError = false;

            do
            {
                ulong randomPrefix = Random.Default.SecureNextULongNotZero();
                while (randomPrefix == markData)
                {
                    randomPrefix = Random.Default.SecureNextULongNotZero();
                }
                socket.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL;
                sender.SendMarkData    = 0;
                long lastTicks = ticks;
                TcpServer.ReturnValue <bool> isVerify = verify(sender, userID, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks);
                if (isVerify.Value)
                {
                    sender.SendMarkData = socket.ReceiveMarkData;
                    if (isError)
                    {
                        socket.Log.Debug(sender.ClientSocket.IpAddress.ToString() + ":" + sender.ClientSocket.Port.toString() + " TCP客户端验证时间重试成功");
                    }
                    return(true);
                }
                if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks)
                {
                    socket.Log.Error(sender.ClientSocket.IpAddress.ToString() + ":" + sender.ClientSocket.Port.toString() + " TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString());
                    return(false);
                }
                socket.Log.Error(sender.ClientSocket.IpAddress.ToString() + ":" + sender.ClientSocket.Port.toString() + " TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString());
                isError = true;
            }while (true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="sender"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpOpenServer.Client client)
        {
            long            ticks;
            ServerAttribute attribute    = client.Attribute;
            string          verifyString = attribute.VerifyString;

            if (verifyString == null)
            {
                ticks = 0;
                return(verify(sender, 0, null, ref ticks).Value);
            }
            ulong markData = 0;

            if (attribute.IsMarkData)
            {
                markData = attribute.VerifyHashCode;
            }
            ticks = Date.NowTime.SetUtc().Ticks;
            TcpServer.ClientSocketBase socket = sender.ClientSocket;
            do
            {
                ulong randomPrefix = Random.Default.SecureNextULongNotZero();
                while (randomPrefix == markData)
                {
                    randomPrefix = Random.Default.SecureNextULongNotZero();
                }
                socket.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL;
                sender.SendMarkData    = 0;
                long lastTicks = ticks;
                TcpServer.ReturnValue <bool> isVerify = verify(sender, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks);
                if (isVerify.Value)
                {
                    sender.SendMarkData = socket.ReceiveMarkData;
                    return(true);
                }
                if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks)
                {
                    socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString());
                    return(false);
                }
                socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString());
            }while (true);
        }
 /// <summary>
 /// 获取消息
 /// </summary>
 /// <returns>保持异步回调</returns>
 public AutoCSer.Net.TcpServer.KeepCallback getMessage(Action <AutoCSer.Net.TcpServer.ReturnValue <AutoCSer.TestCase.ChatData.Message> > _onReturn_)
 {
     AutoCSer.Net.Callback <AutoCSer.Net.TcpServer.ReturnValue <TcpOpenServer._p5> > _onOutput_ = _TcpClient_.GetCallback <AutoCSer.TestCase.ChatData.Message, TcpOpenServer._p5>(_onReturn_);
     try
     {
         AutoCSer.Net.TcpOpenServer.ClientSocketSender _socket_ = _TcpClient_.Sender;
         if (_socket_ != null)
         {
             return(_socket_.GetKeep <TcpOpenServer._p5>(_ac4, ref _onOutput_));
         }
     }
     finally
     {
         if (_onOutput_ != null)
         {
             AutoCSer.Net.TcpServer.ReturnValue <TcpOpenServer._p5> _outputParameter_ = new AutoCSer.Net.TcpServer.ReturnValue <TcpOpenServer._p5> {
                 Type = AutoCSer.Net.TcpServer.ReturnType.ClientException
             };
             _onOutput_.Call(ref _outputParameter_);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
 /// <summary>
 /// GC 垃圾回收
 /// </summary>
 public AutoCSer.Net.TcpServer.ReturnValue gcCollect()
 {
     AutoCSer.Net.TcpServer.AutoWaitReturnValue _wait_ = AutoCSer.Net.TcpServer.AutoWaitReturnValue.Pop();
     try
     {
         AutoCSer.Net.TcpOpenServer.ClientSocketSender _socket_ = _TcpClient_.Sender;
         if (_socket_ != null)
         {
             return(new AutoCSer.Net.TcpServer.ReturnValue {
                 Type = _socket_.WaitCall(_c7, ref _wait_)
             });
         }
     }
     finally
     {
         if (_wait_ != null)
         {
             AutoCSer.Net.TcpServer.AutoWaitReturnValue.PushNotNull(_wait_);
         }
     }
     return(new AutoCSer.Net.TcpServer.ReturnValue {
         Type = AutoCSer.Net.TcpServer.ReturnType.ClientException
     });
 }
            /// <summary>
            /// 客户端同步计算测试
            /// </summary>
            public AutoCSer.Net.TcpServer.ReturnValue <int> add(int left, int right)
            {
                AutoCSer.Net.TcpServer.AutoWaitReturnValue <TcpOpenServer._p2> _wait_ = AutoCSer.Net.TcpServer.AutoWaitReturnValue <TcpOpenServer._p2> .Pop();

                AutoCSer.Net.TcpOpenServer.ClientSocketSender _socket_ = null;
                try
                {
                    _socket_ = _TcpClient_.Sender;
                    if (_socket_ != null)
                    {
                        TcpOpenServer._p1 _inputParameter_ = new TcpOpenServer._p1
                        {
                            left = left,

                            right = right,
                        };
                        TcpOpenServer._p2 _outputParameter_ = new TcpOpenServer._p2
                        {
                        };
                        AutoCSer.Net.TcpServer.ReturnType _returnType_ = _socket_.WaitGet <TcpOpenServer._p1, TcpOpenServer._p2>(_c0, ref _wait_, ref _inputParameter_, ref _outputParameter_);
                        return(new AutoCSer.Net.TcpServer.ReturnValue <int> {
                            Type = _returnType_, Value = _outputParameter_.Return
                        });
                    }
                }
                finally
                {
                    if (_wait_ != null)
                    {
                        AutoCSer.Net.TcpServer.AutoWaitReturnValue <TcpOpenServer._p2> .PushNotNull(_wait_);
                    }
                }
                return(new AutoCSer.Net.TcpServer.ReturnValue <int> {
                    Type = _socket_ == null ? AutoCSer.Net.TcpServer.ReturnType.ClientSocketNull : AutoCSer.Net.TcpServer.ReturnType.ClientException
                });
            }