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 ConnectionCommand Connect() { ConnectionCommand = new ConnectionCommand(); State = ConnectionState.WaitForServerGreet; Tcp.Connect(IPEndPoint, (e, tcp) => { Socket = tcp; tcp.Read((buffer) => { buffers.Add(new ByteBuffer(buffer)); byte[] packet; byte packetNumber; switch (State) { case ConnectionState.ParsePackets: if (!HandleWorker()) { return; } if (ReadPacket(out packetNumber, out packet)) { Worker = ProcessRequest(packetNumber, packet).GetEnumerator(); Worker.MoveNext(); } break; default: if (ReadPacket(out packetNumber, out packet)) { ConnectionRead(packetNumber, packet); } break; } }); tcp.Resume(); }); return(ConnectionCommand); }
public ConnectionCommand Connect() { ConnectionCommand = new ConnectionCommand(); State = ConnectionState.WaitForServerGreet; Tcp.Connect(IPEndPoint, (e, tcp) => { Socket = tcp; tcp.Read((buffer) => { buffers.Add(new ByteBuffer(buffer)); byte[] packet; byte packetNumber; switch (State) { case ConnectionState.ParsePackets: if (!HandleWorker()) { return; } if (ReadPacket(out packetNumber, out packet)) { Worker = ProcessRequest(packetNumber, packet).GetEnumerator(); Worker.MoveNext(); } break; default: if (ReadPacket(out packetNumber, out packet)) { ConnectionRead(packetNumber, packet); } break; } }); tcp.Resume(); }); return ConnectionCommand; }