private void ConnectionRead(byte packetNumber, byte[] packet) { packetReader.NewPacket(packet); switch (State) { case ConnectionState.WaitForServerGreet: var connPacket = MySqlConnectionPacket.Parse(packetReader); bool version = connPacket.ServerVersion.IsAtLeast(4, 1, 1); if (!version) { } var response = new ClientAuthResponse() { ClientFlags = 0xA685, MaxPacketSize = 256 * 256, CharsetNumber = connPacket.ServerLanguage, User = Username, }; packetBuilder.NewPacket(); Socket.Write(response.Serialize(packetBuilder)); State = ConnectionState.WaitForLoginResponse; break; case ConnectionState.WaitForLoginResponse: var res = ResponsePacket.Parse(packetReader); if (res is OkPacket) { ConnectionCommand.FireSuccess(res as OkPacket); State = ConnectionState.ParsePackets; FireFirstCommand(); } else if (res is Error) { ConnectionCommand.FireError(res as Error); } break; } }
public static MySqlConnectionPacket Parse(PacketReader packetReader) { MySqlConnectionPacket packet = new MySqlConnectionPacket(); packet.ProtocolVersion = packetReader.ReadByte(); packet.ServerVersion = DatabaseVersion.Parse(packetReader.ReadString(Encoding.ASCII)); packet.ThreadId = packetReader.ReadInt(); packet.ScrambleBuffer = packetReader.ReadBytes(sizeof(long)); packet.Filler = packetReader.ReadByte(); packet.ServerCapabilities = packetReader.ReadShort(); packet.ServerLanguage = packetReader.ReadByte(); packet.ServerStatus = packetReader.ReadShort(); packet.ServerCapabilitiesUpper = packetReader.ReadShort(); packet.ScrambleLength = packetReader.ReadByte(); packet.SecondFiller = packetReader.ReadBytes(10); packetReader.ReadByte(); packet.SecondScramble = packetReader.ReadBytes(packetReader.Length - packetReader.Position - 1); return packet; }
public static MySqlConnectionPacket Parse(PacketReader packetReader) { MySqlConnectionPacket packet = new MySqlConnectionPacket(); packet.ProtocolVersion = packetReader.ReadByte(); packet.ServerVersion = DatabaseVersion.Parse(packetReader.ReadString(Encoding.ASCII)); packet.ThreadId = packetReader.ReadInt(); packet.ScrambleBuffer = packetReader.ReadBytes(sizeof(long)); packet.Filler = packetReader.ReadByte(); packet.ServerCapabilities = packetReader.ReadShort(); packet.ServerLanguage = packetReader.ReadByte(); packet.ServerStatus = packetReader.ReadShort(); packet.ServerCapabilitiesUpper = packetReader.ReadShort(); packet.ScrambleLength = packetReader.ReadByte(); packet.SecondFiller = packetReader.ReadBytes(10); packetReader.ReadByte(); packet.SecondScramble = packetReader.ReadBytes(packetReader.Length - packetReader.Position - 1); return(packet); }