private void Negotiate(MySqlStream channel) { var body = channel.ReadPacket(); HandshakeInitializationPacket handshakePacket = new HandshakeInitializationPacket(); handshakePacket.FromBytes(body); ConnectionId = handshakePacket.ThreadId; _logger.LogInformation("Handshake initialization packet received, prepare the client authentication packet to send"); ClientAuthenticationPacket clientAuth = new ClientAuthenticationPacket(); clientAuth.CharsetNumber = CharsetNumber; clientAuth.UserName = UserName; clientAuth.Password = Password; clientAuth.DatabaseName = DefaultSchema; clientAuth.ScrumbleBuff = handshakePacket.EncryptionSeed; var clientAuthPkgBody = clientAuth.ToBytes(); channel.SendPacket(clientAuthPkgBody); _logger.LogInformation("Client Authentication Packet is sent out."); channel.ReadPacket(); }
public ResultSetPacket Query(string queryString) { _channel.SequenceByte = 0; QueryCommandPacket cmd = new QueryCommandPacket(); cmd.QueryString = queryString; _channel.SendPacket(cmd.ToBytes()); var result = _channel.ReadPacket(); ResultSetHeaderPacket rsHeader = new ResultSetHeaderPacket(); rsHeader.FromBytes(result); var fields = new List <FieldPacket>(); for (int i = 0; i < rsHeader.ColumnCount; i++) { var fp = new FieldPacket(); fp.FromBytes(_channel.ReadPacket()); fields.Add(fp); } ReadEofPacket(); var rowData = new List <RowDataPacket>(); while (true) { var body = _channel.ReadPacket(); if (body.Buffer[0] == 254) { break; } var rowDataPacket = new RowDataPacket(); rowDataPacket.FromBytes(body); rowData.Add(rowDataPacket); } var resultSet = new ResultSetPacket(); resultSet.FieldDescriptors.AddRange(fields); foreach (var r in rowData) { resultSet.FieldValues.AddRange(r.Columns); } resultSet.SourceAddress = Address; return(resultSet); }