public static Boolean login(Client c, String username, String password) { StringBuilder conString = new StringBuilder("SERVER="); conString.Append(MainClass.getProperty("DBHost")); conString.Append(";"); conString.Append("DATABASE="); conString.Append(MainClass.getProperty("DB")); conString.Append(";"); conString.Append("UID="); conString.Append(MainClass.getProperty("DBUser")); conString.Append(";"); conString.Append("PASSWORD="******"DBPass")); conString.Append(";"); MySqlConnection connection = new MySqlConnection(conString.ToString()); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader = null; command.CommandText = "SELECT * FROM users WHERE email='" + username + "' AND pass='******';"; try { connection.Open(); Reader = command.ExecuteReader(); while(Reader.Read() == true) { if (!Reader.IsDBNull(0)) { for (int i = 0; i < Reader.FieldCount; i++) { switch (Reader.GetName(i)) { case "uid": c.User.UID = Reader.GetInt32(i); break; case "username": c.User.Username = Reader.GetString(i); break; } } c.User.Email = username; Reader.Close(); connection.Close(); return true; } } Reader.Close(); connection.Close(); } catch (Exception e) { ConsoleEventLog.addEvent(new ConsoleEventError("Mysql error1." + e.Message, e), true); Reader.Close(); connection.Close(); } return false; //Failure }
private void SockConnect(IAsyncResult AsyncCall) { //Accept the connection. TcpListener listener = (TcpListener)AsyncCall.AsyncState; Client c = new Client(); c.GetAcceptedSocket(listener.EndAcceptTcpClient(AsyncCall)); ClientContainer.AddClient(c); Start(); }
private void run() { try { Sock.Start(); } catch (SocketException e) { ConsoleEventLog.addEvent(new ConsoleEventError("Socket error.", e), true); MainClass.Stop(); } Sock.Server.ReceiveTimeout = 500; Sock.Server.SendTimeout = 500; Sock.Server.Blocking = false; Sock.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000); while (!endIt) { Client c = new Client(); try { c.GetAcceptedSocket(Sock.AcceptTcpClient()); ClientContainer.AddClient(c); } catch (InvalidOperationException ioe) { } catch (SocketException se) { if (se.SocketErrorCode == SocketError.WouldBlock) { Thread.Sleep(1000); } } } }