/// <summary> /// Send a logging request to the server /// </summary> /// <param name="pUsername">Username of the user</param> /// <param name="pPassword">Password of the user</param> public async void SendLoggingRequest(string pPassword) { if (!IsConnected) { throw new InvalidOperationException("Can't send a logging request while not connected to a server"); } if (IsLoggedIn) { throw new InvalidOperationException("Can't send a logging resquest while already logged in"); } //Ask the server for a new salt m_salt = null; m_client.Send(new byte[] { (byte)CommandType.SaltRequest }); //Wait until we received the session salt from the server await Task.Run(() => { int timeWaiting = 0; while (m_salt == null && timeWaiting < 15000) { Thread.Sleep(25); timeWaiting += 25; } ; }); if (m_salt == null) { if (OnLoggingFeedback != null) { OnLoggingFeedback(this, new AuthenticationFeedbackArgs(AuthenticationResult.Error, m_client.InfoHandler)); } return; } SHA256Managed hashstring = new SHA256Managed(); byte[] password = new byte[pPassword.Length + m_salt.Length]; //= Encoding.UTF8.GetBytes(pPassword); Encoding.UTF8.GetBytes(pPassword).CopyTo(password, 0); Array.Copy(m_salt, 0, password, pPassword.Length, m_salt.Length); byte[] hashedPassword = hashstring.ComputeHash(password); byte[] command = new byte[hashedPassword.Length + 2]; command[0] = (byte)CommandType.Login; command[1] = (byte)hashedPassword.Length; hashedPassword.CopyTo(command, 2); m_client.Send(command); }
/// <summary> /// Send a command to the server /// </summary> /// <param name="pCommand">Command to send</param> public void SendCommand(Command pCommand) { if (!IsConnected) { throw new InvalidOperationException("Cannot send commands while not connected to a server"); } m_client.Send(pCommand.ToByteArray()); }
public void SendImage(Image image, Wallpaper.Style style) { ImageConverter imgCon = new ImageConverter(); byte[] imageArr = (byte[])imgCon.ConvertTo(image, typeof(byte[])); byte[] data = new byte[imageArr.Length + 1]; data[0] = (byte)style; Array.Copy(imageArr, 0, data, 1, imageArr.Length); m_client.Send(Command.PrefixCommand(CommandType.Wallpaper, data)); }
public void SendMessage() { byte[] data = Command.PrefixCommand(CommandType.Notification, "Hello World!"); m_client.Send(data); }
public void Send(byte[] buff) { handle.Send(buff); }