Exemple #1
0
        public static void Initialize(TestContext context)
        {
            var info = new ServerInfo
            {
                Address        = IPAddress.Any,
                Port           = Port,
                MaxConnections = 2,
                VersionString  = Version
            };
            var daemon = new ServerDaemon();

            Assert.IsTrue(daemon.Start(info));
            Assert.IsTrue(daemon.IsRunning);

            _client = new TcpClient("localhost", Port);

            Assert.IsTrue(_client.Connected);

            _stream = _client.GetStream();
            var rec   = new byte[5000];
            var i     = _stream.Read(rec, 0, rec.Length);
            var hello =
                "2a0000000A43727970746f53716c0000000000111111111111111100000008020000000000000000000000000000"
                .ToByteArray();

            CollectionAssert.AreEqual(hello, rec.Take(i).ToArray());
            var login = "******".ToByteArray();

            _stream.Write(login, 0, login.Length);
            i = _stream.Read(rec, 0, rec.Length);
            var ok = new OKPacket(number: 2).ToByteArray();

            CollectionAssert.AreEqual(ok, rec.Take(i).ToArray());
        }
Exemple #2
0
        public OKPacket Update(string updateString)
        {
            _channel.SequenceByte = 0;

            var cmd = new QueryCommandPacket();

            cmd.QueryString = updateString;
            _channel.SendPacket(cmd.ToBytes());

            _logger.LogDebug("Read update result.");

            var result = _channel.ReadPacket();

            var okPacket = new OKPacket();

            okPacket.FromBytes(result);

            return(okPacket);
        }
        public static ResultPacket GetResultPacket(PacketData packetData)
        {
            ResultPacket resultPacket = null;

            if (packetData.Data[4] == 0xfe && packetData.BodyLength <= 9)
            {
                resultPacket = new EOFPacket();
            }
            else if (packetData.Data[4] == 0x00)
            {
                resultPacket = new OKPacket();
            }
            else if (packetData.Data[4] == 0xff)
            {
                resultPacket = new ErrorPacket();
            }

            if (resultPacket != null)
            {
                resultPacket.Read(packetData.Data);
            }
            return(resultPacket);
        }
Exemple #4
0
        private void ReceiveHandShake()
        {
            var request = new HandshakeResponse41Packet();

            ReceivePacket(request);
            MySqlPacket response = null;

            if (VerifyChallenge(request.UserName, request.AuthResponse))
            {
                response = new OKPacket()
                {
                    AffectedRows = 0,
                    LastInsertId = 0,
                    Status       = StatusFlags.SERVER_STATUS_AUTOCOMMIT,
                    Capabilities = CapabilityFlags.CLIENT_PROTOCOL_41,
                    Info         = string.Empty
                };
            }
            else
            {
            }

            SendPacket(response);
        }